9
9
10
10
# Third-party imports
11
11
import numpy
12
+ import pandas as pd
12
13
13
14
# PyCSEP imports
14
15
from csep .utils .time_utils import strptime_to_utc_datetime , \
18
19
from csep .utils .iris import gcmt_search
19
20
from csep .core .regions import QuadtreeGrid2D
20
21
from csep .core .exceptions import CSEPIOException
22
+ from csep .core .regions import CartesianGrid2D
21
23
22
24
23
25
def ndk (filename ):
@@ -901,11 +903,11 @@ def mapping_GEAR1(GEAR1_file, area_file, grid_file, b_value=False):
901
903
902
904
grid_file (str): Two-column, n-row array containing the centered longitude and latitude
903
905
coordinates of all the cells (with spatial resolution of 0.1 x 0.1) that
904
- make up the new testing region. E.g. 25.15, 33.25
905
- 25.25, 33.25
906
- 25.35, 33.25
907
- Each lon lat coordinate must be a two-decimal floating number ending in 5,
908
- i.e., the cell midpoint, as seen above.
906
+ make up the new testing region. E.g. 25.15 33.25
907
+ 25.25 33.25
908
+ 25.35 33.25
909
+ Each lon lat coordinate, separated by single blank space, must be a two-
910
+ decimal floating number ending in 5, i.e., the cell midpoint, as seen above.
909
911
910
912
b_value (float): If modellers wish to extroplate GEAR1 M 5.95+ earthquake rates to a lower
911
913
magnitude threshold, they must provide a generic b value of the region.
@@ -915,7 +917,7 @@ def mapping_GEAR1(GEAR1_file, area_file, grid_file, b_value=False):
915
917
b_value variable should remain False.
916
918
917
919
Returns
918
- GEAR1_region.dat: Input text file containing GEAR 1 earthquake rates in cells defined within
920
+ GEAR1_region.dat: Input text file containing GEAR1 earthquake rates in cells defined within
919
921
the desired geographic region. This file feeds a so-called read_GEAR1_format
920
922
function, which translates the format in which the GEAR1 forecasts were
921
923
originally provided into a pyCSEP-friendly format.
@@ -928,8 +930,8 @@ def mapping_GEAR1(GEAR1_file, area_file, grid_file, b_value=False):
928
930
929
931
"""
930
932
print ('Reading data...' )
931
- bulk_dataW = np .loadtxt (GEAR1_file , skiprows = 1 , delimiter = ',' )
932
- bulk_areaW = np .loadtxt (area_file , skiprows = 1 , delimiter = ',' )
933
+ bulk_dataW = numpy .loadtxt (GEAR1_file , skiprows = 1 , delimiter = ',' )
934
+ bulk_areaW = numpy .loadtxt (area_file , skiprows = 1 , delimiter = ',' )
933
935
934
936
# This part of the code is aimed to ensure that all lon and lat coordinates are two-digits floating
935
937
# numbers. This is important, because the projection of GEAR1 onto a geographical region is basically
@@ -939,8 +941,8 @@ def mapping_GEAR1(GEAR1_file, area_file, grid_file, b_value=False):
939
941
longitudesW = []
940
942
941
943
for i in range (len (bulk_dataW )):
942
- longitudesW .append (np . float ('%.2f' % round (bulk_dataW [:,0 ][i ],2 )))
943
- latitudesW .append (np . float ('%.2f' % round (bulk_dataW [:,1 ][i ],2 )))
944
+ longitudesW .append (float ('%.2f' % round (bulk_dataW [:,0 ][i ],2 )))
945
+ latitudesW .append (float ('%.2f' % round (bulk_dataW [:,1 ][i ],2 )))
944
946
945
947
# This is the first Pandas data frame when no extrapolations are needed:
946
948
if not b_value :
@@ -1038,14 +1040,14 @@ def mapping_GEAR1(GEAR1_file, area_file, grid_file, b_value=False):
1038
1040
longitudesW = []
1039
1041
1040
1042
# This is the second Pandas data frame:
1041
- bulk_dataR = np .loadtxt (grid_file , skiprows = 0 , delimiter = ' ' )
1043
+ bulk_dataR = numpy .loadtxt (grid_file , skiprows = 0 , delimiter = ' ' )
1042
1044
1043
1045
grid_longitudes = []
1044
1046
grid_latitudes = []
1045
1047
1046
1048
for i in range (len (bulk_dataR )):
1047
- grid_longitudes .append (np . float ('%.2f' % round (bulk_dataR [:,0 ][i ],2 )))
1048
- grid_latitudes .append (np . float ('%.2f' % round (bulk_dataR [:,1 ][i ],2 )))
1049
+ grid_longitudes .append (float ('%.2f' % round (bulk_dataR [:,0 ][i ],2 )))
1050
+ grid_latitudes .append (float ('%.2f' % round (bulk_dataR [:,1 ][i ],2 )))
1049
1051
1050
1052
polygon = pd .DataFrame ()
1051
1053
polygon ['longitude' ] = grid_longitudes
@@ -1080,13 +1082,13 @@ def read_GEAR1_format(filename, area_filename, magnitudes):
1080
1082
Returns:
1081
1083
:class:`csep.core.forecasts.GriddedForecast`
1082
1084
"""
1083
- t0 = time . time ()
1084
- bulk_data = np .loadtxt (filename , skiprows = 1 , delimiter = ',' )
1085
+
1086
+ bulk_data = numpy .loadtxt (filename , skiprows = 1 , delimiter = ',' )
1085
1087
1086
1088
# Construction of the testing region:
1087
1089
lons = bulk_data [:,1 ]
1088
1090
lats = bulk_data [:,2 ]
1089
- coords = np .column_stack ([lons , lats ])
1091
+ coords = numpy .column_stack ([lons , lats ])
1090
1092
1091
1093
# Coordinates are given as midpoints origin should be in the 'lower left' corner:
1092
1094
r = CartesianGrid2D .from_origins (coords , magnitudes = magnitudes )
@@ -1095,16 +1097,16 @@ def read_GEAR1_format(filename, area_filename, magnitudes):
1095
1097
bulk_data_no_coords = bulk_data [:, 3 :]
1096
1098
1097
1099
# Original GEAR1 format provides cumulative rates per meter**2
1098
- incremental_yrly_density = np .diff (np .fliplr (bulk_data_no_coords ))
1100
+ incremental_yrly_density = numpy .diff (numpy .fliplr (bulk_data_no_coords ))
1099
1101
1100
1102
# Computing the differences, but returning array with the same shape:
1101
- incremental_yrly_density = np .column_stack ([np .fliplr (incremental_yrly_density ), bulk_data_no_coords [:,- 1 ]])
1103
+ incremental_yrly_density = numpy .column_stack ([numpy .fliplr (incremental_yrly_density ), bulk_data_no_coords [:,- 1 ]])
1102
1104
1103
1105
# Read in area to denormalize back onto csep grid
1104
- area = np .loadtxt (area_filename , skiprows = 1 , delimiter = ',' )
1106
+ area = numpy .loadtxt (area_filename , skiprows = 1 , delimiter = ',' )
1105
1107
1106
1108
# Allows to use broadcasting
1107
- m2_per_cell = np .reshape (area [:,- 1 ], (len (area [:,1 ]), 1 ))
1109
+ m2_per_cell = numpy .reshape (area [:,- 1 ], (len (area [:,1 ]), 1 ))
1108
1110
incremental_yrly_rates = incremental_yrly_density * m2_per_cell
1109
1111
1110
1112
return incremental_yrly_rates , r , magnitudes
0 commit comments