Skip to content
Snippets Groups Projects
Commit 6632e8f3 authored by Cain, Payton David's avatar Cain, Payton David Committed by Jeremy M Fee
Browse files

Merge pcdcp methods, simplify time calculations

parent eaadad80
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
""" """
from __future__ import absolute_import from __future__ import absolute_import
from .PCDCPFactory import PCDCPFactory from .PCDCPFactory import PCDCPFactory, PCDCP_FILE_PATTERN
from .PCDCPFactory import PCDCP_FILE_PATTERN
from .StreamPCDCPFactory import StreamPCDCPFactory from .StreamPCDCPFactory import StreamPCDCPFactory
from .PCDCPParser import PCDCPParser from .PCDCPParser import PCDCPParser
from .PCDCPWriter import PCDCPWriter from .PCDCPWriter import PCDCPWriter
......
...@@ -4,15 +4,16 @@ import sys ...@@ -4,15 +4,16 @@ import sys
from datetime import datetime from datetime import datetime
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from obspy.core import UTCDateTime from obspy.core import UTCDateTime, Stream
import typer import typer
from ..algorithm.FilterAlgorithm import FilterAlgorithm
from ..edge.EdgeFactory import EdgeFactory from ..edge.EdgeFactory import EdgeFactory
from ..pcdcp import PCDCPFactory, PCDCP_FILE_PATTERN from ..pcdcp import PCDCPFactory, PCDCP_FILE_PATTERN
from ..residual import WebAbsolutesFactory, CalFileFactory from ..residual import WebAbsolutesFactory, CalFileFactory
CAL_FILENAME_FORMAT = "{OBSERVATORY}/{OBSERVATORY}{YEAR}PCD.cal" CAL_FILENAME_FORMAT = "{OBSERVATORY}/{OBSERVATORY}{YEAR}PCD.cal"
MIN_TEMPLATE = "file://c:/USGSDCP/%(OBS)s/" + PCDCP_FILE_PATTERN MIN_TEMPLATE = "%(OBS)s/" + PCDCP_FILE_PATTERN
RAW_TEMPLATE = "%(OBS)s/" + PCDCP_FILE_PATTERN RAW_TEMPLATE = "%(OBS)s/" + PCDCP_FILE_PATTERN
...@@ -21,14 +22,47 @@ def main(): ...@@ -21,14 +22,47 @@ def main():
def prepfiles(observatory: str, year: int, month: int): def prepfiles(observatory: str, year: int, month: int):
starttime = datetime(year, month, 1) month_start = datetime(year, month, 1)
endtime = starttime + relativedelta(months=+1) month_end = month_start + relativedelta(months=1)
write_cal_file(starttime, endtime, observatory) write_cal_file(
starttime=UTCDateTime(month_start - relativedelta(months=1)),
endtime=UTCDateTime(month_end + relativedelta(months=1)),
observatory=observatory,
)
timeseries_min, timeseries_sec = gather_data(
starttime=UTCDateTime(month_start),
endtime=UTCDateTime(month_end),
observatory=observatory,
)
write_pcdcp_file(
starttime=UTCDateTime(month_start),
endtime=UTCDateTime(month_end),
timeseries=timeseries_sec,
observatory=observatory,
interval="second",
base_directory="file://c:/RAW/",
template=RAW_TEMPLATE,
)
write_pcdcp_file(
starttime=UTCDateTime(month_start),
endtime=UTCDateTime(month_end),
timeseries=timeseries_min,
observatory=observatory,
interval="minute",
base_directory="file://c:/USGSDCP/",
template=MIN_TEMPLATE,
)
def write_cal_file( def write_cal_file(
starttime, endtime, observatory, base_directory="file://c:/Calibrat/" starttime: UTCDateTime,
endtime: UTCDateTime,
observatory: str,
base_directory: str = "file://c:/Calibrat/",
): ):
filename = CAL_FILENAME_FORMAT.format(OBSERVATORY=observatory, YEAR=starttime.year) filename = CAL_FILENAME_FORMAT.format(OBSERVATORY=observatory, YEAR=starttime.year)
starttime = starttime + relativedelta(months=-1) starttime = starttime + relativedelta(months=-1)
...@@ -48,74 +82,41 @@ def write_cal_file( ...@@ -48,74 +82,41 @@ def write_cal_file(
CalFileFactory().write_file(path=base_directory + filename, readings=readings) CalFileFactory().write_file(path=base_directory + filename, readings=readings)
def write_raw_file(starttime, endtime, observatory, base_directory="file://c:/RAW/"): def gather_data(starttime: UTCDateTime, endtime: UTCDateTime, observatory: str):
starttime = UTCDateTime( f = FilterAlgorithm(input_sample_period=1.0, output_sample_period=60.0)
year=starttime.year, month=starttime.month, day=starttime.day f_starttime, f_endtime = f.get_input_interval(starttime, endtime)
) e = EdgeFactory()
endtime = UTCDateTime(year=endtime.year, month=endtime.month, day=endtime.day) timeseries_sec = e.get_timeseries(
starttime=f_starttime,
channels = ["H", "E", "Z", "F"] endtime=f_endtime,
edge_factory = EdgeFactory()
raw_timeseries = edge_factory.get_timeseries(
observatory=observatory,
starttime=starttime,
endtime=endtime,
channels=channels,
interval="second",
type="variation",
)
raw_factory = PCDCPFactory(
observatory=observatory, observatory=observatory,
channels=channels, channels=["H", "E", "Z", "F"],
type="variation", type="variation",
interval="second", interval="second",
urlInterval=86400,
urlTemplate=base_directory + f"{RAW_TEMPLATE}",
) )
return (
raw_factory.put_timeseries( f.process(timeseries_sec),
timeseries=raw_timeseries, timeseries_sec.trim(starttime=starttime, endtime=endtime),
starttime=starttime,
endtime=endtime,
interval="second",
type="variation",
channels=channels,
) )
def write_min_file(starttime, endtime, observatory, base_directory="file://c:/MIN/"): def write_pcdcp_file(
starttime = UTCDateTime( starttime: UTCDateTime,
year=starttime.year, month=starttime.month, day=starttime.day endtime: UTCDateTime,
) timeseries: Stream,
endtime = UTCDateTime(year=endtime.year, month=endtime.month, day=endtime.day) observatory: str,
interval: str,
channels = ["H", "E", "Z", "F"] base_directory: str,
template: str = PCDCP_FILE_PATTERN,
min_timeseries = EdgeFactory().get_timeseries( ):
observatory=observatory, raw_factory = PCDCPFactory(
starttime=starttime, urlInterval=86400, urlTemplate=base_directory + f"{template}",
endtime=endtime,
channels=channels,
interval="minute",
type="variation",
)
min_factory = PCDCPFactory(
observatory=observatory,
channels=channels,
type="variation",
interval="minute",
urlInterval=86400,
urlTemplate=base_directory + f"{MIN_TEMPLATE}",
) )
min_factory.put_timeseries( raw_factory.put_timeseries(
timeseries=min_timeseries, timeseries=timeseries,
starttime=starttime, starttime=starttime,
endtime=endtime, endtime=endtime,
interval="minute", interval=interval,
type="variation", type="variation",
channels=channels,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment