@@ -52,10 +52,7 @@ def california_relm_collection_region(dh_scale=1, magnitudes=None, name="relm-ca
52
52
53
53
# turn points into polygons and make region object
54
54
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 )
59
56
60
57
return relm_region
61
58
@@ -97,10 +94,8 @@ def california_relm_region(dh_scale=1, magnitudes=None, name="relm-california",
97
94
98
95
# turn points into polygons and make region object
99
96
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 )
104
99
105
100
return relm_region
106
101
@@ -145,10 +140,8 @@ def italy_csep_region(dh_scale=1, magnitudes=None, name="csep-italy", use_midpoi
145
140
146
141
# turn points into polygons and make region object
147
142
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 )
152
145
153
146
return italy_region
154
147
@@ -187,10 +180,8 @@ def italy_csep_collection_region(dh_scale=1, magnitudes=None, name="csep-italy-c
187
180
188
181
# turn points into polygons and make region object
189
182
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 )
194
185
195
186
return relm_region
196
187
@@ -229,10 +220,8 @@ def nz_csep_region(dh_scale=1, magnitudes=None, name="csep-nz", use_midpoint=Tru
229
220
230
221
# turn points into polygons and make region object
231
222
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 )
236
225
237
226
return nz_region
238
227
@@ -271,10 +260,8 @@ def nz_csep_collection_region(dh_scale=1, magnitudes=None, name="csep-nz-collect
271
260
272
261
# turn points into polygons and make region object
273
262
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 )
278
265
279
266
return nz_collection_region
280
267
@@ -294,9 +281,9 @@ def global_region(dh=0.1, name="global", magnitudes=None):
294
281
lons = cleaner_range (- 180.0 , 179.9 , dh )
295
282
lats = cleaner_range (- 90 , 89.9 , dh )
296
283
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
+
300
287
return region
301
288
302
289
def magnitude_bins (start_magnitude , end_magnitude , dmw ):
@@ -585,7 +572,7 @@ class CartesianGrid2D:
585
572
Custom regions can be easily created by using the from_polygon classmethod. This function will accept an arbitrary closed
586
573
polygon and return a CartesianGrid class with only points inside the polygon to be valid.
587
574
"""
588
- def __init__ (self , polygons , dh , name = 'cartesian2d' , mask = None ):
575
+ def __init__ (self , polygons , dh , name = 'cartesian2d' , mask = None , magnitudes = None ):
589
576
self .polygons = polygons
590
577
self .poly_mask = mask
591
578
self .dh = dh
@@ -601,6 +588,7 @@ def __init__(self, polygons, dh, name='cartesian2d', mask=None):
601
588
# Bounds [origin, top_right]
602
589
orgs = self .origins ()
603
590
self .bounds = numpy .column_stack ((orgs , orgs + dh ))
591
+ self .magnitudes = magnitudes
604
592
605
593
def __eq__ (self , other ):
606
594
return self .to_dict () == other .to_dict ()
@@ -758,9 +746,11 @@ def from_origins(cls, origins, dh=None, magnitudes=None, name=None):
758
746
dh1 = numpy .abs (lats [1 ]- lats [0 ])
759
747
dh = numpy .max ([dh1 , dh2 ])
760
748
761
- region = CartesianGrid2D ([Polygon (bbox ) for bbox in compute_vertices (origins , dh )], dh , name = name )
762
- if magnitudes is not None :
763
- region .magnitudes = magnitudes
749
+ region = CartesianGrid2D (polygons = [Polygon (bbox ) for bbox in compute_vertices (origins , dh )],
750
+ dh = dh ,
751
+ magnitudes = magnitudes ,
752
+ name = name )
753
+
764
754
return region
765
755
766
756
def _build_bitmask_vec (self ):
0 commit comments