@@ -809,7 +809,11 @@ def _smooth_polygon_edges_between_intersections(
809809
810810
811811def 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