nextgis / qgis_molusce

Modules for Land Use Change Simulations
https://github.com/nextgis/molusce
GNU General Public License v2.0
43 stars 15 forks source link

Infinit loop in stratified sampling #28

Open KolesovDmitry opened 6 years ago

KolesovDmitry commented 6 years ago

Stratified sampling uses the next procedure:

For every transition classes repeat:
 1.  sample random pixel from input-output-factor rasters; get the neighbours of the pixel;
 2. check if all neighbors and inpit/output pixels are not Null.
 3. if all neighbor pixels are not Null, create input sample and add it to sample table
 4. repeat 1-3 until desired number of samples is not created.

(see https://github.com/nextgis/molusce/blob/master/algorithms/models/sampler/sampler.py#L326-L334)

So if a pixel of the transition class is located near raster boundaries, then at least one neighbor of the selected pixel lies outside => the pixel can't be used in sample => the pixel is skipped.

The problem appears when ALL pixels of a transition class lie near boundaries. In this case we get infinite loop.