def copy_as_alternate(old_v, data_mgr, **kwargs): """Wrapper for :py:func:`dataclasses.replace` that creates a copy of an existing variable (:class:`~src.diagnostic.VarlistEntry`) *old_v* and sets appropriate attributes to designate it as an alternate variable. """ if 'coords' not in kwargs: # dims, scalar_coords are derived attributes set by __post_init__ # if we aren't changing them, must use this syntax to pass them through kwargs['coords'] = (old_v.dims + old_v.scalar_coords) new_v = dataclasses.replace( old_v, _id=util.MDTF_ID(), # assign distinct ID stage=diagnostic.VarlistEntryStage.INITED, # reset state from old_v status=core.ObjectStatus.INACTIVE, # new VE meant as an alternate requirement=diagnostic.VarlistEntryRequirement.ALTERNATE, # plus the specific replacements we want to make: **kwargs) return new_v
def __post_init__(self): if self._id is None: # assign unique ID # so that we don't need to rely on names being unique self._id = util.MDTF_ID() # init object-level logger self.log = util.MDTFObjectLogger.get_logger(self._log_name)
def __post_init__(self): if self.glob_id is None: self.glob_id = util.MDTF_ID() # assign unique ID # if self._has_user_metadata is None: self._has_user_metadata = bool(self.metadata)