Skip to content

Commit

Permalink
getting rid of print() statements + cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed May 26, 2023
1 parent f9489e1 commit 6f160b1
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 218 deletions.
75 changes: 0 additions & 75 deletions .travis.yml

This file was deleted.

59 changes: 0 additions & 59 deletions appveyor.yml

This file was deleted.

6 changes: 5 additions & 1 deletion msnoise/plots/ccftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def main(sta1, sta2, filterid, components, mov_stack=1, ampli=5, seismic=False,

logger.info("Fetching CCF data for %s-%s-%i-%i" % (pair, components, filterid,
mov_stack))
stack_total = xr_get_ccf(sta1, sta2, components, filterid, mov_stack, taxis)
try:
stack_total = xr_get_ccf(sta1, sta2, components, filterid, mov_stack, taxis)
except FileNotFoundError as fullpath:
logger.error("FILE DOES NOT EXIST: %s, exiting" % fullpath)
sys.exit(1)

# convert index to mdates
stack_total.index = mdates.date2num(stack_total.index.to_pydatetime())
Expand Down
9 changes: 5 additions & 4 deletions msnoise/plots/data_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from ..api import *


def main(chan, show=False, outfile=None):
def main(chan, show=False, outfile=None, loglevel="INFO"):
logger = get_logger('msnoise.plot_da', loglevel,
with_pid=True)
db = connect()
start, end, datelist = build_movstack_datelist(db)
dates = []
Expand Down Expand Up @@ -68,11 +70,10 @@ def main(chan, show=False, outfile=None):
new = True
for di in data.groups[group]:
if new:
print(group, di)
logger.info("Loading: %s : %s" % (group, di))
new = False
dt = (di-start).days
matrix[i, dt] = 1
print(di)

gs = gridspec.GridSpec(2, 1, height_ratios=[4, 1])

Expand Down Expand Up @@ -105,7 +106,7 @@ def main(chan, show=False, outfile=None):
now = datetime.datetime.now()
now = now.strftime('data availability on %Y-%m-%d %H.%M.%S')
outfile = outfile.replace('?', now)
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)
if show:
plt.show()
8 changes: 5 additions & 3 deletions msnoise/plots/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


def main(filterid, components, ampli=1, show=True, outfile=None,
refilter=None, virtual_source=None, **kwargs):
logger = get_logger('msnoise.plotdistance_child', "DEBUG",
refilter=None, virtual_source=None, loglevel="INFO", **kwargs):
logger = get_logger('msnoise.plotdistance_child', loglevel,
with_pid=True)
db = connect()

Expand All @@ -49,6 +49,8 @@ def main(filterid, components, ampli=1, show=True, outfile=None,
# TODO get distance for LOCids!!
dist = get_interstation_distance(station1, station2,
station1.coordinates)
if dist == 0 and station1 != station2:
logger.warning("Distance is 0.0 km for %s.%s:%s.%s" % (station1.net, station1.sta, station2.net, station2.sta))
dists.append(dist)
for loc1 in station1.locs():
for loc2 in station2.locs():
Expand Down Expand Up @@ -106,7 +108,7 @@ def main(filterid, components, ampli=1, show=True, outfile=None,
newname = 'distance %s-f%i' % (components,
filterid)
outfile = outfile.replace('?', newname)
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)
if show:
plt.show()
12 changes: 7 additions & 5 deletions msnoise/plots/dtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@


def main(sta1, sta2, filterid, components, day, mov_stack=1, show=True,
outfile=None):
outfile=None, loglevel="INFO"):
logger = get_logger('msnoise.cc_dvv_plot_dtt', loglevel,
with_pid=True)
db = connect()
dtt_lag = get_config(db, "dtt_lag")
dtt_v = float(get_config(db, "dtt_v"))
dtt_minlag = float(get_config(db, "dtt_minlag"))
dtt_width = float(get_config(db, "dtt_width"))
dbmaxlag = int(float(get_config(db, "maxlag")))
if sta2 < sta1:
print("Stations STA1 STA2 should be sorted alphabetically")
logger.error("Stations STA1 STA2 should be sorted alphabetically")
return

sta1 = check_stations_uniqueness(db, sta1)
Expand All @@ -52,7 +54,7 @@ def main(sta1, sta2, filterid, components, day, mov_stack=1, show=True,

fname = os.path.join('MWCS', "%02i" % filterid, "%03i_DAYS" % mov_stack,
components, pair, '%s.txt' % day)
print(fname)

t = []
dt = []
err = []
Expand All @@ -73,7 +75,7 @@ def main(sta1, sta2, filterid, components, day, mov_stack=1, show=True,
alldf.append(df)
alldf = pd.concat(alldf)
line = alldf[alldf['Pairs'] == pair].copy()
print(line)

M = float(line["M"])
M0 = float(line["M0"])
A = float(line["A"])
Expand Down Expand Up @@ -123,7 +125,7 @@ def main(sta1, sta2, filterid, components, day, mov_stack=1, show=True,
mov_stack, day)
outfile = outfile.replace('?', basename)
outfile = "dtt_" + outfile
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)

if show:
Expand Down
2 changes: 1 addition & 1 deletion msnoise/plots/dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def main(mov_stack=None, dttname="M", components='ZZ', filterid=1,
filterid,
dttname))
outfile = "dvv " + outfile
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)
if show:
plt.show()
Expand Down
17 changes: 11 additions & 6 deletions msnoise/plots/interferogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@


