Esempio n. 1
0
def reshuffle(input_root, outputpath,
              startdate, enddate,
              parameters=None, land_points=True, ignore_meta=False,
              imgbuffer=200):
    """
    Reshuffle method applied to ESA CCI SM images.

    Parameters
    ----------
    input_root: string
        input path where era interim data was downloaded
    outputpath : string
        Output path.
    startdate : datetime
        Start date.
    enddate : datetime
        End date.
    parameters: list, optional (default: None)
        parameters to read and convert
        If none are passed, we read an image in the root path and use vars from
        the image.
    land_points : bool, optional (default: True)
        Use the land grid to calculate time series on.
        Leads to faster processing and smaller files.
    imgbuffer: int, optional
        How many images to read at once before writing time series.
    """
    if land_points:
        grid = CCILandGrid()
    else:
        grid = CCICellGrid()

    if not os.path.exists(outputpath):
        os.makedirs(outputpath)

    file_args, file_vars = parse_filename(input_root)

    if parameters is None:
        parameters = [p for p in file_vars if p not in ['lat', 'lon', 'time']]

    input_dataset = CCI_SM_025Ds(data_path=input_root, parameter=parameters,
                                 subgrid=grid, array_1D=True)

    if not ignore_meta:
        global_attr, ts_attributes = read_metadata(sensortype=file_args['sensor_type'],
                                                   version=int(file_args['version']),
                                                   varnames=parameters)
        global_attr['time_coverage_start'] = str(startdate)
        global_attr['time_coverage_end'] = str(enddate)
    else:
        global_attr = {'product' : 'ESA CCI SM'}
        ts_attributes = None


    reshuffler = Img2Ts(input_dataset=input_dataset, outputpath=outputpath,
                        startdate=startdate, enddate=enddate, input_grid=grid,
                        imgbuffer=imgbuffer, cellsize_lat=5.0, cellsize_lon=5.0,
                        global_attr=global_attr, zlib=True,
                        unlim_chunksize=1000, ts_attributes=ts_attributes)
    reshuffler.calc()
Esempio n. 2
0
    def __init__(self,
                 filename,
                 mode='r',
                 parameter=None,
                 subgrid=None,
                 array_1D=False):

        super(CCI_SM_025Img, self).__init__(filename, mode=mode)

        self.parameters = [parameter] if isinstance(parameter,
                                                    str) else parameter
        self.grid = CCICellGrid() if not subgrid else subgrid
        self.array_1D = array_1D
Esempio n. 3
0
    def __init__(self,
                 filename,
                 mode='r',
                 parameter='sm',
                 subgrid=None,
                 array_1D=False):
        super(CCI_SM_025Img, self).__init__(filename, mode=mode)

        if type(parameter) != list:
            parameter = [parameter]
        self.parameters = parameter
        self.grid = CCICellGrid() if not subgrid else subgrid
        self.array_1D = array_1D
Esempio n. 4
0
    def test_CCICellGrid(self):
        grid = CCICellGrid()
        gp, dist = grid.find_nearest_gpi(75.625, 14.625)
        assert gp == 602942
        lon, lat = grid.gpi2lonlat(602942)
        assert lon == 75.625
        assert lat == 14.625
        assert np.where(
            grid.get_grid_points()[0] == 602942)[0][0] == 434462  # index
        assert grid.get_grid_points()[1][434462] == lon
        assert grid.get_grid_points()[2][434462] == lat
        assert grid.gpi2cell(602942) == 1856
        assert grid.gpis.size == 1036800
        assert grid.gpis[0] == 1035360
        assert np.unique(grid.get_grid_points()[3]).size == 2592

        lon, lat = grid.gpi2lonlat(642933)
        assert lon == -6.625
        assert lat == 21.625
        assert np.where(
            grid.get_grid_points()[0] == 642933)[0][0] == 393813  # index
        assert grid.get_grid_points()[1][393813] == lon
        assert grid.get_grid_points()[2][393813] == lat
        assert grid.gpi2cell(642933) == 1246
Esempio n. 5
0
def reshuffle(input_root,
              outputpath,
              startdate,
              enddate,
              parameters=None,
              land_points=True,
              ignore_meta=False,
              imgbuffer=200):
    """
    Reshuffle method applied to ESA CCI SM images.

    Parameters
    ----------
    input_root: string
        input path where era interim data was downloaded
    outputpath : string
        Output path.
    startdate : datetime
        Start date.
    enddate : datetime
        End date.
    parameters: list, optional (default: None)
        parameters to read and convert
        If none are passed, we read an image in the root path and use vars from
        the image.
    land_points : bool, optional (default: True)
        Use the land grid to calculate time series on.
        Leads to faster processing and smaller files.
    imgbuffer: int, optional
        How many images to read at once before writing time series.
    """
    if land_points:
        grid = CCILandGrid()
    else:
        grid = CCICellGrid()

    gpis, lons, lats, cells = grid.get_grid_points()
    grid_vars = {'gpis': gpis, 'lons': lons, 'lats': lats}
    # repurpose cannot handle masked arrays
    for k, v in grid_vars.items():  # type v: np.ma.MaskedArray
        if isinstance(v, np.ma.MaskedArray):
            grid_vars[k] = v.filled()

    grid = BasicGrid(lon=grid_vars['lons'],
                     lat=grid_vars['lats'],
                     gpis=grid_vars['gpis']).to_cell_grid(5.)

    if not os.path.exists(outputpath):
        os.makedirs(outputpath)

    file_args, file_vars = parse_filename(input_root)

    if parameters is None:
        parameters = [p for p in file_vars if p not in ['lat', 'lon', 'time']]

    input_dataset = CCI_SM_025Ds(data_path=input_root,
                                 parameter=parameters,
                                 subgrid=grid,
                                 array_1D=True)

    if not ignore_meta:
        global_attr, ts_attributes = read_metadata(
            sensortype=file_args['sensor_type'],
            version=int(file_args['version']),
            varnames=parameters,
            subversion=file_args['sub_version'])
    else:
        global_attr = {'product': 'ESA CCI SM'}
        ts_attributes = None

    reshuffler = Img2Ts(input_dataset=input_dataset,
                        outputpath=outputpath,
                        startdate=startdate,
                        enddate=enddate,
                        input_grid=grid,
                        imgbuffer=imgbuffer,
                        cellsize_lat=5.0,
                        cellsize_lon=5.0,
                        global_attr=global_attr,
                        zlib=True,
                        unlim_chunksize=1000,
                        ts_attributes=ts_attributes)
    reshuffler.calc()