raster_func module

This module contains raster functions and methods.

It comprises (amongst others) reading, writing, rescaling, sampling, reprojecting, operators, statistics, conditionals, window operations on raster data.

Raster data is stored in rasterArr objects, basicly a numpy MaskedArray and a dict with geographical information.

All GDAL supported raster formats are handled. Additionally iMOD raster files (IDF) are handled.

Rescaling/resampling is done automatically if needed.

raster_func.crs2epsg(crs, alt=”)

Function to create EPSG string from a crs reference.

Parameters:

crs : int or str

Crs reference.

One of the following forms:

Integer: EPSG reference number.

String: ‘EPSG:i’ where i denotes a EPSG reference number.

String: ‘UTMiC’ where i denotes a UTM zone number and C denotes ‘N’ or ‘S’ for the hemisphere.

String: GDAL’s so called WellKnownGeogCS string, e.g. ‘WGS84’.

String: Ohter recognized strings are: ‘amersfoort’, ‘rd’, ‘gda94’, ‘gda94_vicgrid’

String: WKT string

alt : str (optional)

Alternative string to be returned if crs could not be converted to WKT.

Returns:

epsg : str

‘EPSG:i’ string or ‘UTMiC’ string.

See also

Projection

raster_func.crs2prj(f_prj, crs)

Function to write crs as WKT to prj file.

Parameters:

f_prj : str

File name of prj file.

Extension of the file is replaced by ‘.prj’.

crs : int or str

Crs reference.

One of the following forms:

Integer: EPSG reference number.

String: ‘EPSG:i’ where i denotes a EPSG reference number.

String: ‘UTMiC’ where i denotes a UTM zone number and C denotes ‘N’ or ‘S’ for the hemisphere.

String: GDAL’s so called WellKnownGeogCS string, e.g. ‘WGS84’.

String: Ohter recognized strings are: ‘amersfoort’, ‘rd’, ‘gda94’, ‘gda94_vicgrid’

String: WKT string

raster_func.crs2wkt(crs, alt=”)

Function to create WKT string from a crs reference.

Parameters:

crs : int or str

Crs reference.

One of the following forms:

Integer: EPSG reference number.

String: ‘EPSG:i’ where i denotes a EPSG reference number.

String: ‘UTMiC’ where i denotes a UTM zone number and C denotes ‘N’ or ‘S’ for the hemisphere.

String: GDAL’s so called WellKnownGeogCS string, e.g. ‘WGS84’.

String: Ohter recognized strings are: ‘amersfoort’, ‘rd’, ‘gda94’, ‘gda94_vicgrid’

String: WKT string

alt : str (optional)

Alternative string to be returned if crs could not be converted to WKT.

Returns:

wkt : str

See also

Projection

raster_func.equal_gi(gi1, gi2, tol=1e-07)

Function to check if 2 geographical information dicts/lists are equal.

Parameters:

gi1 : dict or list

Geographical information dict/list.

gi2 : dict or list

Geographical information dict/list.

tol : float (optional)

Tolerance factor. If values differ less than tol they are considered to be equal.

Returns:

equal : bool

raster_func.get_gi(rA, *args)

Function to get a list of specified geographical information elements of a rasterArr object or a geographical information dict/list.

Parameters:

rA : rasterArr object, dict, list or tuple

The input raster or the geographical information dict/list.

If rA is a list or tuple it is assumed that this contains the basic geographical information, in fixed order: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

args : arguments (str)

Recognized arguments are: ‘gi’, ‘gi_list’, ‘nodata’, ‘xll’, ‘xur’, ‘yll’, ‘yur’, ‘dx’, ‘Dx’, ‘dy’, ‘Dy’, ‘ieq’, ‘nrow’, ‘ncol’, ‘proj’, ‘ang’. Other arguments are ignored.

If rA is a dict the recognized arguments are limited to what is included in the dict.

If rA is a list or tuple the recognized arguments are limited to ‘xll’, ‘yll’, ‘dx’, ‘dy’, ‘nrow’, ‘ncol’, ‘proj’, ‘ang’.

If ‘gi’ is specified the dict of the basic geographical information is returned. If ‘gi_list’ is specified the basic geographical information is returned as list with fixed order: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

result : list

The list with the specified elements.

raster_func.get_global_method()

Function to get the global method for rescaling/resampling.

The global method is used if rescaling/resampling is needed, but no method is specified by the programmer.

Returns:

method : str or None

The global method for rescaling/resampling. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

raster_func.get_nodataASC()

Function to get the global ASC nodata value.

The global ASC nodata value is used in writing an ASC file if no specific nodata value is specified.

Returns:

nodata : int, float or None

The global ASC nodata value.

raster_func.get_nodataIDF()

Function to get the global IDF nodata value.

The global IDF nodata value is used in writing an IDF file if no specific nodata value is specified.

Returns:

nodata : int, float or None

The global IDF nodata value.

raster_func.get_raster_crs(f_raster, f_hdr=None)

Function to get the crs of a file.

Parameters:

f_raster : str

File name.

f_hdr : str or None (optional)

Header file name for BIL file.

Returns:

crs : str

String referring to the crs of the raster file.

See also

Projection

raster_func.get_raster_format(f_raster)

Function to get the raster format of a file.

Parameters:

f_raster : str

File name.

Returns:

raster_format : str

String referring to the format of the raster file.

See also

Raster formats

raster_func.get_raster_minmax(f_raster)

Function to get the minimum and maximum value of a PCRaster or IDF file.

Parameters:

f_raster : str

File name of PCRaster or IDF file

Returns:

result : tuple

Minimum and maximum value.

raster_func.get_raster_nodata(f_raster, f_hdr=None)

Function to get the nodata value of a raster file.

Parameters:

f_raster : str

Raster file name.

f_hdr : str or None (optional)

Header file name for BIL file.

Returns:

nodata : float

raster_func.get_raster_pcrMapType(f_raster)

Function to get the map type (valueScale) of a PCRaster file.

Recognized types are: ‘boolean’, ‘nominal’, ‘scalar’, ‘directional’, ‘ordinal’, ‘ldd’.

Parameters:

f_raster : str

File name of PCRaster file

Returns:

pcrMapType : string

PCRaster map type; returns None if f_raster is not a PCRaster file.

raster_func.gi2dict(gi=None, **kwargs)

Function to convert and set geographical information into a dict with at least the basic geographical information.

Parameters:

gi : list, dict, None

Existing geographical information.

If gi is specified as a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

If gi is None it is ignored.

kwargs : keyword arguments

Existing keywords in gi will be overruled.

Returns:

result : dict

raster_func.gi2list(gi=None, **kwargs)

Function to convert and set geographical information into a list with the basic geographical information.

Parameters:

gi : list, dict, None

Existing geographical information.

If gi is specified as a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

