Skip to content

Commit 43692b5

Browse files
committed
added coherence subplot in tilt figure, cleaned up code base, and updated documentation
1 parent fa761b5 commit 43692b5

File tree

6 files changed

+53
-33
lines changed

6 files changed

+53
-33
lines changed

docs/atacr.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ Usage
487487
--debug Plot intermediate steps for debugging. [Default does not
488488
plot figure]
489489
--figAverage Plot daily average figure. [Default does not plot figure]
490-
--figCoh Plot Coherence and Phase figure. [Default does not plot
490+
--figTilt Plot coherence, phase and tilt direction figure. [Default does not plot
491491
figure]
492492
--figCross Plot cross-spectra figure. [Default does not plot figure]
493493
--save-fig Set this option if you wish to save the figure(s). [Default
@@ -1034,7 +1034,7 @@ therefore using all available data) and plot the results, we can type in a termi
10341034

10351035
.. code-block::
10361036
1037-
$ atacr_clean_spectra --figQC --figAverage --figCoh --figCross M08A.pkl
1037+
$ atacr_clean_spectra --figQC --figAverage --figTilt --figCross M08A.pkl
10381038
10391039
###################################################################
10401040
# _ _ #
@@ -1071,8 +1071,13 @@ therefore using all available data) and plot the results, we can type in a termi
10711071
10721072
...
10731073
1074-
And so on until all ``DayNoise`` objects are averaged into a ``StaNoise``
1075-
object, which is saved to a newly created folder called ``AVG_STA/7D.M08A/``.
1074+
* Clean station spectra saved to:
1075+
* AVG_STA/7D.M08A/2011.293-2012.200.avg_sta.pkl
1076+
1077+
* Tilt direction as function of time saved to:
1078+
* AVG_STA/7D.M08A/2011.293-2012.200.tilt.csv
1079+
1080+
The new ``StaNoise`` object and the daily tilt directions are saved to a newly created folder called ``AVG_STA/7D.M08A/``.
10761081

10771082
.. note ::
10781083
@@ -1095,9 +1100,13 @@ Several figures are also produced, including Figures 4, 6-9.
10951100

10961101
Figure 4: The orientation of maximum coherence between the vertical and the two
10971102
horizontal components for M08A during March 2012. (Left) Coherence as a function
1098-
of angle from the H1 component. (Right) Phase as a function of the angle. In this
1099-
example, the coherence is low indicating the absence of dominant, uni-directional tilt
1100-
noise.
1103+
of angle from the H1 component. (Right) Phase as a function of the angle.
1104+
(Bottom) Tilt direction measured from the H1 component as a function of time.
1105+
In this example, the coherence is low indicating low tilt noise.
1106+
1107+
.. note ::
1108+
1109+
In the MATLAB version of ``ATaCR``, the "Angle from H1" (Figure 4 in the manual) corresponds to a counter-clockwise rotation of H1 and H2, and the orientation is chosen at the lowest phase. Here, the angle corresponds to a clockwise rotation and the estimate is chosen to lie between 0 and 180 degrees. There is therefore a 225-degree difference between those two estimates, and the plots are mirrored.
11011110
11021111
.. figure:: ../obstools/examples/figures/Figure_6.png
11031112
:align: center

obstools/atacr/plotting.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,31 +267,37 @@ def fig_coh_ph(coh, ph, direc, tilt, date):
267267
mediantilt = np.median(tilt)
268268

269269
plt.rcParams['date.converter'] = 'concise'
270-
f = plt.figure()
271-
gs = GridSpec(3, 2, figure=f)
272-
ax1 = f.add_subplot(gs[0:-1, 0])
273-
ax2 = f.add_subplot(gs[0:-1, 1])
270+
f = plt.figure(layout='constrained')
271+
gs = GridSpec(4, 2, figure=f)
272+
ax1 = f.add_subplot(gs[0:-2, 0])
273+
ax2 = f.add_subplot(gs[0:-2, 1])
274274
ax3 = f.add_subplot(gs[2, :])
275+
ax4 = f.add_subplot(gs[3, :])
275276
ax3.axhline(
276-
np.mean(tilt),
277+
meantilt,
277278
ls='--',
278-
label='Mean: {0:.0f} $\pm$ {1:.1f}'.format(meantilt, stdetilt))
279+
label=r'Mean: {0:.0f} $\pm$ {1:.1f}'.format(meantilt, stdetilt))
279280
ax3.axhline(
280-
np.median(tilt),
281+
mediantilt,
281282
ls=':',
282-
label='Median: {0:.0f}'.format(np.median(tilt)))
283+
label='Median: {0:.0f}'.format(mediantilt))
283284
for i, (co, p, d, t) in enumerate(zip(coh, ph, date, tilt)):
285+
mcoh = np.max(co)
284286
ax1.plot(direc, co, c=colors[i])
285287
ax2.plot(direc, p*180./np.pi, c=colors[i])
286288
ax3.plot(d, t, 'o', c=colors[i])
287-
ax3.legend(loc='best', fontsize=8)
289+
ax4.plot(d, mcoh, 'o', c=colors[i])
288290
ax1.set_ylabel('Coherence Z-H1')
289291
ax1.set_ylim((0, 1.))
290-
ax2.set_ylabel('Phase Z-H1')
291-
ax3.set_ylabel('Tilt direction (deg)')
292292
ax1.set_xlabel('Angle clockwise from H1 (deg)')
293+
ax2.set_ylabel('Phase Z-H1')
293294
ax2.set_xlabel('Angle clockwise from H1 (deg)')
294-
plt.tight_layout()
295+
ax3.legend(loc='best', fontsize=8)
296+
ax3.set_xticklabels([])
297+
ax3.set_ylabel('Tilt dir. (deg)')
298+
ax3.set_ylim(-10, 190)
299+
ax4.set_ylabel('Coherence')
300+
ax4.set_ylim(-0.1, 1.1)
295301

