forestatrisk.misc package¶
forestatrisk.misc.countpix module¶
- countpix(input_raster, value=1, blk_rows=0)[source]¶
Count the number of pixels having a specific value.
Count the number of pixels (and the corresponding area in ha) having a specific value.
- Parameters:
input_raster – Input raster file.
value – Target value.
blk_rows – if > 0, number of lines per block.
- Returns:
A dictionary with the number of pixels having the specified value (npix) and the total area (area, in ha).
forestatrisk.misc.miscellaneous module¶
- invlogit(x)[source]¶
Compute the inverse-logit of a numpy array.
We differenciate the positive and negative values to avoid under/overflow with the use of exp().
- Parameters:
x – Numpy array.
- Returns:
Return the inverse-logit of the array.
- make_dir(newdir)[source]¶
Make new directory
Already exists, silently complete
Regular file in the way, raise an exception
Parent directory(ies) does not exist, make them as well
- Parameters:
newdir – Directory path to create.
- make_square(rasterfile, square_size=33)[source]¶
Compute square information.
This function computes block information from the caracteristics of a raster file and an indication on the number of rows to consider.
- Parameters:
rasterfile – Path to a raster file.
square_size – Pixel number to define square side size.
- Returns:
A tuple of length 6 including square number, square number on x axis, square number on y axis, square offsets on x axis, square offsets on y axis, square sizes on x axis, square sizes on y axis.
- makeblock(rasterfile, blk_rows=128)[source]¶
Compute block information.
This function computes block information from the caracteristics of a raster file and an indication on the number of rows to consider.
- Parameters:
rasterfile – Path to a raster file.
blk_rows – If > 0, number of rows for block. If <=0, the block size will be 256 x 256.
- Returns:
A tuple of length 6 including block number, block number on x axis, block number on y axis, block offsets on x axis, block offsets on y axis, block sizes on x axis, block sizes on y axis.
- progress_bar(niter, i)[source]¶
Draw progress_bar
- Parameters:
niter – Total number of iterations.
i – Current number of iteration (starts at 1).
- rescale(value)[source]¶
Rescale probability values to 1-65535.
This function rescales probability values (float in [0, 1]) to integer values in [1, 65535]. Raster data can then be of type UInt16 with 0 as nodata value.
- Parameters:
value – Numpy array of float values in [0, 1].
- Returns:
Rescaled numpy array of integer values in [1, 65535].