Skip to content
Snippets Groups Projects

Poetry

Merged Jeremy M Fee requested to merge ghsc/users/jmfee/geomag-algorithms:poetry into master
2 files
+ 10
25
Compare changes
  • Side-by-side
  • Inline
Files
2
#! /usr/bin/env python
#! /usr/bin/env python
"""Monitor """
"""Monitor """
from os import path
import sys
import sys
from typing import List
from typing import List
import argparse
import argparse
import sys
import sys
from obspy.core import UTCDateTime
from obspy.core import UTCDateTime
import typer
# ensure geomag is on the path before importing
from .. import TimeseriesUtility, edge
try:
import geomagio # noqa (tells linter to ignore this line.)
except ImportError:
script_dir = path.dirname(path.abspath(__file__))
sys.path.append(path.normpath(path.join(script_dir, "..")))
import geomagio.TimeseriesUtility as TimeseriesUtility
import geomagio.edge as edge
def _main():
typer.run(generate_report)
def calculate_warning_threshold(warning_threshold, interval):
def calculate_warning_threshold(warning_threshold, interval):
@@ -292,8 +278,8 @@ def print_observatories(
@@ -292,8 +278,8 @@ def print_observatories(
def generate_report(
def generate_report(
starttime: str,
starttime: UTCDateTime,
endtime: str,
endtime: UTCDateTime,
observatories: List[str],
observatories: List[str],
edge_host: str = "127.0.0.1",
edge_host: str = "127.0.0.1",
channels: List[str] = ["H", "E", "Z", "F"],
channels: List[str] = ["H", "E", "Z", "F"],
@@ -304,8 +290,6 @@ def generate_report(
@@ -304,8 +290,6 @@ def generate_report(
title: str = "",
title: str = "",
warning_threshold: int = 60,
warning_threshold: int = 60,
):
):
starttime = UTCDateTime(starttime)
endtime = UTCDateTime(endtime)
print_html_header(starttime=starttime, endtime=endtime, title=title)
print_html_header(starttime=starttime, endtime=endtime, title=title)
warning_issued = print_observatories(
warning_issued = print_observatories(
starttime=starttime,
starttime=starttime,
@@ -324,7 +308,7 @@ def generate_report(
@@ -324,7 +308,7 @@ def generate_report(
sys.exit(warning_issued)
sys.exit(warning_issued)
def main(args):
def main(args=None):
"""command line tool for building geomag monitoring reports
"""command line tool for building geomag monitoring reports
Inputs
Inputs
@@ -336,6 +320,8 @@ def main(args):
@@ -336,6 +320,8 @@ def main(args):
parses command line options using argparse
parses command line options using argparse
Output is in HTML.
Output is in HTML.
"""
"""
 
if args is None:
 
args = parse_args(sys.argv[1:])
generate_report(
generate_report(
starttime=args.starttime,
starttime=args.starttime,
endtime=args.endtime,
endtime=args.endtime,
@@ -370,14 +356,14 @@ def parse_args(args):
@@ -370,14 +356,14 @@ def parse_args(args):
parser.add_argument(
parser.add_argument(
"--starttime",
"--starttime",
required=True,
required=True,
type=str,
type=UTCDateTime,
default=None,
default=None,
help="UTC date YYYY-MM-DD HH:MM:SS",
help="UTC date YYYY-MM-DD HH:MM:SS",
)
)
parser.add_argument(
parser.add_argument(
"--endtime",
"--endtime",
required=True,
required=True,
type=str,
type=UTCDateTime,
default=None,
default=None,
help="UTC date YYYY-MM-DD HH:MM:SS",
help="UTC date YYYY-MM-DD HH:MM:SS",
)
)
@@ -431,5 +417,4 @@ def parse_args(args):
@@ -431,5 +417,4 @@ def parse_args(args):
if __name__ == "__main__":
if __name__ == "__main__":
args = parse_args(sys.argv[1:])
main()
main(args)
Loading