reVX.handlers.layered_h5.LayeredTransmissionH5

class LayeredTransmissionH5(h5_file=None, hsds=False, chunks=(128, 128), template_file=None, layer_dir='.')[source]

Bases: LayeredH5

Handle reading and writing H5 files and GeoTiffs

Parameters:
  • h5_file (path-like, optional) – Path to layered transmission HDF5 file. If this file is to be created, a template_file must be provided (and must exist on disk). Otherwise, the template_file input can be ignored and this input will be used as the template file. This input can be set to None if only the tiff conversion utilities are required, but the template_file input must be provided in this case. By default, None.

  • hsds (bool, optional) – Boolean flag to use h5pyd to handle HDF5 ‘files’ hosted on AWS behind HSDS. By default, False.

  • chunks (tuple, optional) – Chunk size of exclusions in HDF5 file and any output GeoTIFFs. By default, (128, 128).

  • template_file (path-like, optional) – Path to template GeoTIFF (*.tif or *.tiff) or HDF5 (*.h5) file containing the profile and transform to be used for the layered transmission file. If None, then the h5_file input is used as the template. If None and the h5_file input is also Nonee, an error is thrown. By default, None.

  • layer_dir (path-like, optional) – Directory to search for layers in, if not found in current directory. By default, '.'.

Methods

create_new([overwrite])

Create a new layered HDF5 file.

extract_all_layers(out_dir)

Extract all layers from HDF5 file and save to disk as GeoTIFFs.

extract_layers(layers)

Extract layers from HDF5 file and save to disk as GeoTIFFs.

layer_to_geotiff(layer, geotiff)

Extract layer from HDF5 file and write to GeoTIFF file.

layers_to_h5(layers[, replace, check_tiff, ...])

Transfer GeoTIFF layers into layered HDF5 file.

load_data_using_h5_profile(geotiff[, band, ...])

Load GeoTIFF data, converting to H5 profile if necessary.

reproject(src_raster, src_profile[, dtype, ...])

Reproject a raster onto the template raster and transform.

save_data_using_h5_profile(data, geotiff)

Write to GeoTIFF file.

write_geotiff_to_h5(geotiff, layer_name[, ...])

Transfer GeoTIFF to HDF5 confirming it matches existing layers.

write_layer_to_h5(values, layer_name[, ...])

Write a layer to the HDF5 file.

Attributes

SUPPORTED_FILE_ENDINGS

Supported template file endings.

layers

Available layers in HDF5 file.

profile

Template layer profile.

shape

Template layer shape.

template_file

Path to template file.

load_data_using_h5_profile(geotiff, band=1, reproject=False, skip_profile_test=False)[source]

Load GeoTIFF data, converting to H5 profile if necessary.

Parameters:
  • geotiff (str) – Path to GeoTIFF from which data should be read. If just the file name is provided, the class layer_dir attribute value is prepended to get the full path.

  • band (int, optional) – Band to load from GeoTIFF. By default, 1.

  • reproject (bool, optional) – Reproject raster to standard CRS and transform if True. By default, False.

  • skip_profile_test (bool, optional) – Skip checking that shape, transform, and CRS match template raster if True. By default, False.

Returns:

array-like – Raster data.

SUPPORTED_FILE_ENDINGS = {'.h5', '.tif', '.tiff'}

Supported template file endings.

create_new(overwrite=False)

Create a new layered HDF5 file.

Parameters:

overwrite (bool, optional) – Overwrite HDF5 file if is exists. By default, False.

extract_all_layers(out_dir)

Extract all layers from HDF5 file and save to disk as GeoTIFFs.

Parameters:

out_dir (str) – Path to output directory into which layers should be saved as GeoTIFFs.

extract_layers(layers)

Extract layers from HDF5 file and save to disk as GeoTIFFs.

Parameters:

layers (dict) – Dictionary mapping layer names to GeoTIFF files to create.

layer_to_geotiff(layer, geotiff)

Extract layer from HDF5 file and write to GeoTIFF file.

Parameters:
  • layer (str) – Layer to extract,

  • geotiff (str) – Path to output GeoTIFF file.

property layers

Available layers in HDF5 file.

Type:

list

layers_to_h5(layers, replace=True, check_tiff=True, transform_atol=0.01, descriptions=None, scale_factors=None)

Transfer GeoTIFF layers into layered HDF5 file.

If layered HDF5 file does not exist, it is created and populated.

Parameters:
  • layers (list | dict) – List of geotiffs to load or dictionary mapping goetiffs to the layers to load.

  • replace (bool, optional) – Option to replace existing layers if needed. By default, True

  • check_tiff (bool, optional) – Flag to check tiff profile and coordinates against layered HDF5 profile and coordinates. By default, True.

  • transform_atol (float, optional) – Absolute tolerance parameter when comparing GeoTIFF and layered HDF5 transforms. By default, 0.01.

  • description (dict, optional) – Mapping of layer name to layer description of layers. By default, None, which does not store any descriptions.

  • scale_factor (dict, optional) – Scale factors and dtypes to use when scaling given layers. By default, None, which does not apply any scale factors.

property profile

Template layer profile.

Type:

dict

reproject(src_raster, src_profile, dtype='float32', init_dest=-1.0)

Reproject a raster onto the template raster and transform.

Parameters:
  • src_raster (array-like) – Source raster.

  • src_profile (dict) – Source raster profile.

  • dtype (np.dtype, optional) – Data type for destination raster. By default, "float32".

  • init_des (float, optional) – Value for cells outside of boundary of src_raster. By default, -1.0.

Returns:

array-like – Source data reprojected into the template projection.

save_data_using_h5_profile(data, geotiff)

Write to GeoTIFF file.

Parameters:
  • layer (str) – Layer to extract,

  • geotiff (str) – Path to output GeoTIFF file.

property shape

Template layer shape.

Type:

tuple

property template_file

Path to template file.

Type:

str

write_geotiff_to_h5(geotiff, layer_name, check_tiff=True, transform_atol=0.01, description=None, scale_factor=None, dtype='int16', replace=True)

Transfer GeoTIFF to HDF5 confirming it matches existing layers.

Parameters:
  • geotiff (str) – Path to GeoTIFF file.

  • layer_name (str) – Name of layer to be written to HDF5 file.

  • check_tiff (bool, optional) – Option to check GeoTIFF profile, CRS, and shape against layered HDF5 profile, CRS, and shape. By default, True.

  • transform_atol (float, optional) – Absolute tolerance parameter when comparing GeoTIFF transform data. By default, 0.01.

  • description (str, optional) – Optional description of layer. By default, None.

  • scale_factor (int | float, optional) – Scale factor to use to scale GeoTIFF data when added to the layered HDF5 file, by default None

  • dtype (str, optional) – Dtype to save GeoTIFF data as in the layered HDF5 file. Only used when scale_factor input is not None. By default, "int16".

  • replace (bool, optional) – Option to replace existing layer (if any). By default, True.

write_layer_to_h5(values, layer_name, profile=None, description=None, scale_factor=None)

Write a layer to the HDF5 file.

Parameters:
  • values (ndarray) – Layer data.

  • layer_name (str) – Dataset name in HDF5 file.

  • profile (dict, optional) – Layer profile (attributes). If None, the profile from the Layered HDF5 file is used instead.

  • description (str, optional) – Description of layer being added. By default, None, which does not store a description in the layer attributes.

  • scale_factor (int | float, optional) – Scale factor to use to scale geotiff data when added to the HDF5 file. By default, None, which does not scale the values.