enpt.processors.spatial_transform package

Submodules

enpt.processors.spatial_transform.spatial_transform module

EnPT module ‘spatial transform’, containing everything related to spatial transformations.

class enpt.processors.spatial_transform.spatial_transform.Geometry_Transformer(lons: ndarray, lats: ndarray, backend='gdal', resamp_alg: str = 'nearest', nprocs: int = 24, **options)[source]

Bases: Transformer

Get an instance of Transformer.

Parameters:
  • lons – 2D or 3D longitude array (3D array allows specific transformations per band)

  • lats – 2D or 3D latitude array (3D array allows specific transformations per band)

  • backend – ‘gdal’ or ‘pyresample’

  • resamp_alg

    resampling algorithm

    The ‘gdal’ backend supports:

    ’nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’

    The ‘pyresample’ backend supports:

    ’nearest’, ‘bilinear’, ‘gauss’, ‘custom’

  • nprocs – number of processor cores to be used

  • options – Additional options for configuring the Transformer. See the possible keys depending on the chosen backend below.

Possible options in case of the gdal backend:

Key georef_convention:
specifies to which pixel position the given coordinates refer

(‘PIXEL_CENTER’ (corresponds to pyresample implementation) or ‘TOP_LEFT_CORNER’)

Possible options in case of the pyresample backend:

Key mp_alg:

multiprocessing algorithm [ONLY in case of 3D geolayers] (default: auto)

  • ‘bands’: parallelize over bands using multiprocessing lib

  • ‘tiles’: parallelize over tiles using OpenMP

  • ‘auto’: automatically choose the algorithm

Key radius_of_influence:

<float> Cut off distance in meters (default: pixel size in meters for nearest, gauss, and custom resampling; 1.5 * pixelsize for bilinear resampling)

Key sigmas:

<list of floats or float> [ONLY ‘gauss’] List of sigmas to use for the gauss weighting of each channel 1 to k, w_k = exp(-dist^2/sigma_k^2). If only one channel is resampled sigmas is a single float value.

Key neighbours:

<int> [ONLY ‘bilinear’, ‘gauss’] Number of neighbours to consider for each grid point when searching the closest corner points

Key epsilon:

<float> Allowed uncertainty in meters. Increasing uncertainty reduces execution time

Key weight_funcs:

<list of function objects or function object> [ONLY ‘custom’] List of weight functions f(dist) to use for the weighting of each channel 1 to k. If only one channel is resampled weight_funcs is a single function object.

Key reduce_data:

<bool> Perform initial coarse reduction of source dataset in order to reduce execution time

Key segments:

<int or None> Number of segments to use when resampling. If set to None an estimate will be calculated

Key with_uncert:

<bool> [ONLY ‘gauss’ and ‘custom’] Calculate uncertainty estimates

NOTE: resampling function has 3 return values instead of 1: result, stddev, count

Note

Refer to the Pyresample API reference for a complete list of options.

to_map_geometry(path_or_geoarray_sensorgeo: str | GeoArray | ndarray, tgt_prj: str | int, tgt_extent: Tuple[float, float, float, float] = None, tgt_res: Tuple = None, tgt_coordgrid: Tuple[Tuple, Tuple] = None, src_nodata: int = None, tgt_nodata: int = None, area_definition: AreaDefinition = None) Tuple[ndarray, tuple, str][source]

Transform the input sensor geometry array into map geometry.

Parameters:
  • data – 2D or 3D numpy array (representing sensor geometry) to be warped to map geometry

  • tgt_prj – target projection (WKT or ‘epsg:1234’ or <EPSG_int>)

  • tgt_extent – extent coordinates of output map geometry array (LL_x, LL_y, UR_x, UR_y) in the tgt_prj

  • tgt_res – target X/Y resolution (e.g., (30, 30))

  • tgt_coordgrid – target coordinate grid ((x, x), (y, y)): if given, the output extent is moved to this coordinate grid and tgt_res is obsolete

  • area_definition – an instance of pyresample.geometry.AreaDefinition; OVERRIDES tgt_prj, tgt_extent and tgt_res; saves computation time for the pyresample backend, ignored if the GDAL backend is used

  • src_nodata – no-data value of the input array to be ignored in resampling

  • tgt_nodata – value for undetermined pixels in the output

