Skip to content

Commit 9be50d6

Browse files
authored
Merge pull request #18 from paudetseis/stdb_updates
Stdb updates
2 parents 2b77001 + 96acf35 commit 9be50d6

File tree

8 files changed

+200
-167
lines changed

8 files changed

+200
-167
lines changed

Scripts/rfpy_calc.py

+24-27
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from obspy import UTCDateTime
3636
from numpy import nan
3737

38+
3839
def get_calc_arguments(argv=None):
3940
"""
4041
Get Options from :class:`~optparse.OptionParser` objects.
@@ -83,6 +84,15 @@ def get_calc_arguments(argv=None):
8384
default=False,
8485
help="Force the overwriting of pre-existing data. " +
8586
"[Default False]")
87+
parser.add_argument(
88+
"-L", "--long-name",
89+
action="store_true",
90+
dest="lkey",
91+
default=False,
92+
help="Force folder names to use long-key form (NET.STN.CHN). " +
93+
"Default behaviour uses short key form (NET.STN) for the folder " +
94+
"names, regardless of the key type of the database."
95+
)
8696

8797
# Server Settings
8898
ServerGroup = parser.add_argument_group(
@@ -148,7 +158,7 @@ def get_calc_arguments(argv=None):
148158
action="store_true",
149159
dest="saveZ12",
150160
default=False,
151-
help="Specify to save Z12 (un-rotated) components. [Default "+
161+
help="Specify to save Z12 (un-rotated) components. [Default " +
152162
"False]")
153163

154164
# Event Selection Criteria
@@ -479,38 +489,24 @@ def main():
479489
args = get_calc_arguments()
480490

481491
# Load Database
482-
# stdb=0.1.4
483-
try:
484-
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
485-
486-
# stdb=0.1.3
487-
except:
488-
db = stdb.io.load_db(fname=args.indb)
489-
490-
# Construct station key loop
491-
allkeys = db.keys()
492-
sorted(allkeys)
493-
494-
# Extract key subset
495-
if len(args.stkeys) > 0:
496-
stkeys = []
497-
for skey in args.stkeys:
498-
stkeys.extend([s for s in allkeys if skey in s])
499-
else:
500-
stkeys = db.keys()
501-
sorted(stkeys)
492+
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
502493

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

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

500+
# Construct Folder Name
501+
stfld = stkey
502+
if not args.lkey:
503+
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]
504+
509505
# Define path to see if it exists
510506
if args.phase in ['P', 'PP']:
511-
datapath = Path('P_DATA') / stkey
507+
datapath = Path('P_DATA') / stfld
512508
elif args.phase in ['S', 'SKS']:
513-
datapath = Path('S_DATA') / stkey
509+
datapath = Path('S_DATA') / stfld
514510
if not datapath.exists():
515511
print('Path to '+str(datapath)+' doesn`t exist - creating it')
516512
datapath.mkdir(parents=True)
@@ -668,10 +664,11 @@ def main():
668664
print(
669665
"* Dep: {0:6.2f} km; Mag: {1:3.1f}".format(
670666
rfdata.meta.dep, rfdata.meta.mag))
671-
print("* Dist: {0:7.2f} km;".format(rfdata.meta.epi_dist) +
672-
" Epi dist: {0:6.2f} deg\n".format(rfdata.meta.gac) +
673-
"* Baz: {0:6.2f} deg;".format(rfdata.meta.baz) +
674-
" Az: {0:6.2f} deg".format(rfdata.meta.az))
667+
print(
668+
"* Dist: {0:7.2f} km;".format(rfdata.meta.epi_dist) +
669+
" Epi dist: {0:6.2f} deg\n".format(rfdata.meta.gac) +
670+
"* Baz: {0:6.2f} deg;".format(rfdata.meta.baz) +
671+
" Az: {0:6.2f} deg".format(rfdata.meta.az))
675672

676673
# Event Folder
677674
timekey = rfdata.meta.time.strftime("%Y%m%d_%H%M%S")

Scripts/rfpy_ccp.py

+38-32
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def get_ccp_arguments(argv=None):
7979
default=False,
8080
help="Force the overwriting of pre-existing data. " +
8181
"[Default False]")
82+
parser.add_argument(
83+
"-L", "--long-name",
84+
action="store_true",
85+
dest="lkey",
86+
default=False,
87+
help="Force folder names to use long-key form (NET.STN.CHN). " +
88+
"Default behaviour uses short key form (NET.STN) for the folder " +
89+
"names, regardless of the key type of the database."
90+
)
8291

8392
LineGroup = parser.add_argument_group(
8493
title='Line Geometry Settings',
@@ -286,8 +295,8 @@ def get_ccp_arguments(argv=None):
286295
action="store",
287296
dest="weights",
288297
default=None,
289-
help="Option to define weights for each of the three phases: "+
290-
"Ps, Pps and Pss, by specifying three comma-separated floats. "+
298+
help="Option to define weights for each of the three phases: " +
299+
"Ps, Pps and Pss, by specifying three comma-separated floats. " +
291300
"[Default 1., 3., -3.]")
292301

293302
FigGroup = parser.add_argument_group(
@@ -430,26 +439,10 @@ def main():
430439
args = get_ccp_arguments()
431440

432441
# Load Database
433-
# stdb=0.1.4
434-
try:
435-
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
436-
437-
# stdb=0.1.3
438-
except:
439-
db = stdb.io.load_db(fname=args.indb)
440-
441-
# Construct station key loop
442-
allkeys = db.keys()
443-
sorted(allkeys)
444-
445-
# Extract key subset
446-
if len(args.stkeys) > 0:
447-
stkeys = []
448-
for skey in args.stkeys:
449-
stkeys.extend([s for s in allkeys if skey in s])
450-
else:
451-
stkeys = db.keys()
452-
sorted(stkeys)
442+
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
443+
444+
# Track processed folders
445+
procfold = []
453446

454447
if args.load:
455448

@@ -468,9 +461,9 @@ def main():
468461
print("|-----------------------------------------------|")
469462
print("| Gridding: ")
470463
print("| start = {0:5.1f},{1:6.1f}".format(
471-
args.coord_start[0],args.coord_start[1]))
464+
args.coord_start[0], args.coord_start[1]))
472465
print("| end = {0:5.1f},{1:6.1f}".format(
473-
args.coord_end[0],args.coord_end[1]))
466+
args.coord_end[0], args.coord_end[1]))
474467
print("| dz = {0} (km)".format(str(args.dz)))
475468
print("| dx = {0} (km)".format(str(args.dx)))
476469
print()
@@ -486,13 +479,24 @@ def main():
486479
# Extract station information from dictionary
487480
sta = db[stkey]
488481

482+
# Construct Folder Name
483+
stfld = stkey
484+
if not args.lkey:
485+
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]
486+
487+
# Check for folder already processed
488+
if stfld in procfold:
489+
print('{0} already processed...skipping '.format(stfld))
490+
continue
491+
489492
# Define path to see if it exists
490493
if args.phase in ['P', 'PP', 'allP']:
491-
datapath = Path('P_DATA') / stkey
494+
datapath = Path('P_DATA') / stfld
492495
elif args.phase in ['S', 'SKS', 'allS']:
493-
datapath = Path('S_DATA') / stkey
496+
datapath = Path('S_DATA') / stfld
494497
if not datapath.is_dir():
495-
print('Path to ' + str(datapath) + ' doesn`t exist - continuing')
498+
print('Path to ' + str(datapath) +
499+
' doesn`t exist - continuing')
496500
continue
497501

498502
# Temporary print locations
@@ -565,11 +569,14 @@ def main():
565569

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

571575
ccpimage.add_rfstream(rfRstream)
572576

577+
# Update processed folders
578+
procfold.append(stfld)
579+
573580
if len(ccpimage.radialRF) > 0:
574581
ccpimage.save("CCP_load.pkl")
575582
ccpimage.is_ready_for_prep = True
@@ -606,7 +613,7 @@ def main():
606613
print("| nslow = {0}".format(str(args.nslow)))
607614
print()
608615

609-
ccpfile = open(load_file,"rb")
616+
ccpfile = open(load_file, "rb")
610617
ccpimage = pickle.load(ccpfile)
611618
ccpfile.close()
612619
ccpimage.prep_data(f1=args.f1, f2ps=args.f2ps,
@@ -620,7 +627,6 @@ def main():
620627
else:
621628
pass
622629

623-
624630
if args.prestack:
625631

626632
prestack_file = Path("CCP_prestack.pkl")
@@ -693,7 +699,7 @@ def main():
693699

694700
if args.ccp_figure:
695701
ccpimage.plot_ccp(save=args.save_figure, fmt=args.fmt,
696-
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
702+
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
697703

698704
else:
699705
pass
@@ -741,7 +747,7 @@ def main():
741747

742748
if args.ccp_figure:
743749
ccpimage.plot_gccp(save=args.save_figure, fmt=args.fmt,
744-
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
750+
vmin=-1.*args.cbound, vmax=args.cbound, title=args.title)
745751

746752
else:
747753
pass

Scripts/rfpy_harmonics.py

+33-25
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from os.path import exists as exist
3636
from numpy import nan
3737

38+
3839
def get_harmonics_arguments(argv=None):
3940
"""
4041
Get Options from :class:`~optparse.OptionParser` objects.
@@ -78,6 +79,15 @@ def get_harmonics_arguments(argv=None):
7879
default=False,
7980
help="Force the overwriting of pre-existing data. " +
8081
"[Default False]")
82+
parser.add_argument(
83+
"-L", "--long-name",
84+
action="store_true",
85+
dest="lkey",
86+
default=False,
87+
help="Force folder names to use long-key form (NET.STN.CHN). " +
88+
"Default behaviour uses short key form (NET.STN) for the folder " +
89+
"names, regardless of the key type of the database."
90+
)
8191

