Skip to content

Commit

Permalink
Merge pull request #18 from paudetseis/stdb_updates
Browse files Browse the repository at this point in the history
Stdb updates
  • Loading branch information
paudetseis authored Dec 2, 2020
2 parents 2b77001 + 96acf35 commit 9be50d6
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 167 deletions.
51 changes: 24 additions & 27 deletions Scripts/rfpy_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from obspy import UTCDateTime
from numpy import nan


def get_calc_arguments(argv=None):
"""
Get Options from :class:`~optparse.OptionParser` objects.
Expand Down Expand Up @@ -83,6 +84,15 @@ def get_calc_arguments(argv=None):
default=False,
help="Force the overwriting of pre-existing data. " +
"[Default False]")
parser.add_argument(
"-L", "--long-name",
action="store_true",
dest="lkey",
default=False,
help="Force folder names to use long-key form (NET.STN.CHN). " +
"Default behaviour uses short key form (NET.STN) for the folder " +
"names, regardless of the key type of the database."
)

# Server Settings
ServerGroup = parser.add_argument_group(
Expand Down Expand Up @@ -148,7 +158,7 @@ def get_calc_arguments(argv=None):
action="store_true",
dest="saveZ12",
default=False,
help="Specify to save Z12 (un-rotated) components. [Default "+
help="Specify to save Z12 (un-rotated) components. [Default " +
"False]")

# Event Selection Criteria
Expand Down Expand Up @@ -479,38 +489,24 @@ def main():
args = get_calc_arguments()

# Load Database
# stdb=0.1.4
try:
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# stdb=0.1.3
except:
db = stdb.io.load_db(fname=args.indb)

# Construct station key loop
allkeys = db.keys()
sorted(allkeys)

# Extract key subset
if len(args.stkeys) > 0:
stkeys = []
for skey in args.stkeys:
stkeys.extend([s for s in allkeys if skey in s])
else:
stkeys = db.keys()
sorted(stkeys)
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# Loop over station keys
for stkey in list(stkeys):

# Extract station information from dictionary
sta = db[stkey]

# Construct Folder Name
stfld = stkey
if not args.lkey:
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]

# Define path to see if it exists
if args.phase in ['P', 'PP']:
datapath = Path('P_DATA') / stkey
datapath = Path('P_DATA') / stfld
elif args.phase in ['S', 'SKS']:
datapath = Path('S_DATA') / stkey
datapath = Path('S_DATA') / stfld
if not datapath.exists():
print('Path to '+str(datapath)+' doesn`t exist - creating it')
datapath.mkdir(parents=True)
Expand Down Expand Up @@ -668,10 +664,11 @@ def main():
print(
"* Dep: {0:6.2f} km; Mag: {1:3.1f}".format(
rfdata.meta.dep, rfdata.meta.mag))
print("* Dist: {0:7.2f} km;".format(rfdata.meta.epi_dist) +
" Epi dist: {0:6.2f} deg\n".format(rfdata.meta.gac) +
"* Baz: {0:6.2f} deg;".format(rfdata.meta.baz) +
" Az: {0:6.2f} deg".format(rfdata.meta.az))
print(
"* Dist: {0:7.2f} km;".format(rfdata.meta.epi_dist) +
" Epi dist: {0:6.2f} deg\n".format(rfdata.meta.gac) +
"* Baz: {0:6.2f} deg;".format(rfdata.meta.baz) +
" Az: {0:6.2f} deg".format(rfdata.meta.az))

# Event Folder
timekey = rfdata.meta.time.strftime("%Y%m%d_%H%M%S")
Expand Down
70 changes: 38 additions & 32 deletions Scripts/rfpy_ccp.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def get_ccp_arguments(argv=None):
default=False,
help="Force the overwriting of pre-existing data. " +
"[Default False]")
parser.add_argument(
"-L", "--long-name",
action="store_true",
dest="lkey",
default=False,
help="Force folder names to use long-key form (NET.STN.CHN). " +
"Default behaviour uses short key form (NET.STN) for the folder " +
"names, regardless of the key type of the database."
)

LineGroup = parser.add_argument_group(
title='Line Geometry Settings',
Expand Down Expand Up @@ -286,8 +295,8 @@ def get_ccp_arguments(argv=None):
action="store",
dest="weights",
default=None,
help="Option to define weights for each of the three phases: "+
"Ps, Pps and Pss, by specifying three comma-separated floats. "+
help="Option to define weights for each of the three phases: " +
"Ps, Pps and Pss, by specifying three comma-separated floats. " +
"[Default 1., 3., -3.]")

FigGroup = parser.add_argument_group(
Expand Down Expand Up @@ -430,26 +439,10 @@ def main():
args = get_ccp_arguments()

# Load Database
# stdb=0.1.4
try:
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# stdb=0.1.3
except:
db = stdb.io.load_db(fname=args.indb)

# Construct station key loop
allkeys = db.keys()
sorted(allkeys)

# Extract key subset
if len(args.stkeys) > 0:
stkeys = []
for skey in args.stkeys:
stkeys.extend([s for s in allkeys if skey in s])
else:
stkeys = db.keys()
sorted(stkeys)
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# Track processed folders
procfold = []

if args.load:

Expand All @@ -468,9 +461,9 @@ def main():
print("|-----------------------------------------------|")
print("| Gridding: ")
print("| start = {0:5.1f},{1:6.1f}".format(
args.coord_start[0],args.coord_start[1]))
args.coord_start[0], args.coord_start[1]))
print("| end = {0:5.1f},{1:6.1f}".format(
args.coord_end[0],args.coord_end[1]))
args.coord_end[0], args.coord_end[1]))
print("| dz = {0} (km)".format(str(args.dz)))
print("| dx = {0} (km)".format(str(args.dx)))
print()
Expand All @@ -486,13 +479,24 @@ def main():
# Extract station information from dictionary
sta = db[stkey]

# Construct Folder Name
stfld = stkey
if not args.lkey:
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]

# Check for folder already processed
if stfld in procfold:
print('{0} already processed...skipping '.format(stfld))
continue

# Define path to see if it exists
if args.phase in ['P', 'PP', 'allP']:
datapath = Path('P_DATA') / stkey
datapath = Path('P_DATA') / stfld
elif args.phase in ['S', 'SKS', 'allS']:
datapath = Path('S_DATA') / stkey
datapath = Path('S_DATA') / stfld
if not datapath.is_dir():
print('Path to ' + str(datapath) + ' doesn`t exist - continuing')
print('Path to ' + str(datapath) +
' doesn`t exist - continuing')
continue

# Temporary print locations
Expand Down Expand Up @@ -565,11 +569,14 @@ def main():

print("Station: {0:>2s}.{1:5s} - {2} traces loaded".format(
sta.network, sta.station, len(rfRstream)))
if len(rfRstream)==0:
if len(rfRstream) == 0:
continue

ccpimage.add_rfstream(rfRstream)

# Update processed folders
procfold.append(stfld)

if len(ccpimage.radialRF) > 0:
ccpimage.save("CCP_load.pkl")
ccpimage.is_ready_for_prep = True
Expand Down Expand Up @@ -606,7 +613,7 @@ def main():
print("| nslow = {0}".format(str(args.nslow)))
print()

ccpfile = open(load_file,"rb")
ccpfile = open(load_file, "rb")
ccpimage = pickle.load(ccpfile)
ccpfile.close()
ccpimage.prep_data(f1=args.f1, f2ps=args.f2ps,
Expand All @@ -620,7 +627,6 @@ def main():
else:
pass


if args.prestack:

prestack_file = Path("CCP_prestack.pkl")
Expand Down Expand Up @@ -693,7 +699,7 @@ def main():

if args.ccp_figure:
ccpimage.plot_ccp(save=args.save_figure, fmt=args.fmt,
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)

else:
pass
Expand Down Expand Up @@ -741,7 +747,7 @@ def main():

if args.ccp_figure:
ccpimage.plot_gccp(save=args.save_figure, fmt=args.fmt,
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)

else:
pass
Expand Down
58 changes: 33 additions & 25 deletions Scripts/rfpy_harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from os.path import exists as exist
from numpy import nan


def get_harmonics_arguments(argv=None):
"""
Get Options from :class:`~optparse.OptionParser` objects.
Expand Down Expand Up @@ -78,6 +79,15 @@ def get_harmonics_arguments(argv=None):
default=False,
help="Force the overwriting of pre-existing data. " +
"[Default False]")
parser.add_argument(
"-L", "--long-name",
action="store_true",
dest="lkey",
default=False,
help="Force folder names to use long-key form (NET.STN.CHN). " +
"Default behaviour uses short key form (NET.STN) for the folder " +
"names, regardless of the key type of the database."
)