to_sensor_geometry(path_or_geoarray_mapgeo: str | GeoArray, src_gt: Tuple[float, float, float, float, float, float] = None, src_prj: str | int = None, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the input map geometry array into sensor geometry.

Parameters:
  • data – 2D or 3D numpy array (representing map geometry) to be warped to sensor geometry

  • src_gt – GDAL GeoTransform tuple of the input map geometry array

  • src_prj – projection of the input map geometry array (WKT or ‘epsg:1234’ or <EPSG_int>)

  • src_nodata – no-data value of the input array to be ignored in resampling

  • tgt_nodata – value for undetermined pixels in the output

class enpt.processors.spatial_transform.spatial_transform.RPC_3D_Geolayer_Generator(rpc_coeffs_per_band: dict, elevation: str | GeoArray | int | float, enmapIm_cornerCoords: Tuple[Tuple[float, float]], enmapIm_dims_sensorgeo: Tuple[int, int], CPUs: int = None)[source]

Bases: object

Class for creating band- AND pixel-wise longitude/latitude arrays based on rational polynomial coeff. (RPC).

Get an instance of RPC_3D_Geolayer_Generator.

Parameters:
  • rpc_coeffs_per_band

    dictionary of RPC coefficients for each EnMAP band ({‘band_1’: <rpc_coeffs_dict>,

    ’band_2’: <rpc_coeffs_dict>, …})

  • elevation – digital elevation model in MAP geometry (file path or instance of GeoArray) OR average elevation in meters as integer or float

  • enmapIm_cornerCoords – corner coordinates as tuple of lon/lat pairs

  • enmapIm_dims_sensorgeo – dimensions of the EnMAP image in sensor geometry (rows, colunms)

  • CPUs – number of CPUs to use

static _compute_geolayer_for_unique_coeffgroup(kwargs)[source]
_get_bandgroups_with_unique_rpc_coeffs() List[List][source]
compute_geolayer()[source]
class enpt.processors.spatial_transform.spatial_transform.RPC_Geolayer_Generator(rpc_coeffs: dict, elevation: str | GeoArray | int | float, enmapIm_cornerCoords: Tuple[Tuple[float, float]], enmapIm_dims_sensorgeo: Tuple[int, int])[source]

Bases: object

Class for creating pixel-wise longitude/latitude arrays based on rational polynomial coefficients (RPC).

Get an instance of RPC_Geolayer_Generator.

Parameters:
  • rpc_coeffs – RPC coefficients for a single EnMAP band

  • elevation – digital elevation model in map geometry (file path or instance of GeoArray) OR average elevation in meters as integer or float

  • enmapIm_cornerCoords – corner coordinates as tuple of lon/lat pairs

  • enmapIm_dims_sensorgeo – dimensions of the EnMAP image in sensor geometry (rows, columns)

_compute_normalized_image_coordinates(lon_norm: ~numpy.ndarray, lat_norm: ~numpy.ndarray, height_norm: ~numpy.ndarray) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

Compute normalized sensor geometry coordinates for the given lon/lat/height positions.

Parameters:
  • lon_norm – normalized longitudes

  • lat_norm – normalized latitudes

  • height_norm – normalized elevation

Returns:

_denormalize_image_coordinates(row_norm: ~numpy.ndarray, col_norm: ~numpy.ndarray) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

De-normalize normalized sensor geometry coordinates to get valid image coordinates.

Parameters:
  • row_norm – normalized rows

  • col_norm – normalized columns

Returns:

de-normalized rows array, de-normalized columns array,

static _fill_nans_at_corners(arr: ndarray, along_axis: int = 0) ndarray[source]
_normalize_map_coordinates(lon: ~numpy.ndarray, lat: ~numpy.ndarray, height: ~numpy.ndarray) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

Normalize map coordinates to [-1, +1] to improve numerical precision.

Parameters:
  • lon – longitude array

  • lat – latitude array

  • height – elevation array

compute_geolayer() -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

Compute pixel-wise lon/lat arrays based on RPC coefficients, corner coordinates and image dimensions.

Returns:

(2D longitude array, 2D latitude array)

transform_LonLatHeight_to_RowCol(lon: ~numpy.ndarray, lat: ~numpy.ndarray, height: ~numpy.ndarray) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)[source]

Get sensor geometry image coordinates for the given 3D map coordinate positions using RPC coefficients.

Parameters:
  • lon – longitude array

  • lat – latitude array

  • height – elevation array

Returns:

rows array, columns array

class enpt.processors.spatial_transform.spatial_transform.VNIR_SWIR_SensorGeometryTransformer(lons_vnir: ndarray, lats_vnir: ndarray, lons_swir: ndarray, lats_swir: ndarray, prj_vnir: str | int, prj_swir: str | int, res_vnir: Tuple[float, float], res_swir: Tuple[float, float], resamp_alg: str = 'nearest', src_nodata: int = None, tgt_nodata: int = None, nprocs: int = 24)[source]

Bases: object

