Skip to content

Commit 6bea3f6

Browse files
EliEli
authored andcommitted
Add filter of station list so that buoy stations are not queried for tides and current stations and vice versa. Still needs checking.
1 parent 5d7d845 commit 6bea3f6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

dms_datastore/download_noaa.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
stationfile_or_stations,
1515
)
1616
from dms_datastore import dstore_config
17-
from .logging_config import logger
17+
from dms_datastore.logging_config import logger
1818

1919
__all__ = ["noaa_download"]
2020

@@ -83,6 +83,12 @@ def faulty_output(text):
8383
return "Please make sure" in text or len(text) < 300
8484

8585

86+
def subprogram(df):
87+
return df.agency_id.apply(
88+
lambda x: "tidecurrent" if isinstance(x, str) and len(x) == 7 and x.isdigit() else "buoy"
89+
)
90+
91+
8692
def download_station_data(
8793
row, dest_dir, start, end, param, overwrite, endfile, skips, verbose
8894
):
@@ -265,8 +271,15 @@ def noaa_download(stations, dest_dir, start, end=None, param=None, overwrite=Fal
265271
os.mkdir(dest_dir)
266272
skips = []
267273

274+
# This is an attempt to short-circuit the download of water levels for non-tidal stations
275+
# The correctness of this remains to be checked.
276+
if param in ("elev","water_level", "hourly_height", "predictions"):
277+
stations = stations.loc[subprogram(stations)=="tidecurrent"]
278+
elif param in ("temp","temperature","conductivity","ec"):
279+
stations = stations.loc[subprogram(stations)=="buoy"]
280+
268281
# Use ThreadPoolExecutor
269-
with concurrent.futures.ThreadPoolExecutor(max_workers=6) as executor:
282+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
270283
# Schedule the download tasks and handle them asynchronously
271284
futures = []
272285
for ndx, row in stations.iterrows():

0 commit comments

Comments
 (0)