# Event Selection Criteria
TimeGroup = parser.add_argument_group(
Expand Down Expand Up @@ -320,7 +330,6 @@ def get_harmonics_arguments(argv=None):
return args



def main():

print()
Expand All @@ -340,40 +349,30 @@ def main():
args = get_harmonics_arguments()

# Load Database
# stdb=0.1.4
try:
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# stdb=0.1.3
except:
db = stdb.io.load_db(fname=args.indb)

# Construct station key loop
allkeys = db.keys()
sorted(allkeys)

# Extract key subset
if len(args.stkeys) > 0:
stkeys = []
for skey in args.stkeys:
stkeys.extend([s for s in allkeys if skey in s])
else:
stkeys = db.keys()
sorted(stkeys)
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)

# Track processed folders
procfold = []

# Loop over station keys
for stkey in list(stkeys):

# Extract station information from dictionary
sta = db[stkey]

# Construct Folder Name
stfld = stkey
if not args.lkey:
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]

# Define path to see if it exists
if args.phase in ['P', 'PP', 'allP']:
datapath = Path('P_DATA') / stkey
datapath = Path('P_DATA') / stfld
elif args.phase in ['S', 'SKS', 'allS']:
datapath = Path('S_DATA') / stkey
datapath = Path('S_DATA') / stfld
if not datapath.is_dir():
print('Path to ' + str(datapath) + ' doesn`t exist - continuing')
print('Path to ' + str(datapath) +
' doesn`t exist - continuing')
continue

# Get search start time
Expand Down Expand Up @@ -421,6 +420,11 @@ def main():
sta.enddate.strftime("%Y-%m-%d %H:%M:%S")))
print("|-----------------------------------------------|")

# Check for folder already processed
if stfld in procfold:
print(' {0} already processed...skipping '.format(stfld))
continue

rfRstream = Stream()
rfTstream = Stream()

Expand All @@ -443,7 +447,8 @@ def main():
if filename.is_file():
file = open(filename, "rb")
rfdata = pickle.load(file)
if rfdata[0].stats.snrh > args.snrh and rfdata[0].stats.snr and \
if rfdata[0].stats.snrh > args.snrh and \
rfdata[0].stats.snr and \
rfdata[0].stats.cc > args.cc:

rfRstream.append(rfdata[1])
Expand Down Expand Up @@ -513,6 +518,9 @@ def main():
".harmonics.pkl")
harmonics.save()

# Update processed folders
procfold.append(stfld)


if __name__ == "__main__":

Expand Down
Loading

0 comments on commit 9be50d6

Please sign in to comment.