If gi is None it is ignored.

kwargs : keyword arguments

Existing keywords in gi will be overruled.

Returns:

result : list

raster_func.gi_extended(rA, as_list=False)

Function to get the extended geographical information of a rasterArr object or a basic geographical information dict/list.

The extended geographical information comprises: xur, yur, Dx, Dy.

Parameters:

rA : rasterArr object, dict, list or tuple

The input raster or the basic geographical information dict/list.

as_list : bool (optional)

True = return result as list; order of elements is fixed: see above.

False = return result as dict.

Returns:

gi : dict or list

The extended geographical information.

raster_func.gi_get_Dx(gi)

Function to get Dx (total extent/width in x direction) from a geographical information dict/list.

Parameters:

gi : dict or list

Geographical information dict/list.

Returns:

Dx : float

raster_func.gi_get_Dy(gi)

Function to get Dy (total extent/height in y direction) from a geographical information dict/list.

Parameters:

gi : dict or list

Geographical information dict/list.

Returns:

Dy : float

raster_func.gi_get_xur(gi)

Function to get xur (x coordinate of upper right corner) from a geographical information dict/list.

Parameters:

gi : dict or list

Geographical information dict/list.

Returns:

xur : float

raster_func.gi_get_yur(gi)

Function to get yur (y coordinate of upper right corner) from a geographical information dict/list.

Parameters:

gi : dict or list

Geographical information dict/list.

Returns:

yur : float

raster_func.gi_set_dxdy(gi, dx=None, dy=None)

Function to set (change) the cell size of a geographical information dict/list.

Parameters:

gi : dict or list

Geographical information dict/list.

dx : float, int, numpy array or array_like (optional)

Cell size in x direction (column width)

If dx is a numpy array (or array_like) the number of columns (ncol) is adjusted too.

dy : float, int or numpy array (optional)

Cell size in y direction (row height)

If dy is a numpy array (or array_like) the number of rows (nrow) is adjusted too.

Returns:

result : dict

New geographical information dict

raster_func.gi_set_extent(gi, l_extent, snap=False)

Function to set (change) the extent of a geographical information dict/list.

Does not work for non-equidistant rasters.

Parameters:

gi : dict or list

Geographical information dict/list.

l_extent : list

A list containing xll, yll, xur and yur of the new extent (in this order).

snap : bool (optional)

Flag to snap (shift) the new extent to match with the original cell boundaries.

True = snap is performed to the nearest cell boundaries.

False = snap is not performed

Returns:

result : dict

New geographical information dict

raster_func.idfs2mdf(l_idf, f_mdf, rgb=None)

Function to group a list of IDF files into a MDF file.

Parameters:

l_idf : list

Lisf of IDF files to be grouped.

f_mdf : string

Output MDF file.

rgb : list, tuple or None (optional)

RGB color code(s) for the IDF files (layers).

raster_func.idfs2stat(l_idf, stat=’mean’, ncel=100000, assume_same_mask=True, weights=None)

Function to calculate cell-by-cell statistics for a list of iMOD IDF files.

Because reading entire rasters for a large number of files could cause memory errors, the function uses memory mapping to read a user-defined number of cells at the same time.

All files should have the same extent and cell sizes.

Parameters:

l_idf : list

List of iMOD IDF files.

stat : str (optional)

The statistic to be calculated. Recognized are: ‘sum’, ‘count’, ‘mean’, ‘std’, ‘var’, ‘min’, ‘max’, ‘median’ and percentiles in the form of ‘pQ’ where Q represents an integer between 0 and 100 (e.g. ‘p10’).

ncel : int or None (optional)

The number of cells to be read at the same time.

If ncel is None all cells will be read at the same time.

assume_same_mask : bool (optional)

Flag to specify if the mask (nodata) of the cells could be assumed to be same or not.

True = assume same masks

False = do not assume same masks; this will be much slower

weights : array, array_like or None (optional)

The weights to be applied for the IDF files. Only relevant if stat is ‘sum’, ‘count’, ‘mean’, ‘median’ or a percentile. If stat is ‘sum’ or ‘count’ weights is used as multiplier.

If weights is an array (or array_like) it should be 1 dimensional and containing one weight for each file.

If weights is None all files will have the same weight.

Returns:

result : rasterArr object

See also

Statistics

raster_func.if_then(if_statement, then_statement)

Function to perform a conditional operation (if-then).

Same as if_then_else(..) function without an else statement.

At least one of the if and then statements should be a rasterArr object.

If needed rescaling/resampling is performed using the global method (see Rescaling/resampling). If more than one statement is a rasterArr object the geographical information dict for rescaling/resampling is taken from one of them in the following prefered order: then, if.

The datatype of the result is based on the datatype of the then statement.

Parameters:

if_statement : rasterArr object, single numerical value, numpy array or array_like (boolean or boolean_like)

The if statement.

then_statement : rasterArr object, single numerical value, numpy array or array_like

The then statement.

Returns:

result : rasterArr object

raster_func.if_then_else(if_statement, then_statement, else_statement=None)

Function to perform a conditional operation (if-then-else).

At least one of the if, then and else statements should be a rasterArr object.

If needed rescaling/resampling is performed using the global method (see Rescaling/resampling). If more than one statement is a rasterArr object the geographical information dict for rescaling/resampling is taken from one of them in the following prefered order: then, else, if.

The datatype of the result is based on the datatype of the then statement.

Parameters:

if_statement : rasterArr object, single numerical value, numpy array or array_like (boolean or boolean_like)

The if statement.

then_statement : rasterArr object, single numerical value, numpy array or array_like

The then statement.

else_statement : rasterArr object, single numerical value, numpy array or array_like

The else statement.

Returns:

result : rasterArr object

raster_func.maps2stat(l_map, stat=’mean’, ncel=10000, assume_same_mask=True, weights=None)

Function to calculate cell-by-cell statistics for a list of PCRaster files.

Because reading entire rasters for a large number of files could cause memory errors, the function uses memory mapping to read a user-defined number of cells at the same time.

All files should have the same extent and cell sizes.

Parameters:

l_map : list

List of PCRaster files.

stat : str (optional)

The statistic to be calculated. Recognized are: ‘sum’, ‘count’, ‘mean’, ‘std’, ‘var’, ‘min’, ‘max’, ‘median’ and percentiles in the form of ‘pQ’ where Q represents an integer between 0 and 100 (e.g. ‘p10’).

ncel : int or None (optional)

The number of cells to be read at the same time.

If ncel is None all cells will be read at the same time.

assume_same_mask : bool (optional)

Flag to specify if the mask (nodata) of the cells could be assumed to be same or not.

True = assume same masks

False = do not assume same masks; this will be much slower

weights : array, array_like or None (optional)

