-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
183 lines (164 loc) · 4.85 KB
/
Copy path__init__.py
File metadata and controls
183 lines (164 loc) · 4.85 KB
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
import click
from cwmscli import requirements as reqs
from cwmscli.utils import (
api_key_loc_option,
api_key_option,
api_root_option,
get_api_key,
office_option,
)
from cwmscli.utils.deps import requires
@click.group()
def usgs_group():
"""USGS utilities"""
pass
days_back_option = click.option(
"-d",
"--days-back",
default="1",
type=float,
help="Days back from current time to get data. Can be decimal and integer values",
)
@usgs_group.command(
"timeseries", help="Get USGS timeseries values and store into CWMS database"
)
@office_option
@days_back_option
@api_root_option
@api_key_option
@api_key_loc_option
@click.option(
"-b",
"--backfill",
default=None,
type=str,
help='Backfill timeseries ids, use list of timeseries ids (e.g. "ts_id1, ts_id2") to attempt to backfill a subset of timeseries with USGS data',
)
@requires(reqs.cwms, reqs.requests)
def getusgs_timeseries(office, days_back, api_root, api_key, api_key_loc, backfill):
from cwmscli.usgs.getusgs_cda import getusgs_cda
if backfill is not None:
backfill_list = [item.strip() for item in backfill.split(",") if item.strip()]
else:
backfill_list = None
api_key = get_api_key(api_key, api_key_loc)
getusgs_cda(
api_root=api_root,
office_id=office,
days_back=days_back,
api_key=api_key,
backfill_tsids=backfill_list,
)
@usgs_group.command("ratings", help="Get USGS ratings and store into CWMS database")
@office_option
@days_back_option
@api_root_option
@api_key_option
@api_key_loc_option
@click.option(
"-rs",
"--rating-subset",
default=None,
type=str,
help='subset of rating spec ids to grab latest rating for (e.g. "rating_spec_id1, rating_spec_id2").',
)
@requires(reqs.cwms, reqs.requests, reqs.dataretrieval)
def getusgs_ratings(office, days_back, api_root, api_key, api_key_loc, rating_subset):
from cwmscli.usgs.getUSGS_ratings_cda import getusgs_rating_cda
if rating_subset is not None:
rating_list = [
item.strip() for item in rating_subset.split(",") if item.strip()
]
else:
rating_list = None
api_key = get_api_key(api_key, api_key_loc)
getusgs_rating_cda(
api_root=api_root,
office_id=office,
days_back=days_back,
api_key=api_key,
rating_subset=rating_list,
)
@usgs_group.command(
"ratings-ini-file-import",
help="Store rating ini file information into database to be used with getusgs_ratings",
)
@click.option(
"-f",
"--filename",
required=True,
type=str,
help="filename of ratings ini file to be processed",
)
@click.option(
"--dry-run",
is_flag=True,
default=False,
help="Preview changes without updating the database",
)
@api_root_option
@api_key_option
@api_key_loc_option
@requires(reqs.cwms, reqs.requests)
def ratingsinifileimport(filename, dry_run, api_root, api_key, api_key_loc):
from cwmscli.usgs.rating_ini_file_import import rating_ini_file_import
api_key = get_api_key(api_key, api_key_loc)
rating_ini_file_import(
api_root=api_root, api_key=api_key, ini_filename=filename, dry_run=dry_run
)
@usgs_group.command("measurements", help="Store USGS measurements into CWMS database")
@click.option(
"-d",
"--days-back-modified",
default=2,
type=int,
help="Days back from current time measurements have been modified in USGS database. Can be integer value",
)
@click.option(
"-c",
"--days-back-collected",
default=365,
type=int,
help="Days back from current time measurements have been collected. Can be integer value",
)
@office_option
@api_root_option
@api_key_option
@api_key_loc_option
@click.option(
"-b",
"--backfill",
default=None,
type=str,
help="Backfill POR data, use list of USGS IDs (e.g. 05057200, 05051300) or the word 'group' to attempt to backfill all sites in the OFFICE id's Data Acquisition->USGS Measurements group",
)
@requires(reqs.cwms, reqs.requests, reqs.dataretrieval)
def getusgs_measurements(
days_back_modified,
days_back_collected,
office,
api_root,
api_key,
api_key_loc,
backfill,
):
from cwmscli.usgs.getusgs_measurements_cda import getusgs_measurement_cda
backfill_group = False
backfill_list = False
if backfill is not None:
if "group" in backfill:
backfill_group = True
elif type(backfill) == str:
backfill_list = [
item.strip() for item in backfill.split(",") if item.strip()
]
api_key = get_api_key(api_key, api_key_loc)
getusgs_measurement_cda(
api_root=api_root,
office_id=office,
api_key=api_key,
days_back_modified=days_back_modified,
days_back_collected=days_back_collected,
backfill_list=backfill_list,
backfill_group=backfill_group,
)