Ejemplo n.º 1
0
    def check_time(self, wind, model_time):
        '''
            Should have an option to extrapolate but for now we do by default

            TODO, FIXME: This function does not appear to be used by anything.
                         Removing it does not break any of the unit tests.
                         If it is not used, it should probably go away.
        '''
        new_model_time = model_time

        if wind is not None:
            if model_time is not None:
                timeval = date_to_sec(model_time)
                start_time = wind.get_start_time()
                end_time = wind.get_end_time()

                if end_time == start_time:
                    return model_time

                if timeval < start_time:
                    new_model_time = sec_to_datetime(start_time)

                if timeval > end_time:
                    new_model_time = sec_to_datetime(end_time)
            else:
                return model_time

        return new_model_time
Ejemplo n.º 2
0
    def __init__(self, wind=None, extrapolate=False, **kwargs):
        #def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            kwargs['make_default_refs'] = \
                kwargs.pop('make_default_refs', False)
            kwargs['name'] = \
                kwargs.pop('name', wind.name)

        self.extrapolate = extrapolate
        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

        # this will have to be updated when wind is set or changed
        if self.wind is not None:
            self.real_data_start = time_utils.sec_to_datetime(
                self.wind.ossm.get_start_time())
            self.real_data_stop = time_utils.sec_to_datetime(
                self.wind.ossm.get_end_time())
Ejemplo n.º 3
0
    def __init__(self, wind=None, extrapolate=False, **kwargs):
    #def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            kwargs['make_default_refs'] = \
                kwargs.pop('make_default_refs', False)
            kwargs['name'] = \
                kwargs.pop('name', wind.name)

        self.extrapolate = extrapolate
        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

		# this will have to be updated when wind is set or changed
        if self.wind is not None:
            self.real_data_start = time_utils.sec_to_datetime(self.wind.ossm.get_start_time())
            self.real_data_stop = time_utils.sec_to_datetime(self.wind.ossm.get_end_time())
Ejemplo n.º 4
0
    def check_time(self, wind, model_time):
        '''
            Should have an option to extrapolate but for now we do by default

            TODO, FIXME: This function does not appear to be used by anything.
                         Removing it does not break any of the unit tests.
                         If it is not used, it should probably go away.
        '''
        new_model_time = model_time

        if wind is not None:
            if model_time is not None:
                timeval = date_to_sec(model_time)
                start_time = wind.get_start_time()
                end_time = wind.get_end_time()

                if end_time == start_time:
                    return model_time

                if timeval < start_time:
                    new_model_time = sec_to_datetime(start_time)

                if timeval > end_time:
                    new_model_time = sec_to_datetime(end_time)
            else:
                return model_time

        return new_model_time
Ejemplo n.º 5
0
    def __init__(self,
                 filename,
                 topology_file=None,
                 extrapolate=False,
                 time_offset=0,
                 **kwargs):
        """
        :param wind_file: file containing wind data on a grid
        :param filename: file containing wind data on a grid
        :param topology_file: Default is None. When exporting topology, it
                              is stored in this file
        :param wind_scale: Value to scale wind data
        :param extrapolate: Allow current data to be extrapolated before and
                            after file data
        :param time_offset: Time zone shift if data is in GMT

        Pass optional arguments to base class
        uses super: super(GridWindMover,self).__init__(\*\*kwargs)
        """

        if not os.path.exists(filename):
            raise ValueError(
                'Path for wind file does not exist: {0}'.format(filename))

        if topology_file is not None:
            if not os.path.exists(topology_file):
                raise ValueError(
                    'Path for Topology file does not exist: {0}'.format(
                        topology_file))

        # is wind_file and topology_file is stored with cy_gridwind_mover?
        self.filename = filename
        self.topology_file = topology_file
        self.mover = CyGridWindMover(wind_scale=kwargs.pop('wind_scale', 1))
        self.name = os.path.split(filename)[1]

        super(GridWindMover, self).__init__(**kwargs)

        self.mover.text_read(filename, topology_file)

        self.real_data_start = sec_to_datetime(self.mover.get_start_time())
        self.real_data_stop = sec_to_datetime(self.mover.get_end_time())

        self.mover.extrapolate_in_time(extrapolate)
        self.mover.offset_time(time_offset * 3600.)
Ejemplo n.º 6
0
    def data_stop(self):
        """
        The stop time of the valid data for this wind timeseries

        If there is one data point -- it's a constant wind
        so data_start is -InfDateTime
        """
        if self.ossm.get_num_values() == 1:
            return InfDateTime("inf")
        else:
            return sec_to_datetime(self.ossm.get_end_time())
