Skip to content

Commit 9923d06

Browse files
committed
handling of tstart with only complete days; cleanup of scripts
1 parent ca45367 commit 9923d06

File tree

7 files changed

+92
-104
lines changed

7 files changed

+92
-104
lines changed

obstools/scripts/atacr_clean_spectra.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ def get_cleanspec_arguments(argv=None):
229229
args.pd = [float(val) for val in args.pd.split(',')]
230230
args.pd = sorted(args.pd)
231231
if (len(args.pd)) != 2:
232-
raise(Exception(
232+
raise Exception(
233233
"Error: --freq-band should contain 2 " +
234-
"comma-separated floats"))
234+
"comma-separated floats")
235235

236236
return args
237237

@@ -285,9 +285,9 @@ def main(args=None):
285285
# Path where spectra are located
286286
specpath = Path('SPECTRA') / stkey
287287
if not specpath.is_dir():
288-
raise(Exception(
288+
raise Exception(
289289
"Path to " + str(specpath) +
290-
" doesn`t exist - aborting"))
290+
" doesn`t exist - aborting")
291291

292292
# Path where average spectra will be saved
293293
avstpath = Path('AVG_STA') / stkey
@@ -564,6 +564,7 @@ def main(args=None):
564564
plot.savefig(
565565
str(plotpath / (fname + '.' + args.form)),
566566
dpi=300, bbox_inches='tight', format=args.form)
567+
plot.close()
567568
else:
568569
plot.show()
569570

@@ -581,6 +582,7 @@ def main(args=None):
581582
plot.savefig(
582583
str(plotpath / (fname + '.' + args.form)),
583584
dpi=300, bbox_inches='tight', format=args.form)
585+
plot.close()
584586
else:
585587
plot.show()
586588

@@ -599,6 +601,7 @@ def main(args=None):
599601
plot.savefig(
600602
str(plotpath / (fname + '.' + args.form)),
601603
dpi=300, bbox_inches='tight', format=args.form)
604+
plot.close()
602605
else:
603606
plot.show()
604607

@@ -615,6 +618,7 @@ def main(args=None):
615618
plot.savefig(
616619
str(plotpath / (fname + '.' + args.form)),
617620
dpi=300, bbox_inches='tight', format=args.form)
621+
plot.close()
618622
else:
619623
plot.show()
620624

