Shared Functions

Submodules

shared_functions.utilities module

shared_functions.utilities.add_clipped_raster_to_map(map_object, raster_path, vis_params=None)[source]
Parameters:
  • map_object – The map object to which the clipped raster will be added.

  • raster_path – The file path or URL of the raster data to be added.

  • vis_params – Optional visualization parameters for the raster layer. Default is None.

Returns:

None

This method adds a clipped raster layer to the specified map object. The raster data is loaded from the provided raster_path. If visualization parameters are not specified, default parameters * will be used. Once the raster layer is created, it is added to the map object and the map view is adjusted to fit the bounds of the raster data.

If a ValueError is raised during the process, it will be caught and a corresponding error message will be printed. Other types of exceptions will also be caught and an error message * will be printed.

shared_functions.utilities.calculate_bounds(input_geom)[source]
shared_functions.utilities.clip_raster(*args, **kwargs)[source]
shared_functions.utilities.generate_bbox(geometry)[source]
shared_functions.utilities.get_raster_min_max(raster_path)[source]
Parameters:

raster_path – The file path of the raster to be processed.

Returns:

A tuple containing the minimum value, maximum value, and nodata value of the raster.

This method retrieves the minimum value, maximum value, and nodata value of a given raster file. It assumes that the raster file has only one band.

First, the method opens the raster file using the GDAL library and gets the first band of the dataset.

Then, it checks if the band provides the minimum and maximum values. If not, it computes the minimum and maximum values using the ComputeRasterMinMax() method of the band.

Next, it reads the band data as an array.

If the band data contains values equal to 9999, it masks the data to ignore those values. It then finds the maximum value in the masked data and sets it as the new maximum value.

Finally, the method closes the dataset and returns a tuple containing the minimum value, maximum value, and nodata value of the raster.

shared_functions.utilities.inspect_grib_file(file_path: str)[source]

Inspect GRIB File

Parameters:

file_path – The path to the GRIB file to be inspected.

Returns:

None

This method opens the given GRIB file using the pygrib library and prints information about each message in the file. It does not return any value.

Example usage:

inspect_grib_file(“path/to/grib/file.grib”)

shared_functions.utilities.mosaic_images(file_names, output_filename='mosaic.tif')[source]

Merges multiple raster files into a mosaic and saves it to an output file.

Parameters:
  • file_names – A list of file names of the raster files to be merged.

  • output_filename – The name of the output file to be created. Default is ‘mosaic.tif’.

Returns:

None

shared_functions.utilities.process_and_clip_raster(file_path, geometry, params=None, ee_instance=None)[source]
Parameters:
  • file_path – The file path of the raster file to be processed and clipped.

  • geometry – The geometry object to be used for clipping the raster.

  • params – Optional parameters for controlling the processing and clipping.

  • ee_instance – An instance of the Earth Engine API for using Earth Engine functions.

Returns:

If params[‘clip_to_geometry’] is True, returns the file path of the clipped raster. If params[‘clip_to_geometry’] is False, returns the original file path.

shared_functions.utilities.suppress_external_warnings(func)[source]

Module contents