geoarray package

Submodules

geoarray.baseclasses module

class geoarray.baseclasses.GeoArray(path_or_array: Union[str, numpy.ndarray, geoarray.baseclasses.GeoArray], geotransform: Optional[tuple] = None, projection: Optional[str] = None, bandnames: Optional[list] = None, nodata: Optional[float] = None, basename: str = '', progress: bool = True, q: bool = False)[source]

Bases: object

A class providing a fast Python interface for geodata - either on disk or in memory.

GeoArray can be instanced with a file path or with a numpy array and the corresponding geoinformation. Instances can always be indexed and sliced like normal numpy arrays, no matter if it has been instanced from file or from an in-memory array. GeoArray provides a wide range of geo-related attributes belonging to the dataset as well as some functions for quickly visualizing the data as a map, a simple image or an interactive image.

property arr
property bandnames
property bands

Get the number of bands of the associated image array.

property box
cache_array_subset(arr_pos: list) None[source]

Set the array cache of the GeoArray instance to the given array to speed up calculations afterwards.

Parameters

arr_pos – a list of array indices as passed to __getitem__

calc_mask_nodata(fromBand: Optional[int] = None, overwrite: bool = False, flag: str = 'all') numpy.ndarray[source]

Calculate a no data mask with values False (=nodata) and True (=data).

Parameters
  • fromBand – index of the band to be used (if None, all bands are used)

  • overwrite – whether to overwrite existing nodata mask that has already been calculated

  • flag – algorithm how to flag pixels (default: ‘all’) ‘all’: flag those pixels as nodata that contain the nodata value in ALL bands ‘any’: flag those pixels as nodata that contain the nodata value in ANY band

Returns

clip_to_footprint()[source]

Clip the GeoArray instance to the outer bounds of the actual footprint.

clip_to_poly(poly: shapely.geometry.polygon.Polygon) None[source]

Clip the GeoArray instance to the outer bounds of a given shapely polygon.

Parameters

poly – instance of shapely.geometry.Polygon

property cols
property columns

Get the number of columns of the associated image array.

deepcopy_array()[source]
property dtype

Get the numpy data type of the associated image array.

dump(out_path: str) None[source]

Serialize the whole object instance to disk using dill.

property epsg

Get the EPSG code of the projection of the GeoArray.

find_noDataVal(bandIdx=0, sz=3)[source]

Try to derive no data value from homogenious corner pixels within 3x3 windows (by default).

Parameters
  • bandIdx

  • sz – window size in which corner pixels are analysed

flush_cache()[source]

Clear the array cache of the GeoArray instance.

property footprint_poly

Get the footprint polygon of the associated image array (shapely.geometry.Polygon).

from_path(path: str, getitem_params: Optional[list] = None) numpy.ndarray[source]

Read a GDAL compatible raster image from disk, with respect to the given image position.

NOTE: If the requested array position is already in cache, it is returned from there.

Parameters
  • path – <str> the file path of the image to read

  • getitem_params – <list> a list of slices in the form [row_slice, col_slice, band_slice]

Return out_arr

<np.ndarray> the output array

property geotransform

Get the GDAL GeoTransform of the associated image, e.g., (283500.0, 5.0, 0.0, 4464500.0, 0.0, -5.0).

get_mapPos(mapBounds: tuple, mapBounds_prj: Union[str, int] = None, band2get: int = None, out_prj: Union[str, int] = None, out_gsd: tuple = None, arr_gt: tuple = None, arr_prj: str = None, fillVal: int = None, rspAlg: str = 'near', progress: bool = None, v: bool = False)[source]

Return the array data of GeoArray at a given geographic position.

NOTE: The given mapBounds are snapped to the pixel grid of GeoArray. If the given mapBounds include areas outside of the extent of GeoArray, these areas are filled with the fill value of GeoArray.

Parameters
  • mapBounds – xmin, ymin, xmax, ymax

  • mapBounds_prj – WKT projection string or EPSG code corresponding to mapBounds

  • band2get – band index of the band to be returned (full array if not given)

  • out_prj – output projection as WKT string or EPSG code. If not given, the self.projection is used.

  • out_gsd – output spatial resolution in map units of the output projection (XGSD, YGSD)

  • arr_gt – GDAL GeoTransform (taken from self if not given)

  • arr_prj – WKT projection string (taken from self if not given)

  • fillVal – nodata value

  • rspAlg – <str> Resampling method to use. Available methods are: near, bilinear, cubic, cubicspline, lanczos, average, mode, max, min, med, q1, q2

  • progress – whether to show progress bars or not

  • v – verbose mode (not related to GeoArray.v; must be explicitly set)