def main(sta1, sta2, filterid, components, mov_stack=1, show=True,
outfile=None, refilter=None, **kwargs):
outfile=None, refilter=None, loglevel="INFO", **kwargs):
logger = get_logger('msnoise.cc_plot_interferogram', loglevel,
with_pid=True)
db = connect()
maxlag = float(get_config(db, 'maxlag'))
cc_sampling_rate = float(get_config(db, 'cc_sampling_rate'))
Expand All @@ -41,18 +43,21 @@ def main(sta1, sta2, filterid, components, mov_stack=1, show=True,
fig = plt.figure(figsize=(12, 9))

if sta2 < sta1:
print("Stations STA1 STA2 should be sorted alphabetically")
logger.error("Stations STA1 STA2 should be sorted alphabetically")
return

sta1 = check_stations_uniqueness(db, sta1)
sta2 = check_stations_uniqueness(db, sta2)

pair = "%s:%s" % (sta1, sta2)

print("New Data for %s-%s-%i-%i" % (pair, components, filterid,
logger.info("Fetching CCF data for %s-%s-%i-%i" % (pair, components, filterid,
mov_stack))

data = xr_get_ccf(sta1, sta2, components, filterid, mov_stack, taxis)
try:
data = xr_get_ccf(sta1, sta2, components, filterid, mov_stack, taxis)
except FileNotFoundError as fullpath:
logger.error("FILE DOES NOT EXIST: %s, exiting" % fullpath)
sys.exit(1)

xextent = (date2num(data.index[0]), date2num(data.index[-1]), -maxlag, maxlag)
ax = plt.subplot(111)
Expand Down Expand Up @@ -101,7 +106,7 @@ def main(sta1, sta2, filterid, components, mov_stack=1, show=True,
filterid,
mov_stack))
outfile = "interferogram " + outfile
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)
if show:
plt.show()
18 changes: 9 additions & 9 deletions msnoise/plots/mwcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


def main(sta1, sta2, filterid, components, mov_stack=1, show=True,
outfile=None):
outfile=None, loglevel='INFO'):
logger = get_logger('msnoise.cc_dvv_plot_mwcs', loglevel,
with_pid=True)
db = connect()
maxlag = float(get_config(db, 'maxlag'))
start, end, datelist = build_movstack_datelist(db)
Expand All @@ -49,7 +51,7 @@ def plot_lags(minlag, maxlag):
plt.axhline(-maxlag, c='g')

if sta2 < sta1:
print("Stations STA1 STA2 should be sorted alphabetically")
logger.error("Stations STA1 STA2 should be sorted alphabetically")
return

sta1 = check_stations_uniqueness(db, sta1)
Expand All @@ -67,12 +69,12 @@ def plot_lags(minlag, maxlag):
else:
minlag = get_interstation_distance(station1, station2,
station1.coordinates) / dtt_v
print(minlag)


maxlag2 = minlag + dtt_width

print("New Data for %s-%s-%i-%i" % (pair, components, filterid,
mov_stack))
logger.info("Fetching CCF data for %s-%s-%i-%i" % (pair, components, filterid,
mov_stack))

id = []
alldt = []
Expand All @@ -87,7 +89,6 @@ def plot_lags(minlag, maxlag):
allcoh.append(df["coh"])
id.append(day)
del df
print(len(alldt[0]))

alldt = pd.DataFrame(alldt, index=pd.DatetimeIndex(id))
allcoh = pd.DataFrame(allcoh, index=pd.DatetimeIndex(id))
Expand All @@ -113,8 +114,7 @@ def plot_lags(minlag, maxlag):
plt.title('%s : %s : dt' % (sta1, sta2))
plot_lags(minlag, maxlag2)
plt.setp(ax1.get_xticklabels(), visible=False)
print(type(alldt))
print(alldt)

plt.subplot(gs[1], sharey=ax1)
plt.plot(alldt.mean(axis=0), alldt.columns, c='k')
plt.grid()
Expand Down Expand Up @@ -166,7 +166,7 @@ def plot_lags(minlag, maxlag):
filterid,
mov_stack))
outfile = "mwcs " + outfile
print("output to: %s" % outfile)
logger.info("output to: %s" % outfile)
plt.savefig(outfile)
if show:
plt.show()

0 comments on commit 6f160b1

Please sign in to comment.