Ejemplo n.º 7
0
    def data_stop(self):
        """
        The stop time of the valid data for this wind timeseries

        If there is one data point -- it's a constant wind
        so data_start is -InfDateTime
        """
        if self.ossm.get_num_values() == 1:
            return InfDateTime("inf")
        else:
            return sec_to_datetime(self.ossm.get_end_time())
Ejemplo n.º 8
0
    def __init__(self, wind_file, topology_file=None,
                 extrapolate=False, time_offset=0,
                 **kwargs):
        """
        :param wind_file: file containing wind data on a grid
        :param topology_file: Default is None. When exporting topology, it
                              is stored in this file
        :param wind_scale: Value to scale wind data
        :param extrapolate: Allow current data to be extrapolated before and
                            after file data
        :param time_offset: Time zone shift if data is in GMT

        Pass optional arguments to base class
        uses super: super(GridWindMover,self).__init__(\*\*kwargs)
        """

        if not os.path.exists(wind_file):
            raise ValueError('Path for wind file does not exist: {0}'
                             .format(wind_file))

        if topology_file is not None:
            if not os.path.exists(topology_file):
                raise ValueError('Path for Topology file does not exist: {0}'
                                 .format(topology_file))

        # is wind_file and topology_file is stored with cy_gridwind_mover?
        self.wind_file = wind_file
        self.topology_file = topology_file
        self.mover = CyGridWindMover(wind_scale=kwargs.pop('wind_scale', 1))
        self.name = os.path.split(wind_file)[1]
        super(GridWindMover, self).__init__(**kwargs)

        self.mover.text_read(wind_file, topology_file)
        self.real_data_start = time_utils.sec_to_datetime(self.mover.get_start_time())
        self.real_data_stop = time_utils.sec_to_datetime(self.mover.get_end_time())
        self.mover.extrapolate_in_time(extrapolate)
        self.mover.offset_time(time_offset * 3600.)
Ejemplo n.º 9
0
 def data_stop(self):
     return sec_to_datetime(self.mover.get_end_time())
Ejemplo n.º 10
0
 def data_start(self):
     return sec_to_datetime(self.mover.get_start_time())
Ejemplo n.º 11
0
 def data_stop(self):
     """
     The stop time of the valid data for this wind timeseries
     """
     return sec_to_datetime(self.ossm.get_end_time())
Ejemplo n.º 12
0
    def __init__(self, filename,
                 topology_file=None,
                 extrapolate=False,
                 time_offset=0,
                 current_scale=1,
                 uncertain_along=0.5,
                 uncertain_across=0.25,
                 num_method='Euler',
                 **kwargs):
        """
        Initialize a GridCurrentMover

        :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 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
        :param num_method: Numerical method for calculating movement delta.
                           Default Euler
                           option: Runga-Kutta 4 (RK4)

        uses super, super(GridCurrentMover,self).__init__(\*\*kwargs)
        """
        # if child is calling, the self.mover is set by child - do not reset
        if type(self) == GridCurrentMover:
            self.mover = CyGridCurrentMover()

        if not os.path.exists(filename):
            raise ValueError('Path for current file does not exist: {0}'
                             .format(filename))

        if topology_file is not None:
            if not os.path.exists(topology_file):
                raise ValueError('Path for Topology file does not exist: {0}'
                                 .format(topology_file))

        super(GridCurrentMover, self).__init__(**kwargs)

        # check if this is stored with cy_gridcurrent_mover?
        self.filename = filename
        self.name = os.path.split(filename)[1]

        # check if this is stored with cy_gridcurrent_mover?
        self.topology_file = topology_file
        self.current_scale = current_scale
        self.uncertain_along = uncertain_along
        self.uncertain_across = uncertain_across

        self.mover.text_read(filename, topology_file)
        self.mover.extrapolate_in_time(extrapolate)
        self.mover.offset_time(time_offset * 3600.)

        if type(self) != CurrentCycleMover:
            self.real_data_start = sec_to_datetime(self.mover.get_start_time())
            self.real_data_stop = sec_to_datetime(self.mover.get_end_time())

        self.num_method = num_method

        # super(GridCurrentMover, self).__init__(**kwargs)

        if self.topology_file is None:
            self.topology_file = filename + '.dat'
            self.export_topology(self.topology_file)
Ejemplo n.º 13
0
 def data_stop(self):
     return sec_to_datetime(self.mover.get_end_time())
Ejemplo n.º 14
0
 def data_start(self):
     return sec_to_datetime(self.mover.get_start_time())
Ejemplo n.º 15
0
 def data_stop(self):
     if isinstance(self.cy_obj, CyShioTime):
         return InfDateTime("inf")
     else:
         return sec_to_datetime(self.cy_obj.get_end_time())