-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
215 lines (176 loc) · 6.59 KB
/
main.py
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import logging
import sys
from datetime import datetime, timedelta
from enum import Enum
import typer
from sqlalchemy import create_engine
from dscreator.config import SETTINGS
from dscreator.datasets import timeseries, trajectories
from dscreator.runner import DataRunner
from dscreator.sources import ferrybox, odm2
app = typer.Typer()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(module)s.%(funcName)s %(levelname)s - %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)
class ACDDOptions(str, Enum):
no = "no"
"""Do not add ACDD attributes"""
yes = "yes"
"""Add ACDD attributes"""
ncml = "ncml"
"""Add ACDD attributes and create a ncml template"""
@app.command()
def msource_inlet(max_time_slice: int = 24, stop_after_n_files: int = -1, acdd: ACDDOptions = "no"):
"""Build an msource inlet dataset from data in odm2
The dataset tries to follow the climate & forecast convention and is dumped as netcdf.
"""
logging.info("Exporting MSOURCE dataset")
engine = create_engine(SETTINGS.odm2_connection_str)
timeseries_extractor = odm2.extractor.TimeseriesExtractor(
engine,
sampling_feature_code="MSOURCE1",
variable_codes=["Temp", "LevelValue", "Turbidity", "CondValue"],
)
dataset_builder = timeseries.msource.MSourceInletBuilder(
uuid="no.niva:d2675936-8ebf-4fc5-988c-4a5198b2df57",
dataset_name="msource-inlet",
station_name="msource-inlet",
grouping="Multisource",
is_acdd=False if acdd == "no" else True,
)
runner = DataRunner(
custom_start_time=datetime(2022, 9, 23),
extractor=timeseries_extractor,
dataset_builder=dataset_builder,
hourly_delta=max_time_slice,
n_intervals=stop_after_n_files,
ncml=True if acdd == "ncml" else False,
)
runner.start()
@app.command()
def msource_outlet(max_time_slice: int = 24, stop_after_n_files: int = -1, acdd: ACDDOptions = "no"):
"""Build an msource outlet dataset from data in odm2
The dataset tries to follow the climate & forecast convention and is dumped as netcdf.
"""
logging.info("Exporting MSOURCE dataset")
engine = create_engine(SETTINGS.odm2_connection_str)
timeseries_extractor = odm2.extractor.TimeseriesExtractor(
engine,
sampling_feature_code="MSOURCE2",
variable_codes=["LevelValue", "Turbidity", "CondValue"],
)
dataset_builder = timeseries.msource.MSourceOutletBuilder(
uuid="no.niva:4b123377-e0a6-4c7e-b466-2f8a3199bc86",
dataset_name="msource-outlet",
station_name="msource-outlet",
grouping="Multisource",
is_acdd=False if acdd == "no" else True,
)
runner = DataRunner(
custom_start_time=datetime(2022, 9, 23),
extractor=timeseries_extractor,
dataset_builder=dataset_builder,
hourly_delta=max_time_slice,
n_intervals=stop_after_n_files,
ncml=True if acdd == "ncml" else False,
)
runner.start()
@app.command()
def glomma_baterod(max_time_slice: int = 24, stop_after_n_files: int = -1, acdd: ACDDOptions = "no"):
"""Build glomma Baterød dataset from data in odm2
The dataset tries to follow the climate & forecast convention and is dumped as netcdf.
"""
logging.info("Exporting Glomma Baterød dataset")
engine = create_engine(SETTINGS.odm2_connection_str)
timeseries_extractor = odm2.extractor.TimeseriesExtractor(
engine,
sampling_feature_code="Baterod",
variable_codes=[
"Temp_water_Avg",
"PhValue_Avg",
"CondValue_Avg",
"Turbidity_Avg",
"CDOMdigitalFinal"
],
)
dataset_builder = timeseries.glomma.GlommaBuilder (
uuid="no.niva:af047ff6-e92a-47a0-a9ab-1b2d1e011092",
dataset_name="baterod",
station_name="Baterod",
grouping="glomma",
is_acdd=False if acdd == "no" else True,
)
runner = DataRunner(
extractor=timeseries_extractor,
dataset_builder=dataset_builder,
hourly_delta=max_time_slice,
n_intervals=stop_after_n_files,
ncml=True if acdd == "ncml" else False,
end_time_delay=timedelta(days=7),
)
runner.start()
@app.command()
def sios(max_time_slice: int = 24, stop_after_n_files: int = -1, acdd: ACDDOptions = "no"):
"""Build test sios dataset from data in odm2
The dataset tries to follow the climate & forecast convention and is dumped as netcdf.
"""
logging.info("Exporting SIOS dataset")
engine = create_engine(SETTINGS.odm2_connection_str)
timeseries_extractor = odm2.extractor.TimeseriesExtractor(
engine,
sampling_feature_code="bbee7983-e91c-4282-9a5d-d0894a9b7cb0",
variable_codes=[
"Temp",
"TurbCalib",
"Salinity",
"ChlaCalib",
"CondValue",
"fDOMCalib",
],
)
dataset_builder = timeseries.sios.SiosBuilder(
uuid="no.niva:29b7de62-e1fa-4dce-90e4-7ff8a0931397",
dataset_name="sios",
station_name="adventfjorden",
grouping="SIOS",
is_acdd=False if acdd == "no" else True,
)
runner = DataRunner(
extractor=timeseries_extractor,
dataset_builder=dataset_builder,
hourly_delta=max_time_slice,
n_intervals=stop_after_n_files,
ncml=True if acdd == "ncml" else False,
)
runner.start()
@app.command()
def nrt_color_fantasy(max_time_slice: int = 24, stop_after_n_files: int = -1, acdd: ACDDOptions = "no"):
"""Build nrt color fantasy dataset from data in tsb"""
logging.info("Exporting NRT FA dataset")
trajectory_extractor = ferrybox.extractor.TrajectoryExtractor(
create_engine(SETTINGS.tsb_connection_str),
variable_codes=["temperature", "salinity", "oxygen_sat", "chlorophyll", "turbidity", "fdom"],
variable_uuid_map=ferrybox.uuid_variable_code_mapper.MAPPER["FA_19"],
qc_flags=[1],
)
dataset_builder = trajectories.ferrybox.DailyFantasy(
uuid="no.niva:af11ba01-dfe3-4432-b9d2-4e6fd10714db",
dataset_name="color_fantasy",
station_name="color_fantasy",
grouping="nrt",
is_acdd=False if acdd == "no" else True,
)
runner = DataRunner(
custom_start_time=datetime(2023, 1, 1),
extractor=trajectory_extractor,
dataset_builder=dataset_builder,
hourly_delta=max_time_slice,
n_intervals=stop_after_n_files,
ncml=True if acdd == "ncml" else False,
end_time_delay=timedelta(minutes=90),
)
runner.start()
if __name__ == "__main__":
app()