Skip to content

Commit

Permalink
rename CORDEX_domain to domain_id argument
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbuntemeyer committed Jun 22, 2024
1 parent 6f60db6 commit 81427e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
52 changes: 27 additions & 25 deletions cordex/cmor/cmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def prepare_variable(
allow_units_convert=False,
allow_resample=False,
input_freq=None,
CORDEX_domain=None,
domain_id=None,
time_units=None,
rewrite_time_axis=False,
use_cftime=False,
Expand Down Expand Up @@ -500,11 +500,12 @@ def prepare_variable(
# remove point coordinates, e.g, height2m
if squeeze is True:
var_ds = var_ds.squeeze(drop=True)
if CORDEX_domain is not None:
var_ds.attrs["CORDEX_domain"] = CORDEX_domain
var_ds = _crop_to_cordex_domain(var_ds, CORDEX_domain)
if domain_id is not None:
var_ds.attrs["domain_id"] = domain_id
var_ds = _crop_to_cordex_domain(var_ds, domain_id)
if replace_coords is True:
grid = cordex_domain(CORDEX_domain, bounds=True)
domain_id = domain_id or var_ds.cx.domain_id
grid = cordex_domain(domain_id, bounds=True)
var_ds = var_ds.assign_coords(rlon=grid.rlon, rlat=grid.rlat)
var_ds = var_ds.assign_coords(lon=grid.lon, lat=grid.lat)
var_ds = var_ds.assign_coords(
Expand Down Expand Up @@ -533,8 +534,8 @@ def prepare_variable(
try:
mapping = ds.cf["grid_mapping"] # _get_pole(ds)
except KeyError:
warn(f"adding pole from archive specs: {CORDEX_domain}")
mapping = _get_cordex_pole(CORDEX_domain)
warn(f"adding pole from archive specs: {domain_id}")
mapping = _get_cordex_pole(domain_id)

if "time" in mapping.coords:
raise Exception("grid_mapping variable should have no time coordinate!")
Expand All @@ -556,7 +557,7 @@ def cmorize_variable(
allow_units_convert=False,
allow_resample=False,
input_freq=None,
CORDEX_domain=None,
domain_id=None,
time_units=None,
rewrite_time_axis=False,
outpath=None,
Expand Down Expand Up @@ -599,8 +600,8 @@ def cmorize_variable(
The frequency of the input dataset in pandas notation. It ``None`` and the dataset
contains a time axis, the frequency will be determined automatically using
``pandas.infer_freq`` if possible.
CORDEX_domain: str
Cordex domain short name. If ``None``, the domain will be determined by the ``CORDEX_domain``
domain_id: str
Cordex domain short name. If ``None``, the domain will be determined by the ``domain_id``
global attribute if available.
time_units: str
Time units of the cmorized dataset (``ISO 8601``).
Expand All @@ -622,15 +623,16 @@ def cmorize_variable(
"""
ds = ds.copy()

if CORDEX_domain is None:
if domain_id is None:
try:
CORDEX_domain = ds.CORDEX_domain
except Exception:
domain_id = ds.cx.domain_id
except Exception as e:
warn(e)
warn(
"could not identify CORDEX domain, try to set the 'CORDEX_domain' argument"
"could not identify CORDEX domain, try to set the 'domain_id' argument"
)
elif "CORDEX_domain" not in ds.attrs:
ds.attrs["CORDEX_domain"] = CORDEX_domain
elif "domain_id" not in ds.attrs:
ds.attrs["domain_id"] = domain_id

if inpath is None:
inpath = os.path.dirname(cmor_table)
Expand All @@ -645,7 +647,7 @@ def cmorize_variable(
ds,
out_name,
cmor_table,
CORDEX_domain=CORDEX_domain,
domain_id=domain_id,
mapping_table=mapping_table,
replace_coords=replace_coords,
input_freq=input_freq,
Expand Down Expand Up @@ -677,7 +679,7 @@ def __init__(
allow_units_convert=False,
allow_resample=False,
input_freq=None,
CORDEX_domain=None,
domain_id=None,
time_units=None,
rewrite_time_axis=False,
outpath=None,
Expand Down Expand Up @@ -712,8 +714,8 @@ def __init__(
The frequency of the input dataset in pandas notation. It ``None`` and the dataset
contains a time axis, the frequency will be determined automatically using
``pandas.infer_freq`` if possible.
CORDEX_domain: str
Cordex domain short name. If ``None``, the domain will be determined by the ``CORDEX_domain``
domain_id: str
Cordex domain short name. If ``None``, the domain will be determined by the ``domain_id``
global attribute if available.
time_units: str
Time units of the cmorized dataset (``ISO 8601``).
Expand All @@ -734,7 +736,7 @@ def __init__(
self.replace_coords = replace_coords
self.allow_units_convert = allow_units_convert
self.allow_resample = allow_resample
self.CORDEX_domain = CORDEX_domain
self.domain_id = domain_id
self.time_units = time_units
self.rewrite_time_axis = rewrite_time_axis
self.outpath = outpath
Expand All @@ -754,7 +756,7 @@ def preprocess(
allow_units_convert=False,
allow_resample=False,
input_freq=None,
CORDEX_domain=None,
domain_id=None,
time_units=None,
rewrite_time_axis=False,
use_cftime=False,
Expand All @@ -770,7 +772,7 @@ def preprocess(
allow_units_convert=allow_units_convert or self.allow_units_convert,
allow_resample=allow_resample or self.allow_resample,
input_freq=input_freq,
CORDEX_domain=CORDEX_domain or self.CORDEX_domain,
domain_id=domain_id or self.domain_id,
time_units=time_units or self.time_units,
rewrite_time_axis=rewrite_time_axis or self.rewrite_time_axis,
use_cftime=use_cftime,
Expand Down Expand Up @@ -820,8 +822,8 @@ def cmorize(self, ds, out_name, cmor_table):
The frequency of the input dataset in pandas notation. It ``None`` and the dataset
contains a time axis, the frequency will be determined automatically using
``pandas.infer_freq`` if possible.
CORDEX_domain: str
Cordex domain short name. If ``None``, the domain will be determined by the ``CORDEX_domain``
domain_id: str
Cordex domain short name. If ``None``, the domain will be determined by the ``domain_id``
global attribute if available.
time_units: str
Time units of the cmorized dataset (``ISO 8601``).
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def run_cmorizer(ds, out_name, domain_id, table_id, dataset_table=None, **kwargs
cmor_table=cordex_cmor_table(f"{table_prefix}_{table_id}"),
dataset_table=dataset_table,
grids_table=cordex_cmor_table(f"{table_prefix}_grids"),
CORDEX_domain=domain_id,
domain_id=domain_id,
replace_coords=True,
allow_units_convert=True,
allow_resample=True,
Expand Down

0 comments on commit 81427e0

Please sign in to comment.