def populate(fromda): """Rapidly scan the archive filenames and find Network/Stations""" if fromda: logging.info("Overriding workflow...") from ..msnoise_table_def import DataAvailability from ..api import update_station db = connect() stations = db.query(DataAvailability.net, DataAvailability.sta). \ group_by(DataAvailability.net, DataAvailability.sta) for net, sta in stations: print('Adding:', net, sta) X = 0.0 Y = 0.0 altitude = 0.0 coordinates = 'UTM' instrument = 'N/A' update_station(db, net, sta, X, Y, altitude, coordinates=coordinates, instrument=instrument) else: from ..s002populate_station_table import main main()
def station_map(ctx, show, outfile): """Plots the station map (very very basic)""" if ctx.obj['MSNOISE_custom']: from station_map import main else: from ..plots.station_map import main main(show, outfile)
def scan_archive(ctx, init, path, recursively): """Scan the archive and insert into the Data Availability table.""" if path: logging.info("Overriding workflow...") from obspy import UTCDateTime from ..s01scan_archive import worker db = connect() startdate = UTCDateTime(get_config(db, "startdate")) enddate = UTCDateTime(get_config(db, "enddate")) cc_sampling_rate = float(get_config(db, "cc_sampling_rate")) db.close() if recursively: for root, dirs, _ in os.walk(path): for d in dirs: tmppath = os.path.join(root, d) _ = os.listdir(tmppath) if not len(_): continue worker(sorted(_), tmppath, startdate, enddate, cc_sampling_rate, init=True) worker(sorted(os.listdir(path)), path, startdate, enddate, cc_sampling_rate, init=True) else: from ..s01scan_archive import main main(init, threads=ctx.obj['MSNOISE_threads'])
def install(): """DEPRECATED: This command launches the installer.""" click.echo( 'DEPRECATED command since MSNoise 1.6, please use "msnoise init"' ' instead') from ..s000installer import main main()
def data_availability(ctx, show, outfile): """Plots the Data Availability vs time""" if ctx.obj['MSNOISE_custom']: from data_availability import main else: from ..plots.data_availability import main main(show, outfile)
def config_gui(): """ Run the deprecated configuration GUI tool. Please use the configuration web interface using 'msnoise admin' instead. """ from ..s001configurator import main click.echo("Let's Configure MSNoise !") main()
def distance(ctx, filterid, comp, ampli, show, outfile, refilter, virtual_source): """Plots the REFs of all pairs vs distance""" if ctx.obj['MSNOISE_custom']: from distance import main else: from ..plots.distance import main main(filterid, comp, ampli, show, outfile, refilter, virtual_source)
def mwcs(ctx, sta1, sta2, filterid, comp, mov_stack, show, outfile): """Plots the mwcs results between sta1 and sta2 (parses the CCFs)\n STA1 and STA2 must be provided with this format: NET.STA !""" if ctx.obj['MSNOISE_custom']: from mwcs import main else: from ..plots.mwcs import main main(sta1, sta2, filterid, comp, mov_stack, show, outfile)
def interferogram(ctx, sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter): """Plots the interferogram between sta1 and sta2 (parses the CCFs)\n STA1 and STA2 must be provided with this format: NET.STA !""" if ctx.obj['MSNOISE_custom']: from interferogram import main else: from ..plots.interferogram import main main(sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter)
def dtt(ctx, sta1, sta2, filterid, day, comp, mov_stack, show, outfile): """Plots a graph of dt against t\n STA1 and STA2 must be provided with this format: NET.STA !\n DAY must be provided in the ISO format: YYYY-MM-DD""" if ctx.obj['MSNOISE_custom']: from dtt import main else: from ..plots.dtt import main main(sta1, sta2, filterid, comp, day, mov_stack, show, outfile)
def ccftime(ctx, sta1, sta2, filterid, comp, mov_stack, ampli, seismic, show, outfile, envelope, refilter): """Plots the ccf vs time between sta1 and sta2 (parses the dt/t results)\n STA1 and STA2 must be provided with this format: NET.STA !""" if ctx.obj['MSNOISE_custom']: from ccftime import main else: from ..plots.ccftime import main main(sta1, sta2, filterid, comp, mov_stack, ampli, seismic, show, outfile, envelope, refilter)
def config(set, sync): """This command should now only be used to use the command line to set a parameter value in the data base. It used to launch the Configurator but the recommended way to configure MSNoise is to use the "msnoise admin" web interface.""" if set: from ..default import default if not set.count("="): click.echo("!! format of the set command is name=value !!") return name, value = set.split("=") if name not in default: click.echo("!! unknown parameter %s !!" % name) return from ..api import connect, update_config db = connect() update_config(db, name, value) db.commit() db.close() click.echo("Successfully updated parameter %s = %s" % (name, value)) elif sync: import glob from ..api import connect, get_config, get_stations, update_station,\ preload_instrument_responses db = connect() responses = preload_instrument_responses(db) netsta = [] for id, row in responses.iterrows(): net, sta, loc, chan = row["channel_id"].split(".") netsta.append("%s.%s" % (net, sta)) responses["netsta"] = netsta for station in get_stations(db): id = "%s.%s" % (station.net, station.sta) coords = responses[responses["netsta"] == id] lon = float(coords["longitude"].values[0]) lat = float(coords["latitude"].values[0]) update_station( db, station.net, station.sta, lon, lat, 0, "DEG", ) logging.info("Added coordinates (%.5f %.5f) for station %s.%s" % (lon, lat, station.net, station.sta)) db.close() else: from ..s001configurator import main click.echo('Let\'s Configure MSNoise !') main()
def mwcs(ctx, sta1, sta2, filterid, comp, mov_stack, show, outfile): """Plots the mwcs results between sta1 and sta2 (parses the CCFs)\n STA1 and STA2 must be provided with this format: NET.STA !""" if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from mwcs import main else: from ..plots.mwcs import main main(sta1, sta2, filterid, comp, mov_stack, show, outfile)
def distance(ctx, filterid, comp, ampli, show, outfile, refilter, virtual_source, extra_args): """Plots the REFs of all pairs vs distance""" if ctx.obj['MSNOISE_custom']: from distance import main else: from ..plots.distance import main main(filterid, comp, ampli, show, outfile, refilter, virtual_source, **extra_args)
def dtt(ctx, sta1, sta2, filterid, day, comp, mov_stack, show, outfile): """Plots a graph of dt against t\n STA1 and STA2 must be provided with this format: NET.STA !\n DAY must be provided in the ISO format: YYYY-MM-DD""" if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from dtt import main else: from ..plots.dtt import main main(sta1, sta2, filterid, comp, day, mov_stack, show, outfile)
def spectime(ctx, sta1, sta2, filterid, comp, mov_stack, ampli, show, outfile, refilter): """Plots the ccf's spectrum vs time between sta1 and sta2\n STA1 and STA2 must be provided with this format: NET.STA !""" if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from spectime import main else: from ..plots.spectime import main main(sta1, sta2, filterid, comp, mov_stack, ampli, show, outfile, refilter)
def timing(ctx, mov_stack, comp, dttname, filterid, pair, all, show, outfile): """Plots the timing (parses the dt/t results)\n Individual pairs can be plotted extra using the -p flag one or more times.\n Example: msnoise plot timing -p ID_KWUI_ID_POSI\n Example: msnoise plot timing -p ID_KWUI_ID_POSI -p ID_KWUI_ID_TRWI\n Remember to order stations alphabetically ! """ if ctx.obj['MSNOISE_custom']: from timing import main else: from ..plots.timing import main main(mov_stack, dttname, comp, filterid, pair, all, show, outfile)
def new_jobs(init, nocc, hpc=""): """Determines if new CC jobs are to be defined""" if not hpc: from ..s02new_jobs import main main(init, nocc) if hpc: from ..api import connect left, right = hpc.split(":") db = connect() db.execute( "INSERT INTO jobs (pair, day, jobtype, flag) SELECT pair, day, '%s', 'T' from jobs where jobtype='%s' and flag='D';" % (right, left)) db.commit() db.close()
def ccftime(ctx, sta1, sta2, filterid, comp, mov_stack, ampli, seismic, show, outfile, envelope, refilter, extra_args): """Plots the ccf vs time between sta1 and sta2\n STA1 and STA2 must be provided with this format: NET.STA !""" if extra_args: extra_args = parse_extra_args(extra_args) if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from ccftime import main else: from ..plots.ccftime import main main(sta1, sta2, filterid, comp, mov_stack, ampli, seismic, show, outfile, envelope, refilter, **extra_args)
def spectime(ctx, sta1, sta2, filterid, comp, mov_stack, ampli, show, outfile, refilter, extra_args): """Plots the ccf's spectrum vs time between sta1 and sta2\n STA1 and STA2 must be provided with this format: NET.STA !""" if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from spectime import main else: from ..plots.spectime import main main(sta1, sta2, filterid, comp, mov_stack, ampli, show, outfile, refilter, **extra_args)
def interferogram(ctx, sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter, extra_args): """Plots the interferogram between sta1 and sta2 (parses the CCFs)\n STA1 and STA2 must be provided with this format: NET.STA !""" if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from interferogram import main else: from ..plots.interferogram import main main(sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter, **extra_args)
def interferogram(ctx, sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter, extra_args): """Plots the interferogram between sta1 and sta2 (parses the CCFs)\n STA1 and STA2 must be provided with this format: NET.STA !""" if extra_args: extra_args = parse_extra_args(extra_args) if sta1 > sta2: click.echo("Stations STA1 and STA2 must be sorted alphabetically.") return if ctx.obj['MSNOISE_custom']: from interferogram import main else: from ..plots.interferogram import main main(sta1, sta2, filterid, comp, mov_stack, show, outfile, refilter, **extra_args)
def compute_cc2(ctx): """Computes the CC jobs (based on the "New Jobs" identified)""" from ..s03compute_no_rotation import main from multiprocessing import Process threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] if threads == 1: main() else: processes = [] for i in range(threads): p = Process(target=main) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def new_jobs(init, nocc, hpc=""): """Determines if new CC jobs are to be defined""" if not hpc: from ..s02new_jobs import main main(init, nocc) if hpc: from ..api import connect, read_db_inifile dbini = read_db_inifile() prefix = (dbini.prefix + '_') if dbini.prefix != '' else '' left, right = hpc.split(':') db = connect() db.execute("INSERT INTO {prefix}jobs (pair, day, jobtype, flag) " "SELECT pair, day, '{right_type}', 'T' FROM {prefix}jobs " "WHERE jobtype='{left_type}' AND flag='D';" .format(prefix=prefix, right_type=right, left_type=left)) db.commit() db.close()
def compute_mwcs(ctx): """Computes the MWCS based on the new stacked data""" from ..s05compute_mwcs import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] if threads == 1: main() else: from multiprocessing import Process processes = [] for i in range(threads): p = Process(target=main) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def new_jobs(init, nocc, hpc=""): """Determines if new CC jobs are to be defined""" if not hpc: from ..s02new_jobs import main main(init, nocc) if hpc: from ..api import connect, read_db_inifile dbini = read_db_inifile() prefix = (dbini.prefix + '_') if dbini.prefix != '' else '' left, right = hpc.split(':') db = connect() db.execute("INSERT INTO {prefix}jobs (pair, day, jobtype, flag) " "SELECT pair, day, '{right_type}', 'T' FROM {prefix}jobs " "WHERE jobtype='{left_type}' AND flag='D';".format( prefix=prefix, right_type=right, left_type=left)) db.commit() db.close()
def compute_cc2(ctx): """Computes the CC jobs (based on the "New Jobs" identified)""" from ..s03compute_no_rotation import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] loglevel = ctx.obj['MSNOISE_verbosity'] if threads == 1: main(loglevel=loglevel) else: from multiprocessing import Process processes = [] for i in range(threads): p = Process(target=main, kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def compute_dtt(ctx, interval): """Computes the dt/t jobs based on the new MWCS data""" from ..s06compute_dtt import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] loglevel = ctx.obj['MSNOISE_verbosity'] if threads == 1: main(loglevel=loglevel) else: from multiprocessing import Process processes = [] for i in range(threads): p = Process(target=main, kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def compute_cc(ctx): """Computes the CC jobs (based on the "New Jobs" identified)""" from ..s03compute_cc import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] loglevel = ctx.obj['MSNOISE_verbosity'] if threads == 1: main(loglevel=loglevel) else: from multiprocessing import Process processes = [] for i in range(threads): p = Process(target=main, kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def populate(fromda): """Rapidly scan the archive filenames and find Network/Stations""" if fromda: logging.info("Overriding workflow...") db = connect() stations = db.query(DataAvailability.net, DataAvailability.sta). \ group_by(DataAvailability.net, DataAvailability.sta) for net, sta in stations: print('Adding:', net, sta) X = 0.0 Y = 0.0 altitude = 0.0 coordinates = 'UTM' instrument = 'N/A' update_station(db, net, sta, X, Y, altitude, coordinates=coordinates, instrument=instrument) else: from ..s002populate_station_table import main main()
def stack(ctx, ref, mov, step): """Stacks the [REF] and/or [MOV] windows""" click.secho('Lets STACK !', fg='green') from ..s04stack import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] loglevel = ctx.obj['MSNOISE_verbosity'] if threads == 1: if ref: main('ref', loglevel=loglevel) if mov: main('mov', loglevel=loglevel) if step: main('step', loglevel=loglevel) else: from multiprocessing import Process processes = [] if ref: for i in range(threads): p = Process(target=main, args=[ "ref", ], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join() if mov: for i in range(threads): p = Process(target=main, args=[ "mov", ], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join() if step: for i in range(threads): p = Process(target=main, args=[ "step", ], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def stack(ctx, ref, mov, step): """Stacks the [REF] and/or [MOV] windows""" click.secho('Lets STACK !', fg='green') from ..s04stack import main threads = ctx.obj['MSNOISE_threads'] delay = ctx.obj['MSNOISE_threadsdelay'] loglevel = ctx.obj['MSNOISE_verbosity'] if threads == 1: if ref: main('ref', loglevel=loglevel) if mov: main('mov', loglevel=loglevel) if step: main('step', loglevel=loglevel) else: from multiprocessing import Process processes = [] if ref: for i in range(threads): p = Process(target=main, args=["ref",], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join() if mov: for i in range(threads): p = Process(target=main, args=["mov",], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join() if step: for i in range(threads): p = Process(target=main, args=["step",], kwargs={"loglevel": loglevel}) p.start() processes.append(p) time.sleep(delay) for p in processes: p.join()
def init(tech): """This command initializes the current folder to be a MSNoise Project by creating a database and a db.ini file.""" click.echo('Launching the init') from ..s000installer import main main(tech)
def compute_stretching(): """[experimental] Computes the stretching based on the new stacked data""" from ..stretch import main main()
def admin(port): from ..msnoise_admin import main main(port)
def test(prefix): """Runs the test suite, should be executed in an empty folder!""" import matplotlib.pyplot as plt plt.switch_backend("agg") from ..test.tests import main main(prefix=prefix)
def bugreport(ctx, sys, modules, env, all): """This command launches the Bug Report script.""" click.echo('Let\'s Bug Report MSNoise !') # click.echo('Working on %i threads' % ctx.obj['MSNOISE_threads']) from ..bugreport import main main(sys, modules, env, all)
def admin(port): """Starts the Web Admin on http://localhost:5000 by default""" from ..msnoise_admin import main main(port)