Returns

get_subset(xslice: Optional[slice] = None, yslice: Optional[slice] = None, zslice: Optional[Union[slice, list]] = None, return_GeoArray: bool = True, reset_bandnames: bool = False) geoarray.baseclasses.GeoArray[source]

Return a new GeoArray instance representing a subset of the initial one wit respect to given array position.

Parameters
  • xslice – a slice providing the X-position for the subset in the form slice(xstart, xend, xstep)

  • yslice – a slice providing the Y-position for the subset in the form slice(ystart, yend, ystep)

  • zslice – a slice providing the Z-position for the subset in the form slice(zstart, zend, zstep) or a list containing the indices of the bands to extract

  • return_GeoArray – whether to return an instance of GeoArray (default) or a tuple(np.ndarray, gt, prj)

  • reset_bandnames – whether band names of subset should be copied from source GeoArray or reset to ‘B1’, ‘B2’, ‘B3’, …

Returns

property gt
property is_inmem

Check if associated image array is completely loaded into memory.

property is_map_geo

Return ‘True’ if the image has a valid geoinformation with map instead of image coordinates.

property is_rotated

Return ‘True’ if the image has a rotation in the map info (i.e., is pseudo-projected).

property mask_baddata

Return the bad data mask.

Note: The mask must be explicitly set to a file path or a numpy array before.

property mask_nodata

Get the nodata mask of the associated image array. It is generated based on all image bands.

property meta
property metadata

Return a DataFrame containing all available metadata (read from file if available).

Use ‘metadata[band_index].to_dict()’ to get a metadata dictionary for a specific band. Use ‘metadata.loc[row_name].to_dict()’ to get all metadata values of the same key for all bands as dictionary. Use ‘metadata.loc[row_name, band_index] = value’ to set a new value.

Returns

instance of GDAL_Metadata

property ndim

Get the number dimensions of the associated image array.

property nodata

Get the nodata value of the GeoArray instance.

If GeoArray has been instanced with a file path the metadata of the file on disk is checked for an existing nodata value. Otherwise, (if no value is exlicitly given during object instanciation) an automatic detection based on 3x3 windows at each image corner is run that analyzes the mean and standard deviation of these windows.

property prj
property projection

Get the projection of the associated image.

Setting the projection is only allowed if GeoArray has been instanced from memory or the associated file on disk has no projection.

read_pointData(mapXY_points, mapXY_points_prj=None, band=None, offside_val=nan)[source]

Return the array values for the given set of X/Y coordinates.

NOTE: If GeoArray has been instanced with a file path, the function will read the dataset into memory.

Parameters
  • mapXY_points – <np.ndarray, tuple> X/Y coordinates of the points of interest. If a numpy array is given, it must have the shape [Nx2]

  • mapXY_points_prj – <str, int> WKT string or EPSG code of the projection corresponding to the given coordinates.

  • band – <int> the band index of the band of interest. If None, the values of all bands are returned.

  • offside_val – fill value in case input coordinates are geographically outside of the GeoArray instance

Returns

  • int in case only a singe coordinate is passed

  • np.ndarray with shape [Nx1] in case only one band is requested

  • np.ndarray with shape [Nx1xbands] in case all bands are requested

reproject_to_new_grid(prototype=None, tgt_prj=None, tgt_xygrid=None, rspAlg='cubic', CPUs=None)[source]

Reproject all array-like attributes to a given target grid.

Parameters
  • prototype – <GeoArray> an instance of GeoArray to be used as pixel grid reference

  • tgt_prj – <str> WKT string of the projection

  • tgt_xygrid – <list> target XY grid, e.g. [[xmin,xmax], [ymax, ymin]] for the UL corner

  • rspAlg – <str, int> GDAL compatible resampling algorithm code

  • CPUs – <int> number of CPUs to use (default: None -> use all available CPUs)

Returns

property rows

Get the number of rows of the associated image array.

save(out_path: str, fmt: str = 'ENVI', creationOptions: Optional[list] = None) None[source]

Write the raster data to disk.