296302
else:
297303
plt.figure()

obstools/atacr/utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def get_event(eventpath, tstart, tend):
304304
# Find out how many events from Z.SAC files
305305
eventfiles = list(eventpath.glob('*Z.SAC'))
306306
if not eventfiles:
307-
raise(Exception("No event found in folder "+str(eventpath)))
307+
raise Exception("No event found in folder "+str(eventpath))
308308

309309
# Extract events from time stamps
310310
prefix = [file.name.split('.') for file in eventfiles]
@@ -451,6 +451,8 @@ def calculate_tilt(ft1, ft2, ftZ, ftP, f, goodwins, tiltfreqs):
451451
tilt += 180.
452452
if tilt > 360.:
453453
tilt -= 360.
454+
if tilt > 180.:
455+
tilt -= 180.
454456

455457
# print('Tilt corrected = ', tilt)
456458

@@ -489,6 +491,8 @@ def calculate_tilt(ft1, ft2, ftZ, ftP, f, goodwins, tiltfreqs):
489491
tilt -= 360.
490492
elif tilt < 0:
491493
tilt += 360.
494+
if tilt > 180.:
495+
tilt -= 180.
492496

493497
# Now calculate spectra at tilt direction
494498
ftH = rotate_dir(ft1, ft2, tilt)
@@ -617,16 +621,14 @@ def phase(Gxy):
617621

618622
def rotate_dir(x, y, theta):
619623

620-
d = -theta*np.pi/180.
621-
rot_mat = [[np.cos(d), -np.sin(d)],
622-
[np.sin(d), np.cos(d)]]
624+
d = theta*np.pi/180.
625+
rot_mat = [[np.cos(d), np.sin(d)],
626+
[-np.sin(d), np.cos(d)]]
623627

624628
vxy = [x, y]
625629
vxy_rotated = np.tensordot(rot_mat, vxy, axes=1)
626-
tr_2 = vxy_rotated[0]
627-
tr_1 = vxy_rotated[1]
628630

629-
return tr_1
631+
return vxy_rotated[1]
630632

631633

632634
def ftest(res1, pars1, res2, pars2):
-18.1 KB
Loading

obstools/scripts/atacr_clean_spectra.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def get_cleanspec_arguments(argv=None):
166166
action="store_true",
167167
dest="fig_tilt",
168168
default=False,
169-
help="Plot Coherence, phase and tilt direction figure. " +
169+
help="Plot coherence, phase and tilt direction figure. " +
170170
"[Default does not plot figure]")
171171
FigureGroup.add_argument(
172172
"--figCross",
@@ -349,7 +349,7 @@ def main(args=None):
349349
dstart = str(tstart.year).zfill(4)+'.'+str(tstart.julday).zfill(3)+'-'
350350
dend = str(tend.year).zfill(4)+'.'+str(tend.julday).zfill(3)+'.'
351351
fileavst = avstpath / (dstart+dend+'avg_sta.pkl')
352-
filetilt = avstpath / (dstart+dend+'tilt.txt')
352+
filetilt = avstpath / (dstart+dend+'tilt.csv')
353353

354354
if fileavst.exists():
355355
if not args.ovr:
@@ -387,6 +387,7 @@ def main(args=None):
387387
# Date + tilt list
388388
date_list = []
389389
tilt_list = []
390+
coh_list = []
390391

391392
# Loop through each day withing time range
392393
while t1 < tend:
@@ -408,6 +409,7 @@ def main(args=None):
408409
file.close()
409410
tilt_list.append(daynoise.rotation.tilt)
410411
date_list.append(t1.date)
412+
coh_list.append(daynoise.rotation.coh_value)
411413
stanoise += daynoise
412414
else:
413415
t1 += 3600.*24.
@@ -624,13 +626,14 @@ def main(args=None):
624626

625627
# Write out events
626628
print()
627-
print("* Tilt direction as function of time saved to: ")
629+
print("* Tilt direction and coherence as function of time saved to: ")
628630
print("* "+str(filetilt))
629631
print()
630632
fid = open(filetilt, 'w')
631-
fid.writelines("Date, Tilt azimuth (deg from H1)\n")
633+
fid.writelines("Date, Tilt dir. (deg from H1), Max coherehce\n")
632634
for i in range(len(tilt_list)):
633-
line1 = "{0},{1:.0f}\n".format(date_list[i], tilt_list[i])
635+
line1 = "{0},{1:.0f},{2:.2f}\n".format(
636+
date_list[i], tilt_list[i], coh_list[i])
634637
fid.writelines(line1.replace(" ", ""))
635638
fid.close()
636639

obstools/scripts/atacr_download_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def main(args=None):
414414
while t2 <= tend:
415415

416416
# Time stamp
417-
tstamp = str(t1.year).zfill(4)+'.'+str(t1.julday).zfill(3)+'.'
417+
tstamp = str(t1.year).zfill(4)+'.'+str(t1.julday).zfill(3)
418418

419419
print("\n"+"*"*60)
420420
print("* Downloading day-long data for key {0} and day {1}.{2:03d}".format(
@@ -441,7 +441,7 @@ def main(args=None):
441441
t2 += dt
442442
continue
443443

444-
print("* "+tstamp +"*.SAC")
444+
print("* " + tstamp + ".*.SAC")
445445
# Get waveforms from client, one channel at a time
446446
try:
447447
cha = sta.channel.upper() + '1'

0 commit comments

Comments
 (0)