GeoEco.Datasets.Virtual.BlockStatisticGrid
- class GeoEco.Datasets.Virtual.BlockStatisticGrid(grid, statistic, xySize=None, zSize=None, tSize=None, tUnit=None, tStart=None, tSemiRegularity=None)
Bases:
GridA
Gridrepresenting a block statistic computed over anotherGrid.This class partitions the input
Gridinto non-overlapping blocks of cells and computes a summary statistic for each block, yielding a reduced resolution representation of it. This operation is sometimes known as downsampling.- Parameters:
grid (
Grid) –Gridfor which a block statistic should be computed. This input grid must have a constant increment in each dimension for which summarization is requested. For example, if the zSize parameter is given, indicating that summarization should be performed in the depth dimension, then the input grid must havezcoordinates that increment by a constant value. If it does not, thenBlockStatisticGridcannot summarize in thezdimension, and zSize should be left asNone. In that situation, theBlockStatisticGridwill have the same number of cells in thezdirection as the input grid.statistic (
str) –Summary statistic to calculate for each block, one of:
count- number of cells in the block that have data.maximum- miniumum value of call cells in the block with data.mean- mean value of all cells in the block with data.median- median value of all cells in the block with data.minimum- miniumum value of all cells in the block with data.range- maximum value minus the minimum value, considering all cells in the block with data.standard_deviation- sample standard deviation (i.e. the standard deviation estimated using Bessel’s correction) of all cells in the block with data. In order to calculate this, there must be at least two cells in the block with data.sum- sum of all cells in the block with data.
In all statistics, NoData values are ignored. For example, if a 5 x 5 block has 2 cells with the NoData value, all statistics will be based on the 23 cells that have data. If no cells in a block have data, i.e., they all have the NoData value, the result is the NoData value.
Allowed values꞉
'count','maximum','mean','median','minimum','range','standard_deviation','sum'.xySize (
int, optional) – Size of the block in thexandydirections. If not given, 1 will be used, and summarization will not be performed for thexorydimensions. In this situation, the block statistic grid will have the same number of cells in thexandydirections as the input grid. Minimum value꞉ 1.zSize (
int, optional) – Size of the block in thez(depth) direction. If not given, 1 will be used, and summarization will not be performed for thezdimension. In this situation, the block statistic grid will have the same number of cells in thezdirection as the input grid. This parameter should be omitted if the input grid does not have azdimension. Minimum value꞉ 1.tSize (
int, optional) –Size of the block in the
t(time) direction, in the units given by the tUnit parameter. If not given, 1 will be used, and summarization will not be performed for thetdimension. In this situation, the block statistic grid will have the same number of cells in thetdirection as the input grid. This parameter should be omitted if the input grid does not have atdimension.The length of time specified by tSize and tUnit must be longer than the time increment of the input grid. If tUnit is
monthoryearand the tIncrementUnit of the input grid isday,hour,minute, orsecond, then the resulting blocks will be based on however many days, hours, minutes, or seconds actually fall within each block of months or years.A time slice of the input grid will be included in a block if its start time is greater than or equal to the start time of the block, and less than or equal to the end time of the block. By default, the start times of the blocks are aligned with midnight of January 1 of the year the input grid starts. The tStart parameter can override this behavior.
For example, if the input grid contains hourly time slices and starts on 2012-02-19 13:00:00, and the block statistic grid is defined with a tSize of
1, a tUnit ofmonth, and tStart is not given, then the first block will summarize slices that start 2012-02-01 00:00:00 through 2012-02-29 23:00:00, inclusive. The second time slice will summarize slices that start 2012-03-01 00:00:00 through 2012-03-31 23:00:00, inclusive.If tUnit is
day,hour,minute, orsecondand the tSize would yield a series of blocks with a block that overlapped the transition from December to January, the tSemiRegularity parameter controls what happens.Minimum value꞉ 1.
tUnit (
str, optional) – Unit of the tSize parameter. This parameter should be omitted if the input grid does not have atdimension. Allowed values꞉'year','month','day','hour','minute','second'.tStart (
datetime, optional) –Date and time to which the summary blocks’ minimum
tcoordinates should be aligned (or “snapped”). Ignored if no summarization is performed in thetdirection (i.e., tSize is not given).If a start date and time is given, it must be less than or equal to the minimum
tcoordinate of the first time slice of the input grid. If it is not given, it will be set to midnight on January 1 of the year the input grid starts.Blocks will be laid out in the
tdirection starting at this date and time until a block is found that starts on or before the minimumtcoordinate of the input grid and ends after that coordinate. That block will become the first in the block statistic grid (the ones before it will be dropped).If tUnit is
month, then the start date and time must be midnight on the first day of a month. The resulting summary blocks will thus encompass whole months. Starting the blocks at any time other than the very beginning of the month is not currently supported.If tSemiRegularity is
annual, then the start date and time must be midnight on January 1 of a year.tSemiRegularity (
str, optional) –Type of semi-regularity to use for the
tcoordinate. Ignored if no summarization is performed in thetdirection (i.e., tSize is not given), or if tUnit ismonthoryear.If tUnit is
day,hour,minute, orsecondand tSemiRegularity is not given, then the resulting series of summary blocks will be allowed to contain blocks that overlap the December/January transition. For example, this would happen if tUnit isdayand tSize is anything other than1. This may be fine for many applications, but sometimes it is desirable for the first block of every year to start at midnight on January 1. To enable that, set tSemiRegularity toannual.When tSemiRegularity is
annual, the final block of each year will be prevented from extending into January 1. Once the maximum number of whole blocks are fitted into the year, the remaining fraction of time until midnight January 1 of the next year is calculated. If it is less than half a block long, then the final whole block is expanded to include the remaining fraction. But if it is half or more of a block long, the remaining fraction is added to the year as an additional, shorter-than-usual block.For example, if tSize is
8, tUnit isday, and tSemiRegularity isannual, then the first block of every year will always start on midnight January 1. There will always be 46 blocks per year. The 46th block of every year will always start midnight December 27 on non leap years, and midnight December 26 on leap years. In either case, the 46th block will stop at midnight January 1 of the following year, spanning 5 days on non leap years and 6 days on leap years.Allowed values꞉
'annual'. Case sensitive.
- Returns:
BlockStatisticGridinstance.- Return type:
Properties
- property CenterCoords
(
object) Coordinates of the grid cell centers, indexed using the 1-character dimension of interest and optionally arangeto retrieve anumpy.ndarrayof coordinates (e.g.CenterCoords['x', 0:4]) or an integer to retrieve afloatfor a single coordinate (e.g.CenterCoords['x', 10]). Coordinates for thetdimension are returned asdatetimeinstances. Read only.
- property CoordDependencies
(
tupleofstr) Same length asDimensions. Dimensions that each dimension depends on for determining its coordinates.Nonefor dimensions that have a constant coordinate increment. Read only.
- property CoordIncrements
(
tupleoffloat) Same length asDimensions. Coordinate increment for each dimension.Nonefor 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,Datacan be assigned to write values to the grid, e.g.grid.Data[0,1] = 5orgrid.Data[:,:] = numpy.zeros(grid.Shape). Returns and acceptsnumpy.ndarray,float, andint. Read only.
- property DataIsScaled
(
bool) If True, the underlying raw data are stored as theUnscaledDataTypeto save storage space and then transformed by a scaling equation on the fly when they are returned byData. The raw data can be accessed withUnscaledData. If False, the raw data are returned as is, with no transformation needed, andUnscaledDataTypeandDataTypeare the same, andUnscaledDatareturns the same values asData. 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 byDatahave 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 arangeto retrieve anumpy.ndarrayof coordinates (e.g.MaxCoords['x', 0:4]) or an integer to retrieve afloatfor a single coordinate (e.g.MaxCoords['x', 10]). Coordinates for thetdimension are returned asdatetimeinstances. 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 arangeto retrieve anumpy.ndarrayof coordinates (e.g.MinCoords['x', 0:4]) or an integer to retrieve afloatfor a single coordinate (e.g.MinCoords['x', 10]). Coordinates for thetdimension are returned asdatetimeinstances. Read only.
- property NoDataValue
(
objectorNone)int,float, or single-element numpy array giving the value that indicates that cells ofDatashould be interpreted as having no data (these are also known as missing, NA, or NULL cells), orNoneif all cells must have data. Read only.
- property ParentCollection
(
DatasetCollectionorNone) ParentDatasetCollectionthat this object is part of (if any). Read only.
- property Shape
(
tupleofint) Same length asDimensions. Length (number of grid cells) of each dimension. Read only.
- property TCountPerSemiRegularPeriod
(
intorNone) Number of time slices per semi-regular period (i.e. per year).Noneif the grid’s dimensions do not contain atcoordinate or thetcoordinate is not semi-regular. Read only.
- property TIncrementUnit
(
strorNone) Unit of thetcoordinate.Noneif the grid’s dimensions do not contain atcoordinate. Read only. Allowed values꞉'year','month','day','hour','minute','second'. Case sensitive.
- property TSemiRegularity
(
strorNone) Type of semi-regularity used for thetcoordinate.Noneif the grid’s dimensions do not contain atcoordinate or thetcoordinate 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.UnscaledDatais 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,UnscaledDatacan be assigned to write values to the grid, e.g.grid.UnscaledData[0,1] = 5orgrid.UnscaledData[:,:] = numpy.zeros(grid.Shape). Returns and acceptsnumpy.ndarray,float, andint. 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 byUnscaledDatahave this type. If no transformation is needed (DataIsScaledis False), thenUnscaledDataTypeandScaledDataTypeare the same, andUnscaledDatareturns the same values asData. Read only. Allowed values꞉'int8','uint8','int16','uint16','int32','uint32','float32','float64'. Case sensitive.
- property UnscaledNoDataValue
(
objectorNone)intorfloatvalue that indicates that cells ofUnscaledDatashould be interpreted as having no data (these are also known as missing, NA, or NULL cells), orNoneif all cells must have data. Read only.
Methods
Closes any open files or connections associated with this object and releases any other resources allocated to access it.
Converts a spatial reference from one format to another, such as an OGC WKT string to a Proj4 string.
Deletes the lazy property with the specified name.
Returns a list of all queryable attributes.
Given a
tupleorlistof coordinates, returns alistofintindices intoDatafor the cell that contains the coordinates.Returns the value of the lazy property with the specified name.
Returns the queryable attribute with the specified name.
Returns the value of the queryable attribute with the specified name.
Returns a list queryable attributes having the specified data type.
Returns the spatial reference of this dataset.
Returns True if the specified lazy property has a value.
Sets the lazy property with the specified name to the specified value.
Sets the spatial reference of this dataset.
Tests whether a capability is supported by this class or an instance of it.