Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from os import path
import os
import sys
from datetime import datetime
from dateutil.relativedelta import relativedelta
from obspy.core import UTCDateTime
import typer
from ..edge.EdgeFactory import EdgeFactory
from ..pcdcp import PCDCPFactory, PCDCP_FILE_PATTERN
from ..residual import WebAbsolutesFactory, CalFileFactory
CAL_FILENAME_FORMAT = "{OBSERVATORY}/{OBSERVATORY}{YEAR}PCD.cal"
MIN_TEMPLATE = "file://c:/USGSDCP/%(OBS)s/" + PCDCP_FILE_PATTERN
RAW_TEMPLATE = "%(OBS)s/" + PCDCP_FILE_PATTERN
def main():
typer.run(prepfiles)
def prepfiles(observatory: str, year: int, month: int):
starttime = datetime(year, month, 1)
endtime = starttime + relativedelta(months=+1)
write_cal_file(starttime, endtime, observatory)
def write_cal_file(
starttime, endtime, observatory, base_directory="file://c:/Calibrat/"
):
filename = CAL_FILENAME_FORMAT.format(OBSERVATORY=observatory, YEAR=starttime.year)
starttime = starttime + relativedelta(months=-1)
endtime = endtime + relativedelta(months=+2)
starttime = UTCDateTime(
year=starttime.year, month=starttime.month, day=starttime.day
)
endtime = UTCDateTime(year=endtime.year, month=endtime.month, day=endtime.day)
filename = CAL_FILENAME_FORMAT.format(OBSERVATORY=observatory, YEAR=starttime.year)
readings = WebAbsolutesFactory().get_readings(
observatory=observatory,
starttime=starttime,
endtime=endtime,
include_measurements=True,
)
calfile = CalFileFactory().format_readings(readings=readings)
with open(base_directory + filename, "wb") as f:
f.write(calfile)
def write_raw_file(starttime, endtime, observatory, base_directory="file://c:/RAW/"):
starttime = UTCDateTime(
year=starttime.year, month=starttime.month, day=starttime.day
)
endtime = UTCDateTime(year=endtime.year, month=endtime.month, day=endtime.day)
channels = ["H", "E", "Z", "F"]
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,
channels=channels,
type="variation",
interval="second",
urlInterval=86400,
urlTemplate=base_directory + f"{RAW_TEMPLATE}",
)
raw_factory.put_timeseries(
timeseries=raw_timeseries,
starttime=starttime,
endtime=endtime,
interval="second",
type="variation",
channels=channels,
)
def write_min_file(starttime, endtime, observatory, base_directory="file://c:/MIN/"):
starttime = UTCDateTime(
year=starttime.year, month=starttime.month, day=starttime.day
)
endtime = UTCDateTime(year=endtime.year, month=endtime.month, day=endtime.day)
channels = ["H", "E", "Z", "F"]
min_timeseries = EdgeFactory().get_timeseries(
observatory=observatory,
starttime=starttime,
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(
timeseries=min_timeseries,
starttime=starttime,
endtime=endtime,
interval="minute",
type="variation",
channels=channels,
)