The weights to be applied for the IDF files. Only relevant if stat is ‘sum’, ‘count’, ‘mean’, ‘median’ or a percentile. If stat is ‘sum’ or ‘count’ weights is used as multiplier.

If weights is an array (or array_like) it should be 1 dimensional and containing one weight for each file.

If weights is None all files will have the same weight.

Returns:

result : rasterArr object

See also

Statistics

raster_func.masks2rc_overlap(rA1, rA2)

Function to calculated row and column indices of the overlapping area of 2 rasters.

Parameters:

rA1 : rasterArr object

First raster.

rA2 : rasterArr object

Second raster.

Returns:

rc : numpy ndarray

Array with the overlapping and non-masked row and column indices of the two rasters.

2x2xN array: [[irow1 array, icol1 array],[irow2 array,icol2 array]]

rect : numpy ndarray

Array with the ‘from’ and ‘to’ row and column indices for overlapping area (including masked cells) of the two rasters.

2x2x2 array: [[(irow1 from,irow1 to),(icol1 from,icol1 to)],[(irow2 from,irow2 to),(icol2 from,icol2 to)]]

raster_func.prj2crs(f_prj, epsg=True)

Function to create EPSG or WKT string from prj file.

Parameters:

f_prj : str

File name of prj file.

Returns:

wkt : str

raster_func.put_rA(rA, rA_in, method=’sample’)

Function to replace a part of the data of a rasterArr object with another rasterArr object.

If needed rescaling/resampling is performed.

Parameters:

rA : rasterArr object

Base rasterArr object.

rA_in : rasterArr object

raterArr object containing the data to be put into the base rasterArr object.

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Returns:

result : rasterArr object

raster_func.rA_nonequi2equi(rA, dx=None, dy=None)

Function to resample a non-equidistant raster to an equidistant raster.

Parameters:

rA : rasterArr object

dx : float, int or None (optional)

Cell size in x direction (column width).

If dx is None then the minimum column width of the non-equidistant raster is used.

dy : float, int or None (optional)

Cell size in y direction (row height).

If dy is None then the minimum row height of the non-equidistant raster is used.

Returns:

result : rasterArr object

raster_func.raster2arr(f_raster, nodata=None, gi=None, method=’sample’, step_xy=1, dtype_asc=None, f_hdr=None)

Function to read a raster file and create a rasterArr object.

Parameters:

f_raster : str

Raster file name.

nodata : float, int or None (optional)

Nodata value to be applied.

gi : dict, list or None (optional)

Basic geographical information dict/list.

If gi is specified a rescaling/resampling is performed to meet gi. The rescaling/resampling method is specified with the parameter method. If method is None no rescaling/resampling is performed, but only the extent of the raster is set to meet gi (“crop”).

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Rescaling/resampling is only applied if gi is specified. See above.

step_xy : int or list (optional)

The resampling step size in x and y direction, with 1 as lowest value meaning no resampling.

Note: if step_xy is specified resampling is performed irrespective of rescaling/resampling invoked by gi and method. Resampling with step_xy is done before rescaling/resampling to meet gi.

The step size is not necessarily the same in x in y direction.

If step_xy is an int or a list with only one value the step size in x and y direction are both set to this value.

dtype_asc : numpy dtype or None (optional)

Data type for the resulting data array if the raster file is an ArcInfo ASCII Grid.

If dtype_asc is not specified the resulting data type will be float64.

f_hdr: str or None (optional)

Header file name for BIL file.

Returns:

result : rasterArr object

raster_func.raster2gi(f_raster, f_hdr=None)

Function to get the basic geographical information of the raster.

Parameters:

f_raster : str

Raster file name.

f_hdr : str or None (optional)

Header file name for BIL file.

Returns:

gi : dict

Basic geographical information.

class raster_func.rasterArr(arr, gi=None, nodata=None, **kwargs)

Bases: object

Raster data object class.

Parameters:

arr : array, array_like, rasterArr object, float or int

Raster values.

arr could be an existing rasterArr object, a numpy array (ndarray or MaskedArray) or an array_like object (list or tuple). It could be 2-D or 3-D (map stack).

gi : dict or list (optional)

Geographical information.

If gi is specified as a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs. If arr is specified as rasterArr object then gi is overruled with the geographical information of arr.

nodata : bool, int or float (optional)

Nodata value to be applied.

kwargs : keyword arguments (optional)

The keyword arguments could be used to set basic geographical information. Recognized keywords are: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

result : rasterArr object

Notes

Some internal methods for consistency are applied upon initialisation. This comprises the number of dimensions of the object (see below), nodata value and mask, nrow and ncol of arr and gi etc.

If the number of dimensions of the object is lower than 2 the number of dimensions is increased to 2 by adding new dimensions. E.g. the 1-D array [1,2] becomes the 2-D array [[1,2]].

If the number of dimensions of the object is higher than 3 the number of dimensions is decreased to 3 by removing dimensions. From each dimension higher than 3 the first element is taken. The other elements are removed. E.g. the 4-D array [ [[(1,2),(3,4)],[(11,12),(13,14)]], [[(101,102),(103,104)],[(111,112),(113,114)]] ] becomes the 3-D array [[(1,2),(3,4)],[(11,12),(13,14)]].

Methods

Dx()

Method to get Dx (total extent/width in x direction).

Returns:Dx : float
Dy()

Method to get Dy (total extent/height in y direction).

Returns:Dy : float
abs()

Method to calculate the absolute value.

result = abs(self)

Returns:result : rasterArr object
ang()

Method to get ang (angle/rotation of coordinate system in PCRaster terms).

Returns:ang : float
arr2figure(colorscale=’jet’, n_class=8, scale_type=’linear’, perc_bnd=[0, 100], use_underover=True, list_of_shapes=[])

Method to create a matplotlib figure object with a map and a colorbar.

Parameters:

colorscale : str or legendScale object (optional)

Color scale / legend to be used.

If colorscale is a string and refers to an existing iMOD legend file, then this legend file is used and the arguments n_class and scale_type are ignored.

If colorscale is a string and does not refer to an iMOD legend file, it is interpreted as a colorscale name of matplotlib or plot_func (including the _r option).

If colorscale is a legendScale object (see class legendScale in plot_func library), then this legend is used and the arguments n_class and scale_type are ignored.

n_class : int or None (optional)

Number of intervals. This is an initial number; the final number of intervals may differ depending on the determined interval width.

If n_class is None then the initial number of intervals will be 8.

A minimum number of 2 is required.

scale_type : str (optional)

Two types are supported: ‘linear’ and ‘histogram’.

If scale_type is ‘linear’ then the intervals will have equal widths.

If scale_type is ‘histogram’ then the interval widths will be based on the distribution of values (percentiles).

perc_bnd : numpy array or array_like (optional)

Lower and upper percentiles to be used as initial minimum and maximum boundary values.

use_underover : bool (optional)

