예제 #1
0
 def __init__(self,
              name=None,
              units=None,
              time=None,
              variables=None,
              grid=None,
              grid_file=None,
              data_file=None,
              dataset=None):
     VelocityGrid.__init__(self,
                           name=name,
                           units=units,
                           time=time,
                           variables=variables,
                           grid=grid,
                           grid_file=grid_file,
                           data_file=data_file,
                           dataset=dataset)
     self.angle = None
     df = None
     if dataset is not None:
         df = dataset
     elif data_file is not None:
         df = _get_dataset(data_file)
     if df is not None and 'angle' in df.variables.keys():
         # Unrotated ROMS Grid!
         self.angle = GriddedProp(name='angle',
                                  units='radians',
                                  time=None,
                                  grid=self.grid,
                                  data=df['angle'])
예제 #2
0
 def __init__(self,
              name=None,
              units=None,
              time=None,
              variables=None,
              grid=None,
              grid_file=None,
              data_file=None,
              dataset=None,
              **kwargs):
     VelocityGrid.__init__(self,
                           name=name,
                           units=units,
                           time=time,
                           variables=variables,
                           grid=grid,
                           grid_file=grid_file,
                           data_file=data_file,
                           dataset=dataset)
     self.angle = None
     df = None
     if dataset is not None:
         df = dataset
     elif grid_file is not None:
         df = _get_dataset(grid_file)
     if df is not None and 'angle' in df.variables.keys():
         # Unrotated ROMS Grid!
         self.angle = GriddedProp(name='angle', units='radians', time=None, grid=self.grid, data=df['angle'])
예제 #3
0
def gp2():
    return GriddedProp(name='v;',
                       units='m/s',
                       time=grid_time,
                       data=grid_v,
                       data_file=curr_file,
                       grid=test_grid,
                       grid_file=curr_file)
