Skip to content

Commit 5fcfd2b

Browse files
committed
Period field implemented
1 parent 6880722 commit 5fcfd2b

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

pyml.py

+32-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Operations:
99
# - calculates channel ML on all the three components with several Attenuation Laws
1010
# - 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
1212
#
1313
# Details: Amplitude usage
1414
# Two different approaches are followed to calculate the station ML:
@@ -40,6 +40,8 @@
4040
# In both cases stations with hypocentral distance lower than mindist (tipically 10km) and higher than maxdist (tipically 600) are excluded
4141

4242
import argparse,sys,os,glob,copy,pwd,pathlib,itertools,getpass,socket
43+
import decimal
44+
4345
from geographiclib.geodesic import Geodesic
4446
import pandas
4547
import time
@@ -636,6 +638,7 @@ def json_response_structure():
636638
"time1": null,
637639
"amp2": null,
638640
"time2": null,
641+
"period": null,
639642
# "lat": null,
640643
# "lon": null,
641644
# "elev": null,
@@ -843,6 +846,7 @@ def json_pyml_response(r):
843846
minamp=row['minamp(m)']*unit
844847
except:
845848
try:
849+
print("Ciao io sono AMP12",type(row['amp1']))
846850
minamp=row['amp1']*unit
847851
minamp = False if pandas.isna(row['amp1']) else minamp
848852
except:
@@ -873,6 +877,14 @@ def json_pyml_response(r):
873877
time_maxamp = False if pandas.isna(row['time2']) else time_maxamp
874878
except:
875879
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
876888
# Station's coordinates
877889
try:
878890
stla=False if pandas.isna(row['lat']) else float(row['lat'])
@@ -988,11 +1000,11 @@ def json_pyml_response(r):
9881000
ml[1] = False
9891001

9901002
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]
9921004
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]
9941006
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]
9961008
else:
9971009
if log_out:
9981010
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):
10061018
msg_sum='HuttonBoore List is empty'
10071019
msg_ext = 'All the stations missing due to only one channel is present, or out of minmax distance'
10081020
if log_out:
1009-
log_out.write(msg+"\n")
1021+
log_out.write(msg_sts+":"+msg_sum+" --> "+msg_ext+"\n")
10101022
mlhb = False
10111023
else:
10121024
#meanmag_ml = list(list(zip(*meanmag_ml_sta))[1])
@@ -1043,7 +1055,7 @@ def json_pyml_response(r):
10431055
msg_sum='Dibona List is empty'
10441056
msg_ext = 'All the stations missing due to only one channel is present, or out of minmax distance'
10451057
if log_out:
1046-
log_out.write(msg+"\n")
1058+
log_out.write(msg_sts+":"+msg_sum+" --> "+msg_ext+"\n")
10471059
mldb = False
10481060
else:
10491061
#meanmag_ml = list(list(zip(*meanmag_ml_sta))[1])
@@ -1191,17 +1203,18 @@ def json_pyml_response(r):
11911203
jstmag["time1"] = components_N[key][6]
11921204
jstmag["amp2"] = components_N[key][1][1]
11931205
jstmag["time2"] = components_N[key][7]
1206+
jstmag["period"] = components_N[key][8]
11941207
jstmag["ep_distance_km"] = components_N[key][2]
11951208
jstmag["ep_distance_delta"] = components_N[key][3]
11961209
jstmag["orig_distance"] = components_N[key][4]
1197-
if components_N[key][8]:
1198-
jstmag["lat"] = components_N[key][8]
11991210
if components_N[key][9]:
1200-
jstmag["lon"] = components_N[key][9]
1211+
jstmag["lat"] = components_N[key][9]
12011212
if components_N[key][10]:
1202-
jstmag["elev"] = components_N[key][10]
1213+
jstmag["lon"] = components_N[key][10]
12031214
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]
12051218
if channels_dictionary[key]:
12061219
jstmag["hb"] = {"ml": channels_dictionary[key][0][0], "w": float(channels_dictionary[key][0][1])}
12071220
jstmag["db"] = {"ml": channels_dictionary[key][0][2], "w": float(channels_dictionary[key][0][3])}
@@ -1215,7 +1228,7 @@ def json_pyml_response(r):
12151228
#logmch['status'] = 'ok'
12161229
#logmch['level'] = 'channel'
12171230
#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]:
12191232
resp["stationmagnitudes"].append(jstmag)
12201233
#resp["log"].append(logmch)
12211234
jstmag = copy.deepcopy(jstationmagnitude)
@@ -1230,17 +1243,18 @@ def json_pyml_response(r):
12301243
jstmag["time1"] = components_E[key][6]
12311244
jstmag["amp2"] = components_E[key][1][1]
12321245
jstmag["time2"] = components_E[key][7]
1246+
jstmag["period"] = components_E[key][8]
12331247
jstmag["ep_distance_km"] = components_E[key][2]
12341248
jstmag["ep_distance_delta"] = components_E[key][3]
12351249
jstmag["orig_distance"] = components_E[key][4]
1236-
if components_E[key][8]:
1237-
jstmag["lat"] = components_E[key][8]
12381250
if components_E[key][9]:
1239-
jstmag["lon"] = components_E[key][9]
1251+
jstmag["lat"] = components_E[key][9]
12401252
if components_E[key][10]:
1241-
jstmag["elev"] = components_E[key][10]
1253+
jstmag["lon"] = components_E[key][10]
12421254
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]
12441258
if channels_dictionary[key]:
12451259
jstmag["hb"] = {"ml": channels_dictionary[key][1][0], "w": float(channels_dictionary[key][1][1])}
12461260
jstmag["db"] = {"ml": channels_dictionary[key][1][2], "w": float(channels_dictionary[key][1][3])}
@@ -1255,7 +1269,7 @@ def json_pyml_response(r):
12551269
#logmch['status'] = 'ok'
12561270
#logmch['level'] = 'channel'
12571271
#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]:
12591273
resp["stationmagnitudes"].append(jstmag)
12601274
#resp["log"].append(logmch)
12611275
#resp["stationmagnitudes"].append(jstmag)

0 commit comments

Comments
 (0)