True = color_under and color_over are used if needed.

False = color_under and color_over are not used.

list_of_shapes : list (optional)

List containing the information of point/polyline/polygon overlays. The list contains records; each record contains the following information (in fixed order):

  • shape type (str) = type of the overlay; recognized are ‘POINT’, ‘POLYLINE’ and ‘POLYGON’
  • shape xy (list or numpy ndarray) = x,y coordinates of the shapes; see gis_func.write_gen() or gis_func.write_shp()
  • fill color (rgb or rgba tuple; value range 0-1); optional; default = (0,0,0,0)
  • line color (rgb or rgba tuple; value range 0-1); optional; default = (0.5,0.5,0.5,1)
  • line width (int) = widht of the lines; optional; default = 1
  • marker (str) = type of marker, matplotlib style; optional; default = ‘o’
  • marker size (int) = size of the markers; optional; default = 4
Returns:

fig : matplotlib figure object

arr2raster(f_raster, raster_format=0, frm_asc=’%s’, xy_center_asc=False, nodata_asc=None, itb_idf=None, nodata_idf=None, frm_map=None, f_hdr=None)

Method to write a 2-D or 3-D rasterArr object to raster file(s).

Same as method write(..).

bool()

Method to convert data type to bool.

Returns:result : rasterArr object
copy()

Method to create a deep copy of the rasterArr object.

Returns:

result : rasterArr object

A deep copy of the rasterArr object.

count(axis=None)

Method to calculate the number of non-nodata elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

count : numpy array

See also

Statistics

cover(other)

Method to fill (cover) nodata cells.

Parameters:

other : rasterArr object, numpy array (ndarry or MaskedArray) or single numeric value

If other is a rasterArr object it is rescaled/resampled to meet self if needed, using the global method.

Returns:

result : rasterArr object

crop()

Method to crop the raster to non-nodata values.

Returns:result : rasterArr object
crs()

Method to get crs (coordinate reference system).

Returns:ang : float
dtype()

Method to get the dtype of the data array.

Returns:dtype : numpy dtype object
dx()

Method to get dx (cell size in x direction).

Returns:

dx : float or numpy array (1-D)

If the raster is non-equidistant the dx is a numpy array containing the cell sizes of each column.

dxarr()

Method to get dx (cell size in x direction) for all cells of a rasterArr object and return them as a rasterArr object.

Returns:dx : rasterArr object
dy()

Method to get dy (cell size in y direction).

Returns:

dy : float or numpy array (1-D)

If the raster is non-equidistant the dy is a numpy array containing the cell sizes of each row.

dyarr()

Method to get dy (cell size in y direction) for all cells of a rasterArr object and return them as a rasterArr object.

Returns:dy : rasterArr object
exp()

Method to calculate exponential (base e).

result = exp(self) = e ** self

Returns:result : rasterArr object
exp10()

Method to calculate exponential (base 10).

result = exp10(self) = 10 ** self

Returns:result : rasterArr object
extent()

Method to get the extent: xll, yll, xur, yur.

Returns:extent : list
float()

Method to convert data type to float (float32 or float64).

Returns:result : rasterArr object
get_gi(*args)

Method to get a list of specified geographical information elements.

Parameters:

args : arguments (str)

Recognized arguments are: ‘gi’, ‘gi_list’, ‘nodata’, ‘xll’, ‘xur’, ‘yll’, ‘yur’, ‘dx’, ‘Dx’, ‘dy’, ‘Dy’, ‘ieq’, ‘nrow’, ‘ncol’, ‘proj’, ‘ang’, ‘crs’. Other arguments are ignored.

If ‘gi’ is specified the dict of the basic geographical information is returned. If ‘gi_list’ is specified the basic geographical information is returned as list with fixed order: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

result : list

The list with the specified elements.

gi()

Method to get the basic geographical information dict.

The basic geographical information comprises: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

gi : dict

The basic geographical information.

gi_extended(as_list=False)

Method to get the extended geographical information.

The extended geographical information comprises: xur, yur, Dx, Dy.

Parameters:

as_list : bool (optional)

True = return result as list; order of elements is fixed: see above.

False = return result as dict.

Returns:

gi : dict or list

The extended geographical information.

gi_list()

Method to get the basic geographical information as list.

The basic geographical information comprises: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

gi : list

The basic geographical information.

The order of the elements is fixed: see above.

ieq()

Method to get ieq (equidistant flag).

Returns:

ieq : int

0 = equidistant raster

1 = non-equidistant raster

int()

Method to convert data type to int (int8, int16, int32 or int64).

Returns:result : rasterArr object
log()

Method to calculate natural logarithm (base e).

result = log(self)

Returns:result : rasterArr object
log10()

Method to calculate logarithm (base 10).

result = log10(self)

Returns:result : rasterArr object
mask()

Method to get the mask.

Returns:mask : numpy array
max(axis=None)

Method to get the maximum value of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

max : numpy array

See also

Statistics

mean(axis=None)

Method to calculate the mean of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

mean : numpy array

See also

Statistics

median(axis=None)

Method to calculate the median of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

median : numpy array

See also

Statistics

min(axis=None)

Method to get the minimum value of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

min : numpy array

See also

Statistics

ncol()

Method to get ncol (number of columns).

Returns:ncol : int
nodata()

Method to get the nodata value.

Returns:nodata : bool, int or float
nonequi2equi(dx=None, dy=None)

Method to resample a non-equidistant raster to an equidistant raster.

Parameters:

dx : float, int or None (optional)

Cell size in x direction (column width).

If dx is None then the minimum column width of the non-equidistant raster is used.

dy : float, int or None (optional)

Cell size in y direction (row height).

If dy is None then the minimum row height of the non-equidistant raster is used.

Returns:

result : rasterArr object

nrow()

Method to get nrow (number of rows).

Returns:nrow : int
percentile(p=50, axis=None)

Method to calculate a percentile of the array elements over the given axis.

Parameters:

p : int or float in range 0-100

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

percentile : numpy array

See also

Statistics

proj()

Method to get proj (projection flag in PCRaster terms).

Returns:

proj : int

0 = y coordinates increase from top to bottom

1 = y coordinates increase from bottom to top

reproject(to_crs, from_crs=None, method=’sample’, xyur=None)

Method to reproject.

Does not work for non-equidistant rasters.

Parameters:

to_crs : str, int, list or dict

Target crs.

If this is a list or a dict it is interpreted as geographical information from which the crs, extent and cell size are taken.

from_crs : str, int, list, dict or None (optional)

Source crs. Will be used if the crs of the raster is not specified.

If this is a list or a dict it is interpreted as geographical information from which the crs is taken.

method : str or None (optional)

The reprojecting method. Possible methods are: ‘mean’ or ‘average’, ‘sample’ or ‘near’, ‘bilinear’, ‘cubic’, ‘cubicspline’, ‘lanczos’, ‘mode’, None.

