Skip to content

Commit

Permalink
More pr stuff (NOAA-GFDL#570)
Browse files Browse the repository at this point in the history
* add property and setter methods to DataModel DmVariable class attributes that are updated in the preprocessor

* update the translation attributes in each varlistentry with setter functions in the precip rate and level
extraction edit_routines and return the original varlistentry
append the 4-D variable as an alternate attribute in the level extraction function

* remove unused imports from preprocessor
  • Loading branch information
wrongkindofdoctor authored May 20, 2024
1 parent 8047594 commit 7560e74
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ def dim_axes(self):
"""
return self.build_axes(self.dims, verify=False)

@dim_axes.setter
def dim_axes(self, value):
self._dim_axes = value

@property
def X(self):
"""Return X axis dimension coordinate if defined, else None."""
Expand Down Expand Up @@ -638,6 +642,10 @@ def dim_axes_set(self):
"""Return frozenset of dimension coordinate axes labels."""
return frozenset(self.dim_axes.keys())

@dim_axes_set.setter
def dim_axes_set(self, value):
self._dim_axes_set = value

@property
def is_static(self):
"""Whether the variable has time dependence (bool)."""
Expand Down Expand Up @@ -773,6 +781,10 @@ def axes(self):
"""
return self.build_axes(self.dims, self.scalar_coords, verify=False)

@axes.setter
def axes(self, value):
self._axes = value

@property
def axes_set(self):
"""Superset of the :meth:`dim_axes_set` frozenset (which contains axes labels
Expand All @@ -781,6 +793,53 @@ def axes_set(self):
"""
return frozenset(self.axes.keys())

@axes_set.setter
def axes_set(self, value):
self._axes_set = value

@property
def name(self):
return self._name

@name.setter
def name(self, value: str):
self._name = value

@property
def standard_name(self):
return self._standard_name

@standard_name.setter
def standard_name(self, value: str):
self._standard_name = value.lower()

@property
def units(self):
return self._units

@units.setter
def units(self, value):
self._units = value

@property
def long_name(self):
return self._long_name

@long_name.setter
def long_name(self, value: str):
self._long_name = value

@property
def realm(self):
return self._realm

@realm.setter
def realm(self, value: str):
self._realm = value




def add_scalar(self, ax, ax_value, **kwargs):
"""Metadata operation corresponding to taking a slice of a higher-dimensional
variable (extracting its values at axis *ax* = *ax_value*). The
Expand Down
16 changes: 13 additions & 3 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def edit_request(self, v: varlist_util.VarlistEntry, **kwargs):
The signature of this method is altered by the :func:`edit_request_wrapper`
decorator.
"""
v_to_translate = None

std_name = getattr(v, 'standard_name', "")
if std_name not in self._rate_d and std_name not in self._flux_d:
# logic not applicable to this VE; do nothing and return varlistEntry for
Expand Down Expand Up @@ -310,7 +310,10 @@ def edit_request(self, v: varlist_util.VarlistEntry, **kwargs):
return None
new_v = copy_as_alternate(v)
new_v.translation = new_tv
return new_v
v.translation.standard_name = new_tv.standard_name
v.translation.units = new_tv.units
v.translation.long_name = new_tv.long_name
return v

def execute(self, var, ds, **kwargs):
"""Convert units of dependent variable *ds* between precip rate and
Expand Down Expand Up @@ -565,7 +568,14 @@ def edit_request(self, v: varlist_util.VarlistEntry, **kwargs):
)
new_v = copy_as_alternate(v)
new_v.translation = new_tv
return new_v
v.alternates.append(v.translation)
v.translation.name = new_tv.name
v.translation.long_name = new_tv.long_name
v.translation.units = new_tv.units
v.translation.dim_axes = new_tv.dim_axes
v.translation.dim_axes_set = new_tv.dim_axes_set

return v

def execute(self, var, ds, **kwargs):
"""Determine if level extraction is needed (if *var* has a scalar Z
Expand Down

0 comments on commit 7560e74

Please sign in to comment.