class CurrentCycleMover(GridCurrentMover): _schema = CurrentCycleMoverSchema def __init__(self, filename=None, topology_file=None, tide=None, **kwargs): """ Initialize a CurrentCycleMover :param filename: Absolute or relative path to the data file: could be netcdf or filelist :param topology_file=None: Absolute or relative path to topology file. If not given, the GridCurrentMover will compute the topology from the data file. :param tide: A gnome.environment.Tide object to be attached to CatsMover :param active_range: Range of datetimes for when the mover should be active :type active_range: 2-tuple of datetimes :param current_scale: Value to scale current data :param uncertain_duration: How often does a given uncertain element get reset :param uncertain_time_delay: when does the uncertainly kick in. :param uncertain_cross: Scale for uncertainty perpendicular to the flow :param uncertain_along: Scale for uncertainty parallel to the flow :param extrapolate: Allow current data to be extrapolated before and after file data :param time_offset: Time zone shift if data is in GMT uses super: super(CurrentCycleMover,self).__init__(**kwargs) """ # NOTE: will need to add uncertainty parameters # and other dialog fields. # use super with kwargs to invoke base class __init__ self.mover = CyCurrentCycleMover() self._tide = None if tide: self.tide = tide super(CurrentCycleMover, self).__init__(filename=filename, topology_file=topology_file, **kwargs) def __repr__(self): return ( 'CurrentCycletMover(uncertain_duration={0.uncertain_duration}, ' 'uncertain_time_delay={0.uncertain_time_delay}, ' 'uncertain_cross={0.uncertain_cross}, ' 'uncertain_along={0.uncertain_along}, ' 'active_range={1.active_range}, ' 'on={1.on})'.format(self.mover, self)) def __str__(self): return ('CurrentCycleMover - current _state.\n' ' uncertain_duration={0.uncertain_duration}\n' ' uncertain_time_delay={0.uncertain_time_delay}\n' ' uncertain_cross={0.uncertain_cross}\n' ' uncertain_along={0.uncertain_along}' ' active_range time={1.active_range}' ' current on/off status={1.on}'.format(self.mover, self)) @property def tide(self): return self._tide @tide.setter def tide(self, tide_obj): if not isinstance(tide_obj, Tide): raise TypeError('tide must be of type environment.Tide') if isinstance(tide_obj.cy_obj, CyShioTime): self.mover.set_shio(tide_obj.cy_obj) elif isinstance(tide_obj.cy_obj, CyOSSMTime): self.mover.set_ossm(tide_obj.cy_obj) else: raise TypeError('Tide.cy_obj attribute must be either ' 'CyOSSMTime or CyShioTime type ' 'for CurrentCycleMover.') self._tide = tide_obj @property def data_start(self): if self.tide is not None: return self.tide.data_start else: return MinusInfTime() @property def data_stop(self): if self.tide is not None: return self.tide.data_stop else: return InfTime() @property def is_data_on_cells(self): return None
class CurrentCycleMover(GridCurrentMover): _schema = CurrentCycleMoverSchema def __init__(self, filename=None, topology_file=None, tide=None, **kwargs): """ Initialize a CurrentCycleMover :param filename: Absolute or relative path to the data file: could be netcdf or filelist :param topology_file=None: Absolute or relative path to topology file. If not given, the GridCurrentMover will compute the topology from the data file. :param tide: A gnome.environment.Tide object to be attached to CatsMover :param active_range: Range of datetimes for when the mover should be active :type active_range: 2-tuple of datetimes :param current_scale: Value to scale current data :param uncertain_duration: How often does a given uncertain element get reset :param uncertain_time_delay: when does the uncertainly kick in. :param uncertain_cross: Scale for uncertainty perpendicular to the flow :param uncertain_along: Scale for uncertainty parallel to the flow :param extrapolate: Allow current data to be extrapolated before and after file data :param time_offset: Time zone shift if data is in GMT uses super: super(CurrentCycleMover,self).__init__(**kwargs) """ # NOTE: will need to add uncertainty parameters # and other dialog fields. # use super with kwargs to invoke base class __init__ self.mover = CyCurrentCycleMover() self._tide = None if tide: self.tide = tide super(CurrentCycleMover, self).__init__(filename=filename, topology_file=topology_file, **kwargs) def __repr__(self): return ('CurrentCycletMover(uncertain_duration={0.uncertain_duration}, ' 'uncertain_time_delay={0.uncertain_time_delay}, ' 'uncertain_cross={0.uncertain_cross}, ' 'uncertain_along={0.uncertain_along}, ' 'active_range={1.active_range}, ' 'on={1.on})' .format(self.mover, self)) def __str__(self): return ('CurrentCycleMover - current _state.\n' ' uncertain_duration={0.uncertain_duration}\n' ' uncertain_time_delay={0.uncertain_time_delay}\n' ' uncertain_cross={0.uncertain_cross}\n' ' uncertain_along={0.uncertain_along}' ' active_range time={1.active_range}' ' current on/off status={1.on}' .format(self.mover, self)) @property def tide(self): return self._tide @tide.setter def tide(self, tide_obj): if not isinstance(tide_obj, Tide): raise TypeError('tide must be of type environment.Tide') if isinstance(tide_obj.cy_obj, CyShioTime): self.mover.set_shio(tide_obj.cy_obj) elif isinstance(tide_obj.cy_obj, CyOSSMTime): self.mover.set_ossm(tide_obj.cy_obj) else: raise TypeError('Tide.cy_obj attribute must be either ' 'CyOSSMTime or CyShioTime type ' 'for CurrentCycleMover.') self._tide = tide_obj @property def data_start(self): if self.tide is not None: return self.tide.data_start else: return MinusInfTime() @property def data_stop(self): if self.tide is not None: return self.tide.data_stop else: return InfTime() @property def is_data_on_cells(self): return None
class CurrentCycleMover(GridCurrentMover, Serializable): _state = copy.deepcopy(GridCurrentMover._state) _state.add_field([Field('tide', save=True, update=True, save_reference=True)]) _schema = CurrentCycleMoverSchema def __init__(self, filename, topology_file=None, **kwargs): """ Initialize a CurrentCycleMover :param filename: Absolute or relative path to the data file: could be netcdf or filelist :param topology_file=None: Absolute or relative path to topology file. If not given, the GridCurrentMover will compute the topology from the data file. :param tide: A gnome.environment.Tide object to be attached to CatsMover :param active_start: datetime when the mover should be active :param active_stop: datetime after which the mover should be inactive :param current_scale: Value to scale current data :param uncertain_duration: How often does a given uncertain element get reset :param uncertain_time_delay: when does the uncertainly kick in. :param uncertain_cross: Scale for uncertainty perpendicular to the flow :param uncertain_along: Scale for uncertainty parallel to the flow :param extrapolate: Allow current data to be extrapolated before and after file data :param time_offset: Time zone shift if data is in GMT uses super: super(CurrentCycleMover,self).__init__(**kwargs) """ # NOTE: will need to add uncertainty parameters # and other dialog fields. # use super with kwargs to invoke base class __init__ self.mover = CyCurrentCycleMover() self._tide = None tide = kwargs.pop('tide', None) if tide is not None: self.tide = tide super(CurrentCycleMover, self).__init__(filename=filename, topology_file=topology_file, **kwargs) def __repr__(self): return ('GridCurrentMover(uncertain_duration={0.uncertain_duration}, ' 'uncertain_time_delay={0.uncertain_time_delay}, ' 'uncertain_cross={0.uncertain_cross}, ' 'uncertain_along={0.uncertain_along}, ' 'active_start={1.active_start}, ' 'active_stop={1.active_stop}, ' 'on={1.on})' .format(self.mover, self)) def __str__(self): return ('GridCurrentMover - current _state.\n' ' uncertain_duration={0.uncertain_duration}\n' ' uncertain_time_delay={0.uncertain_time_delay}\n' ' uncertain_cross={0.uncertain_cross}\n' ' uncertain_along={0.uncertain_along}' ' active_start time={1.active_start}' ' active_stop time={1.active_stop}' ' current on/off status={1.on}' .format(self.mover, self)) @property def tide(self): return self._tide @tide.setter def tide(self, tide_obj): if not isinstance(tide_obj, Tide): raise TypeError('tide must be of type environment.Tide') if isinstance(tide_obj.cy_obj, CyShioTime): self.mover.set_shio(tide_obj.cy_obj) elif isinstance(tide_obj.cy_obj, CyOSSMTime): self.mover.set_ossm(tide_obj.cy_obj) else: raise TypeError('Tide.cy_obj attribute must be either ' 'CyOSSMTime or CyShioTime type ' 'for CurrentCycleMover.') self._tide = tide_obj @property def is_data_on_cells(self): return None def serialize(self, json_='webapi'): """ Since 'tide' property is saved as a reference when used in save file and 'save' option, need to add appropriate node to CurrentCycleMover schema """ toserial = self.to_serialize(json_) schema = self.__class__._schema() if json_ == 'webapi' and 'tide' in toserial: schema.add(TideSchema(name='tide')) return schema.serialize(toserial) @classmethod def deserialize(cls, json_): """ append correct schema for tide object """ schema = cls._schema() if 'tide' in json_: schema.add(TideSchema()) return schema.deserialize(json_)
class CurrentCycleMover(GridCurrentMover, serializable.Serializable): _state = copy.deepcopy(GridCurrentMover._state) _state.add_field([serializable.Field('tide', save=True, update=True, save_reference=True)]) _schema = CurrentCycleMoverSchema def __init__(self, filename, topology_file=None, **kwargs): """ Initialize a CurrentCycleMover :param filename: Absolute or relative path to the data file: could be netcdf or filelist :param topology_file=None: Absolute or relative path to topology file. If not given, the GridCurrentMover will compute the topology from the data file. :param tide: A gnome.environment.Tide object to be attached to CatsMover :param active_start: datetime when the mover should be active :param active_stop: datetime after which the mover should be inactive :param current_scale: Value to scale current data :param uncertain_duration: How often does a given uncertain element get reset :param uncertain_time_delay: when does the uncertainly kick in. :param uncertain_cross: Scale for uncertainty perpendicular to the flow :param uncertain_along: Scale for uncertainty parallel to the flow :param extrapolate: Allow current data to be extrapolated before and after file data :param time_offset: Time zone shift if data is in GMT uses super: super(CurrentCycleMover,self).__init__(**kwargs) """ # NOTE: will need to add uncertainty parameters # and other dialog fields. # use super with kwargs to invoke base class __init__ self.mover = CyCurrentCycleMover() tide = kwargs.pop('tide', None) self._tide = None if tide is not None: self.tide = tide super(CurrentCycleMover, self).__init__(filename=filename, topology_file=topology_file, **kwargs) def __repr__(self): return ('GridCurrentMover(uncertain_duration={0.uncertain_duration}, ' 'uncertain_time_delay={0.uncertain_time_delay}, ' 'uncertain_cross={0.uncertain_cross}, ' 'uncertain_along={0.uncertain_along}, ' 'active_start={1.active_start}, ' 'active_stop={1.active_stop}, ' 'on={1.on})' .format(self.mover, self)) def __str__(self): return ('GridCurrentMover - current _state.\n' ' uncertain_duration={0.uncertain_duration}\n' ' uncertain_time_delay={0.uncertain_time_delay}\n' ' uncertain_cross={0.uncertain_cross}\n' ' uncertain_along={0.uncertain_along}' ' active_start time={1.active_start}' ' active_stop time={1.active_stop}' ' current on/off status={1.on}' .format(self.mover, self)) @property def tide(self): return self._tide @tide.setter def tide(self, tide_obj): if not isinstance(tide_obj, environment.Tide): raise TypeError('tide must be of type environment.Tide') if isinstance(tide_obj.cy_obj, CyShioTime): self.mover.set_shio(tide_obj.cy_obj) elif isinstance(tide_obj.cy_obj, CyOSSMTime): self.mover.set_ossm(tide_obj.cy_obj) else: raise TypeError('Tide.cy_obj attribute must be either ' 'CyOSSMTime or CyShioTime type ' 'for CurrentCycleMover.') self._tide = tide_obj def serialize(self, json_='webapi'): """ Since 'tide' property is saved as a reference when used in save file and 'save' option, need to add appropriate node to CurrentCycleMover schema """ toserial = self.to_serialize(json_) schema = self.__class__._schema() if json_ == 'webapi' and 'tide' in toserial: schema.add(environment.TideSchema(name='tide')) return schema.serialize(toserial) @classmethod def deserialize(cls, json_): """ append correct schema for tide object """ schema = cls._schema() if 'tide' in json_: schema.add(environment.TideSchema()) return schema.deserialize(json_)