xyur : list or None (optional)

X and Y coordinates of upper right corner. May be used by gdalwarp if to_crs is geographical information, but xur and yur could not be calculated (e.g. because dx and dy are None).

Returns:

result : rasterArr object

resample(step_xy=[1, 1])

Method to resample using a step size.

Parameters:

step_xy : int, list or dict

The step size in x and y direction, with 1 as lowest value meaning no resampling.

The step size is not necessarily the same in x in y direction.

If step_xy is an int or a list with only one value the step size in x and y direction are both set to this value.

If step_xy is a dict it is assumed that it is a basic geographical information dict. The step sizes are then determined using this dict. See also the rescale(..) method.

Returns:

result : rasterArr object

rescale(to_gi, method=’sample’)

Method to rescale/resample.

Does not work for non-equidistant rasters.

Parameters:

to_gi : dict or list

The target geographical information dict/list to which the rescaling/resampling is done.

If to_gi is specified as a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs. See also Geographical information.

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Returns:

result : rasterArr object

set_arr(arr, method=’sample’)

Method to set the data array (in-place).

Does not work for non-equidistant rasters if rescaling/resampling is needed.

Parameters:

arr : numpy array (ndarray or MaskedArray), rasterArr object, bool, int or float

The new data array.

If arr is of type bool, int or float the data array is set to this value on all cells.

If arr is a rasterArr object a rescaling/resampling of arr is applied if needed.

method : str or None (optional)

Method for rescaling/resampling, if needed.

set_dxdy(dx=None, dy=None, method=’sample’)

Method to create a new rasterArr object with changed cellsize.

Parameters:

dx : float, int, numpy array or array_like (optional)

Cell size in x direction (column width).

If dx is a numpy array (or array_like) the number of columns (ncol) is adjusted too.

dy : float, int or numpy array (optional)

Cell size in y direction (row height).

If dy is a numpy array (or array_like) the number of rows (nrow) is adjusted too.

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Returns:

result : rasterArr object

RasterArr object with new cellsize.

set_extent(l_extent, snap=True)

Method to create a new rasterArr object with a changed extent.

Parameters:

extent : list

A list containing xll, yll, xur and yur of the new extent (in this order).

snap : bool (optional)

Flag to snap (shift) the new extent to match with the original cell boundaries.

True = snap is performed to the nearest cell boundaries.

False = snap is not performed

Returns:

result : rasterArr object

RasterArr object with new extent.

set_gi(**kwargs)

Method to set geographical information using keyword arguments (in-place).

Parameters:

kwargs : keyword arguments

Recognized keyword arguments are: xll, yll, dx, dy, nrow, ncol, proj, ang, crs. Other keyword arguments are ignored.

set_mask(mask=None, add=False)

Method to set the mask (in-place).

Parameters:

mask : numpy array (ndarray or MaskedArray), rasterArr object, bool, int, float or str

The mask to be applied.

If mask is of type bool, int, float or str this value is used to set the nodata value. See raster_func.rasterArr.set_nodata().

add : bool (optional)

True = add new masked cells to existing mask

False = change existing mask to new mask

set_nodata(nodata=None)

Method to set the nodata value (in-place).

Original nodata cells are kept; new nodata cells are added if applicable.

Parameters:

nodata : bool, int, float or str

If nodata is of type str then nodata is used in a where condition. E.g. ‘>10’ means that all values greater than 10 are set to nodata.

set_nodata_mask()

Method to set all cells with nodata value to masked cells (in-place).

shape()

Method to get the shape of the data array.

Returns:shape : tuple
slice(l_rowcol)

Method to crop the raster to a given slice.

Parameters:

l_rowcol : list

Minimum and maximum row and column numbers: [iRow_min,iRow_max,iCol_min,iCol_max]

iRow_max and iCol_max are not included in the slice.

Returns:

result : rasterArr object

std(axis=None)

Method to calculate the standard deviation of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

std : numpy array

See also

Statistics

sum(axis=None)

Method to calculate the sum of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

sum : numpy array

See also

Statistics

toGDALobj()

Method to create a GDAL in-memory object from the rasterArr object.

Does not work for 3-D rasterArr objects and for non-equidistant rasters.

Returns:result : GDAL object
unique()

Method to get the unique values of the data array.

Returns:result : numpy array (1-D)
var(axis=None)

Method to calculate the variance of the array elements over the given axis.

Parameters:

axis : int or None (optional)

Axis over which the calculation is done.

If axis is None the calculation is done over all dimensions, resulting in a single value.

Returns:

var : numpy array

See also

Statistics

warp(to_crs, from_crs=None, exe_warp=None, screen_output=False, xyur=None)

Method to reproject by using gdalwarp.

Does not work for non-equidistant rasters.

Parameters:

to_crs : str, int, list or dict

Target crs.

If this is a list or a dict it is interpreted as geographical information from which the crs, extent and cell size are taken.

from_crs : str, int, list, dict or None (optional)

Source crs. Will be used if the crs of the raster is not specified.

If this is a list or a dict it is interpreted as geographical information from which the crs is taken.

exe_warp : str or None (optional)

File name of the gdalwarp executable. If exe_warp is None then ‘gdalwarp’ is used; this only works if ‘gdalwarp’ is known to the system (e.g. in the PATH environment).

screen_output : bool (optional)

True = output of gdal’s process to the screen. False = no output of gdal’s process to the screen.

xyur : list or None (optional)

X and Y coordinates of upper right corner. May be used by gdalwarp if to_crs is geographical information, but xur and yur could not be calculated (e.g. because dx and dy are None).

Returns:

result : rasterArr object

write(f_raster, raster_format=0, frm_asc=’%s’, xy_center_asc=False, nodata_asc=None, itb_idf=None, nodata_idf=None, frm_map=None, f_hdr=None)

Method to write a 2-D or 3-D rasterArr object to raster file(s).

Parameters:

f_raster : str or list

Raster file name(s).

For a 2-D rasterArr object only one file name is required. For a 3-D rasterArr object (map stack) a list of file names is required if the raster format only supports 2-D rasters.

raster_format : int or str (optional)

Number or string referring to the format of the raster file.

See Raster formats.

If raster_format is 0 the raster format is determined from the extension of the file.

frm_asc : str (optional)

% format for writing ASCII grid file.

Include a divider if needed, e.g. ‘ %.1f’ for a single space divider; divider is set automatically to ‘ ‘ for the formats ‘%s’, ‘%d’ and ‘%f’.

xy_center_asc : bool (optional)

True = xll,yll coordinates for the center of the cell (XLLCENTER and YLLCENTER)

False = xll,yll coordinates for the corner of the cell (XLLCORNER and YLLCORNER)

nodata_asc : int, float or None (optional)

