Ejemplo n.º 1
0
def load_array(filename, meta=None, band_specs=None, reader=None):
    '''Create ElmStore from HDF4 / 5 or NetCDF files or TIF directories

    Parameters:
        :filename:   filename (HDF4 / 5 or NetCDF) or directory name (TIF)
        :meta:       meta data from "filename" already loaded
        :band_specs: list of strings or earthio.BandSpec objects
        :reader:     named reader from earthio - one of:  ('tif', 'hdf4', 'hdf5', 'netcdf')

    Returns:
        :es:         ElmStore (xarray.Dataset) with bands specified by band_specs as DataArrays in "data_vars" attribute
    '''
    ftype = reader or _find_file_type(filename)
    if meta is None:
        if ftype == 'tif':
            meta = _load_meta(filename, ftype, band_specs=band_specs)
        else:
            meta = _load_meta(filename, ftype)
    if ftype == 'netcdf':
        return load_netcdf_array(filename, meta, band_specs=band_specs)
    elif ftype == 'hdf5':
        return load_hdf5_array(filename, meta, band_specs=band_specs)
    elif ftype == 'hdf4':
        return load_hdf4_array(filename, meta, band_specs=band_specs)
    elif ftype == 'tif':
        return load_dir_of_tifs_array(filename, meta, band_specs=band_specs)
    elif ftype == 'hdf':
        try:
            es = load_hdf4_array(filename, meta, band_specs=band_specs)
        except Exception as e:
            logger.info(
                'NOTE: guessed HDF4 type. Failed: {}. \nTrying HDF5'.format(
                    repr(e)))
            es = load_hdf5_array(filename, meta, band_specs=band_specs)
        return es
Ejemplo n.º 2
0
def test_reader_kwargs():
    sub_dataset_names, band_specs = get_band_specs(HDF5_FILES[0])
    band_specs_kwargs = []
    for b in band_specs:
        b = attr.asdict(b)
        b['buf_xsize'], b['buf_ysize'] = 200, 300
        band_specs_kwargs.append(BandSpec(**b))
    meta = load_hdf5_meta(HDF5_FILES[0])
    es = load_hdf5_array(HDF5_FILES[0], meta, band_specs_kwargs)
    for b in es.band_order:
        assert getattr(es, b).values.shape == (300, 200)
Ejemplo n.º 3
0
def test_read_array(filename):
    sub_dataset_names, band_specs = get_band_specs(filename)
    meta = load_hdf5_meta(filename)
    es = load_hdf5_array(filename, meta, band_specs)
    assert len(es.data_vars) == len(sub_dataset_names)
    for band in es.data_vars:
        sample = getattr(es, band)
        assert sample.y.size == 1800
        assert sample.x.size == 3600
        assert len(es.data_vars) == len(band_specs)
        assertions_on_band_metadata(sample.attrs)
Ejemplo n.º 4
0
def test_reader_kwargs():
    sub_dataset_names, layer_specs = get_layer_specs(HDF5_FILES[0])
    layer_specs_kwargs = []
    for b in layer_specs:
        b = b.get_params()
        b['buf_xsize'], b['buf_ysize'] = 200, 300
        layer_specs_kwargs.append(LayerSpec(**b))
    meta = load_hdf5_meta(HDF5_FILES[0])
    dset = load_hdf5_array(HDF5_FILES[0], meta, layer_specs_kwargs)
    for b in dset.layer_order:
        assert getattr(dset, b).values.shape == (300, 200)
Ejemplo n.º 5
0
def test_read_array(filename):
    sub_dataset_names, layer_specs = get_layer_specs(filename)
    meta = load_hdf5_meta(filename)
    dset = load_hdf5_array(filename, meta, layer_specs)
    assert len(dset.data_vars) == len(sub_dataset_names)
    for layer in dset.data_vars:
        sample = getattr(dset, layer)
        assert sample.y.size == 1800
        assert sample.x.size == 3600
        assert len(dset.data_vars) == len(layer_specs)
        assertions_on_layer_metadata(sample.attrs)