8292
# Event Selection Criteria
8393
TimeGroup = parser.add_argument_group(
@@ -320,7 +330,6 @@ def get_harmonics_arguments(argv=None):
320330
return args
321331

322332

323-
324333
def main():
325334

326335
print()
@@ -340,40 +349,30 @@ def main():
340349
args = get_harmonics_arguments()
341350

342351
# Load Database
343-
# stdb=0.1.4
344-
try:
345-
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
346-
347-
# stdb=0.1.3
348-
except:
349-
db = stdb.io.load_db(fname=args.indb)
350-
351-
# Construct station key loop
352-
allkeys = db.keys()
353-
sorted(allkeys)
354-
355-
# Extract key subset
356-
if len(args.stkeys) > 0:
357-
stkeys = []
358-
for skey in args.stkeys:
359-
stkeys.extend([s for s in allkeys if skey in s])
360-
else:
361-
stkeys = db.keys()
362-
sorted(stkeys)
352+
db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys)
353+
354+
# Track processed folders
355+
procfold = []
363356

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

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

363+
# Construct Folder Name
364+
stfld = stkey
365+
if not args.lkey:
366+
stfld = stkey.split('.')[0]+"."+stkey.split('.')[1]
367+
370368
# Define path to see if it exists
371369
if args.phase in ['P', 'PP', 'allP']:
372-
datapath = Path('P_DATA') / stkey
370+
datapath = Path('P_DATA') / stfld
373371
elif args.phase in ['S', 'SKS', 'allS']:
374-
datapath = Path('S_DATA') / stkey
372+
datapath = Path('S_DATA') / stfld
375373
if not datapath.is_dir():
376-
print('Path to ' + str(datapath) + ' doesn`t exist - continuing')
374+
print('Path to ' + str(datapath) +
375+
' doesn`t exist - continuing')
377376
continue
378377

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

423+
# Check for folder already processed
424+
if stfld in procfold:
425+
print(' {0} already processed...skipping '.format(stfld))
426+
continue
427+
424428
rfRstream = Stream()
425429
rfTstream = Stream()
426430

@@ -443,7 +447,8 @@ def main():
443447
if filename.is_file():
444448
file = open(filename, "rb")
445449
rfdata = pickle.load(file)
446-
if rfdata[0].stats.snrh > args.snrh and rfdata[0].stats.snr and \
450+
if rfdata[0].stats.snrh > args.snrh and \
451+
rfdata[0].stats.snr and \
447452
rfdata[0].stats.cc > args.cc:
448453

449454
rfRstream.append(rfdata[1])
@@ -513,6 +518,9 @@ def main():
513518
".harmonics.pkl")
514519
harmonics.save()
515520

521+
# Update processed folders
522+
procfold.append(stfld)
523+
516524

517525
if __name__ == "__main__":
518526

0 commit comments

Comments
 (0)