@@ -147,7 +147,12 @@ def initialize_rivers(prj: "Project") -> None:
147147
148148 id_label = "node" if prj .rivers .target_id_col == "node_id" else "reach"
149149 logger .info (
150- "Initialized river %s ids: %s" ,
150+ "Found river %s %s ids" ,
151+ len (prj .rivers .target_ids ),
152+ id_label ,
153+ )
154+ logger .debug (
155+ "Found river %s ids: %s" ,
151156 id_label ,
152157 ", " .join (str (target_id ) for target_id in prj .rivers .target_ids ),
153158 )
@@ -217,15 +222,15 @@ def _ensure_sword_database(prj: "Project") -> str:
217222 "SWORD_v17b database not found in %s. Downloading and extracting it now." ,
218223 sword_dir ,
219224 )
220- general .ifnotmakedirs (sword_dir )
225+ general .ifnotmakedirs (os . path . join ( prj . dirs [ "main" ], "SWORD_v17b_gpkg" ) )
221226
222227 zip_path = os .path .join (prj .dirs ["main" ], "SWORD_v17b_gpkg.zip" )
223228 url_request .urlretrieve (SWORD_V17B_ZIP_URL , zip_path )
224229
225230 with zipfile .ZipFile (zip_path , "r" ) as zip_ref :
226- zip_ref .extractall (sword_dir )
231+ zip_ref .extractall (os . path . join ( prj . dirs [ "main" ], "SWORD_v17b_gpkg" ) )
227232
228- os .remove (zip_path )
233+ # os.remove(zip_path)
229234 return sword_dir
230235
231236
@@ -484,13 +489,14 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
484489 waterbody_groups = _group_river_targets_by_waterbody (prj )
485490
486491 summary = {
487- "requested" : len ( waterbody_groups ) ,
492+ "requested" : 0 ,
488493 "successful" : 0 ,
489494 "failed" : 0 ,
490495 "empty_after_filter" : 0 ,
491496 }
492497
493498 for wb_id , target_ids in waterbody_groups .items ():
499+ summary ["requested" ] = summary ["requested" ] + len (target_ids )
494500 output_path = os .path .join (
495501 prj .dirs ["swot" ], "rivers" , str (wb_id ), "timeseries.csv"
496502 )
@@ -501,8 +507,16 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
501507 if latest_obs is not None :
502508 wb_startdate = latest_obs
503509
510+ deferred_warnings = []
511+
512+ def _defer_warning (message , * args ):
513+ if args :
514+ deferred_warnings .append (message % args )
515+ else :
516+ deferred_warnings .append (message )
517+
504518 frames = []
505- for target_id in target_ids :
519+ for target_id in tqdm ( target_ids , desc = "Downloading hydrocron data" ) :
506520 try :
507521 query_params = {
508522 "feature" : feature ,
@@ -520,7 +534,7 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
520534 status_code = getattr (response , "status" , response .getcode ())
521535 payload = json .loads (response .read ().decode ("utf-8" ))
522536 except Exception as exc :
523- logger . warning (
537+ _defer_warning (
524538 "Hydrocron request failed for %s %s: %s" ,
525539 prj .rivers .target_id_col ,
526540 target_id ,
@@ -535,7 +549,7 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
535549 else None
536550 )
537551 if status_code != 200 or not csv_payload :
538- logger . warning (
552+ _defer_warning (
539553 "Hydrocron returned status %s for %s %s" ,
540554 status_code ,
541555 prj .rivers .target_id_col ,
@@ -547,7 +561,7 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
547561 try :
548562 df = pd .read_csv (StringIO (csv_payload ))
549563 except Exception as exc :
550- logger . warning (
564+ _defer_warning (
551565 "Failed to parse CSV for %s %s: %s" ,
552566 prj .rivers .target_id_col ,
553567 target_id ,
@@ -558,13 +572,13 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
558572
559573 if df .empty or quality_column not in df .columns :
560574 if df .empty :
561- logger . info (
575+ _defer_warning (
562576 "Hydrocron returned no data for %s %s" ,
563577 prj .rivers .target_id_col ,
564578 target_id ,
565579 )
566580 else :
567- logger . warning (
581+ _defer_warning (
568582 "Quality column %s not in Hydrocron response for %s %s" ,
569583 quality_column ,
570584 prj .rivers .target_id_col ,
@@ -574,7 +588,7 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
574588
575589 df = df [df [quality_column ] <= max_q ]
576590 if df .empty :
577- logger . info (
591+ _defer_warning (
578592 "All Hydrocron observations filtered for %s %s (quality > %s)" ,
579593 prj .rivers .target_id_col ,
580594 target_id ,
@@ -590,8 +604,11 @@ def _download_swot_hydrocron_timeseries(prj: "Project", startdate, enddate) -> N
590604 combined = pd .concat (frames , ignore_index = True )
591605 combined .to_csv (output_path , index = False )
592606
607+ for warning in deferred_warnings :
608+ logger .debug (warning )
609+
593610 logger .info (
594- "Hydrocron download complete: %s requested, %s successful, %s failed, %s empty after filtering" ,
611+ "Hydrocron download complete: %s requested, %s successful, %s failed, %s empty after filtering. See file logs for more info. " ,
595612 summary ["requested" ],
596613 summary ["successful" ],
597614 summary ["failed" ],
0 commit comments