Skip to content

Commit 60c95bb

Browse files
committed
cleanup
1 parent 3e9d947 commit 60c95bb

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

cmip7_prep/pipeline.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pathlib import Path
77
from typing import Optional, Sequence, Union, Dict, List
88
import re
9-
from venv import logger
9+
import logging
1010
import warnings
1111
import glob
1212
import sys
@@ -16,7 +16,7 @@
1616
from .regrid import regrid_to_1deg_ds
1717
from .vertical import to_plev19
1818

19-
19+
logger = logging.getLogger(__name__)
2020
# --------------------------- file discovery ---------------------------
2121

2222
_VAR_TOKEN = re.compile(r"(?<![A-Za-z0-9_])([A-Za-z0-9_]+)(?![A-Za-z0-9_])")
@@ -222,7 +222,7 @@ def realize_regrid_prepare(
222222
ds_native = open_native_for_cmip_vars(
223223
[cmip_var], ds_or_glob, mapping, **open_kwargs
224224
)
225-
if not "landfrac" in ds_native and not "ncol" in ds_native:
225+
if "landfrac" not in ds_native and "ncol" not in ds_native:
226226
logger.info("Variable has no 'landfrac' or 'ncol' dim; assuming ocn variable.")
227227
# Add MOM6 grid info if provided
228228
if mom6_grid:
@@ -234,10 +234,8 @@ def realize_regrid_prepare(
234234

235235
else:
236236
logger.error("No MOM6 grid info provided; geolat/geolon not added.")
237-
return (
238-
cmip_var,
239-
f"ERROR: MOM6 grid information is required for variable {cmip_var} "
240-
"but was not provided.",
237+
raise ValueError(
238+
f"MOM6 grid information is required for variable {cmip_var} but was not provided."
241239
)
242240
# 2) Realize the target variable
243241
ds_v = mapping.realize(ds_native, cmip_var)

cmip7_prep/regrid.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def regrid_to_1deg_ds(
511511
force_method="conservative",
512512
realm=realm,
513513
) # fx always conservative
514-
print(f"using fx map: {spec.path}")
514+
logger.info("using fx map: %s", spec.path)
515515
ds_fx = _regrid_fx_once(spec.path, ds_in) # ← uses cache
516516
if ds_fx:
517517
# Don’t overwrite if user already computed and passed them in
@@ -620,8 +620,12 @@ def regrid_to_1deg(
620620
force_method=method,
621621
realm=realm,
622622
)
623-
print(
624-
f"Regridding {varname} using {spec.method_label} map: {spec.path} for realm {realm}"
623+
logger.info(
624+
"Regridding %s using %s map: %s for realm %s",
625+
varname,
626+
spec.method_label,
627+
spec.path,
628+
realm,
625629
)
626630
regridder = _RegridderCache.get(spec.path, spec.method_label)
627631

@@ -642,11 +646,15 @@ def regrid_to_1deg(
642646
*non_spatial, "lon", "lat"
643647
)
644648
da2_2d = da2_2d.assign_coords(lon=((da2_2d.lon % 360)))
645-
print(
646-
f"da2_2d range: {da2_2d['lat'].min().item()} to {da2_2d['lat'].max().item()} lat, "
647-
f"{da2_2d['lon'].min().item()} to {da2_2d['lon'].max().item()} lon"
649+
logger.info(
650+
"da2_2d range: %f to %f lat, %f to %f lon",
651+
da2_2d["lat"].min().item(),
652+
da2_2d["lat"].max().item(),
653+
da2_2d["lon"].min().item(),
654+
da2_2d["lon"].max().item(),
648655
)
649-
if hdim == "lndgrid":
656+
657+
if realm == "lnd":
650658
out_norm = regridder(da2_2d, **kwargs)
651659
out = _denormalize_land_field(out_norm, ds_in, spec.path)
652660
else:

scripts/monthly_cmor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _extract_array(val):
244244
f"Exception while processing {varname} with dims {dims}: {e!r}"
245245
)
246246
results.append((varname, f"ERROR: {e!r}"))
247-
return results if len(results) > 1 else results[0]
247+
return results
248248

249249

250250
process_one_var_delayed = delayed(process_one_var)

0 commit comments

Comments
 (0)