@@ -719,7 +719,7 @@ def _parse_datetime_to_zmap(date, time):
719
719
out ['second' ] = dt .second
720
720
return out
721
721
722
- def load_quadtree_forecast (ascii_fname ):
722
+ def quadtree_ascii_loader (ascii_fname ):
723
723
""" Load quadtree forecasted stored as ascii text file
724
724
725
725
Note: This function is adapted form csep.forecasts.load_ascii
@@ -756,4 +756,33 @@ def load_quadtree_forecast(ascii_fname):
756
756
# reshape rates into correct 2d format
757
757
rates = data [:, - 1 ].reshape (n_poly , n_mag_bins )
758
758
759
+ return rates , region , mws
760
+
761
+
762
+ def quadtree_csv_loader (csv_fname ):
763
+ """ Load quadtree forecasted stored as csv file
764
+
765
+ The format expects forecast as a comma separated file, in which first column corresponds to quadtree grid cell (quadkey).
766
+ The second and thrid columns indicate depth range.
767
+ The corresponding enteries in the respective row are forecast rates corresponding to the magnitude bins.
768
+ The first line of forecast is a header, and its format is listed here:
769
+ 'Quadkey', depth_min, depth_max, Mag_0, Mag_1, Mag_2, Mag_3 , ....
770
+ Quadkey is a string. Rest of the values are floats.
771
+ For the purposes of defining region objects quadkey is used.
772
+
773
+ We assume that the starting value of magnitude bins are provided in the header.
774
+ Args:
775
+ csv_fname: file name of csep forecast in csv format
776
+ Returns:
777
+ rates, region, mws (numpy.ndarray, QuadtreeRegion2D, numpy.ndarray): rates, region, and magnitude bins needed
778
+ to define QuadTree forecasts
779
+ """
780
+
781
+ data = numpy .genfromtxt (csv_fname , dtype = 'str' , delimiter = ',' )
782
+ quadkeys = data [1 :, 0 ]
783
+ mws = data [0 , 3 :]
784
+ rates = data [1 :, 3 :]
785
+ rates = rates .astype (float )
786
+ region = QuadtreeGrid2D .from_quadkeys (quadkeys , magnitudes = mws )
787
+
759
788
return rates , region , mws
0 commit comments