8
8
# Operations:
9
9
# - calculates channel ML on all the three components with several Attenuation Laws
10
10
# - calculates station ML on all the stations either as a mean of channel's one or as ML of the mean amplitude
11
- # - calculates event ML for all the Attenuation Laws with different possibile statistical approaches
11
+ # - calculates event ML for all the Attenuation Laws with different possible statistical approaches
12
12
#
13
13
# Details: Amplitude usage
14
14
# Two different approaches are followed to calculate the station ML:
40
40
# In both cases stations with hypocentral distance lower than mindist (tipically 10km) and higher than maxdist (tipically 600) are excluded
41
41
42
42
import argparse ,sys ,os ,glob ,copy ,pwd ,pathlib ,itertools ,getpass ,socket
43
+ import decimal
44
+
43
45
from geographiclib .geodesic import Geodesic
44
46
import pandas
45
47
import time
@@ -636,6 +638,7 @@ def json_response_structure():
636
638
"time1" : null ,
637
639
"amp2" : null ,
638
640
"time2" : null ,
641
+ "period" : null ,
639
642
# "lat": null,
640
643
# "lon": null,
641
644
# "elev": null,
@@ -843,6 +846,7 @@ def json_pyml_response(r):
843
846
minamp = row ['minamp(m)' ]* unit
844
847
except :
845
848
try :
849
+ print ("Ciao io sono AMP12" ,type (row ['amp1' ]))
846
850
minamp = row ['amp1' ]* unit
847
851
minamp = False if pandas .isna (row ['amp1' ]) else minamp
848
852
except :
@@ -873,6 +877,14 @@ def json_pyml_response(r):
873
877
time_maxamp = False if pandas .isna (row ['time2' ]) else time_maxamp
874
878
except :
875
879
time_maxamp = False
880
+ try :
881
+ period = row ['period' ]
882
+ except :
883
+ try :
884
+ period = row ['period' ]
885
+ period = False if pandas .isna (row ['period' ]) else period
886
+ except :
887
+ period = False
876
888
# Station's coordinates
877
889
try :
878
890
stla = False if pandas .isna (row ['lat' ]) else float (row ['lat' ])
@@ -988,11 +1000,11 @@ def json_pyml_response(r):
988
1000
ml [1 ] = False
989
1001
990
1002
if cha [2 ] == 'N' :
991
- components_N [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,stla ,stlo ,stel * km ,epi_azimuth ]
1003
+ components_N [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,period , stla ,stlo ,stel * km ,epi_azimuth ]
992
1004
elif cha [2 ] == 'E' :
993
- components_E [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,stla ,stlo ,stel * km ,epi_azimuth ]
1005
+ components_E [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,period , stla ,stlo ,stel * km ,epi_azimuth ]
994
1006
elif cha [2 ] == 'Z' :
995
- components_Z [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,stla ,stlo ,stel * km ,epi_azimuth ]
1007
+ components_Z [components_key_met ]= [ml ,[minamp ,maxamp ],epi_dist_km ,epi_dist_deg ,hypo_dist ,[s_hutton ,s_dibona ],time_minamp ,time_maxamp ,period , stla ,stlo ,stel * km ,epi_azimuth ]
996
1008
else :
997
1009
if log_out :
998
1010
log_out .write (' ' .join (("Component not recognized for " ,str (net ),str (sta ),str (loc ),str (cha ),"\n " )))
@@ -1006,7 +1018,7 @@ def json_pyml_response(r):
1006
1018
msg_sum = 'HuttonBoore List is empty'
1007
1019
msg_ext = 'All the stations missing due to only one channel is present, or out of minmax distance'
1008
1020
if log_out :
1009
- log_out .write (msg + "\n " )
1021
+ log_out .write (msg_sts + ":" + msg_sum + " --> " + msg_ext + "\n " )
1010
1022
mlhb = False
1011
1023
else :
1012
1024
#meanmag_ml = list(list(zip(*meanmag_ml_sta))[1])
@@ -1043,7 +1055,7 @@ def json_pyml_response(r):
1043
1055
msg_sum = 'Dibona List is empty'
1044
1056
msg_ext = 'All the stations missing due to only one channel is present, or out of minmax distance'
1045
1057
if log_out :
1046
- log_out .write (msg + "\n " )
1058
+ log_out .write (msg_sts + ":" + msg_sum + " --> " + msg_ext + "\n " )
1047
1059
mldb = False
1048
1060
else :
1049
1061
#meanmag_ml = list(list(zip(*meanmag_ml_sta))[1])
@@ -1191,17 +1203,18 @@ def json_pyml_response(r):
1191
1203
jstmag ["time1" ] = components_N [key ][6 ]
1192
1204
jstmag ["amp2" ] = components_N [key ][1 ][1 ]
1193
1205
jstmag ["time2" ] = components_N [key ][7 ]
1206
+ jstmag ["period" ] = components_N [key ][8 ]
1194
1207
jstmag ["ep_distance_km" ] = components_N [key ][2 ]
1195
1208
jstmag ["ep_distance_delta" ] = components_N [key ][3 ]
1196
1209
jstmag ["orig_distance" ] = components_N [key ][4 ]
1197
- if components_N [key ][8 ]:
1198
- jstmag ["lat" ] = components_N [key ][8 ]
1199
1210
if components_N [key ][9 ]:
1200
- jstmag ["lon " ] = components_N [key ][9 ]
1211
+ jstmag ["lat " ] = components_N [key ][9 ]
1201
1212
if components_N [key ][10 ]:
1202
- jstmag ["elev " ] = components_N [key ][10 ]
1213
+ jstmag ["lon " ] = components_N [key ][10 ]
1203
1214
if components_N [key ][11 ]:
1204
- jstmag ["azimuth" ] = components_N [key ][11 ]
1215
+ jstmag ["elev" ] = components_N [key ][11 ]
1216
+ if components_N [key ][12 ]:
1217
+ jstmag ["azimuth" ] = components_N [key ][12 ]
1205
1218
if channels_dictionary [key ]:
1206
1219
jstmag ["hb" ] = {"ml" : channels_dictionary [key ][0 ][0 ], "w" : float (channels_dictionary [key ][0 ][1 ])}
1207
1220
jstmag ["db" ] = {"ml" : channels_dictionary [key ][0 ][2 ], "w" : float (channels_dictionary [key ][0 ][3 ])}
@@ -1215,7 +1228,7 @@ def json_pyml_response(r):
1215
1228
#logmch['status'] = 'ok'
1216
1229
#logmch['level'] = 'channel'
1217
1230
#logmch['info'] = {"summary": n+' '+s+' '+jstmag["loc"]+' '+c+'E', "extended": ''}
1218
- if components_N [key ][8 ] and components_N [key ][9 ] and components_N [key ][10 ]:
1231
+ if components_N [key ][9 ] and components_N [key ][10 ] and components_N [key ][11 ]:
1219
1232
resp ["stationmagnitudes" ].append (jstmag )
1220
1233
#resp["log"].append(logmch)
1221
1234
jstmag = copy .deepcopy (jstationmagnitude )
@@ -1230,17 +1243,18 @@ def json_pyml_response(r):
1230
1243
jstmag ["time1" ] = components_E [key ][6 ]
1231
1244
jstmag ["amp2" ] = components_E [key ][1 ][1 ]
1232
1245
jstmag ["time2" ] = components_E [key ][7 ]
1246
+ jstmag ["period" ] = components_E [key ][8 ]
1233
1247
jstmag ["ep_distance_km" ] = components_E [key ][2 ]
1234
1248
jstmag ["ep_distance_delta" ] = components_E [key ][3 ]
1235
1249
jstmag ["orig_distance" ] = components_E [key ][4 ]
1236
- if components_E [key ][8 ]:
1237
- jstmag ["lat" ] = components_E [key ][8 ]
1238
1250
if components_E [key ][9 ]:
1239
- jstmag ["lon " ] = components_E [key ][9 ]
1251
+ jstmag ["lat " ] = components_E [key ][9 ]
1240
1252
if components_E [key ][10 ]:
1241
- jstmag ["elev " ] = components_E [key ][10 ]
1253
+ jstmag ["lon " ] = components_E [key ][10 ]
1242
1254
if components_E [key ][11 ]:
1243
- jstmag ["azimuth" ] = components_E [key ][11 ]
1255
+ jstmag ["elev" ] = components_E [key ][11 ]
1256
+ if components_E [key ][12 ]:
1257
+ jstmag ["azimuth" ] = components_E [key ][12 ]
1244
1258
if channels_dictionary [key ]:
1245
1259
jstmag ["hb" ] = {"ml" : channels_dictionary [key ][1 ][0 ], "w" : float (channels_dictionary [key ][1 ][1 ])}
1246
1260
jstmag ["db" ] = {"ml" : channels_dictionary [key ][1 ][2 ], "w" : float (channels_dictionary [key ][1 ][3 ])}
@@ -1255,7 +1269,7 @@ def json_pyml_response(r):
1255
1269
#logmch['status'] = 'ok'
1256
1270
#logmch['level'] = 'channel'
1257
1271
#logmch['info'] = {"summary": n+' '+s+' '+jstmag["loc"]+' '+c+'N', "extended": ''}
1258
- if components_E [key ][8 ] and components_E [key ][9 ] and components_E [key ][10 ]:
1272
+ if components_E [key ][9 ] and components_E [key ][10 ] and components_E [key ][11 ]:
1259
1273
resp ["stationmagnitudes" ].append (jstmag )
1260
1274
#resp["log"].append(logmch)
1261
1275
#resp["stationmagnitudes"].append(jstmag)
0 commit comments