Skip to content

Commit

Permalink
Merge pull request #321 from asyates/master
Browse files Browse the repository at this point in the history
tidied error outputs
  • Loading branch information
ThomasLecocq committed Feb 7, 2024
2 parents efaa9d9 + da5b88a commit 4096d9e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
21 changes: 18 additions & 3 deletions msnoise/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2326,9 +2326,18 @@ def xr_save_dvv(components, filterid, mov_stack, dataframe):
"%s.nc" % components)
if not os.path.isdir(os.path.split(fn)[0]):
os.makedirs(os.path.split(fn)[0])
d = dataframe.stack().stack()
d.index = d.index.set_names(["times", "level1", "level0"])
d = d.reorder_levels(["times", "level0", "level1"])

if dataframe.columns.nlevels > 1:
d = dataframe.stack().stack()
else:
d = dataframe.stack()

level_names = ["times", "level1", "level0"]
d.index = d.index.set_names(level_names[:d.index.nlevels])

if d.index.nlevels == 3:
d = d.reorder_levels(["times", "level0", "level1"])

d.columns = ["DVV"]
# taxis = np.unique(d.index.get_level_values('taxis'))
dr = xr_create_or_open(fn, taxis=[], name="DVV")
Expand Down Expand Up @@ -2414,6 +2423,12 @@ def compute_dvv(session, filterid, mov_stack, pairs=None, components=None, param
comps = components.split(',')

for comp in comps:

if (s1 == s2) and (comp not in params.components_to_compute_single_station):
continue
if (s1 != s2) and (comp not in params.components_to_compute):
continue

try:
dtt = xr_get_dtt(s1, s2, comp, filterid, mov_stack)
all.append(dtt)
Expand Down
7 changes: 4 additions & 3 deletions msnoise/move2obspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def mwcs(current, reference, freqmin, freqmax, df, tmin, window_length, step,
time_axis = []

window_length_samples = int(window_length * df)
step_samples = int(step * df)
# try:
# from sf.helper import next_fast_len
# except ImportError:
Expand All @@ -434,8 +435,8 @@ def mwcs(current, reference, freqmin, freqmax, df, tmin, window_length, step,
cri = scipy.signal.detrend(cri, type='linear')
cri *= tp

minind += int(step * df)
maxind += int(step * df)
minind += step_samples
maxind += step_samples

fcur = sf.fft(cci, n=padd)[:padd // 2]
fref = sf.fft(cri, n=padd)[:padd // 2]
Expand Down Expand Up @@ -497,7 +498,7 @@ def mwcs(current, reference, freqmin, freqmax, df, tmin, window_length, step,

delta_err.append(e)
delta_mcoh.append(np.real(mcoh))
time_axis.append(tmin + window_length / 2. + count * step)
time_axis.append(tmin + window_length / 2. + count * (step_samples/df))
count += 1

del fcur, fref
Expand Down
11 changes: 7 additions & 4 deletions msnoise/s04_stack2.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ def main(stype, interval=1.0, loglevel="INFO"):
sta1, sta2 = pair.split(':')
for f in filters:
filterid = int(f.ref)
for components in params.all_components:
pair = "%s:%s" % (sta1, sta2)
sta1 = sta1
sta2 = sta2

if sta1 == sta2:
components_to_compute = params.components_to_compute_single_station
else:
components_to_compute = params.components_to_compute

for components in components_to_compute:
logger.info('Processing %s-%s-%i' %
(pair, components, filterid))

Expand Down
14 changes: 10 additions & 4 deletions msnoise/s05compute_mwcs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,16 @@ def ww(a):
n = next_fast_len(len(a))
return whiten(a, n, 1./params.cc_sampling_rate,
low, high, returntime=True)
for components in params.all_components:
ref_name = pair.replace(':', '_')
station1, station2 = pair.split(":")
ref_name = pair.replace(':', '_')
station1, station2 = pair.split(":")

if station1 == station2:
components_to_compute = params.components_to_compute_single_station
else:
components_to_compute = params.components_to_compute


for components in components_to_compute:
try:
ref = xr_get_ref(station1, station2, components, filterid, taxis)
ref = ref.CCF.values
Expand Down Expand Up @@ -325,4 +331,4 @@ def ww(a):
if not params.hpc:
for job in jobs:
update_job(db, job.day, job.pair, 'DTT', 'T')
logger.info('*** Finished: Compute MWCS ***')
logger.info('*** Finished: Compute MWCS ***')
9 changes: 7 additions & 2 deletions msnoise/s06compute_dtt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def main(interval=1, loglevel="INFO"):
filterid = int(f.ref)
freqmin = f.mwcs_low
freqmax = f.mwcs_high
for components in params.all_components:
if station1 == station2:
components_to_compute = params.components_to_compute_single_station
else:
components_to_compute = params.components_to_compute

for components in components_to_compute:
for mov_stack in mov_stacks:
output = []
try:
Expand Down Expand Up @@ -146,4 +151,4 @@ def main(interval=1, loglevel="INFO"):

massive_update_job(db, jobs, "D")

logger.info('*** Finished: Compute DTT ***')
logger.info('*** Finished: Compute DTT ***')
2 changes: 2 additions & 0 deletions msnoise/s07_compute_dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def main(interval=1, loglevel="INFO"):
continue
xr_save_dvv("ALL", filterid, mov_stack, dvv)
del dvv

logger.info('*** Finished: Compute DV/V ***')


if __name__ == "__main__":
Expand Down

0 comments on commit 4096d9e

Please sign in to comment.