GeoEco.Datasets.NumpyGrid

class GeoEco.Datasets.NumpyGrid(numpyArray, displayName, spatialReference, dimensions, coordIncrements, cornerCoords, unscaledNoDataValue=None, tIncrementUnit=None, tSemiRegularity=None, tCountPerSemiRegularPeriod=None, tCornerCoordType=None, tOffsetFromParsedTime=None, coordDependencies=None, physicalDimensions=None, physicalDimensionsFlipped=None, scaledDataType=None, scaledNoDataValue=None, scalingFunction=None, unscalingFunction=None, parentCollection=None, queryableAttributes=None, queryableAttributeValues=None, lazyPropertyValues=None)

Bases: Grid

Wraps a numpy.ndarray in the Grid interface.

NumpyGrid provides a convenient mechanism for modifying a Grid. The typical usage pattern is:

  1. Obtain a Grid instance from somewhere (e.g. a GDALRasterBand or an ArcGISRasterBand instance).

  2. Call NumpyGrid.CreateFromGrid() to wrap the Grid in a NumpyGrid.

  3. Get and set slices of the Data property of the NumpyGrid.

  4. Import the NumpyGrid into the desired DatasetCollection.

Parameters:
  • numpyArray (instance of <class 'object'>) – numpy.ndarray to wrap. This array must have 2, 3, or 4 dimensions. Note that the array is not copied. Data written to Data will written to the original array provided by the caller. This array must have one of the following dtypes꞉ 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float32', 'float64'.

  • displayName (str) – Informal name of this object, suitable to be displayed to the user. Minimum length꞉ 1.

  • spatialReference (object) – Spatial reference of the requested type as an osgeo.osr.SpatialReference instance, or None to indicate the spatial reference is unknown.

  • dimensions (str) – Dimensions of this grid. Allowed values꞉ 'yx', 'zyx', 'tyx', 'tzyx'. Case sensitive.

  • coordIncrements (tuple of float) – Coordinate increment for each dimension. None for dimensions that do not have a constant coordinate increment. Must have the same length as dimensions.

  • cornerCoords (tuple of object) – The center coordinates of the lower-left cell of this grid. Must have the same length as dimensions.

  • unscaledNoDataValue (object, optional) – int or float value that indicates that cells of UnscaledData should be interpreted as having no data (these are also known as missing, NA, or NULL cells), or None if all cells must have data.

  • tIncrementUnit (str, optional) – Unit of the t coordinate. None if the grid’s dimensions do not contain a t coordinate. Allowed values꞉ 'year', 'month', 'day', 'hour', 'minute', 'second'. Case sensitive.

  • tSemiRegularity (str, optional) – Type of semi-regularity used for the t coordinate. None if the grid’s dimensions do not contain a t coordinate or the t coordinate is not semi-regular. Allowed values꞉ 'annual'. Case sensitive.

  • tCountPerSemiRegularPeriod (int, optional) – Number of time slices per semi-regular period (i.e. per year). None if the grid’s dimensions do not contain a t coordinate or the t coordinate is not semi-regular.

  • tCornerCoordType (str, optional) – Indicates whether the t coordinate of cornerCoords is the minimum, center, or maximum coordinate for the cell. Ignored if dimensions does not have a t coordinate. Allowed values꞉ 'min', 'center', 'max'. Case sensitive.

  • tOffsetFromParsedTime (float, optional) – Number of seconds to to add to t coordinates after computing them from cornerCoords and coordIncrements. Used for datasets that round off their times, e.g. the file name contains the year, month, and day, but the time slices do not start at midnight. If None, nothing will be added.

  • coordDependencies (tuple of str, optional) – Dimensions that each dimension depends on for determining its coordinates. None for dimensions that have a constant coordinate increment. Must have the same length as dimensions.

  • physicalDimensions (str, optional) – The dimensions physically used by numpyArray. If they do not conform the canonical order given by dimensions, provide their actual order here and Grid will automatically reorder them as needed. Allowed values꞉ 'yx', 'xy', 'zyx', 'zxy', 'yzx', 'yxz', 'xzy', 'xyz', 'tyx', 'txy', 'ytx', 'yxt', 'xty', 'xyt', 'tzyx', 'tzxy', 'tyzx', 'tyxz', 'txzy', 'txyz', 'ztyx', 'ztxy', 'zytx', 'zyxt', 'zxty', 'zxyt', 'ytzx', 'ytxz', 'yztx', 'yzxt', 'yxtz', 'yxzt', 'xtzy', 'xtyz', 'xzty', 'xzyt', 'xytz', 'xyzt'. Case sensitive.

  • physicalDimensionsFlipped (tuple of bool, optional) – tuple of bool indicating how the data of in numpyArray are ordered for each physical dimension. If False, the dimension is ordered in ascending coordinate order; if True, it is in descending coordinate order. Must have the same length as dimensions.

  • scaledDataType (str, optional) – Numeric data type of the grid, after the scaling function (if any) has been applied to the raw data. numpy.ndarrays returned by Data have this type. Allowed values꞉ 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float32', 'float64'. Case sensitive.

  • scaledNoDataValue (object, optional) – int or float value that indicates that cells of Data should be interpreted as having no data (these are also known as missing, NA, or NULL cells), or None if all cells must have data.

  • scalingFunction (object, optional) – Lambda or function for transforming the data of numpyArray before it is returned by Data, or None of no such transformation is needed. The function must take one argument, a slice of numpyArray, and return a numpy.ndarray of the scaledDataType.

  • unscalingFunction (object, optional) – Lambda or function for back-transforming data written to Data (e.g. grid.Data[...] = ...) before it is written to numpyArray, or None of no such transformation is needed. The function must take one argument, a numpy.ndarray of the scaledDataType, and return a numpy.ndarray having the same data type as numpyArray.

  • parentCollection (DatasetCollection, optional) – Parent DatasetCollection that this object is part of (if any).

  • queryableAttributes (tuple of QueryableAttribute, optional) – Queryable attributes defined for this object.

  • queryableAttributeValues (dict mapping str to object, optional) – Values of the queryable attributes, expressed as a dictionary mapping the case-insensitive names of queryable attributes to their values.

  • lazyPropertyValues (dict mapping str to object, optional) – Lazy properties to set when this object is constructed, expressed as a dictionary mapping the names of lazy properties to their values.