Parameters
  • out_path – <str> output path

  • fmt – <str> the output format / GDAL driver code to be used for output creation, e.g. ‘ENVI’ Refer to https://gdal.org/drivers/raster/index.html to get a full list of supported formats.

  • creationOptions – <list> GDAL creation options, e.g., [“QUALITY=80”, “REVERSIBLE=YES”, “WRITE_METADATA=YES”]

set_gdalDataset_meta()[source]

Retrieve GDAL metadata from file.

This is only executed once to avoid overwriting of user defined attributes, that are defined after object instanciation.

property shape

Get the array shape of the associated image array.

show(xlim=None, ylim=None, band=None, boundsMap=None, boundsMapPrj=None, figsize=None, interpolation='none', vmin=None, vmax=None, pmin=2, pmax=98, cmap=None, nodataVal=None, res_factor=None, interactive=False, ax=None, ignore_rotation=False)[source]

Plot the desired array position into a figure.

Parameters
  • xlim – [start_column, end_column]

  • ylim – [start_row, end_row]

  • band – the band index of the band to be plotted (if None and interactive==True all bands are shown, otherwise the first band is chosen)

  • boundsMap – xmin, ymin, xmax, ymax

  • boundsMapPrj

  • figsize

  • interpolation

  • vmin – darkest pixel value to be included in stretching

  • vmax – brightest pixel value to be included in stretching

  • pmin – percentage to be used for excluding the darkest pixels from stretching (default: 2)

  • pmax – percentage to be used for excluding the brightest pixels from stretching (default: 98)

  • cmap

  • nodataVal

  • res_factor – <float> resolution factor for downsampling of the image to be plotted in order to save plotting time and memory (default=None -> downsampling is performed to 1000x1000)

  • interactive – <bool> activates interactive plotting based on ‘holoviews’ library. NOTE: this deactivates the magic ‘% matplotlib inline’ in Jupyter Notebook

  • ax – <matplotlib.axis> only usable in non-interactive mode

  • ignore_rotation – whether to ignore an image rotation angle included in the GDAL GeoTransform tuple for plotting (default: False)

Returns

show_footprint()[source]

Show a web map containing the computed footprint of the GeoArray instance in a Jupyter notebook.

show_histogram(band: int = 1, bins: int = 200, normed: bool = False, exclude_nodata: bool = True, vmin: Optional[float] = None, vmax: Optional[float] = None, figsize: Optional[tuple] = None) None[source]

Show a histogram of a given band.

Parameters
  • band – the band to be used to plot the histogram

  • bins – number of bins to plot (default: 200)

  • normed – whether to normalize the y-axis or not (default: False)

  • exclude_nodata – whether tp exclude nodata value from the histogram

  • vmin – minimum value for the x-axis of the histogram

  • vmax – maximum value for the x-axis of the histogram

  • figsize – figure size (tuple)

show_map(xlim=None, ylim=None, band=0, boundsMap=None, boundsMapPrj=None, out_epsg=None, figsize=None, interpolation='none', vmin=None, vmax=None, pmin=2, pmax=98, cmap=None, nodataVal=None, res_factor=None, return_map=False)[source]

Show a cartopy map of the associated image data (requires geocoding and projection information).

Parameters
  • xlim

  • ylim

  • band – band index (starting with 0)

  • boundsMap – xmin, ymin, xmax, ymax

  • boundsMapPrj

  • out_epsg – EPSG code of the output projection

  • figsize

  • interpolation

  • vmin – darkest pixel value to be included in stretching

  • vmax – brightest pixel value to be included in stretching

  • pmin – percentage to be used for excluding the darkest pixels from stretching (default: 2)

  • pmax – percentage to be used for excluding the brightest pixels from stretching (default: 98)

  • cmap

  • nodataVal

  • res_factor – <float> resolution factor for downsampling of the image to be plotted in order to save plotting time and memory (default=None -> downsampling is performed to 1000x1000)

  • return_map

Returns