Nodata value to be used for writing an ASCII grid file. Otherwise the global ASCII grid nodata value is used.

itb_idf : list or None (optional)

Top and bot values of IDF file: ITB option.

nodata_idf : int, float or None (optional)

Nodata value to be used for writing an IDF file. Otherwise the global IDF nodata value is used.

frm_map : str or None (optional)

PCRaster map type.

Recognized types are: ‘boolean’, ‘nominal’, ‘scalar’, ‘directional’, ‘ordinal’, ‘ldd’.

If frm_map is None then the type is set to ‘boolean’, ‘nominal’ or ‘scalar’ depending on the dtype of the data array.

f_hdr : str, list or None (optional)

Header file name(s) for BIL file.

If f_hdr is None the header file name is taken from the BIL file name (f_raster).

In the case of a map stack to be written to multiple BIL files, f_hdr could be a list of file names (not required).

Returns:

Raster file name(s), e.g. to be used for printing : str or list

x()

Method to get the x coordinates of the column centers of a rasterArr object.

Returns:x : numpy ndarray
xarr()

Method to get the x coordinates of the cell centers of a rasterArr object and return them as a rasterArr object.

Returns:x : rasterArr object
xll()

Method to get xll (x coordinate of lower left corner).

Returns:xll : float
xur()

Method to get xur (x coordinate of upper right corner).

Returns:xur : float
y()

Method to get the y coordinates of the row centers of a rasterArr object.

Returns:y : numpy ndarray
yarr()

Method to get the y coordinates of the cell centers of a rasterArr object and return them as a rasterArr object.

Returns:y : rasterArr object
yll()

Method to get yll (y coordinate of lower left corner).

Returns:yll : float
yur()

Method to get yur (y coordinate of upper right corner).

Returns:yur : float
raster_func.rasterStack(l_rA, nodata=None, to_gi=None, method=’sample’)

Function to create a 3-D rasterArr object (map stack) from 2-D rasterArr objects.

If needed rescaling/resampling is performed to the first rasterArr object.

Parameters:

l_rA : list

List of 2-D rasterArr objects.

nodata : float, int or None (optional)

Nodata value to apply for the map stack.

If nodata is None it is taken from the first rasterArr object.

to_gi : dict, list or None (optional)

Basis geographical information dict/list to rescale/resample to.

If to_gi is None it is taken from the first rasterArr object. If rescaling/resampling of the other rasterArr objects is performed.

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Returns:

result : rasterArr object (3-D)

raster_func.rasters2arr(fl_raster, nodata=None, gi=None, method=’sample’, step_xy=1, dtype_asc=None, fl_hdr=None)

Function to read a list of raster files and create a rasterArr object (map stack).

The raster files are not necessarily of the same raster format and may have different extents and/or cell sizes.

If needed rescaling/resampling is performed to the first raster file in the list.

Parameters:

fl_raster : list or tuple

List of raster file names.

nodata : float, int or None (optional)

Nodata value to be applied.

gi : dict, list or None (optional)

Basic geographical information dict/list.

If gi is specified a rescaling/resampling is performed to meet gi. The rescaling/resampling method is specified with the parameter method. If method is None no rescaling/resampling is performed, but only the extent of the raster is set to meet gi (“crop”).

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Rescaling/resampling is only applied if gi is specified. See above.

step_xy : int or list (optional)

The resampling step size in x and y direction, with 1 as lowest value meaning no resampling.

Note: if step_xy is specified resampling is performed irrespective of rescaling/resampling invoked by gi and method. Resampling with step_xy is done before rescaling/resampling to meet gi.

The step size is not necessarily the same in x in y direction.

If step_xy is an int or a list with only one value the step size in x and y direction are both set to this value.

dtype_asc : numpy dtype or None (optional)

Data type for the resulting data array if the raster file is an ArcInfo ASCII Grid.

If dtype_asc is not specified the resulting data type will be float64.

fl_hdr: str, list, tuple or None (optional)

List of header file names for the BIL files.

If fl_header is a single file name this header file is used for all BIL files.

Returns:

result : rasterArr object (3-D map stack)

raster_func.rasters_max(rA, *args)

Function to calculate the maximum of two or more rasters (or numpy arrays, floats, ints).

Parameters:

rA : rasterArr object

args : rasterArr object(s), numpy array(s), float(s), int(s)

Arbitrary number of arguments.

Returns:

result : rasterArr object

See also

Statistics

raster_func.rasters_mean(rA, *args)

Function to calculate the mean of two or more rasters (or numpy arrays, floats, ints).

Parameters:

rA : rasterArr object

args : rasterArr object(s), numpy array(s), float(s), int(s)

Arbitrary number of arguments.

Returns:

result : rasterArr object

See also

Statistics

raster_func.rasters_min(rA, *args)

Function to calculate the minimum of two or more rasters (or numpy arrays, floats, ints).

Parameters:

rA : rasterArr object

args : rasterArr object(s), numpy array(s), float(s), int(s)

Arbitrary number of arguments.

Returns:

result : rasterArr object

See also

Statistics

raster_func.rc2rc(gi1, gi2, raveled=False, rc_splitted=False)

Function to calculated row and column indices of a raster and the corresponding indices of a second raster.

Parameters:

gi1 : dict or list

The basic geographical information of the first raster.

gi2 : dict or list

The basic geographical information of the second raster.

raveled : bool (optional)

True = ravel/flatten the indices in output (see below)

False = do not ravel/flatten the indices

rc_splitted : bool (optional)

True = split row and column indices in output (see below)

False = keep row and column indices in one array

Returns:

result : tuple

Result is depending on rc_splitted: (rc1,rc2,consecutive) or (r1,c1,r2,c2,consecutive).

rc1 = row and column indices of the first raster; 2-D or 3-D array depending on raveled.

rc2 = corresponding row and column indices of the second raster; 2-D or 3-D array depending on raveled.

consecutive = boolean: True = cells of second raster are in consecutive order; False = cells or second raster are not in consecutive order.

r1 = row indices of the first raster; 1-D or 2-D array depending on raveled.

r2 = corresponding row indices of the second raster; 1-D or 2-D array depending on raveled.

c1 = column indices of the first raster; 1-D or 2-D array depending on raveled.

c2 = corresponding column indices of the second raster; 1-D or 2-D array depending on raveled.

raster_func.rc2xy(rc, gi, ll=False, outsideVal=None)

Function to convert row,col indices to x,y coordinates.

Default the x,y coordinates are for the cell centers.

Does not work for non-equidistant rasters.

Parameters:

rc : array or array_like (2-D)

A 2xN array with the row,col indices. Indices follow Python standard, i.e. starting at 0.

gi : dict or list

The basic geographical information.

ll : bool

True = coordinates for lower left (ll) corner of cell

False = coordinates for cell center.

