예제 #1
0
    def from_netCDF(
        cls,
        filename=None,
        extrapolate=False,
        time_offset=0,
        current_scale=1,
        uncertain_duration=24 * 3600,
        uncertain_time_delay=0,
        uncertain_along=0.5,
        uncertain_across=0.25,
        uncertain_cross=0.25,
        default_num_method="Trapezoid",
        **kwargs
    ):

        wind = GridWind.from_netCDF(filename, **kwargs)
        return cls(
            wind=wind,
            filename=filename,
            extrapolate=extrapolate,
            time_offset=time_offset,
            current_scale=current_scale,
            uncertain_along=uncertain_along,
            uncertain_across=uncertain_across,
            uncertain_cross=uncertain_cross,
            default_num_method=default_num_method,
        )
예제 #2
0
    def test_gen_varnames(self):
        import netCDF4 as nc4
        from gnome.environment import GridCurrent, GridWind, IceVelocity
        ds = nc4.Dataset('testname', 'w', diskless=True, persist=False)
        ds.createDimension('y', 5)
        ds.createDimension('x', 5)
        ds.createVariable('x', 'f8', dimensions=('x', 'y'))
        ds['x'].standard_name = 'eastward_sea_water_velocity'
        ds.createVariable('y', 'f8', dimensions=('x', 'y'))
        ds['y'].standard_name = 'northward_sea_water_velocity'
        ds.createVariable('xw', 'f8', dimensions=('x', 'y'))
        ds['xw'].long_name = 'eastward_wind'
        ds.createVariable('yw', 'f8', dimensions=('x', 'y'))
        ds['yw'].long_name = 'northward_wind'
        ds.createVariable('ice_u', 'f8', dimensions=('x', 'y'))
        ds.createVariable('ice_v', 'f8', dimensions=('x', 'y'))
        names = GridCurrent._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'x'
        assert names[1] == names.v == 'y'
        names = GridWind._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'xw'
        assert names[1] == names.v == 'yw'
        names = IceVelocity._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'ice_u'
        assert names[1] == names.v == 'ice_v'

        curr_file = os.path.join(s_data, 'staggered_sine_channel.nc')
        gc = GridCurrent.from_netCDF(filename=curr_file)
        assert gc.u == gc.variables[0]
        assert gc.varnames[0] == 'u'
예제 #3
0
    def from_netCDF(cls,
                    filename=None,
                    time_offset=0,
                    wind_scale=1,
                    uncertain_duration=24 * 3600,
                    uncertain_time_delay=0,
                    uncertain_along=.5,
                    uncertain_across=.25,
                    uncertain_cross=.25,
                    default_num_method='RK2',
                    **kwargs):

        wind = GridWind.from_netCDF(filename, **kwargs)

        return cls(wind=wind,
                   filename=filename,
                   time_offset=time_offset,
                   wind_scale=wind_scale,
                   uncertain_along=uncertain_along,
                   uncertain_across=uncertain_across,
                   uncertain_cross=uncertain_cross,
                   default_num_method=default_num_method)
예제 #4
0
    def from_netCDF(cls,
                    filename=None,
                    time_offset=0,
                    scale_value=1,
                    uncertain_duration=24 * 3600,
                    uncertain_time_delay=0,
                    uncertain_along=.5,
                    uncertain_across=.25,
                    uncertain_cross=.25,
                    default_num_method='RK2',
                    **kwargs):

        wind = GridWind.from_netCDF(filename, **kwargs)

        return cls(wind=wind,
                   filename=filename,
                   time_offset=time_offset,
                   scale_value=scale_value,
                   uncertain_along=uncertain_along,
                   uncertain_across=uncertain_across,
                   uncertain_cross=uncertain_cross,
                   default_num_method=default_num_method)
예제 #5
0
    def test_gen_varnames(self):
        import netCDF4 as nc4
        from gnome.environment import GridCurrent, GridWind, IceVelocity

        ds = nc4.Dataset('testname', 'w', diskless=True, persist=False)
        ds.createDimension('y', 5)
        ds.createDimension('x', 5)

        ds.createVariable('x', 'f8', dimensions=('x', 'y'))
        ds['x'].standard_name = 'eastward_sea_water_velocity'

        ds.createVariable('y', 'f8', dimensions=('x', 'y'))
        ds['y'].standard_name = 'northward_sea_water_velocity'

        ds.createVariable('xw', 'f8', dimensions=('x', 'y'))
        ds['xw'].long_name = 'eastward_wind'

        ds.createVariable('yw', 'f8', dimensions=('x', 'y'))
        ds['yw'].long_name = 'northward_wind'

        ds.createVariable('ice_u', 'f8', dimensions=('x', 'y'))
        ds.createVariable('ice_v', 'f8', dimensions=('x', 'y'))

        names = GridCurrent._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'x'
        assert names[1] == names.v == 'y'

        names = GridWind._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'xw'
        assert names[1] == names.v == 'yw'

        names = IceVelocity._gen_varnames(dataset=ds)
        assert names[0] == names.u == 'ice_u'
        assert names[1] == names.v == 'ice_v'

        curr_file = os.path.join(s_data, 'staggered_sine_channel.nc')
        gc = GridCurrent.from_netCDF(filename=curr_file)
        assert gc.u == gc.variables[0]
        assert gc.varnames[0] == 'u'