Returns:

NumpyGrid instance.

Return type:

NumpyGrid

Properties

property Array

None

property CenterCoords

(object) Coordinates of the grid cell centers, indexed using the 1-character dimension of interest and optionally a range to retrieve a numpy.ndarray of coordinates (e.g. CenterCoords['x', 0:4]) or an integer to retrieve a float for a single coordinate (e.g. CenterCoords['x', 10]). Coordinates for the t dimension are returned as datetime instances. Read only.

property CoordDependencies

(tuple of str) Same length as Dimensions. Dimensions that each dimension depends on for determining its coordinates. None for dimensions that have a constant coordinate increment. Read only.

property CoordIncrements

(tuple of float) Same length as Dimensions. Coordinate increment for each dimension. None for dimensions that do not have a constant coordinate increment. Read only.

property Data

(object) This grid’s data, indexable using slices (e.g. grid.Data[:, 5:10, -10:]) or integers (e.g. grid.Data[0,1,-2]) or both in combination. Strides and negative indexes are supported in the traditional manner. If the grid is writable, Data can be assigned to write values to the grid, e.g. grid.Data[0,1] = 5 or grid.Data[:,:] = numpy.zeros(grid.Shape). Returns and accepts numpy.ndarray, float, and int. Read only.

property DataIsScaled

(bool) If True, the underlying raw data are stored as the UnscaledDataType to save storage space and then transformed by a scaling equation on the fly when they are returned by Data. The raw data can be accessed with UnscaledData. If False, the raw data are returned as is, with no transformation needed, and UnscaledDataType and DataType are the same, and UnscaledData returns the same values as Data. Read only.

property DataType

(str) Numeric data type of the grid, after the scaling function (if any) has been applied to the raw data. numpy.ndarrays returned by Data have this type. Read only. Allowed values꞉ 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float32', 'float64'. Case sensitive.

property Dimensions

(str) Dimensions of this grid. Read only. Allowed values꞉ 'yx', 'zyx', 'tyx', 'tzyx'. Case sensitive.

property DisplayName

(str) Informal name of this object, suitable to be displayed to the user. Read only. Minimum length꞉ 1.

property MaxCoords

