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, resamp_alg: str = 'nearest', radius_of_influence: int = 30, **opts)[source]

Bases: SensorMapGeometryTransformer

Get an instance of SensorMapGeometryTransformer.

Parameters
  • lons – 2D longitude array corresponding to the 2D sensor geometry array

  • lats – 2D latitude array corresponding to the 2D sensor geometry array

Keyword Arguments

(further documentation here: https://pyresample.readthedocs.io/en/latest/swath.html) - resamp_alg: resampling algorithm (‘nearest’, ‘bilinear’, ‘gauss’, ‘custom’) - radius_of_influence: <float> Cut off distance in meters (default: 30)

NOTE: keyword is named ‘radius’ in case of bilinear resampling

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

  • neighbours: <int> [ONLY ‘bilinear’, ‘gauss’] Number of neighbours to consider for each grid

    point when searching the closest corner points

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

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

  • fill_value: <int or None> Set undetermined pixels to this value (default: 0).

    If fill_value is None a masked array is returned with undetermined pixels masked

  • reduce_data: <bool> Perform initial coarse reduction of source dataset in order to reduce

    execution time

  • nprocs: <int>, Number of processor cores to be used

  • segments: <int or None> Number of segments to use when resampling.

    If set to None an estimate will be calculated

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

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

to_map_geometry(path_or_geoarray_sensorgeo: Union[str, GeoArray, ndarray], tgt_prj: Optional[Union[str, int]] = None, tgt_extent: Optional[Tuple[float, float, float, float]] = None, tgt_res: Optional[Tuple[float, float]] = None, tgt_coordgrid: Optional[Tuple[Tuple, Tuple]] = None, area_definition: Optional[AreaDefinition] = None)[source]

Transform the input sensor geometry array into map geometry.

Parameters
  • data – 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

  • area_definition – an instance of pyresample.geometry.AreaDefinition; OVERRIDES tgt_prj, tgt_extent and tgt_res; saves computation time

to_sensor_geometry(path_or_geoarray_mapgeo: Union[str, GeoArray], src_prj: Optional[Union[str, int]] = None, src_extent: Optional[Tuple[float, float, float, float]] = None)[source]

Transform the input map geometry array into sensor geometry.

Parameters
  • data – numpy array (representing map geometry) to be warped to sensor geometry

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

  • src_extent – extent coordinates of input map geometry array (LL_x, LL_y, UR_x, UR_y) in the src_prj

class enpt.processors.spatial_transform.spatial_transform.Geometry_Transformer_3D(lons: ndarray, lats: ndarray, resamp_alg: str = 'nearest', radius_of_influence: int = 30, mp_alg: str = 'auto', **opts)[source]

Bases: SensorMapGeometryTransformer3D

Get an instance of SensorMapGeometryTransformer.

Parameters
  • lons – 3D longitude array corresponding to the 3D sensor geometry array

  • lats – 3D latitude array corresponding to the 3D sensor geometry array

Keyword Arguments

(further documentation here: https://pyresample.readthedocs.io/en/latest/swath.html) - resamp_alg: resampling algorithm (‘nearest’, ‘bilinear’, ‘gauss’, ‘custom’) - radius_of_influence: <float> Cut off distance in meters (default: 30)

NOTE: keyword is named ‘radius’ in case of bilinear resampling

  • mp_alg multiprocessing algorithm

    ‘bands’: parallelize over bands using multiprocessing lib ‘tiles’: parallelize over tiles using OpenMP ‘auto’: automatically choose the algorithm

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

  • neighbours: <int> [ONLY ‘bilinear’, ‘gauss’] Number of neighbours to consider for each grid

    point when searching the closest corner points

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

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

  • fill_value: <int or None> Set undetermined pixels to this value (default: 0).

    If fill_value is None a masked array is returned with undetermined pixels masked

  • reduce_data: <bool> Perform initial coarse reduction of source dataset in order to reduce

    execution time

  • nprocs: <int>, Number of processor cores to be used

  • segments: <int or None> Number of segments to use when resampling.

    If set to None an estimate will be calculated

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

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

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

Transform the input sensor geometry array into map geometry.

Parameters
  • data – 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

  • area_definition – an instance of pyresample.geometry.AreaDefinition; OVERRIDES tgt_prj, tgt_extent, tgt_res and tgt_coordgrid; saves computation time

to_sensor_geometry(path_or_geoarray_mapgeo: Union[str, GeoArray], src_prj: Optional[Union[str, int]] = None, src_extent: Optional[Tuple[float, float, float, float]] = None)[source]

Transform the input map geometry array into sensor geometry.

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

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

  • src_extent – extent coordinates of input map geometry array (LL_x, LL_y, UR_x, UR_y) in the src_prj

class enpt.processors.spatial_transform.spatial_transform.RPC_3D_Geolayer_Generator(rpc_coeffs_per_band: dict, elevation: Union[str, GeoArray, int, float], enmapIm_cornerCoords: Tuple[Tuple[float, float]], enmapIm_dims_sensorgeo: Tuple[int, int], CPUs: Optional[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: Union[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: Union[str, int], prj_swir: Union[str, int], res_vnir: Tuple[float, float], res_swir: Tuple[float, float], resamp_alg: str = 'nearest', **gt_opts)[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’, ‘bilinear’, ‘gauss’, ‘custom’)

  • gt_opts – additional options to be passed to the Geometric_Transformer class, e.g., ‘fill_value’, ‘radius_of_influence’, ‘nprocs’…

_transform_sensorgeo(data2transform: ndarray, inputgeo: str) 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

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: Union[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: Union[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.