reVX.offshore.dist_to_ports_converter.DistToPortsConverter

class DistToPortsConverter(h5_file, hsds=False, chunks=(128, 128), template_file=None)[source]

Bases: LayeredH5

Convert Distance to Ports goetiff(s) to excl .h5 layers

Parameters:
  • h5_file (path-like) – Path to HDF5 layered 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.

  • 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 file. If None, then the h5_file input is used as the template. By default, None.

Methods

create_new([overwrite])

Create a new layered HDF5 file.

extract_all_layers(out_dir[, extract_lat_lon])

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[, check_tiff, ...])

Create exclusions .h5 file, or load layers into existing exclusion .h5 file from provided dist_to_ports

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_dist_to_ports_to_h5(dist_to_ports, ...)

Transfer geotiff exclusions to h5 confirming they match existing layers

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

LATITUDE

Name of latitude values layer in HDF5 file.

LONGITUDE

Name of longitude values layer in HDF5 file.

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.

write_dist_to_ports_to_h5(dist_to_ports, layer_name, check_tiff=True, transform_atol=0.01, description=None, scale_factor=None, dtype='float32')[source]

Transfer geotiff exclusions to h5 confirming they match existing layers

Parameters:
  • dist_to_ports (str) – Path to directory containing distance to port geotiff files or a list of the distance to port geotiff filepaths

  • layer_name (str) – Layer to create

  • check_tiff (bool, optional) – Flag to check tiff profile and coordinates against exclusion .h5 profile and coordinates, by default True

  • transform_atol (float, optional) – Absolute tolerance parameter when comparing geotiff transform data, by default 0.01

  • description (str, optional) – Description of exclusion layer, by default None

  • scale_factor (int | float, optional) – Scale factor to use to scale geotiff data when added to the .h5 file, by default None

  • dtype (str, optional) – Dtype to save geotiff data as in the .h5 file. Only used when ‘scale_factor’ is not None, by default ‘float32’

layers_to_h5(layers, check_tiff=True, transform_atol=0.01, descriptions=None, scale_factors=None)[source]

Create exclusions .h5 file, or load layers into existing exclusion .h5 file from provided dist_to_ports

Parameters:
  • layers (dict) – Dictionary mapping goetiffs to the layers to load

  • check_tiff (bool, optional) – Flag to check tiff profile and coordinates against exclusion .h5 profile and coordinates, by default True

  • transform_atol (float, optional) – Absolute tolerance parameter when comparing geotiff transform data, by default 0.01

  • coord_atol (float, optional) – Absolute tolerance parameter when comparing new un-projected geotiff coordinates against previous coordinates, by default 0.001

  • description (dict, optional) – Description of exclusion layers, by default None

  • scale_factor (dict, optional) – Scale factors and dtypes to use when scaling given layers, by default None

LATITUDE = 'latitude'

Name of latitude values layer in HDF5 file.

LONGITUDE = 'longitude'

Name of longitude values layer in HDF5 file.

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_lat_lon=False)

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_lat_lon (bool, default=False) – Option to extract latitude and longitude layers in addition to all other layers. By default, False.

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

load_data_using_h5_profile(geotiff, band=1, reproject=False, skip_profile_test=False)

Load GeoTIFF data, converting to H5 profile if necessary.

Parameters:
  • geotiff (str) – Path to GeoTIFF from which data should be read.

  • 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.

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.