(object) Maximum coordinate value for each cell (i.e., the coordinates of the cells’ right edges), indexed using the 1-character dimension of interest and optionally a range to retrieve a numpy.ndarray of coordinates (e.g. MaxCoords['x', 0:4]) or an integer to retrieve a float for a single coordinate (e.g. MaxCoords['x', 10]). Coordinates for the t dimension are returned as datetime instances. Read only.

property MinCoords

(object) Minimum coordinate value for each cell (i.e., the coordinates of the cells’ left edges), indexed using the 1-character dimension of interest and optionally a range to retrieve a numpy.ndarray of coordinates (e.g. MinCoords['x', 0:4]) or an integer to retrieve a float for a single coordinate (e.g. MinCoords['x', 10]). Coordinates for the t dimension are returned as datetime instances. Read only.

property NoDataValue

(object or None) int or float value that indicates that cells of Data should be interpreted as having no data (these are also known as missing, NA, or NULL cells), or None if all cells must have data. Read only.

property ParentCollection

(DatasetCollection or None) Parent DatasetCollection that this object is part of (if any). Read only.

property Shape

(tuple of int) Same length as Dimensions. Length (number of grid cells) of each dimension. Read only.

property TCountPerSemiRegularPeriod

(int or None) Number of time slices per semi-regular period (i.e. per year). None if the grid’s dimensions do not contain a t coordinate or the t coordinate is not semi-regular. Read only.

property TIncrementUnit

(str or None) Unit of the t coordinate. None if the grid’s dimensions do not contain a t coordinate. Read only. Allowed values꞉ 'year', 'month', 'day', 'hour', 'minute', 'second'. Case sensitive.

property TSemiRegularity

(str or None) Type of semi-regularity used for the t coordinate. None if the grid’s dimensions do not contain a t coordinate or the t coordinate is not semi-regular. Read only. Allowed values꞉ 'annual'. Case sensitive.

property UnscaledData

(object) This grid’s data underlying raw data, before it has been transformed by a scaling equation. UnscaledData is indexable using slices (e.g. grid.UnscaledData[:, 5:10, -10:]) or integers (e.g. grid.UnscaledData[0,1,-2]) or both in combination. Strides and negative indexes are supported in the traditional manner. If the grid is writable, UnscaledData can be assigned to write values to the grid, e.g. grid.UnscaledData[0,1] = 5 or grid.UnscaledData[:,:] = numpy.zeros(grid.Shape). Returns and accepts numpy.ndarray, float, and int. Read only.

property UnscaledDataType

(str) Numeric data type of the grid’s raw data, before it has been transformed by a scaling equation. numpy.ndarrays returned by UnscaledData have this type. If no transformation is needed (DataIsScaled is False), then UnscaledDataType and ScaledDataType are the same, and UnscaledData returns the same values as Data. Read only. Allowed values꞉ 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float32', 'float64'. Case sensitive.

property UnscaledNoDataValue

(object or None) int or float value that indicates that cells of UnscaledData should be interpreted as having no data (these are also known as missing, NA, or NULL cells), or None if all cells must have data. Read only.

Methods

Close

Closes any open files or connections associated with this object and releases any other resources allocated to access it.

ConvertSpatialReference

Converts a spatial reference from one format to another, such as an OGC WKT string to a Proj4 string.

CreateFromGrid

Reads an entire Grid into a newly-allocated numpy array and wraps it in a NumpyGrid instance.

DeleteLazyPropertyValue

Deletes the lazy property with the specified name.

GetAllQueryableAttributes

Returns a list of all queryable attributes.

GetIndicesForCoords

Given a tuple or list of coordinates, returns a list of int indices into Data for the cell that contains the coordinates.

GetLazyPropertyValue

Returns the value of the lazy property with the specified name.

GetQueryableAttribute

Returns the queryable attribute with the specified name.

GetQueryableAttributeValue

Returns the value of the queryable attribute with the specified name.

GetQueryableAttributesWithDataType

Returns a list queryable attributes having the specified data type.

GetSpatialReference

Returns the spatial reference of this dataset.

HasLazyPropertyValue

Returns True if the specified lazy property has a value.

SetLazyPropertyValue

Sets the lazy property with the specified name to the specified value.

SetSpatialReference

Sets the spatial reference of this dataset.

TestCapability

Tests whether a capability is supported by this class or an instance of it.

numpy_equal_nan