outsideVal : int, float or None (optional)

X,y coordinate value to be used for row,col indices which are outside the extent of gi.

Returns:

xy : numpy array (2-D)

A 2xN array/matrix with the x,y coordinates.

raster_func.rc_arr2val(rc, rA)

Function to extract cell values of a rasterArr object using row,col indices.

Parameters:

rc : array or array_like (2-D)

A 2xN array with the row,col indices. Indices follow Python standard, i.e. starting at 0.

rA : rasterArr object

Returns:

result : numpy array (MaskedArray)

raster_func.rc_idf2val(rc, f, nodata=None, consecutive=False)

Function to extract cell values of an iMOD IDF file using row,col indices.

Parameters:

rc : array or array_like (2-D)

A 2xN array/matrix with the row,col indices. Indices follow Python standard, i.e. starting at 0.

f : str

Input IDF file.

nodata : float, int or None (optional)

Nodata value to be applied.

consecutive : bool (optional)

True = specified cells form a consecutive series of cells

False = specified cells do not form a consecutive series of cells

Returns:

result : numpy array

raster_func.rc_map2val(rc, f, nodata=None, consecutive=False)

Function to extract cell values of a PCRaster file using row,col indices.

Parameters:

rc : array or array_like (2-D)

A 2xN array/matrix with the row,col indices. Indices follow Python standard, i.e. starting at 0.

f : str

Input PCRaster file.

nodata : float, int or None (optional)

Nodata value to be applied.

consecutive : bool (optional)

True = specified cells form a consecutive series of cells

False = specified cells do not form a consecutive series of cells

Returns:

result : numpy array

raster_func.rc_val2arr(rc, val, rA)

Function to set cell values of a rasterArr object using row,col indices.

Parameters:

rc : array or array_like (2-D)

A 2xN array with the row,col indices. Indices follow Python standard, i.e. starting at 0.

val : int, float, array or array_like (1-D)

Value(s) to set. Single value or array of values for each x,y coordinate.

rA : rasterArr object

Returns:

result : rasterArr object

raster_func.rc_val2idf(rc, val, f, consecutive=False)

Function to write cell values to an existing iMOD IDF file using row,col indices.

Does not work for non-equidistant rasters.

Parameters:

rc : array or array_like (2-D)

A 2xN array/matrix with the row,col indices. Indices follow Python standard, i.e. starting at 0.

val : array or array_like (1-D)

An array/matrix with the values. The values are converted to meet the data type of the IDF file.

f : str

Input IDF file.

consecutive : bool (optional)

True = specified cells form a consecutive series of cells

False = specified cells do not form a consecutive series of cells

raster_func.rc_val2map(rc, val, f, consecutive=False)

Function to write cell values to an existing PCRaster file using row,col indices.

Parameters:

rc : array or array_like (2-D)

A 2xN array/matrix with the row,col indices. Indices follow Python standard, i.e. starting at 0.

val : array or array_like (1-D)

An array/matrix with the values. The values are converted to meet the data type of the PCRaster file.

f : str

Input PCRaster file.

consecutive : bool (optional)

True = specified cells form a consecutive series of cells

False = specified cells do not form a consecutive series of cells

raster_func.reproject_rA(rA, to_crs, from_crs=None, method=’sample’, xyur=None)

Function to reproject a rasterArr object.

Does not work for non-equidistant rasters.

Parameters:

rA : rasterArr object

to_crs : str, int, list or dict

Target crs.

If this is a list or a dict it is interpreted as geographical information from which the crs, extent and cell size are taken.

from_crs : str, int, list, dict or None (optional)

Source crs. Will be used if the crs of the raster is not specified.

If this is a list or a dict it is interpreted as geographical information from which the crs is taken.

method : str or None (optional)

The reprojecting method. Possible methods are: ‘sample’ or ‘near’, ‘bilinear’, ‘cubic’, ‘cubicspline’, ‘lanczos’, ‘mean’ or ‘average’, ‘mode’, None.

xyur : list or None (optional)

X and Y coordinates of upper right corner. May be used by gdalwarp if to_crs is geographical information, but xur and yur could not be calculated (e.g. because dx and dy are None).

Returns:

result : rasterArr object

See also

Projection

raster_func.resample_rA(rA, step_xy=[1, 1])

Function to resample a rasterArr object using a step size.

Parameters:

rA : rasterArr object

step_xy : int, list or dict

The step size in x and y direction, with 1 as lowest value meaning no resampling.

The step size is not necessarily the same in x in y direction.

If step_xy is an int or a list with only one value the step size in x and y direction are both set to this value.

If step_xy is a dict it is assumed that it is a basic geographical information dict. The step sizes are then determined using this dict. See also raster_func.rescale_rA()

Returns:

result : rasterArr object

raster_func.rescale_rA(rA, to_gi, method=’sample’)

Function to rescale/resample a rasterArr object.

Does not work for non-equidistant rasters.

Parameters:

rA : rasterArr object

to_gi : dict or list

The target geographical information dict/list to which the rescaling/resampling is done.

If to_gi is specified as a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs. See also Geographical information.

method : str or None (optional)

The rescaling/resampling method. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

Returns:

result : rasterArr object

raster_func.reset_global_method()

Function to reset the global method for rescaling/resampling to None.

Same as set_global_method(None)

raster_func.same_crs(crs1, crs2)

Function to check if two crs references are the same.

Parameters:

crs1 : int or str

First crs reference.

One of the following forms:

Integer: EPSG reference number.

String: ‘EPSG:i’ where i denotes a EPSG reference number.

String: ‘UTMiC’ where i denotes a UTM zone number and C denotes ‘N’ or ‘S’ for the hemisphere.

String: GDAL’s so called WellKnownGeogCS string, e.g. ‘WGS84’.

String: Ohter recognized strings are: ‘amersfoort’, ‘rd’, ‘gda94’, ‘gda94_vicgrid’

String: WKT string

crs2 : int or str

Second crs reference.

See crs1 for the possible forms.

Returns:

result : bool

True = crs references are the same.

False = crs references are not the same.

See also

Projection

raster_func.set_gi(rA, **kwargs)

Function to set geographical information using keyword arguments.

Parameters:

rA : rasterArr object, list or dict

If rA is a rasterArr object the object is modified in-place.

If rA is a dict or list it is assumed to be a geographical information list/dict. If rA is a list the order of the elements should be: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

kwargs : keyword arguments

Recognized keyword arguments are: xll, yll, dx, dy, nrow, ncol, proj, ang, crs.

Returns:

rA : rasterArr object, list or dict

Result is depending on input type.

raster_func.set_global_method(method=None)

Function to set the global method for rescaling/resampling.

The global method is used if rescaling/resampling is needed, but no method is specified by the programmer.

Parameters:

method : str or None (optional)

The global method for rescaling/resampling. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

