Skip to content

Commit 2b1c315

Browse files
committed
add optional phase diagram mask
1 parent bd694e1 commit 2b1c315

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

contrib/perplex/create_phase_diagram.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import shutil
3-
3+
import numpy as np
44
import burnman
55
from perplex_utils import databases, make_build_file
66
from perplex_utils import run_vertex, run_pssect
@@ -71,25 +71,11 @@ def run_perplex(
7171
"molar",
7272
),
7373
"harzburgite": burnman.Composition(
74-
{
75-
"SiO2": 36.07,
76-
"MgO": 56.51,
77-
"FeO": 6.07,
78-
"CaO": 0.81,
79-
"Al2O3": 0.53,
80-
"Na2O": 0.001,
81-
},
74+
{"SiO2": 36.07, "MgO": 56.51, "FeO": 6.07, "CaO": 0.81, "Al2O3": 0.53},
8275
"molar",
8376
),
8477
"modified_harzburgite": burnman.Composition(
85-
{
86-
"SiO2": 36.04,
87-
"MgO": 56.54,
88-
"FeO": 5.97,
89-
"CaO": 0.79,
90-
"Al2O3": 0.65,
91-
"Na2O": 0.001,
92-
},
78+
{"SiO2": 36.04, "MgO": 56.54, "FeO": 5.97, "CaO": 0.79, "Al2O3": 0.65},
9379
"molar",
9480
),
9581
}
@@ -100,15 +86,15 @@ def run_perplex(
10086
project_name = "basalt"
10187
database = databases["stx21"]
10288
composition = compositions[project_name]
103-
pressure_range_total = [1.0e5, 140.0e9]
104-
temperature_range_total = [200.0, 3000.0]
89+
pressure_range_total = [1.0, 140.0e9]
90+
temperature_range_total = [200.0, 4000.0]
10591

10692
# Split pressure and temperature so that PerpleX
10793
# no temperature splits seems to make diagram with
10894
# less prominent discontinuities
109-
n_pressures_per_split = 121
110-
n_temperatures_per_split = 601
111-
n_splits_pressure = 14
95+
n_pressures_per_split = 101
96+
n_temperatures_per_split = 761
97+
n_splits_pressure = 28
11298
n_splits_temperature = 1
11399

114100
# If this script has already been run, and you just want to
@@ -258,6 +244,10 @@ def run_perplex(
258244

259245
modes_filenames.append(split_project_name + "_modes.dat")
260246

247+
mask_polygon = np.array(
248+
[[0.0, 2150.0], [10.0e9, 4000.0001], [0.0, 4000.001], [0.0, 2150.0]]
249+
)
250+
261251
fig = plt.figure(figsize=(12, 8))
262252
ax = fig.add_subplot(1, 1, 1)
263253

@@ -273,6 +263,7 @@ def run_perplex(
273263
label_scaling=3.0,
274264
label_clearance=0.01,
275265
number_small_fields=True,
266+
mask_polygon=mask_polygon,
276267
)
277268

278269
with open(f"{project_name}_field_ids.txt", "w") as f:

contrib/perplex/perplex_utils.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,11 @@ def _smooth_polygon_edges_between_intersections(
809809

810810

811811
def get_fields_assemblages_and_bounds(
812-
filename, phase_name_replacements, smoothing_window, smoothing_order
812+
filename,
813+
phase_name_replacements,
814+
smoothing_window,
815+
smoothing_order,
816+
mask_polygon=None,
813817
):
814818
"""
815819
Extract phase assemblage fields and plot bounds from a mode tab file.
@@ -823,6 +827,8 @@ def get_fields_assemblages_and_bounds(
823827
:type smoothing_window: int
824828
:param smoothing_order: Polynomial order for smoothing polygon edges.
825829
:type smoothing_order: int
830+
:param mask_polygon: 2D array of points defining a polygon to mask out.
831+
:type mask_polygon: 2D numpy array
826832
:return: Tuple containing list of polygon data dicts and bounds
827833
[[P_min, P_max], [T_min, T_max]].
828834
:rtype: (list[dict], list[list[float]])
@@ -832,8 +838,17 @@ def get_fields_assemblages_and_bounds(
832838
P, T = data[:2]
833839
pressures = P[:, 0]
834840
temperatures = T[0]
835-
836841
phase_modes = data[2:]
842+
843+
if mask_polygon is not None:
844+
poly = Polygon(mask_polygon)
845+
points = np.vstack((P.ravel(), T.ravel())).T
846+
mask = np.array(
847+
[poly.contains(Point(pt)) or poly.touches(Point(pt)) for pt in points]
848+
)
849+
mask = mask.reshape(P.shape)
850+
phase_modes[:, mask] = 0.0
851+
837852
num_phases = phase_modes.shape[0]
838853
phase_names = [phase_name_replacements.get(name, name) for name in column_names[2:]]
839854

@@ -1067,6 +1082,7 @@ def pretty_plot_phase_diagram(
10671082
label_scaling=3.0,
10681083
label_clearance=0.01,
10691084
number_small_fields=True,
1085+
mask_polygon=None,
10701086
):
10711087
"""
10721088
Plot the Perple_X calculated phase diagram on a matplotlib axis.
@@ -1097,19 +1113,25 @@ def pretty_plot_phase_diagram(
10971113
:param number_small_fields: Replace assemblage labels with numbers if
10981114
there is not enough clearance around the label.
10991115
:type number_small_fields: bool
1116+
:param mask_polygon: 2D array of points defining a polygon to mask out.
1117+
:type mask_polygon: 2D numpy array
11001118
:return: List of assemblages corresponding to numbered small fields.
11011119
:rtype: [str]
11021120
"""
11031121

11041122
polygon_data = []
11051123
bounds = []
11061124

1125+
mask_bar = mask_polygon.copy()
1126+
mask_bar[:, 0] = mask_bar[:, 0] / 1.0e5
1127+
11071128
for werami_mode_tab_filename in werami_mode_tab_filenames:
11081129
polygon_data_i, bounds_i = get_fields_assemblages_and_bounds(
11091130
werami_mode_tab_filename,
11101131
phase_name_replacements,
11111132
smoothing_window,
11121133
smoothing_order,
1134+
mask_bar,
11131135
)
11141136
polygon_data.extend(polygon_data_i)
11151137
bounds.append(bounds_i)

0 commit comments

Comments
 (0)