File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed
Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 4444 USGS_VARIABLE_MAPPER
4545)
4646
47- DATETIME_STR_FMT = "%Y-%m-%dT%H:%M:00+0000"
47+ HOURLY_DATETIME_STR_FMT = "%Y-%m-%dT%H:%M:00+0000"
48+ DAILY_DATETIME_STR_FMT = "%Y-%m-%d"
49+
4850DAYLIGHT_SAVINGS_PAD = timedelta (hours = 2 )
4951
5052pd .options .mode .copy_on_write = True
@@ -211,11 +213,22 @@ def _fetch_usgs_streamflow(
211213) -> pd .DataFrame :
212214 """Fetch USGS gage data and format to TEEHR format."""
213215 logger .debug ("Fetching USGS streamflow data from NWIS." )
214- start_dt_str = start_date .strftime (DATETIME_STR_FMT )
216+
217+ if service == "iv" :
218+ datetime_str_format = HOURLY_DATETIME_STR_FMT
219+ elif service == "dv" :
220+ datetime_str_format = DAILY_DATETIME_STR_FMT
221+ else :
222+ err_msg = f"Service '{ service } ' is not supported. Valid options are 'iv' and 'dv'."
223+ logger .error (err_msg )
224+ raise ValueError (err_msg )
225+
226+ start_dt_str = start_date .strftime (datetime_str_format )
227+
215228 end_dt_str = (
216229 end_date
217230 - timedelta (minutes = 1 )
218- ).strftime (DATETIME_STR_FMT )
231+ ).strftime (datetime_str_format )
219232
220233 # Parse out list of sites.
221234 parsed_sites = _parse_site_id_list (sites )
Original file line number Diff line number Diff line change @@ -197,10 +197,44 @@ def test_chunkby_all(tmpdir):
197197 assert df ["value_time" ].max () == pd .Timestamp ("2023-02-25 00:00:00" )
198198
199199
200+ def test_daily_service (tmpdir ):
201+ """Test chunkby location id."""
202+ usgs_to_parquet (
203+ sites = [
204+ "02449838" ,
205+ "02450825" ,
206+ ],
207+ start_date = datetime (2023 , 2 , 20 ),
208+ end_date = datetime (2023 , 2 , 21 ),
209+ output_parquet_dir = Path (tmpdir ),
210+ chunk_by = "location_id" ,
211+ overwrite_output = True ,
212+ convert_to_si = False ,
213+ service = "dv"
214+ )
215+ df1 = pd .read_parquet (
216+ Path (
217+ tmpdir ,
218+ "02449838.parquet"
219+ )
220+ )
221+ df2 = pd .read_parquet (
222+ Path (
223+ tmpdir ,
224+ "02450825.parquet"
225+ )
226+ )
227+ assert len (df1 ) == 1
228+ assert len (df2 ) == 1
229+ assert df1 ["value" ].iloc [0 ] == 157.0 # confirmed with NWIS web
230+ assert df2 ["value" ].iloc [0 ] == 389.0
231+
232+
200233if __name__ == "__main__" :
201234 with tempfile .TemporaryDirectory (prefix = "teehr-" ) as tempdir :
202235 test_chunkby_location_id (tempfile .mkdtemp (dir = tempdir ))
203236 test_chunkby_day (tempfile .mkdtemp (dir = tempdir ))
204237 test_chunkby_week (tempfile .mkdtemp (dir = tempdir ))
205238 test_chunkby_month (tempfile .mkdtemp (dir = tempdir ))
206239 test_chunkby_all (tempfile .mkdtemp (dir = tempdir ))
240+ test_daily_service (tempfile .mkdtemp (dir = tempdir ))
You can’t perform that action at this time.
0 commit comments