예제 #1
0
    def __init__(self, file, grid=None, time=None, monthbegin=False):
        """Open the file and try to understand it.

        Parameters
        ----------
        file: path to the netcdf file
        grid: a Grid object. This will override the normal behavior of
        GeoNetcdf, which is to try to understand the grid automatically.
        time: a time array. This will override the normal behavior of
        GeoNetcdf, which is to try to understand the time automatically.
        monthbegin: set to true if you are sure that your data is monthly
        and that the data provider decided to tag the date as the center of
        the month (stupid)
        """

        self._nc = netCDF4.Dataset(file)
        self.variables = self._nc.variables
        if grid is None:
            grid = sio.grid_from_dataset(self._nc)
        if time is None:
            time = sio.netcdf_time(self._nc, monthbegin=monthbegin)
        dn = self._nc.dimensions.keys()
        self.x_dim = utils.str_in_list(dn, utils.valid_names['x_dim'])[0]
        self.y_dim = utils.str_in_list(dn, utils.valid_names['y_dim'])[0]
        dim = utils.str_in_list(dn, utils.valid_names['t_dim'])
        self.t_dim = dim[0] if dim else None
        dim = utils.str_in_list(dn, utils.valid_names['z_dim'])
        self.z_dim = dim[0] if dim else None

        GeoDataset.__init__(self, grid, time=time)
예제 #2
0
파일: test_misc.py 프로젝트: tbridel/salem
    def test_notimevar(self):

        import xarray as xr
        da = xr.DataArray(np.arange(12).reshape(3, 4), dims=['lat', 'lon'])
        ds = da.to_dataset(name='var')

        t = sio.netcdf_time(ds)
        assert t is None
예제 #3
0
    def test_notimevar(self):

        import xarray as xr

        da = xr.DataArray(np.arange(12).reshape(3, 4), dims=["lat", "lon"])
        ds = da.to_dataset(name="var")

        t = sio.netcdf_time(ds)
        assert t is None