def test_read_using_list_of_variables(): for nc_file in NETCDF_FILES: meta = load_netcdf_meta(nc_file) ds = load_netcdf_array(nc_file, meta, variables_list) _validate_array_test_result(ds) variables_list2 = [BandSpec('', '', v) for v in variables_list] ds = load_netcdf_array(nc_file, meta, variables_list2) _validate_array_test_result(ds)
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
def test_read_using_dict_of_variables(): for nc_file in NETCDF_FILES: meta = load_netcdf_meta(nc_file) ds = load_netcdf_array(nc_file, meta, variables_dict) _validate_array_test_result(ds)