예제 #6
0
    def from_netCDF(cls,
                    filename=None,
                    extrapolate=False,
                    time_offset=0,
                    current_scale=1,
                    uncertain_duration=24 * 3600,
                    uncertain_time_delay=0,
                    uncertain_along=.5,
                    uncertain_across=.25,
                    uncertain_cross=.25,
                    default_num_method='Trapezoid',
                    **kwargs):

        wind = GridWind.from_netCDF(filename, **kwargs)
        return cls(wind=wind,
                   filename=filename,
                   extrapolate=extrapolate,
                   time_offset=time_offset,
                   current_scale=current_scale,
                   uncertain_along=uncertain_along,
                   uncertain_across=uncertain_across,
                   uncertain_cross=uncertain_cross,
                   default_num_method=default_num_method)
예제 #7
0
    def __init__(self,
                 filename=None,
                 wind=None,
                 time_offset=0,
                 uncertain_duration=3,
                 uncertain_time_delay=0,
                 uncertain_speed_scale=2.,
                 uncertain_angle_scale=0.4,
                 wind_scale=1,
                 default_num_method='RK2',
                 extrapolation_is_allowed=False,
                 **kwargs):
        """
        Initialize a PyWindMover

        :param filename: absolute or relative path to the data file(s):
                         could be a string or list of strings in the
                         case of a multi-file dataset
        :param wind: Environment object representing wind to be
                        used. If this is not specified, a GridWind object
                        will attempt to be instantiated from the file

        :param active_range: Range of datetimes for when the mover should be
                             active
        :type active_range: 2-tuple of datetimes

        :param wind_scale: Value to scale wind 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 time_offset: Time zone shift if data is in GMT
        :param num_method: Numerical method for calculating movement delta.
                           Choices:('Euler', 'RK2', 'RK4')
                           Default: RK2

        """
        self.wind = wind
        self.make_default_refs = False

        self.filename = filename

        if self.wind is None:
            if filename is None:
                raise ValueError("must provide a filename or wind object")
            else:
                self.wind = GridWind.from_netCDF(filename=self.filename,
                                                 **kwargs)

        self.extrapolation_is_allowed = extrapolation_is_allowed
        self.uncertain_duration = uncertain_duration
        self.uncertain_time_delay = uncertain_time_delay
        self.uncertain_speed_scale = uncertain_speed_scale
        self.wind_scale = wind_scale
        self.time_offset = time_offset

        # also sets self._uncertain_angle_units
        self.uncertain_angle_scale = uncertain_angle_scale

        (super(PyWindMover, self)
         .__init__(default_num_method=default_num_method, **kwargs))

        self.array_types.update({'windages',
                                 'windage_range',
                                 'windage_persist'})
예제 #8
0
    def __init__(self,
                 filename=None,
                 wind=None,
                 time_offset=0,
                 uncertain_duration=3,
                 uncertain_time_delay=0,
                 uncertain_speed_scale=2.,
                 uncertain_angle_scale=0.4,
                 scale_value=1,
                 default_num_method='RK2',
                 **kwargs):
        """
        Initialize a PyWindMover

        :param filename: absolute or relative path to the data file(s):
                         could be a string or list of strings in the
                         case of a multi-file dataset
        :param wind: Environment object representing wind to be
                        used. If this is not specified, a GridWind object
                        will attempt to be instantiated from the file

        :param active_range: Range of datetimes for when the mover should be
                             active
        :type active_range: 2-tuple of datetimes

        :param scale_value: Value to scale wind 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 time_offset: Time zone shift if data is in GMT
        :param num_method: Numerical method for calculating movement delta.
                           Choices:('Euler', 'RK2', 'RK4')
                           Default: RK2

        """

        (super(PyWindMover,
               self).__init__(default_num_method=default_num_method, **kwargs))
        self.wind = wind
        self.make_default_refs = False

        self.filename = filename

        if self.wind is None:
            if filename is None:
                raise ValueError("must provide a filename or wind object")
            else:
                self.wind = GridWind.from_netCDF(filename=self.filename,
                                                 **kwargs)

        self.uncertain_duration = uncertain_duration
        self.uncertain_time_delay = uncertain_time_delay
        self.uncertain_speed_scale = uncertain_speed_scale
        self.scale_value = scale_value
        self.time_offset = time_offset

        # also sets self._uncertain_angle_units
        self.uncertain_angle_scale = uncertain_angle_scale

        self.array_types.update({
            'windages': gat('windages'),
            'windage_range': gat('windage_range'),
            'windage_persist': gat('windage_persist')
        })
예제 #9
0
            # dataset=ds_c,
            grid_topology={
                'node_lon': 'lonc',
                'node_lat': 'latc'
            })
        c_mover = PyCurrentMover(current=g_curr, default_num_method='RK4')
        model.movers += c_mover

        print 'creating wind MFDataset'
        ds_w = nc4.MFDataset(file_list_w)

        print 'adding a WindMover (Euler):'
        g_wind = GridWind.from_netCDF(
            filename=file_list_w,
            # dataset=ds_w,
            grid_topology={
                'node_lon': 'lonc',
                'node_lat': 'latc'
            })
        w_mover = PyWindMover(wind=g_wind, default_num_method='Euler')
        model.movers += w_mover

        model.environment += g_wind
        water = Water(temperature=290.0, salinity=33.0)
        waves = Waves(g_wind)
        model.weatherers += Evaporation(water=water, wind=g_wind)
        model.weatherers += NaturalDispersion(waves=waves)

        # print 'adding a CurrentMover (Trapeziod/RK4):'
        # c_mover = GridCurrentMover(os.path.join(setup.Data_Dir,setup.CurrCatFile),
        #                            os.path.join(setup.Data_Dir,setup.CurrTopoFile),