@@ -52,10 +52,7 @@ def california_relm_collection_region(dh_scale=1, magnitudes=None, name="relm-ca
5252
5353 # turn points into polygons and make region object
5454 bboxes = compute_vertices (origins , dh )
55- relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
56-
57- if magnitudes is not None :
58- relm_region .magnitudes = magnitudes
55+ relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , magnitudes = magnitudes , name = name )
5956
6057 return relm_region
6158
@@ -97,10 +94,8 @@ def california_relm_region(dh_scale=1, magnitudes=None, name="relm-california",
9794
9895 # turn points into polygons and make region object
9996 bboxes = compute_vertices (origins , dh )
100- relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
101-
102- if magnitudes is not None :
103- relm_region .magnitudes = magnitudes
97+ relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh ,magnitudes = magnitudes ,
98+ name = name )
10499
105100 return relm_region
106101
@@ -145,10 +140,8 @@ def italy_csep_region(dh_scale=1, magnitudes=None, name="csep-italy", use_midpoi
145140
146141 # turn points into polygons and make region object
147142 bboxes = compute_vertices (origins , dh )
148- italy_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
149-
150- if magnitudes is not None :
151- italy_region .magnitudes = magnitudes
143+ italy_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh ,
144+ magnitudes = magnitudes , name = name )
152145
153146 return italy_region
154147
@@ -187,10 +180,8 @@ def italy_csep_collection_region(dh_scale=1, magnitudes=None, name="csep-italy-c
187180
188181 # turn points into polygons and make region object
189182 bboxes = compute_vertices (origins , dh )
190- relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
191-
192- if magnitudes is not None :
193- relm_region .magnitudes = magnitudes
183+ relm_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , magnitudes = magnitudes ,
184+ name = name )
194185
195186 return relm_region
196187
@@ -229,10 +220,8 @@ def nz_csep_region(dh_scale=1, magnitudes=None, name="csep-nz", use_midpoint=Tru
229220
230221 # turn points into polygons and make region object
231222 bboxes = compute_vertices (origins , dh )
232- nz_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
233-
234- if magnitudes is not None :
235- nz_region .magnitudes = magnitudes
223+ nz_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , magnitudes = magnitudes ,
224+ name = name )
236225
237226 return nz_region
238227
@@ -271,10 +260,8 @@ def nz_csep_collection_region(dh_scale=1, magnitudes=None, name="csep-nz-collect
271260
272261 # turn points into polygons and make region object
273262 bboxes = compute_vertices (origins , dh )
274- nz_collection_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh , name = name )
275-
276- if magnitudes is not None :
277- nz_collection_region .magnitudes = magnitudes
263+ nz_collection_region = CartesianGrid2D ([Polygon (bbox ) for bbox in bboxes ], dh ,
264+ magnitudes = magnitudes , name = name )
278265
279266 return nz_collection_region
280267
@@ -294,9 +281,9 @@ def global_region(dh=0.1, name="global", magnitudes=None):
294281 lons = cleaner_range (- 180.0 , 179.9 , dh )
295282 lats = cleaner_range (- 90 , 89.9 , dh )
296283 coords = itertools .product (lons ,lats )
297- region = CartesianGrid2D ([Polygon (bbox ) for bbox in compute_vertices (coords , dh )], dh , name = name )
298- if magnitudes is not None :
299- region . magnitudes = magnitudes
284+ region = CartesianGrid2D ([Polygon (bbox ) for bbox in compute_vertices (coords , dh )], dh ,
285+ magnitudes = magnitudes , name = name )
286+
300287 return region
301288
302289def magnitude_bins (start_magnitude , end_magnitude , dmw ):
@@ -590,7 +577,7 @@ class CartesianGrid2D:
590577 Custom regions can be easily created by using the from_polygon classmethod. This function will accept an arbitrary closed
591578 polygon and return a CartesianGrid class with only points inside the polygon to be valid.
592579 """
593- def __init__ (self , polygons , dh , name = 'cartesian2d' , mask = None ):
580+ def __init__ (self , polygons , dh , name = 'cartesian2d' , mask = None , magnitudes = None ):
594581 self .polygons = polygons
595582 self .poly_mask = mask
596583 self .dh = dh
@@ -606,6 +593,7 @@ def __init__(self, polygons, dh, name='cartesian2d', mask=None):
606593 # Bounds [origin, top_right]
607594 orgs = self .origins ()
608595 self .bounds = numpy .column_stack ((orgs , orgs + dh ))
596+ self .magnitudes = magnitudes
609597
610598 def __eq__ (self , other ):
611599 return self .to_dict () == other .to_dict ()
@@ -763,9 +751,11 @@ def from_origins(cls, origins, dh=None, magnitudes=None, name=None):
763751 dh1 = numpy .abs (lats [1 ]- lats [0 ])
764752 dh = numpy .max ([dh1 , dh2 ])
765753
766- region = CartesianGrid2D ([Polygon (bbox ) for bbox in compute_vertices (origins , dh )], dh , name = name )
767- if magnitudes is not None :
768- region .magnitudes = magnitudes
754+ region = CartesianGrid2D (polygons = [Polygon (bbox ) for bbox in compute_vertices (origins , dh )],
755+ dh = dh ,
756+ magnitudes = magnitudes ,
757+ name = name )
758+
769759 return region
770760
771761 def _build_bitmask_vec (self ):
0 commit comments