Skip to content

Commit

Permalink
Make logging less verbose and enable test mode to process all ISO3s
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahker committed Oct 10, 2024
1 parent c71cdbf commit 5d7ef1e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions run_raster_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def process_chunk(start, end, dataset, mode, df_iso3s, engine_url):
all_results = []
for adm_level in range(max_adm + 1):
gdf = gpd.read_file(f"{td}/{iso3.lower()}_adm{adm_level}.shp")
logger.info(f"Computing stats for adm{adm_level}...")
logger.debug(f"Computing stats for adm{adm_level}...")
df_results = fast_zonal_stats_runner(
ds_clipped,
gdf,
Expand All @@ -88,7 +88,7 @@ def process_chunk(start, end, dataset, mode, df_iso3s, engine_url):
if df_results is not None:
all_results.append(df_results)
df_all_results = pd.concat(all_results, ignore_index=True)
logger.info(f"Writing {len(df_all_results)} rows to database...")
logger.debug(f"Writing {len(df_all_results)} rows to database...")
df_all_results.to_sql(
f"{dataset}",
con=engine,
Expand Down
4 changes: 2 additions & 2 deletions src/config/seas5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ start_date: 1981-01-01
end_date: 2024-10-30
forecast: True
test:
start_date: 1981-01-01
start_date: 2012-01-01
end_date: 2024-10-01
iso3s: ["ETH", "AFG", "CMR"]
iso3s: []
2 changes: 1 addition & 1 deletion src/utils/iso3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_iso3_data(iso3_codes, engine):
A DataFrame containing the ISO3 data for the specified country code(s).
"""
if iso3_codes:
if iso3_codes and len(iso3_codes) > 0:
if len(iso3_codes) == 1:
query = text("SELECT * FROM public.iso3 WHERE iso_3 = :code")
params = {"code": iso3_codes[0]}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/raster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def fast_zonal_stats_runner(
df_stats["iso3"] = iso3

if save_to_database and engine and dataset:
logger.info(f"Writing {len(df_stats)} rows to database...")
logger.warning(f"In raster utils, writing {len(df_stats)} rows to database...")
df_stats.to_sql(
dataset,
con=engine,
Expand Down Expand Up @@ -302,12 +302,12 @@ def prep_raster(ds, gdf_adm, logger=None):
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

logger.info("Clipping raster to iso3 bounds and persisting in memory...")
logger.debug("Clipping raster to iso3 bounds and persisting in memory...")
minx, miny, maxx, maxy = gdf_adm.total_bounds
ds_clip = ds.sel(x=slice(minx, maxx), y=slice(maxy, miny)).persist()
logger.info("Upsampling raster...")
logger.debug("Upsampling raster...")
ds_resampled = upsample_raster(ds_clip, logger=logger)
logger.info("Raster prep completed.")
logger.debug("Raster prep completed.")
return ds_resampled


Expand Down

0 comments on commit 5d7ef1e

Please sign in to comment.