|
sgsPy
structurally guided sampling
|
Functions | |
| template<typename T> | |
| void | sgs::dist::findMinMax (helper::RasterBandMetaData &band, int width, int height, T &min, T &max) |
| template<typename T> | |
| void | sgs::dist::setBins (T min, T max, int nBins, GDALDataType type, std::vector< double > &dbins, std::vector< T > &tbins) |
| template<typename T> | |
| void | sgs::dist::populationDistribution (helper::RasterBandMetaData &band, int width, int height, int nBins, std::vector< T > &binVals, std::vector< int64_t > &counts) |
| template<typename T> | |
| std::vector< int64_t > | sgs::dist::sampleDistribution (helper::RasterBandMetaData &band, std::vector< helper::Index > &samples, std::vector< T > binVals, int nBins) |
| template<typename T> | |
| void | sgs::dist::calculateDist (helper::RasterBandMetaData &band, std::vector< helper::Index > &sampled, int height, int width, int nBins, std::unordered_map< std::string, std::pair< std::vector< double >, std::vector< int64_t > > > &retval) |
| std::unordered_map< std::string, std::pair< std::vector< double >, std::vector< int64_t > > > | sgs::dist::dist (raster::GDALRasterWrapper *p_raster, int index, vector::GDALVectorWrapper *p_vector, std::string layer, int nBins) |
| void sgs::dist::calculateDist | ( | helper::RasterBandMetaData & | band, |
| std::vector< helper::Index > & | sampled, | ||
| int | height, | ||
| int | width, | ||
| int | nBins, | ||
| std::unordered_map< std::string, std::pair< std::vector< double >, std::vector< int64_t > > > & | retval ) |
This is the function which does most of calculations for the distribution calculation. First the findMinMax() function is called to find the minimum and maximum pixel values within the raster. Then the setBins() function is called to set the bin values depending on the minumum and maximum values within the raster. Next, the populationDistribution() function is ran to determine the population distribution within the calculated raster bins. Finally, if the user provided a sample layer to compare against, the sampleDistribution() function is called to determine the distribution within that particular sample.
Both the findMinMax() and populationDistribution() function are called multiple times, each with a different chunk (where the chunk count and chunk size is determined by the number of threads).
| RasterBandMetaData& | band |
| std::vector<Index>& | sampled |
| int | height |
| int | width |
| int | nBins |
| std::unordered_map<std::string,std::pair<std::vector<double>,std::vector<int64_t>>>& | retval |
| std::unordered_map< std::string, std::pair< std::vector< double >, std::vector< int64_t > > > sgs::dist::dist | ( | raster::GDALRasterWrapper * | p_raster, |
| int | index, | ||
| vector::GDALVectorWrapper * | p_vector, | ||
| std::string | layer, | ||
| int | nBins ) |
This function calculates the distribution of a particular raster band, and potentially the distribution of a provided sample network of the same raster band.
First, if there is a sample network provided, all of the points are iterated through and converted to x/y index values usign the inverse geotransform (GDALInvGeoTransform()).
After that, band metadata is acquired, and the calculateDistribution() function is called with a template parameter depending on the raster type. After which, the return variable (which was populated in calculateDistribution()) is returned. This variable is a map where the key is either 'population' or 'sample' to specify whether the distribution of the population or a sample distribution. The pair of vectors represent the bins and counts per bin.
| GDALRasterWrapper | *p_raster |
| int | index |
| GDALVectorWrapper | *p_vector |
| std::string | layer |
| int | nBins |
| void sgs::dist::findMinMax | ( | helper::RasterBandMetaData & | band, |
| int | width, | ||
| int | height, | ||
| T & | min, | ||
| T & | max ) |
This is a helper function for finding the minimum and maximum values within a given raster band.
The min and max variables are passed as references, and the min value is initialized to the largest value the data type can have, and the max value is initialized to the smallest value the data type can have.
| RasterBandMetaData& | band |
| int | width |
| int | height |
| T& | min |
| T& | max |
| void sgs::dist::populationDistribution | ( | helper::RasterBandMetaData & | band, |
| int | width, | ||
| int | height, | ||
| int | nBins, | ||
| std::vector< T > & | binVals, | ||
| std::vector< int64_t > & | counts ) |
This function calculates the distribution of pixels across the entire population (the whole raster band).
The chunk of the raster assigned to this call of the function is iterated through in blocks. All of the pixels in each block are then iterated through, the nan values are ignored.
The bin values are passed as a parameter, and the value in the vector represents the start of a particular bin. This means that the first index in the bins vector which is less than or equal to a particular pixel, is that pixles bin. For each pixel, the iteration starts at the largest bin and iterates down until it reaches a bin value less than or equal to a particular pixel.
| RasterBandMetaData& | band |
| int | width |
| int | height |
| int | nBins |
| std::vector<T>& | binVals |
| std::vector<int64_t>& | counts |
| std::vector< int64_t > sgs::dist::sampleDistribution | ( | helper::RasterBandMetaData & | band, |
| std::vector< helper::Index > & | samples, | ||
| std::vector< T > | binVals, | ||
| int | nBins ) |
This function calculates the probability distribution of a sample network, if a vector layer of samples was provided. It takes the same bin values as the population, and iterates through each sample index. The sample index is read from the raster band using the GDALRasterBand::RasterIO function. The bins counts are updated accordingly.
| RasterBandMetaData& | band |
| std::vector<Index>* | samples |
| std::vector<T> | binVals |
| int | nBins |
| void sgs::dist::setBins | ( | T | min, |
| T | max, | ||
| int | nBins, | ||
| GDALDataType | type, | ||
| std::vector< double > & | dbins, | ||
| std::vector< T > & | tbins ) |
This function calculates the bin values for the distribution.
It takes miniumum and maximum values as parameters. A vector of double values is created to represent the bins, in addition to a vector of the data type of the raster pixels. The vector of doubles is the one returned to the user, the vector of the raster pixel type is used to calculate which bin a particular pixel goes into while iterating through the raster.
The reason why there is an additional vector with the rasters data type is that it will reduce the potentialy overhead of requiring the program to cast the pixel type to double to calculate the bin for every pixel. However, it also means that for integer values a simple static cast will not work, because it will always truncate the value. If the actual bin stops at 10.1, but the vin says 10 instead of 11, then pixels with value 10 will be placed into the wrong bin. The bin value represents the START value of the bin. The final parameter of the double bin is the 'cap' and represents the end of the last bini, as is customary. The raster pixel type bin vector does not have this cap value, as it is not necessary.
| T | min |
| T | max |
| int | nBins |
| GDALDataType | type |
| std::vector<double>& | bins |
| std::vector<T>& | bins |