Skip to content

Commit 74a0a3f

Browse files
committed
black format file
1 parent e8d98f6 commit 74a0a3f

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exclude: ^utils/.*$
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v6.0.0
6+
hooks:
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- id: debug-statements
10+
- repo: https://github.com/psf/black
11+
rev: 25.9.0
12+
hooks:
13+
- id: black
14+
- repo: https://github.com/PyCQA/pylint
15+
rev: v3.3.8
16+
hooks:
17+
- id: pylint

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ disable=
1515
max-line-length=100
1616

1717
[TYPECHECK]
18-
ignored-modules=xarray,xesmf,cmor,numpy,geocat.comp
18+
ignored-modules=xarray,xesmf,cmor,numpy,geocat.comp,yaml
1919
ignored-classes=cmor

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# cmip7-prep (skeleton)
33

44
Quickstart:
5-
1) Ensure you have a precomputed E3SM weights file: `map_ne30pg3_to_1x1d_aave.nc`.
5+
1) Ensure you have a precomputed ESMF weights file: `map_ne30pg3_to_1x1d_aave.nc`.
66
2) Fill in `cmor_dataset.json` placeholders (experiment_id, etc.).
77
3) Export the CMIP7 Data Request v1.2.2 (CSV) as `data_request_v1.2.2.csv`.
88
4) `poetry install`

cmip7_prep/mapping_compat.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# cmip7_prep/mapping_compat.py
32
r"""Mapping loader/evaluator compatible with CMIP6-style lists and CMIP7-style dicts.
43
@@ -48,6 +47,7 @@ def _normalize_table_name(value: Optional[str]) -> Optional[str]:
4847
@dataclass(frozen=True)
4948
class VarConfig:
5049
"""Normalized mapping entry for a single CMIP variable."""
50+
5151
name: str
5252
table: Optional[str] = None
5353
units: Optional[str] = None
@@ -110,6 +110,7 @@ class Mapping:
110110
The loader accepts both dict- and list-based YAML styles. All table names
111111
are normalized to a short form (e.g., 'Amon').
112112
"""
113+
113114
def __init__(self, path: str | Path) -> None:
114115
self.path = Path(path)
115116
self._vars: Dict[str, VarConfig] = self._load_yaml(self.path)
@@ -138,7 +139,9 @@ def _load_yaml(path: Path) -> Dict[str, VarConfig]:
138139
name = str(item["name"])
139140
result[name] = _to_varconfig(name, item)
140141
else:
141-
raise TypeError("Unsupported YAML structure: expected dict or list at top level.")
142+
raise TypeError(
143+
"Unsupported YAML structure: expected dict or list at top level."
144+
)
142145

143146
return result
144147

@@ -208,7 +211,9 @@ def _to_varconfig(name: str, cfg: TMapping[str, Any]) -> VarConfig:
208211
return vc
209212

210213

211-
def _require_vars(ds: xr.Dataset, names: List[str], context: str) -> Dict[str, xr.DataArray]:
214+
def _require_vars(
215+
ds: xr.Dataset, names: List[str], context: str
216+
) -> Dict[str, xr.DataArray]:
212217
missing = [n for n in names if n not in ds]
213218
if missing:
214219
raise KeyError(f"{context}: missing variables {missing}")
@@ -224,7 +229,11 @@ def _realize_core(ds: xr.Dataset, vc: VarConfig) -> xr.DataArray:
224229
return ds[vc.source]
225230

226231
# 2) identity mapping from a single raw variable
227-
if vc.raw_variables and vc.formula in (None, "", "null") and len(vc.raw_variables) == 1:
232+
if (
233+
vc.raw_variables
234+
and vc.formula in (None, "", "null")
235+
and len(vc.raw_variables) == 1
236+
):
228237
var = vc.raw_variables[0]
229238
if var not in ds:
230239
raise KeyError(f"raw variable {var!r} not found in dataset")
@@ -263,7 +272,9 @@ def _apply_unit_conversion(da: xr.DataArray, rule: Any) -> xr.DataArray:
263272
try:
264273
out = _safe_eval(rule, {"x": da})
265274
except Exception as exc:
266-
raise ValueError(f"Error evaluating unit_conversion expression: {exc}") from exc
275+
raise ValueError(
276+
f"Error evaluating unit_conversion expression: {exc}"
277+
) from exc
267278
if not isinstance(out, xr.DataArray):
268279
raise ValueError("unit_conversion expression did not return a DataArray")
269280
return out
@@ -273,4 +284,6 @@ def _apply_unit_conversion(da: xr.DataArray, rule: Any) -> xr.DataArray:
273284
offset = rule.get("offset", 0.0)
274285
return da * float(scale) + float(offset)
275286

276-
raise TypeError("unit_conversion must be a string expression or a dict with 'scale'/'offset'")
287+
raise TypeError(
288+
"unit_conversion must be a string expression or a dict with 'scale'/'offset'"
289+
)

0 commit comments

Comments
 (0)