Class to transform between EnMAP VNIR and SWIR sensor geometry.

Get an instance of VNIR_SWIR_SensorGeometryTransformer.

Parameters:
  • lons_vnir – VNIR longitude array corresponding to the sensor geometry arrays passed later (2D or 3D)

  • lats_vnir – VNIR latitude array corresponding to the sensor geometry arrays passed later (2D or 3D)

  • lons_swir – SWIR longitude array corresponding to the sensor geometry arrays passed later (2D or 3D)

  • lats_swir – SWIR latitude array corresponding to the sensor geometry arrays passed later (2D or 3D)

  • prj_vnir – projection of the VNIR if it would be transformed to map geometry (WKT string or EPSG code)

  • prj_swir – projection of the SWIR if it would be transformed to map geometry (WKT string or EPSG code)

  • res_vnir – pixel dimensions of the VNIR if it would be transformed to map geometry (X, Y)

  • res_swir – pixel dimensions of the SWIR if it would be transformed to map geometry (X, Y)

  • resamp_alg – resampling algorithm (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

  • nprocs – number of CPU cores to use

_transform_sensorgeo(data2transform: ndarray, inputgeo: str, band_outputgeo: int = 0) ndarray[source]

Transform the input array between VNIR and SWIR sensor geometry.

Parameters:
  • data2transform – input array to be transformed

  • inputgeo – ‘vnir’ if data2transform is given in VNIR sensor geometry ‘swir’ if data2transform is given in SWIR sensor geometry

  • band_outputgeo – band index of the band from the sensor geometry should be used to generate the output

transform_sensorgeo_SWIR_to_VNIR(data_swirsensorgeo: ndarray) ndarray[source]

Transform any array in SWIR sensor geometry to VNIR sensor geometry to remove geometric shifts.

Parameters:

data_swirsensorgeo – input array in SWIR sensor geometry

Returns:

input array resampled to VNIR sensor geometry

transform_sensorgeo_VNIR_to_SWIR(data_vnirsensorgeo: ndarray) ndarray[source]

Transform any array in VNIR sensor geometry to SWIR sensor geometry to remove geometric shifts.

Parameters:

data_vnirsensorgeo – input array in VNIR sensor geometry

Returns:

input array resampled to SWIR sensor geometry

enpt.processors.spatial_transform.spatial_transform._initialize_mp(elevation: float | ndarray)[source]

Declare global variables needed for RPC_3D_Geolayer_Generator._compute_geolayer_for_unique_coeffgroup().

Parameters:

elevation – elevation - either as average value (float) or as a numpy array

enpt.processors.spatial_transform.spatial_transform.compute_mapCoords_within_sensorGeoDims(sensorgeoCoords_YX: List[Tuple[float, float]], rpc_coeffs: dict, elevation: str | GeoArray | int | float, enmapIm_cornerCoords: Tuple[Tuple[float, float]], enmapIm_dims_sensorgeo: Tuple[int, int]) List[Tuple[float, float]][source]

Compute map coordinates for a given image coordinate-pair of an EnMAP image in sensor geometry.

Parameters:
  • sensorgeoCoords_YX – list of requested sensor geometry positions [(row, column), (row, column), …]

  • rpc_coeffs – RPC coefficients describing the relation between sensor and map geometry

  • elevation – digital elevation model in MAP geometry (file path or instance of GeoArray) OR average elevation in meters as integer or float

  • enmapIm_cornerCoords – MAP coordinates of the EnMAP image

  • enmapIm_dims_sensorgeo – dimensions of the sensor geometry EnMAP image (rows, columns)

Returns:

enpt.processors.spatial_transform.spatial_transform.get_UTMEPSG_from_LonLat(lon: float, lat: float) int[source]
enpt.processors.spatial_transform.spatial_transform.get_UTMEPSG_from_LonLat_cornersXY(lons: List[float], lats: List[float])[source]
enpt.processors.spatial_transform.spatial_transform.get_center_coord(cornerCoordsXY)[source]
enpt.processors.spatial_transform.spatial_transform.move_extent_to_coord_grid(extent_utm: Tuple[float, float, float, float], tgt_xgrid: Sequence[float], tgt_ygrid: Sequence[float]) Tuple[float, float, float, float][source]

Move the given coordinate extent to a coordinate grid.

Parameters:
  • extent_utm – xmin, ymin, xmax, ymax coordinates

  • tgt_xgrid – target X coordinate grid, e.g. [0, 30]

  • tgt_ygrid – target Y coordinate grid, e.g. [0, 30]

Module contents

EnPT module ‘spatial transform’, containing everything related to spatial transformations.