show_xprofile(row, band, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show an x-profile at the given row/band image position.

Parameters
  • row – image row number (counts from 0)

  • band – image band number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

show_yprofile(column, band, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show a y-profile at the given column/band image position.

Parameters
  • column – image column number (counts from 0)

  • band – image band number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

show_zprofile(row, column, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show a z-profile at the given row/column image position.

Parameters
  • row – image row number (counts from 0)

  • column – image column number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

tiles(tilesize: tuple = (100, 100)) GeneratorLen[source]

Get tiles of the full dataset in the given tile size.

Parameters

tilesize – target size of the tiles (rows, columns) NOTE: If rows or columns are None, all rows/columns are returned

Returns

Generator with elements like: (((rowStart, rowEnd), (colStart, colEnd)), tiledata)

to_disk()[source]

Set self.arr back to None for in-memory instances, to release memory.

Note: This requires that the GeoArray was instanced with a file path.

to_mem()[source]

Read the whole dataset into memory and sets self.arr to the read data.

property xgsd

Get the X resolution in units of the given or detected projection.

property xygrid_specs

Get the specifications for the X/Y coordinate grid.

This returns for example [[15,30], [0,30]] for a coordinate with its origin at X/Y[15,0] and a GSD of X/Y[15,30].

property ygsd

Get the Y resolution in units of the given or detected projection.

class geoarray.baseclasses.MultiGeoArray(GeoArray_list)[source]

Bases: object

property arrs
geoarray.baseclasses.get_GeoArray_from_GDAL_ds(ds)[source]

geoarray.masks module

class geoarray.masks.BadDataMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=False, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

property arr
class geoarray.masks.CloudMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=None, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

to_ENVI_classification()[source]
class geoarray.masks.NoDataMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=False, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

property arr

geoarray.metadata module

class geoarray.metadata.GDAL_Metadata(filePath='', nbands=1, nodata_allbands=None)[source]

Bases: object

property all_meta
property band_meta
classmethod from_file(filePath)[source]
get_subset(bands2extract: Optional[Union[slice, list, numpy.ndarray]] = None, keys2extract: Optional[Union[str, list]] = None) geoarray.metadata.GDAL_Metadata[source]
property global_meta
read_from_file(filePath)[source]
to_DataFrame()[source]
to_ENVI_metadict()[source]

geoarray.subsetting module

geoarray.subsetting.get_array_at_mapPos(arr: T_ndA_gA, arr_gt: tuple, arr_prj: str, out_prj: str, mapBounds: tuple, mapBounds_prj: str = None, out_gsd: tuple = None, band2get: int = None, fillVal: int = 0, rspAlg: str = 'near', progress: bool = True)[source]
Parameters
  • arr

  • arr_gt

  • arr_prj

  • out_prj – output projection as WKT string

  • mapBounds – xmin, ymin, xmax, ymax

  • mapBounds_prj – the projection of the given map bounds (default: output projection)

  • out_gsd – (X,Y)

  • band2get – band index of the band to be returned (full array if not given)

  • fillVal

  • rspAlg – <str> Resampling method to use. Available methods are: near, bilinear, cubic, cubicspline, lanczos, average, mode, max, min, med, q1, q2

  • progress

Returns

geoarray.subsetting.get_array_at_mapPosOLD(arr, arr_gt, arr_prj, mapBounds, mapBounds_prj, band2get=None, fillVal=0)[source]
Parameters
  • arr

  • arr_gt

  • arr_prj

  • mapBounds – xmin, ymin, xmax, ymax

  • mapBounds_prj

  • band2get – band index of the band to be returned (full array if not given)

  • fillVal

Returns

geoarray.version module

Module contents

class geoarray.BadDataMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=False, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

property arr
class geoarray.CloudMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=None, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

to_ENVI_classification()[source]
class geoarray.GeoArray(path_or_array: Union[str, numpy.ndarray, geoarray.baseclasses.GeoArray], geotransform: Optional[tuple] = None, projection: Optional[str] = None, bandnames: Optional[list] = None, nodata: Optional[float] = None, basename: str = '', progress: bool = True, q: bool = False)[source]

Bases: object

A class providing a fast Python interface for geodata - either on disk or in memory.

GeoArray can be instanced with a file path or with a numpy array and the corresponding geoinformation. Instances can always be indexed and sliced like normal numpy arrays, no matter if it has been instanced from file or from an in-memory array. GeoArray provides a wide range of geo-related attributes belonging to the dataset as well as some functions for quickly visualizing the data as a map, a simple image or an interactive image.

property arr
property bandnames
property bands

Get the number of bands of the associated image array.

property box
cache_array_subset(arr_pos: list) None[source]

Set the array cache of the GeoArray instance to the given array to speed up calculations afterwards.

Parameters

arr_pos – a list of array indices as passed to __getitem__

calc_mask_nodata(fromBand: Optional[int] = None, overwrite: bool = False, flag: str = 'all') numpy.ndarray[source]

Calculate a no data mask with values False (=nodata) and True (=data).

Parameters
  • fromBand – index of the band to be used (if None, all bands are used)

  • overwrite – whether to overwrite existing nodata mask that has already been calculated

  • flag – algorithm how to flag pixels (default: ‘all’) ‘all’: flag those pixels as nodata that contain the nodata value in ALL bands ‘any’: flag those pixels as nodata that contain the nodata value in ANY band

Returns

clip_to_footprint()[source]

Clip the GeoArray instance to the outer bounds of the actual footprint.

clip_to_poly(poly: shapely.geometry.polygon.Polygon) None[source]

Clip the GeoArray instance to the outer bounds of a given shapely polygon.

Parameters

poly – instance of shapely.geometry.Polygon

property cols
property columns

Get the number of columns of the associated image array.

deepcopy_array()[source]
property dtype

Get the numpy data type of the associated image array.

dump(out_path: str) None[source]

Serialize the whole object instance to disk using dill.

property epsg

Get the EPSG code of the projection of the GeoArray.

find_noDataVal(bandIdx=0, sz=3)[source]

Try to derive no data value from homogenious corner pixels within 3x3 windows (by default).

Parameters
  • bandIdx

  • sz – window size in which corner pixels are analysed

flush_cache()[source]

Clear the array cache of the GeoArray instance.

property footprint_poly

Get the footprint polygon of the associated image array (shapely.geometry.Polygon).

from_path(path: str, getitem_params: Optional[list] = None) numpy.ndarray[source]

Read a GDAL compatible raster image from disk, with respect to the given image position.

NOTE: If the requested array position is already in cache, it is returned from there.

Parameters
  • path – <str> the file path of the image to read

  • getitem_params – <list> a list of slices in the form [row_slice, col_slice, band_slice]

Return out_arr

<np.ndarray> the output array

property geotransform

Get the GDAL GeoTransform of the associated image, e.g., (283500.0, 5.0, 0.0, 4464500.0, 0.0, -5.0).

get_mapPos(mapBounds: tuple, mapBounds_prj: Union[str, int] = None, band2get: int = None, out_prj: Union[str, int] = None, out_gsd: tuple = None, arr_gt: tuple = None, arr_prj: str = None, fillVal: int = None, rspAlg: str = 'near', progress: bool = None, v: bool = False)[source]

Return the array data of GeoArray at a given geographic position.

NOTE: The given mapBounds are snapped to the pixel grid of GeoArray. If the given mapBounds include areas outside of the extent of GeoArray, these areas are filled with the fill value of GeoArray.

Parameters
  • mapBounds – xmin, ymin, xmax, ymax

  • mapBounds_prj – WKT projection string or EPSG code corresponding to mapBounds

  • band2get – band index of the band to be returned (full array if not given)

  • out_prj – output projection as WKT string or EPSG code. If not given, the self.projection is used.

  • out_gsd – output spatial resolution in map units of the output projection (XGSD, YGSD)

  • arr_gt – GDAL GeoTransform (taken from self if not given)

  • arr_prj – WKT projection string (taken from self if not given)

  • fillVal – nodata value

  • rspAlg – <str> Resampling method to use. Available methods are: near, bilinear, cubic, cubicspline, lanczos, average, mode, max, min, med, q1, q2

  • progress – whether to show progress bars or not

  • v – verbose mode (not related to GeoArray.v; must be explicitly set)

Returns

get_subset(xslice: Optional[slice] = None, yslice: Optional[slice] = None, zslice: Optional[Union[slice, list]] = None, return_GeoArray: bool = True, reset_bandnames: bool = False) geoarray.baseclasses.GeoArray[source]

Return a new GeoArray instance representing a subset of the initial one wit respect to given array position.

Parameters
  • xslice – a slice providing the X-position for the subset in the form slice(xstart, xend, xstep)

  • yslice – a slice providing the Y-position for the subset in the form slice(ystart, yend, ystep)

  • zslice – a slice providing the Z-position for the subset in the form slice(zstart, zend, zstep) or a list containing the indices of the bands to extract

  • return_GeoArray – whether to return an instance of GeoArray (default) or a tuple(np.ndarray, gt, prj)

  • reset_bandnames – whether band names of subset should be copied from source GeoArray or reset to ‘B1’, ‘B2’, ‘B3’, …

Returns

property gt
property is_inmem

Check if associated image array is completely loaded into memory.

property is_map_geo

Return ‘True’ if the image has a valid geoinformation with map instead of image coordinates.

property is_rotated

Return ‘True’ if the image has a rotation in the map info (i.e., is pseudo-projected).

property mask_baddata

Return the bad data mask.

Note: The mask must be explicitly set to a file path or a numpy array before.

property mask_nodata

Get the nodata mask of the associated image array. It is generated based on all image bands.

property meta
property metadata

Return a DataFrame containing all available metadata (read from file if available).

Use ‘metadata[band_index].to_dict()’ to get a metadata dictionary for a specific band. Use ‘metadata.loc[row_name].to_dict()’ to get all metadata values of the same key for all bands as dictionary. Use ‘metadata.loc[row_name, band_index] = value’ to set a new value.

Returns

instance of GDAL_Metadata

property ndim

Get the number dimensions of the associated image array.

property nodata

Get the nodata value of the GeoArray instance.

If GeoArray has been instanced with a file path the metadata of the file on disk is checked for an existing nodata value. Otherwise, (if no value is exlicitly given during object instanciation) an automatic detection based on 3x3 windows at each image corner is run that analyzes the mean and standard deviation of these windows.

property prj
property projection

Get the projection of the associated image.

Setting the projection is only allowed if GeoArray has been instanced from memory or the associated file on disk has no projection.

read_pointData(mapXY_points, mapXY_points_prj=None, band=None, offside_val=nan)[source]

Return the array values for the given set of X/Y coordinates.

NOTE: If GeoArray has been instanced with a file path, the function will read the dataset into memory.

Parameters
  • mapXY_points – <np.ndarray, tuple> X/Y coordinates of the points of interest. If a numpy array is given, it must have the shape [Nx2]

  • mapXY_points_prj – <str, int> WKT string or EPSG code of the projection corresponding to the given coordinates.

  • band – <int> the band index of the band of interest. If None, the values of all bands are returned.

  • offside_val – fill value in case input coordinates are geographically outside of the GeoArray instance

Returns

  • int in case only a singe coordinate is passed

  • np.ndarray with shape [Nx1] in case only one band is requested

  • np.ndarray with shape [Nx1xbands] in case all bands are requested

reproject_to_new_grid(prototype=None, tgt_prj=None, tgt_xygrid=None, rspAlg='cubic', CPUs=None)[source]

Reproject all array-like attributes to a given target grid.

Parameters
  • prototype – <GeoArray> an instance of GeoArray to be used as pixel grid reference

  • tgt_prj – <str> WKT string of the projection

  • tgt_xygrid – <list> target XY grid, e.g. [[xmin,xmax], [ymax, ymin]] for the UL corner

  • rspAlg – <str, int> GDAL compatible resampling algorithm code

  • CPUs – <int> number of CPUs to use (default: None -> use all available CPUs)

Returns

property rows

Get the number of rows of the associated image array.

save(out_path: str, fmt: str = 'ENVI', creationOptions: Optional[list] = None) None[source]

Write the raster data to disk.

Parameters
  • out_path – <str> output path

  • fmt – <str> the output format / GDAL driver code to be used for output creation, e.g. ‘ENVI’ Refer to https://gdal.org/drivers/raster/index.html to get a full list of supported formats.

  • creationOptions – <list> GDAL creation options, e.g., [“QUALITY=80”, “REVERSIBLE=YES”, “WRITE_METADATA=YES”]

set_gdalDataset_meta()[source]

Retrieve GDAL metadata from file.

This is only executed once to avoid overwriting of user defined attributes, that are defined after object instanciation.

property shape

Get the array shape of the associated image array.

show(xlim=None, ylim=None, band=None, boundsMap=None, boundsMapPrj=None, figsize=None, interpolation='none', vmin=None, vmax=None, pmin=2, pmax=98, cmap=None, nodataVal=None, res_factor=None, interactive=False, ax=None, ignore_rotation=False)[source]

Plot the desired array position into a figure.

Parameters
  • xlim – [start_column, end_column]

  • ylim – [start_row, end_row]

  • band – the band index of the band to be plotted (if None and interactive==True all bands are shown, otherwise the first band is chosen)

  • boundsMap – xmin, ymin, xmax, ymax

  • boundsMapPrj

  • figsize

  • interpolation

  • vmin – darkest pixel value to be included in stretching

  • vmax – brightest pixel value to be included in stretching

  • pmin – percentage to be used for excluding the darkest pixels from stretching (default: 2)

  • pmax – percentage to be used for excluding the brightest pixels from stretching (default: 98)

  • cmap

  • nodataVal

  • res_factor – <float> resolution factor for downsampling of the image to be plotted in order to save plotting time and memory (default=None -> downsampling is performed to 1000x1000)

  • interactive – <bool> activates interactive plotting based on ‘holoviews’ library. NOTE: this deactivates the magic ‘% matplotlib inline’ in Jupyter Notebook

  • ax – <matplotlib.axis> only usable in non-interactive mode

  • ignore_rotation – whether to ignore an image rotation angle included in the GDAL GeoTransform tuple for plotting (default: False)

Returns

show_footprint()[source]

Show a web map containing the computed footprint of the GeoArray instance in a Jupyter notebook.

show_histogram(band: int = 1, bins: int = 200, normed: bool = False, exclude_nodata: bool = True, vmin: Optional[float] = None, vmax: Optional[float] = None, figsize: Optional[tuple] = None) None[source]

Show a histogram of a given band.

Parameters
  • band – the band to be used to plot the histogram

  • bins – number of bins to plot (default: 200)

  • normed – whether to normalize the y-axis or not (default: False)

  • exclude_nodata – whether tp exclude nodata value from the histogram

  • vmin – minimum value for the x-axis of the histogram

  • vmax – maximum value for the x-axis of the histogram

  • figsize – figure size (tuple)

show_map(xlim=None, ylim=None, band=0, boundsMap=None, boundsMapPrj=None, out_epsg=None, figsize=None, interpolation='none', vmin=None, vmax=None, pmin=2, pmax=98, cmap=None, nodataVal=None, res_factor=None, return_map=False)[source]

Show a cartopy map of the associated image data (requires geocoding and projection information).

Parameters
  • xlim

  • ylim

  • band – band index (starting with 0)

  • boundsMap – xmin, ymin, xmax, ymax

  • boundsMapPrj

  • out_epsg – EPSG code of the output projection

  • figsize

  • interpolation

  • vmin – darkest pixel value to be included in stretching

  • vmax – brightest pixel value to be included in stretching

  • pmin – percentage to be used for excluding the darkest pixels from stretching (default: 2)

  • pmax – percentage to be used for excluding the brightest pixels from stretching (default: 98)

  • cmap

  • nodataVal

  • res_factor – <float> resolution factor for downsampling of the image to be plotted in order to save plotting time and memory (default=None -> downsampling is performed to 1000x1000)

  • return_map

Returns

show_xprofile(row, band, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show an x-profile at the given row/band image position.

Parameters
  • row – image row number (counts from 0)

  • band – image band number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

show_yprofile(column, band, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show a y-profile at the given column/band image position.

Parameters
  • column – image column number (counts from 0)

  • band – image band number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

show_zprofile(row, column, xlim=None, ylim=None, title=None, figsize=(10, 5), show_nodata=True, return_fig=False)[source]

Show a z-profile at the given row/column image position.

Parameters
  • row – image row number (counts from 0)

  • column – image column number (counts from 0)

  • xlim – x-axis limits to be used in the plot

  • ylim – y-axis limits to be used in the plot

  • title – a custom plot title

  • figsize – figure size (tuple)

  • show_nodata – whether to show no-data values in the plot

  • return_fig – whether to return the figure instead of showing it directly

Returns

plt.figure

tiles(tilesize: tuple = (100, 100)) GeneratorLen[source]

Get tiles of the full dataset in the given tile size.

Parameters

tilesize – target size of the tiles (rows, columns) NOTE: If rows or columns are None, all rows/columns are returned

Returns

Generator with elements like: (((rowStart, rowEnd), (colStart, colEnd)), tiledata)

to_disk()[source]

Set self.arr back to None for in-memory instances, to release memory.

Note: This requires that the GeoArray was instanced with a file path.

to_mem()[source]

Read the whole dataset into memory and sets self.arr to the read data.

property xgsd

Get the X resolution in units of the given or detected projection.

property xygrid_specs

Get the specifications for the X/Y coordinate grid.

This returns for example [[15,30], [0,30]] for a coordinate with its origin at X/Y[15,0] and a GSD of X/Y[15,30].

property ygsd

Get the Y resolution in units of the given or detected projection.

class geoarray.NoDataMask(path_or_array, geotransform=None, projection=None, bandnames=None, nodata=False, progress=True, q=False)[source]

Bases: geoarray.masks._Mask

property arr