raster_func.set_nodataASC(nodata=None)

Function to set the global ASC nodata value.

The global ASC nodata value is used in writing an ASC file if no specific nodata value is specified.

Parameters:

nodata : int, float or None (optional)

The global ASC nodata value.

raster_func.set_nodataIDF(nodata=None)

Function to set the global IDF nodata value.

The global IDF nodata value is used in writing an IDF file if no specific nodata value is specified.

Parameters:

nodata : int, float or None (optional)

The global IDF nodata value.

raster_func.warp_rA(rA, to_crs, from_crs=None, exe_warp=None, method=’sample’, screen_output=False, xyur=None)

Function to reproject a rasterArr object by using gdalwarp.

Does not work for non-equidistant rasters.

Parameters:

rA : rasterArr object

to_crs : str, int, list or dict

Target crs.

If this is a list or a dict it is interpreted as geographical information from which the crs, extent and cell size are taken.

from_crs : str, int, list, dict or None (optional)

Source crs. Will be used if the crs of the raster is not specified.

If this is a list or a dict it is interpreted as geographical information from which the crs is taken.

exe_warp : str or None (optional)

File name of the gdalwarp executable. If exe_warp is None then ‘gdalwarp’ is used; this only works if ‘gdalwarp’ is known to the system (e.g. in the PATH environment).

method : str or None (optional)

The reprojecting method. Possible methods are: ‘sample’ or ‘near’, ‘bilinear’, ‘cubic’, ‘cubicspline’, ‘lanczos’, None.

screen_output : bool (optional)

True = output of gdal’s process to the screen. False = no output of gdal’s process to the screen.

xyur : list or None (optional)

X and Y coordinates of upper right corner. May be used by gdalwarp if to_crs is geographical information, but xur and yur could not be calculated (e.g. because dx and dy are None).

Returns:

result : rasterArr object

See also

Projection

raster_func.window_arr(arr, multArr=None, dWin=None, method=’mean’, round=False, unitCell=True)

Function to perform a window operation.

A ‘window’ could be a rectangle, a circles or a free form.

Does not work for non-equidistant rasters and for different dx and dy.

Parameters:

arr : rasterArr object or numpy array

multArr : numpy ndarray, array_like (2-D) or None (optional)

Multipliers/weights of the cells in the ‘window’.

If used this automatically determines the form/size of the window. It is possible to specify any form in the multArr array. Zeros in the array are ignored (not used as multipliers).

dWin is not used if multArr is specified.

dWin : float, int, str or None (optional)

Window size/radius and form. Will be used if multArr is None. From dWin the multipliers/weights array is constructed.

dWin is an int: ‘radius’ of a square window. The size of the square will be (dWin * 2) + 1. The multipliers/weights will be 1 in all cells within the square.

dWin is a float: same as int, but not necessarily a whole number. The multipliers/weights in the outer cells of the window will be the remaining fraction between 0 and 1.

dWin is a str:

  • ‘circle_radius=<size>’ ==> circle with radius <size>; multipliers are 1 within circle; remaining fraction between 0 and 1 in outer cells.
  • ‘circle_dist_radius=<size>,<offset>’ ==> circle with radius <size>; multipliers are the distance from the centre + <offset>.
  • ‘rectangle_rc=<size R>,<size C>’ ==> rectangle with <size R> and <size C> the ‘radius’ in resp. row (y) and column (x) direction; multipliers are 1 within rectangle; remaining fraction between 0 and 1 in outer cells.

Size(s) in cell units unless unitCell is False.

method : str

The window operation method. Possible methods are: ‘mean’, ‘harm’, ‘log’, ‘log10’, ‘min’, ‘max’, ‘sum’, ‘std’, ‘var’, ‘count’.

round : bool (optional)

True = multipliers/weights constructed from dWin are rounded off.

False = multipliers/weights constructed from dWin are not rounded off.

unitCell : bool (optional)

True = size(s) used in dWin are in cell units.

False = size(s) used in dWin are in raster units (if arr is a rasterArr object).

Returns:

result : rasterArr object or numpy MaskedArray (depending on input)

raster_func.xy2rc(xy, gi, outsideVal=None)

Function to convert x,y coordinates to row,col indices.

Does not work for non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

gi : dict or list

The basic geographical information.

outsideVal : int or None (optional)

Row,col index value to be used for x,y coordinates which are outside the extent of gi.

Returns:

rc : numpy array (2-D)

A 2xN array with the row,col indices. Indices follow Python standard, i.e. starting at 0.

raster_func.xy_arr2val(xy, rA, interpolate=False)

Function to extract cell values of a rasterArr object using x,y coordinates.

It is possible to enable linear interpolation from cell centers to the exact x,y location(s).

Does not work for non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

rA : rasterArr object

interpolate : bool

Flag for linear interpolation from cell centers to x,y location(s).

True = enable linear interpolation

False = disable linear interpolation

Returns:

result : numpy array (MaskedArray)

raster_func.xy_idf2val(xy, f, nodata=None, interpolate=False)

Function to extract cell values of an iMOD IDF file using x,y coordinates.

It is possible to enable linear interpolation from cell centers to the exact x,y location(s).

Does not work for non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

f : str

Input IDF file.

nodata : float, int or None (optional)

Nodata value to be applied.

interpolate : bool (optional)

Flag for linear interpolation from cell centers to x,y location.

True = enable linear interpolation

False = disable linear interpolation

Returns:

result : numpy array

raster_func.xy_map2val(xy, f, nodata=None, interpolate=False)

Function to extract cell values of a PCRaster file using x,y coordinates.

Does not work on non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

f : str

Input PCRaster file.

nodata : float, int or None (optional)

Nodata value to be applied.

interpolate : bool

Flag for linear interpolation from cell centers to x,y location.

True = enable linear interpolation

False = disable linear interpolation

Returns:

result : numpy array

raster_func.xy_val2arr(xy, val, rA)

Function to set cell values of a rasterArr object using x,y coordinates.

Does not work for non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

val : int, float, array or array_like (1-D)

Value(s) to set. Single value or array of values for each x,y coordinate.

rA : rasterArr object

Returns:

result : rasterArr object

raster_func.xy_val2idf(xy, val, f)

Function to write cell values to an existing iMOD IDF file using x,y coordinates.

Does not work for non-equidistant rasters.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

val : array or array_like (1-D)

An array/matrix with the values. The values are converted to meet the data type of the IDF file.

f : str

Input IDF file.

raster_func.xy_val2map(xy, val, f)

Function to write cell values to an existing PCRaster file using x,y coordinates.

Parameters:

xy : array or array_like (2-D)

A 2xN array/matrix with the x,y coordinates.

val : array or array_like (1-D)

An array/matrix with the values. The values are converted to meet the data type of the PCRaster file.

f : str

Input PCRaster file.