예제 #4
0
    def test_construction(self):

        u = GriddedProp(name='u',
                        units='m/s',
                        data=grid_u,
                        grid=test_grid,
                        time=grid_time,
                        data_file='tbofs_example.nc',
                        grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(name='u',
                            units='m/s',
                            data=None,  # NO DATA
                            grid=test_grid,
                            time=grid_time,
                            data_file='tbofs_example.nc',
                            grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(name='u',
                            units='m/s',
                            data=grid_u,
                            grid=None,  # NO GRID
                            time=grid_time,
                            data_file='tbofs_example.nc',
                            grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(name='u',
                            units='m/s',
                            data=u_data,  # BAD DATA SHAPE
                            grid=test_grid,
                            time=grid_time,
                            data_file='tbofs_example.nc',
                            grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(name='u',
                            units='m/s',
                            data=grid_u,
                            grid=test_grid,
                            time=dates2,  # BAD TIME SHAPE
                            data_file='tbofs_example.nc',
                            grid_file='tbofs_example.nc')

        topology = {'node_lon': 'lonc',
                    'node_lat': 'latc'}
        k = GriddedProp.from_netCDF(name='u',
                                    depth=None,
                                    grid_file=curr_file,
                                    grid_topology=topology,
                                    data_file=curr_file,
                                    varname='water_u')
        assert k.name == u.name
        assert k.units == 'meter second-1'
        # fixme: this was failing
        #assert k.time == u.time
        assert k.data[0, 0, 0] == u.data[0, 0, 0]
예제 #5
0
    def test_construction(self):

        u = GriddedProp(name='u',
                        units='m/s',
                        data=grid_u,
                        grid=test_grid,
                        time=grid_time,
                        data_file='tbofs_example.nc',
                        grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(
                name='u',
                units='m/s',
                data=None,  #NO DATA
                grid=test_grid,
                time=grid_time,
                data_file='tbofs_example.nc',
                grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(
                name='u',
                units='m/s',
                data=grid_u,
                grid=None,  #NO GRID
                time=grid_time,
                data_file='tbofs_example.nc',
                grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(
                name='u',
                units='m/s',
                data=u_data,  #BAD DATA SHAPE
                grid=test_grid,
                time=grid_time,
                data_file='tbofs_example.nc',
                grid_file='tbofs_example.nc')
        with pytest.raises(ValueError):
            u = GriddedProp(
                name='u',
                units='m/s',
                data=grid_u,
                grid=test_grid,
                time=dates2,  #BAD TIME SHAPE
                data_file='tbofs_example.nc',
                grid_file='tbofs_example.nc')

        topology = {'node_lon': 'lonc', 'node_lat': 'latc'}
        k = GriddedProp.from_netCDF(name='u',
                                    grid_file=curr_file,
                                    grid_topology=topology,
                                    data_file=curr_file,
                                    varname='water_u')
        assert k.name == u.name
        assert k.units == 'meter second-1'
        assert k.time == u.time
        assert k.data[0, 0, 0] == u.data[0, 0, 0]
예제 #6
0
 def __init__(self, angle=None, **kwargs):
     """
     :param angle: scalar field of cell rotation angles (for rotated/distorted grids)
     """
     if 'variables' in kwargs:
         variables = kwargs['variables']
         if len(variables) == 2:
             variables.append(TimeSeriesProp(name='constant w', data=[0.0], time=Time.constant_time(), units='m/s'))
         kwargs['variables'] = variables
     if angle is None:
         df = None
         if kwargs.get('dataset', None) is not None:
             df = kwargs['dataset']
         elif kwargs.get('grid_file', None) is not None:
             df = _get_dataset(kwargs['grid_file'])
         if df is not None and 'angle' in df.variables.keys():
             # Unrotated ROMS Grid!
             self.angle = GriddedProp(name='angle', units='radians', time=None, grid=kwargs['grid'], data=df['angle'])
         else:
             self.angle = None
     else:
         self.angle = angle
     super(VelocityGrid, self).__init__(**kwargs)
예제 #7
0
vy = vy[np.newaxis, :] * 20
# vx = 1/x[np.newaxis,:]
# vy = 1/y[np.newaxis,:]
# vx[vx == np.inf] = 0
# vy[vy == np.inf] = 0
# vx = vx/mag *30
# vy = vy/mag *30
# v_x = vx.copy()
# v_y - vy.copy()
# sl = [0,0:30,31:61]
# v_x = vx[:,0] * np.cos(angs) - value[:,1] * np.sin(angs)
# y = value[:,0] * np.sin(angs) + value[:,1] * np.cos(angs)
# value[:,0] = x
# value[:,1] = y

vels_x = GriddedProp(name='v_x', units='m/s', time=[t], grid=g, data=vx)
vels_y = GriddedProp(name='v_y', units='m/s', time=[t], grid=g, data=vy)
vg = GridCurrent(variables=[vels_y, vels_x], time=[t], grid=g, units='m/s')
point = np.zeros((1, 2))
print vg.at(point, t)

# define base directory
base_dir = os.path.dirname(__file__)


def make_model():
    duration_hrs = 48
    time_step = 900
    num_steps = duration_hrs * 3600 / time_step
    mod = Model(start_time=t,
                duration=timedelta(hours=duration_hrs),
예제 #8
0
class GridWind(VelocityGrid, Environment):

    _ref_as = 'wind'

    default_names = [['air_u', 'air_v'], ['Air_U', 'Air_V'],
                     ['air_ucmp', 'air_vcmp'], ['wind_u', 'wind_v']]

    def __init__(self,
                 name=None,
                 units=None,
                 time=None,
                 variables=None,
                 grid=None,
                 grid_file=None,
                 data_file=None,
                 dataset=None):
        VelocityGrid.__init__(self,
                              name=name,
                              units=units,
                              time=time,
                              variables=variables,
                              grid=grid,
                              grid_file=grid_file,
                              data_file=data_file,
                              dataset=dataset)
        self.angle = None
        df = None
        if dataset is not None:
            df = dataset
        elif data_file is not None:
            df = _get_dataset(data_file)
        if df is not None and 'angle' in df.variables.keys():
            # Unrotated ROMS Grid!
            self.angle = GriddedProp(name='angle',
                                     units='radians',
                                     time=None,
                                     grid=self.grid,
                                     data=df['angle'])

    def at(self, points, time, units=None, depth=-1, extrapolate=False):
        '''
        Find the value of the property at positions P at time T

        :param points: Coordinates to be queried (P)
        :param time: The time at which to query these points (T)
        :param depth: Specifies the depth level of the variable
        :param units: units the values will be returned in (or converted to)
        :param extrapolate: if True, extrapolation will be supported
        :type points: Nx2 array of double
        :type time: datetime.datetime object
        :type depth: integer
        :type units: string such as ('m/s', 'knots', etc)
        :type extrapolate: boolean (True or False)
        :return: returns a Nx2 array of interpolated values
        :rtype: double
        '''
        value = super(GridWind, self).at(points,
                                         time,
                                         units,
                                         extrapolate=extrapolate)
        if self.angle is not None:
            angs = self.angle.at(points, time, extrapolate=extrapolate)
            x = value[:, 0] * np.cos(angs) - value[:, 1] * np.sin(angs)
            y = value[:, 0] * np.sin(angs) + value[:, 1] * np.cos(angs)
            value[:, 0] = x
            value[:, 1] = y
        return value
예제 #9
0
    pp.pprint(velfromsave)

    velfromsave.at(np.array([(0, 0)]), datetime(2000, 1, 1, 0, 0))

    url = (
        'http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml'
    )
    test_grid = pysgrid.load_grid(url)
    grid_u = test_grid.u
    grid_v = test_grid.v
    grid_time = test_grid.ocean_time._data

    u2 = GriddedProp('u',
                     'm/s',
                     time=grid_time,
                     data=grid_u,
                     grid=test_grid,
                     data_file=url,
                     grid_file=url)
    v2 = GriddedProp('v',
                     'm/s',
                     time=grid_time,
                     data=grid_v,
                     grid=test_grid,
                     data_file=url,
                     grid_file=url)

    print "got here"

    #     pp.pprint(vel2.serialize())
예제 #10
0
class GridWind(VelocityGrid, Environment):

    _ref_as = 'wind'

    default_names = [['air_u', 'air_v'], ['Air_U', 'Air_V'], ['air_ucmp', 'air_vcmp'], ['wind_u', 'wind_v']]

    def __init__(self,
                 name=None,
                 units=None,
                 time=None,
                 variables=None,
                 grid=None,
                 grid_file=None,
                 data_file=None,
                 dataset=None,
                 **kwargs):
        VelocityGrid.__init__(self,
                              name=name,
                              units=units,
                              time=time,
                              variables=variables,
                              grid=grid,
                              grid_file=grid_file,
                              data_file=data_file,
                              dataset=dataset)
        self.angle = None
        df = None
        if dataset is not None:
            df = dataset
        elif grid_file is not None:
            df = _get_dataset(grid_file)
        if df is not None and 'angle' in df.variables.keys():
            # Unrotated ROMS Grid!
            self.angle = GriddedProp(name='angle', units='radians', time=None, grid=self.grid, data=df['angle'])

    def at(self, points, time, units=None, depth=-1, extrapolate=False, **kwargs):
        '''
        Find the value of the property at positions P at time T

        :param points: Coordinates to be queried (P)
        :param time: The time at which to query these points (T)
        :param depth: Specifies the depth level of the variable
        :param units: units the values will be returned in (or converted to)
        :param extrapolate: if True, extrapolation will be supported
        :type points: Nx2 array of double
        :type time: datetime.datetime object
        :type depth: integer
        :type units: string such as ('m/s', 'knots', etc)
        :type extrapolate: boolean (True or False)
        :return: returns a Nx2 array of interpolated values
        :rtype: double
        '''
        mem = kwargs['memoize'] if 'memoize' in kwargs else True
        _hash = kwargs['_hash'] if '_hash' in kwargs else None
        if _hash is None:
            _hash = self._get_hash(points, time)
            if '_hash' not in kwargs:
                kwargs['_hash'] = _hash

        if mem:
            res = self._get_memoed(points, time, self._result_memo, _hash=_hash)
            if res is not None:
                return res

        value = super(GridWind, self).at(points, time, units, extrapolate=extrapolate, **kwargs)
        if self.angle is not None:
            angs = self.angle.at(points, time, extrapolate=extrapolate, **kwargs)
            x = value[:, 0] * np.cos(angs) - value[:, 1] * np.sin(angs)
            y = value[:, 0] * np.sin(angs) + value[:, 1] * np.cos(angs)
            value[:, 0] = x
            value[:, 1] = y
        if mem:
            self._memoize_result(points, time, value, self._result_memo, _hash=_hash)
        return value