@@ -630,9 +634,9 @@ def main(args=None):
630634
print("* "+str(filetilt))
631635
print()
632636
fid = open(filetilt, 'w')
633-
fid.writelines("Date, Tilt dir. (deg from H1), Max coherehce\n")
637+
fid.writelines("Date, Tilt dir. (deg CW from H1), Max coherence\n")
634638
for i in range(len(tilt_list)):
635-
line1 = "{0},{1:.0f},{2:.2f}\n".format(
639+
line1 = "{0},{1:4.1f},{2:4.2f}\n".format(
636640
date_list[i], tilt_list[i], coh_list[i])
637641
fid.writelines(line1.replace(" ", ""))
638642
fid.close()

obstools/scripts/atacr_correct_event.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ def main(args=None):
271271
# Path where transfer functions will be located
272272
transpath = Path('TF_STA') / stkey
273273
if not transpath.is_dir():
274-
raise(Exception("Path to "+str(transpath) +
275-
" doesn`t exist - aborting"))
274+
raise Exception("Path to "+str(transpath) +
275+
" doesn`t exist - aborting")
276276

277277
# Path where event data are located
278278
eventpath = Path('EVENTS') / stkey
279279
if not eventpath.is_dir():
280-
raise(Exception("Path to "+str(eventpath) +
281-
" doesn`t exist - aborting"))
280+
raise Exception("Path to "+str(eventpath) +
281+
" doesn`t exist - aborting")
282282

283283
# Path where plots will be saved
284284
if args.saveplot:
@@ -341,8 +341,8 @@ def main(args=None):
341341

342342
# Check if folders contain anything
343343
if not trans_files:
344-
raise(Exception("There are no transfer functions in folder " +
345-
str(transpath)))
344+
raise Exception("There are no transfer functions in folder " +
345+
str(transpath))
346346

347347
# Cycle through available data
348348
for tr1, tr2, trZ, trP in zip(trE1, trE2, trEZ, trEP):

obstools/scripts/atacr_daily_spectra.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ def get_dailyspec_arguments(argv=None):
281281
args.pd = [float(val) for val in args.pd.split(',')]
282282
args.pd = sorted(args.pd)
283283
if (len(args.pd)) != 2:
284-
raise(Exception(
284+
raise Exception(
285285
"Error: --flag-freqs should contain 2 " +
286-
"comma-separated floats"))
286+
"comma-separated floats")
287287

288288
# Check input frequency band
289289
if args.tf is None:
@@ -292,9 +292,9 @@ def get_dailyspec_arguments(argv=None):
292292
args.tf = [float(val) for val in args.tf.split(',')]
293293
args.tf = sorted(args.tf)
294294
if (len(args.pd)) != 2:
295-
raise(Exception(
295+
raise Exception(
296296
"Error: --tilt-freqs should contain 2 " +
297-
"comma-separated floats"))
297+
"comma-separated floats")
298298

299299
return args
300300

obstools/scripts/atacr_download_data.py

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def main(args=None):
331331
# Define path to see if it exists
332332
datapath = Path('DATA') / Path(stkey)
333333
if not datapath.is_dir():
334-
print("\nPath to "+str(datapath)+
334+
print("\nPath to "+str(datapath) +
335335
" doesn't exist - creating it")
336336
datapath.mkdir(parents=True)
337337

@@ -362,6 +362,8 @@ def main(args=None):
362362
else:
363363
tstart = args.startT
364364

365+
tstart = UTCDateTime(tstart.year, tstart.month, tstart.day)
366+
365367
# Get catalogue search end time
366368
if args.endT is None:
367369
tend = sta.enddate
@@ -458,17 +460,14 @@ def main(args=None):
458460
dum = st1.select(component='1')[0]
459461
print("* ...done")
460462
except Exception:
461-
print("* Warning: Component "+cha+" not found. Continuing")
462-
t1 += dt
463-
t2 += dt
464-
continue
463+
print("* Warning: Component " + cha + " not found. " +
464+
"Continuing")
465+
pass
465466

466467
except Exception:
467-
print(" Client exception: Unable to download "+cha+" component. "+
468-
"Continuing")
469-
t1 += dt
470-
t2 += dt
471-
continue
468+
print(" Client exception: Unable to download " + cha +
469+
" component. Continuing")
470+
pass
472471

473472
try:
474473
cha = sta.channel.upper() + '2'
@@ -485,18 +484,15 @@ def main(args=None):
485484
dum = st2.select(component='2')[0]
486485
print("* ...done")
487486
except Exception:
488-
print("* Warning: Component "+cha+" not found. Continuing")
489-
t1 += dt
490-
t2 += dt
491-
continue
487+
print("* Warning: Component " + cha + " not found. " +
488+
"Continuing")
489+
pass
492490

493491
except Exception:
494-
print(" Client exception: Unable to download "+cha+" component. "+
495-
"Continuing")
496-
t1 += dt
497-
t2 += dt
498-
continue
499-
492+
print(" Client exception: Unable to download " + cha +
493+
" component. Continuing")
494+
pass
495+
500496
try:
501497
cha = sta.channel.upper() + args.zcomp
502498
print("* -> Downloading "+cha+" data... ")
@@ -512,19 +508,14 @@ def main(args=None):
512508
dum = stz.select(component=args.zcomp)[0]
513509
print("* ...done")
514510
except Exception:
515-
print("* Warning: Component "+cha+" not found. "+
516-
"Continuing")
517-
t1 += dt
518-
t2 += dt
519-
continue
511+
print("* Warning: Component " + cha + " not found. " +
512+
"Continuing")
520513

521514
except Exception:
522-
print(" Client exception: Unable to download "+cha+
515+
print(" Client exception: Unable to download " + cha +
523516
" component. Try setting `--zcomp`. Continuing.")
524-
t1 += dt
525-
t2 += dt
526-
continue
527-
517+
pass
518+
528519
try:
529520
print("* -> Downloading ?DH data...")
530521
stp = client.get_waveforms(
@@ -548,19 +539,21 @@ def main(args=None):
548539
dum = stp.select(component='H')[0]
549540
print("* ...done")
550541
except Exception:
551-
print("* Warning: Component ?DH not found. Continuing")
552-
t1 += dt
553-
t2 += dt
554-
continue
542+
print("* Warning: Component ?DH not found. " +
543+
"Continuing")
555544

556545
except Exception:
557-
print(" Client exception: Unable to download ?DH component. "+
546+
print(" Client exception: Unable to download ?DH component. " +
558547
"Continuing")
559-
t1 += dt
560-
t2 += dt
561-
continue
548+
pass
562549

563-
st = st1.merge() + st2.merge() + stz.merge() + stp.merge()
550+
st = (st1.merge(fill_value='latest') +
551+
st2.merge(fill_value='latest') +
552+
stz.merge(fill_value='latest') +
553+
stp.merge(fill_value='latest'))
554+
if len(st) < 2:
555+
raise Exception("Error: number of available traces is: " +
556+
str(len(st)))
564557

565558
# Detrend, filter
566559
st.detrend('demean')

0 commit comments

Comments
 (0)