Skip to content

Commit

Permalink
Merge pull request #23 from eqcorrscan/working-dir
Browse files Browse the repository at this point in the history
Working dir
  • Loading branch information
calum-chamberlain authored Aug 2, 2023
2 parents 7c09c36 + 10efea7 commit 911791c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
19 changes: 16 additions & 3 deletions rt_eqcorrscan/console_scripts/build_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
GPL v3.0
"""

import os
import logging
import faulthandler

Expand All @@ -33,13 +34,20 @@ def run(
):
config = read_config(config_file=kwargs.get("config_file", None))
debug = kwargs.get("debug", False)
working_dir = kwargs.get("working_dir", None)
if debug:
config.log_level = "DEBUG"
print(f"Using the following configuration:\n{config}")
config.setup_logging()
Logger.debug("Running in debug mode - expect lots of output!")

if working_dir:
Logger.info(f"Changing to working directory: {working_dir}")
os.chdir(working_dir)


client = config.rt_match_filter.get_client()
waveform_client = config.rt_match_filter.get_waveform_client()

template_bank = TemplateBank(
config.database_manager.event_path,
Expand Down Expand Up @@ -69,7 +77,7 @@ def run(
Logger.info(f"Will make templates for {len(catalog)} events")

tribe = template_bank.make_templates(
catalog=catalog, rebuild=rebuild, client=client, **config.template)
catalog=catalog, rebuild=rebuild, client=waveform_client, **config.template)
Logger.info(f"Made {len(tribe)} templates")


Expand Down Expand Up @@ -104,6 +112,10 @@ def main():
"-n", "--max-workers", type=int, default=None,
help="Maximum workers for ProcessPoolExecutor, defaults to the number "
"of cores on the machine")
parser.add_argument(
"-w", "--working-dir", type=str,
help="Working directory - will change to this directory after reading "
"config file. All paths must be correct for this working dir.")

args = parser.parse_args()

Expand All @@ -124,11 +136,12 @@ def main():
else:
endtime = UTCDateTime()

kwargs.update({"debug": args.debug, "config_file": args.config})
kwargs.update({"debug": args.debug, "config_file": args.config,
"working_dir": args.working_dir})
run(starttime=starttime, endtime=endtime,
chunk_size=args.chunk_interval, rebuild=args.rebuild,
max_workers=args.max_workers, **kwargs)


if __name__ == "__main__":
main()
main()
13 changes: 12 additions & 1 deletion rt_eqcorrscan/console_scripts/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
GPL v3.0
"""

import os
import logging
import faulthandler

Expand All @@ -34,12 +35,17 @@ def run(**kwargs):
debug = kwargs.get("debug", False)
update_bank = kwargs.get("update_bank", True)
listener_starttime = kwargs.get("listener_starttime", None)
working_dir = kwargs.get("working_dir", '.')
if debug:
config.log_level = "DEBUG"
print("Using the following configuration:\n{0}".format(config))
config.setup_logging()
Logger.debug("Running in debug mode - expect lots of output!")

if working_dir:
Logger.info(f"Changing to working directory: {working_dir}")
os.chdir(working_dir)

client = config.rt_match_filter.get_client()

trigger_func = partial(
Expand Down Expand Up @@ -96,12 +102,17 @@ def main():
"-s", "--listener-starttime", type=UTCDateTime,
help="UTCDateTime parsable starttime for the listener - will collect "
"events from this date to now and react to them.")
parser.add_argument(
"-w", "--working-dir", type=str,
help="Working directory - will change to this directory after reading "
"config file. All paths must be correct for this working dir.")

args = parser.parse_args()

kwargs.update({"debug": args.debug, "config_file": args.config,
"update_bank": args.update_bank,
"listener_starttime": args.listener_starttime})
"listener_starttime": args.listener_starttime,
"working_dir": args.working_dir})
run(**kwargs)


Expand Down

0 comments on commit 911791c

Please sign in to comment.