spatial_functions.py

lib.spatial_functions.adjust_resolution(array, res_data, res_desired, aggfun=None)

description

lib.spatial_functions.aggregate_x_dim(array, res_data, res_desired, aggfun)

description

lib.spatial_functions.aggregate_y_dim(array, res_data, res_desired, aggfun)

description

lib.spatial_functions.array2raster(newRasterfn, rasterOrigin, pixelWidth, pixelHeight, array)

This function saves array to geotiff raster format based on EPSG 4326.

Parameters
  • newRasterfn (string) – Output path of the raster.

  • rasterOrigin (list of two floats) – Latitude and longitude of the Northwestern corner of the raster.

  • pixelWidth (integer) – Pixel width (might be negative).

  • pixelHeight (integer) – Pixel height (might be negative).

  • array (numpy array) – Array to be converted into a raster.

Returns

The raster file will be saved in the desired path newRasterfn.

Return type

None

lib.spatial_functions.calc_geotiff(Crd_all, res_desired)

This function returns a dictionary containing the georeferencing parameters for geotiff creation, based on the desired extent and resolution.

Parameters
  • Crd_all (numpy array) – Coordinates of the bounding box of the spatial scope.

  • res_desired (list) – Desired data resolution in the vertical and horizontal dimensions.

Return GeoRef

Georeference dictionary containing RasterOrigin, RasterOrigin_alt, pixelWidth, and pixelHeight.

Return type

dict

lib.spatial_functions.calc_region(region, Crd_reg, res_desired, GeoRef)

This function reads the region geometry, and returns a masking raster equal to 1 for pixels within and 0 outside of the region.

Parameters
  • region (Geopandas series) – Region geometry

  • Crd_reg (list) – Coordinates of the region

  • res_desired (list) – Desired high resolution of the output raster

  • GeoRef (dict) – Georeference dictionary containing RasterOrigin, RasterOrigin_alt, pixelWidth, and pixelHeight.

Return A_region

Masking raster of the region.

Return type

numpy array

lib.spatial_functions.crd2ind(Crd_points, Crd_all, resolution)

This function converts latitude and longitude of points in high resolution rasters into indices.

Parameters
  • Crd_points (tuple of arrays) – Coordinates of the points in the vertical and horizontal dimensions.

  • Crd_all (numpy array) – Array of coordinates of the bounding box of the spatial scope.

  • resolution (list) – Data resolution in the vertical and horizontal dimensions.

Return Ind_points

Tuple of arrays of indices in the vertical and horizontal axes.

Return type

list of arrays

lib.spatial_functions.crd_merra(Crd_regions, res_weather)

This function calculates coordinates of the bounding box covering MERRA-2 data.

Parameters
  • Crd_regions (numpy array) – Coordinates of the bounding boxes of the regions.

  • res_weather (list) – Weather data resolution.

Return Crd

Coordinates of the bounding box covering MERRA-2 data for each region.

Return type

numpy array

lib.spatial_functions.define_spatial_scope(scope_shp)

This function reads the spatial scope shapefile and returns its bounding box.

Parameters

scope_shp (Geopandas dataframe) – Spatial scope shapefile.

Return box

List of the bounding box coordinates.

Return type

list

lib.spatial_functions.ind2crd(Ind_points, Crd_all, resolution)

This function converts indices of points in high resolution rasters into longitude and latitude coordinates.

Parameters
  • Ind_points (tuple of arrays) – Tuple of arrays of indices in the vertical and horizontal axes.

  • Crd_all (numpy array) – Array of coordinates of the bounding box of the spatial scope.

  • resolution (list) – Data resolution in the vertical and horizontal dimensions.

Return Crd_points

Coordinates of the points in the vertical and horizontal dimensions.

Return type

list of arrays

lib.spatial_functions.ind_global(Crd, res_desired)

This function converts longitude and latitude coordinates into indices on a global data scope, where the origin is at (-90, -180).

Parameters
  • Crd (numpy array) – Coordinates to be converted into indices.

  • res_desired (list) – Desired resolution in the vertical and horizontal dimensions.

Return Ind

Indices on a global data scope.

Return type

numpy array

lib.spatial_functions.ind_merra(Crd, Crd_all, res)

This function converts longitude and latitude coordinates into indices within the spatial scope of MERRA-2 data.

Parameters
  • Crd (numpy array) – Coordinates to be converted into indices.

  • Crd_all (numpy array) – Coordinates of the bounding box of the spatial scope.

  • res (list) – Resolution of the data, for which the indices are produced.

Return Ind

Indices within the spatial scope of MERRA-2 data.

Return type

numpy array

lib.spatial_functions.subset(A, crd, param)

This function retrieves a subset of the global MERRA-2 coverage based on weather resolution and the bounding box coordinates of the spatial scope.

Parameters
  • A (numpy array) – Weather data on a global scale.

  • param (dict) – Dictionary of parameters containing MERRA-2 coverage and the name of the region.

Return subset

The subset of the weather data contained in the bounding box of spatial_scope.

Return type

numpy array