| 1 |
MODULE |
| 2 |
Joint image processing library, developed for the JEODPP infrastructure, European Commission JRC - Ispra |
| 3 |
Developed by: |
| 4 |
Pieter Kempeneers: [email protected] |
| 5 |
Pierre Soille: [email protected] |
| 6 |
END |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
########################################################################################################################################################################### |
| 11 |
# JIPLIB GLOBAL FUNCTIONS |
| 12 |
########################################################################################################################################################################### |
| 13 |
|
| 14 |
FUNC createJim() |
| 15 |
Creates an empty Jim object as an instance of the basis image class of the Joint image processing library. |
| 16 |
|
| 17 |
Returns: |
| 18 |
This instance of Jim object (self) |
| 19 |
|
| 20 |
END |
| 21 |
|
| 22 |
FUNC createJim(**kwargs) |
| 23 |
Creates a Jim object as an instance of the basis image class of the Joint image processing library, using keyword arguments |
| 24 |
|
| 25 |
.. |
| 26 |
Args: |
| 27 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 28 |
|
| 29 |
Supported keys as arguments: |
| 30 |
|
| 31 |
======== =================================================== |
| 32 |
filename input filename to read from (GDAL supported format) |
| 33 |
nodata Nodata value to put in image |
| 34 |
band Bands to open, index starts from 0 |
| 35 |
ulx Upper left x value bounding box |
| 36 |
uly Upper left y value bounding box |
| 37 |
lrx Lower right x value bounding box |
| 38 |
lry Lower right y value bounding box |
| 39 |
dx Resolution in x |
| 40 |
dy Resolution in y |
| 41 |
resample Resample algorithm used for reading pixel data in case of interpolation (default: GRIORA_NearestNeighbour). Check http://www.gdal.org/gdal_8h.html#a640ada511cbddeefac67c548e009d5a for available options. |
| 42 |
extent get boundary from extent from polygons in vector dataset |
| 43 |
noread Set this flag to True to not read data when opening |
| 44 |
======== =================================================== |
| 45 |
|
| 46 |
.. note:: |
| 47 |
You can specify a different spatial reference system to define the region of interest to read set with keys ulx, uly, lrx, and lry with the extra key 't_srs'. Notice this will not re-project the resulting image. You can use the function :py:func:Jim:`warp` for this. |
| 48 |
.. |
| 49 |
resample: (default: GRIORA_NearestNeighbour) Resample algorithm used for reading pixel data in case of interpolation GRIORA_NearestNeighbour | GRIORA_Bilinear | GRIORA_Cubic | GRIORA_CubicSpline | GRIORA_Lanczos | GRIORA_Average | GRIORA_Average | GRIORA_Gauss (check http://www.gdal.org/gdal_8h.html#a640ada511cbddeefac67c548e009d5a) |
| 50 |
|
| 51 |
Supported keys when creating new Jim image object not read from file: |
| 52 |
===== ================= |
| 53 |
ncol Number of columns |
| 54 |
nrow Number of rows |
| 55 |
nband (default: 1) Number of bands |
| 56 |
otype (default: Byte) Data type ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}) |
| 57 |
a_srs Assign the spatial reference for the output file, e.g., psg:3035 to use European projection and force to European grid |
| 58 |
===== ================= |
| 59 |
|
| 60 |
Supported keys used to initialize random pixel values in new Jim image object: |
| 61 |
======= ============================================ |
| 62 |
seed (default: 0) seed value for random generator |
| 63 |
mean (default: 0) Mean value for random generator |
| 64 |
stdev (default: 0) Standard deviation for Gaussian random generator |
| 65 |
uniform (default: 0) Start and end values for random value with uniform distribution |
| 66 |
======= ============================================ |
| 67 |
|
| 68 |
Returns: |
| 69 |
This instance of Jim object (self) |
| 70 |
|
| 71 |
Example: |
| 72 |
|
| 73 |
Create Jim image object by opening an existing file (file content will automatically be read in memory):: |
| 74 |
|
| 75 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 76 |
jim=jl.createJim('filename'=ifn) |
| 77 |
#do stuff with jim ... |
| 78 |
jim.close() |
| 79 |
|
| 80 |
The key 'filename' is optional:: |
| 81 |
|
| 82 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 83 |
jim=jl.createJim(ifn) |
| 84 |
#do stuff with jim ... |
| 85 |
jim.close() |
| 86 |
|
| 87 |
Create Jim image object by opening an existing file for specific region of interest and spatial resolution using cubic convolution resampling:: |
| 88 |
|
| 89 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 90 |
jim0=jl.createJim(filename=ifn,'noread'=True) |
| 91 |
ULX=jim0.getUlx() |
| 92 |
ULY=jim0.getUly() |
| 93 |
LRX=jim0.getUlx()+100*jim0.getDeltaX() |
| 94 |
LRY=jim0.getUly()-100*jim0.getDeltaY() |
| 95 |
jim=jl.Jim.createImg(filename=ifn,ulx:ULX,'uly':ULY,'lrx':LRX,'lry':LRY,'dx':5,'dy':5,'resample':'GRIORA_Cubic'}) |
| 96 |
#do stuff with jim ... |
| 97 |
jim.close() |
| 98 |
|
| 99 |
Create a new georeferenced Jim image object by defining the projection epsg code, bounding box, and pixel size:: |
| 100 |
|
| 101 |
projection='epsg:32612' |
| 102 |
ULX=600000.0 |
| 103 |
ULY=4000020.0 |
| 104 |
LRX=709800.0 |
| 105 |
LRY=3890220.0 |
| 106 |
dict={'ulx':ULX,'uly':ULY,'lrx':LRX,'lry':LRY,'a_srs':projection} |
| 107 |
dict.update({'otype':'GDT_UInt16'}) |
| 108 |
dict.update({'dy':100,'dx':100}) |
| 109 |
jim=jl.Jim.createImg(dict) |
| 110 |
#do stuff with jim ... |
| 111 |
jim.close() |
| 112 |
|
| 113 |
Create a new georeferenced Jim image object for writing by defining the projection epsg code, bounding box and number of rows and columns:: |
| 114 |
|
| 115 |
projection='epsg:32612' |
| 116 |
ULX=600000.0 |
| 117 |
ULY=4000020.0 |
| 118 |
LRX=709800.0 |
| 119 |
LRY=3890220.0 |
| 120 |
dict={'ulx':ULX,'uly':ULY,'lrx':LRX,'lry':LRY,'a_srs':projection} |
| 121 |
dict.update({'otype':'GDT_UInt16'}) |
| 122 |
nrow=1098 |
| 123 |
ncol=1098 |
| 124 |
dict.update({'nrow':nrow,'ncol':ncol}) |
| 125 |
jim=jl.Jim.createImg(dict) |
| 126 |
#do stuff with jim ... |
| 127 |
jim.close() |
| 128 |
|
| 129 |
END |
| 130 |
|
| 131 |
FUNC createJim(*args) |
| 132 |
Creates an empty Jim object as an instance of the basis image class of the Joint image processing library. |
| 133 |
|
| 134 |
Args: |
| 135 |
* ``Jim``: A reference Jim object |
| 136 |
* ``copyData`` (bool): Set to False if reference image is used as a template only, without copying actual pixel dat |
| 137 |
|
| 138 |
Returns: |
| 139 |
This instance of Jim object (self) |
| 140 |
|
| 141 |
END |
| 142 |
|
| 143 |
FUNC createJimList() |
| 144 |
Creates an empty JimList object. |
| 145 |
|
| 146 |
Returns: |
| 147 |
This instance of Jim object (self) |
| 148 |
|
| 149 |
END |
| 150 |
|
| 151 |
FUNC createVector() |
| 152 |
Creates an empty VectorOgr object as an instance of the basis vector class of the Joint image processing library. |
| 153 |
|
| 154 |
Returns: |
| 155 |
This instance of VectorOgr object (self) |
| 156 |
|
| 157 |
END |
| 158 |
|
| 159 |
########## |
| 160 |
#Jim class |
| 161 |
########## |
| 162 |
|
| 163 |
CLASS Jim |
| 164 |
Jim class is the basis image class of the Joint image processing library. |
| 165 |
|
| 166 |
Notes: |
| 167 |
|
| 168 |
The calls to Jim methods can be chained together using the dot (.) syntax returning a new Jim instance:: |
| 169 |
|
| 170 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 171 |
jim0=createJim() |
| 172 |
ULX=600000.0 |
| 173 |
ULY=4000020.0 |
| 174 |
LRX=709800.0 |
| 175 |
LRY=3890220.0 |
| 176 |
jim = jim0.open({'filename':ifn}).crop({'ulx':ULX,'uly':ULY,'lrx':LRX,'lry':LRY}) |
| 177 |
jim0.close() |
| 178 |
#do stuff with jim ... |
| 179 |
jim.close() |
| 180 |
|
| 181 |
END |
| 182 |
|
| 183 |
METHOD nrOfCol() |
| 184 |
Get number of columns in this raster dataset |
| 185 |
|
| 186 |
Returns: |
| 187 |
The number of columns in this raster dataset |
| 188 |
|
| 189 |
END |
| 190 |
|
| 191 |
METHOD nrOfRow() |
| 192 |
Get number of rows in this raster dataset |
| 193 |
|
| 194 |
Returns: |
| 195 |
The number of rows in this raster dataset |
| 196 |
|
| 197 |
END |
| 198 |
|
| 199 |
METHOD nrOfBand() |
| 200 |
Get number of bands in this raster dataset |
| 201 |
|
| 202 |
Returns: |
| 203 |
The number of bands in this raster dataset |
| 204 |
|
| 205 |
END |
| 206 |
|
| 207 |
METHOD nrOfPlane() |
| 208 |
Get number of planes in this raster dataset |
| 209 |
|
| 210 |
Returns: |
| 211 |
The number of planes in this raster dataset |
| 212 |
|
| 213 |
END |
| 214 |
|
| 215 |
METHOD printNoDataValues() |
| 216 |
Print the list of no data values of this raster dataset |
| 217 |
|
| 218 |
Returns: |
| 219 |
This instance of Jim object (self) |
| 220 |
|
| 221 |
END |
| 222 |
|
| 223 |
METHOD pushNoDataValue() |
| 224 |
Push a no data value for this raster dataset |
| 225 |
|
| 226 |
Returns: |
| 227 |
This instance of Jim object (self) |
| 228 |
|
| 229 |
END |
| 230 |
|
| 231 |
METHOD setNoDataValue() |
| 232 |
Set a single no data value for this raster dataset |
| 233 |
|
| 234 |
Returns: |
| 235 |
This instance of Jim object (self) |
| 236 |
|
| 237 |
END |
| 238 |
|
| 239 |
METHOD setNoData(list) |
| 240 |
Set a list of no data values for this raster dataset |
| 241 |
|
| 242 |
Returns: |
| 243 |
This instance of Jim object (self) |
| 244 |
|
| 245 |
END |
| 246 |
|
| 247 |
METHOD clearNoData() |
| 248 |
Clear the list of no data values for this raster dataset |
| 249 |
|
| 250 |
Returns: |
| 251 |
This instance of Jim object (self) |
| 252 |
|
| 253 |
END |
| 254 |
|
| 255 |
METHOD getDataType() |
| 256 |
Get the internal datatype for this raster dataset |
| 257 |
|
| 258 |
Returns: |
| 259 |
The datatype id of this Jim object |
| 260 |
|
| 261 |
========= == |
| 262 |
datatype id |
| 263 |
========= == |
| 264 |
Unknown 0 |
| 265 |
Byte 1 |
| 266 |
UInt16 2 |
| 267 |
Int16 3 |
| 268 |
UInt32 4 |
| 269 |
Int32 5 |
| 270 |
Float32 6 |
| 271 |
Float64 7 |
| 272 |
CInt16 8 |
| 273 |
CInt32 9 |
| 274 |
CFloat32 10 |
| 275 |
CFloat64 11 |
| 276 |
========= == |
| 277 |
|
| 278 |
END |
| 279 |
|
| 280 |
METHOD covers(*args) |
| 281 |
Check if a geolocation is covered by this dataset. Only the coordinates of the point (variant 1) or region of interest (variant 2) are checked, irrespective of no data values. Set the additional flag to True if the region of interest must be entirely covered. |
| 282 |
|
| 283 |
Args (variant 1): |
| 284 |
|
| 285 |
* ``x`` (float): x coordinate in spatial reference system of the raster dataset |
| 286 |
* ``y`` (float): y coordinate in spatial reference system of the raster dataset |
| 287 |
|
| 288 |
|
| 289 |
Args (variant 2): |
| 290 |
|
| 291 |
* ``ulx`` (float): upper left x coordinate in spatial reference system of the raster dataset |
| 292 |
* ``uly`` (float): upper left y coordinate in spatial reference system of the raster dataset |
| 293 |
* ``lrx`` (float): lower right x coordinate in spatial reference system of the raster dataset |
| 294 |
* ``lry`` (float): lower right x coordinate in spatial reference system of the raster dataset |
| 295 |
* ``all`` (bool): set to True if the entire bounding box must be covered by the raster dataset |
| 296 |
|
| 297 |
|
| 298 |
Returns: |
| 299 |
True if the raster dataset covers the point or region of interest. |
| 300 |
|
| 301 |
END |
| 302 |
|
| 303 |
METHOD getGeoTransform() |
| 304 |
Get the geotransform data for this dataset as a list of floats. |
| 305 |
|
| 306 |
Returns: |
| 307 |
List of floats with geotransform data: |
| 308 |
* [0] top left x |
| 309 |
* [1] w-e pixel resolution |
| 310 |
* [2] rotation, 0 if image is "north up" |
| 311 |
* [3] top left y |
| 312 |
* [4] rotation, 0 if image is "north up" |
| 313 |
* [5] n-s pixel resolution |
| 314 |
|
| 315 |
END |
| 316 |
|
| 317 |
METHOD setGeoTransform() |
| 318 |
Set the geotransform data for this dataset. |
| 319 |
|
| 320 |
Args: |
| 321 |
List of floats with geotransform data: |
| 322 |
* [0] top left x |
| 323 |
* [1] w-e pixel resolution |
| 324 |
* [2] rotation, 0 if image is "north up" |
| 325 |
* [3] top left y |
| 326 |
* [4] rotation, 0 if image is "north up" |
| 327 |
* [5] n-s pixel resolution |
| 328 |
|
| 329 |
Returns: |
| 330 |
This instance of Jim object (self) |
| 331 |
|
| 332 |
END |
| 333 |
|
| 334 |
METHOD copyGeoTransform(*args) |
| 335 |
Copy geotransform information from another georeferenced image. |
| 336 |
|
| 337 |
Args: |
| 338 |
* A referenced Jim image |
| 339 |
|
| 340 |
Returns: |
| 341 |
This instance of Jim object (self) |
| 342 |
|
| 343 |
END |
| 344 |
|
| 345 |
METHOD getProjection() |
| 346 |
Get the projection for this dataget in well known text (wkt) format. |
| 347 |
|
| 348 |
|
| 349 |
Returns: |
| 350 |
The projection string in well known text format. |
| 351 |
|
| 352 |
END |
| 353 |
|
| 354 |
METHOD setProjection(*args) |
| 355 |
Set the projection for this dataset in well known text (wkt) format. |
| 356 |
|
| 357 |
Args: |
| 358 |
* The projection string in well known text format (typically an EPSG code, e.g., 'epsg:3035') |
| 359 |
|
| 360 |
Returns: |
| 361 |
This instance of Jim object (self) |
| 362 |
|
| 363 |
END |
| 364 |
|
| 365 |
METHOD getBoundingBox() |
| 366 |
Get the bounding box of this dataset in georeferenced coordinates. |
| 367 |
|
| 368 |
Returns: |
| 369 |
A list with the bounding box of this dataset in georeferenced coordinates. |
| 370 |
|
| 371 |
END |
| 372 |
|
| 373 |
METHOD getCenterPos() |
| 374 |
Get the center position of this dataset in georeferenced coordinates |
| 375 |
|
| 376 |
Returns: |
| 377 |
A list with the center position of this dataset in georeferenced coordinates. |
| 378 |
|
| 379 |
END |
| 380 |
|
| 381 |
METHOD getUlx() |
| 382 |
Get the upper left corner x (georeferenced) coordinate of this dataset |
| 383 |
|
| 384 |
Returns: |
| 385 |
The upper left corner x (georeferenced) coordinate of this dataset |
| 386 |
|
| 387 |
END |
| 388 |
|
| 389 |
METHOD getUly() |
| 390 |
Get the upper left corner y (georeferenced) coordinate of this dataset |
| 391 |
|
| 392 |
Returns: |
| 393 |
The upper left corner y (georeferenced) coordinate of this dataset |
| 394 |
|
| 395 |
END |
| 396 |
|
| 397 |
METHOD getLrx() |
| 398 |
Get the lower left corner x (georeferenced) coordinate of this dataset |
| 399 |
|
| 400 |
Returns: |
| 401 |
The lower left corner x (georeferenced) coordinate of this dataset |
| 402 |
|
| 403 |
END |
| 404 |
|
| 405 |
METHOD getLry() |
| 406 |
Get the lower left corner y (georeferenced) coordinate of this dataset |
| 407 |
|
| 408 |
Returns: |
| 409 |
The lower left corner y (georeferenced) coordinate of this dataset |
| 410 |
|
| 411 |
END |
| 412 |
|
| 413 |
METHOD getDeltaX() |
| 414 |
Get the pixel cell spacing in x. |
| 415 |
|
| 416 |
Returns: |
| 417 |
The pixel cell spacing in x. |
| 418 |
|
| 419 |
END |
| 420 |
|
| 421 |
METHOD getDeltaY() |
| 422 |
Get the piyel cell spacing in y. |
| 423 |
|
| 424 |
Returns: |
| 425 |
The piyel cell spacing in y. |
| 426 |
|
| 427 |
END |
| 428 |
|
| 429 |
|
| 430 |
METHOD getRefPix() |
| 431 |
Calculate the reference pixel as the center of gravity pixel (weighted average of all values not taking into account no data values) for a specific band (start counting from 0). |
| 432 |
|
| 433 |
Returns: |
| 434 |
The reference pixel as the centre of gravity pixel (weighted average of all values not taking into account no data values) for a specific band (start counting from 0). |
| 435 |
|
| 436 |
END |
| 437 |
|
| 438 |
METHOD open(dict) |
| 439 |
Open a raster dataset |
| 440 |
|
| 441 |
Args: |
| 442 |
|
| 443 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 444 |
|
| 445 |
Supported keys in the dict: |
| 446 |
|
| 447 |
======== =================================================== |
| 448 |
filename input filename to read from (GDAL supported format) |
| 449 |
nodata Nodata value to put in image |
| 450 |
band Bands to open, index starts from 0 |
| 451 |
ulx Upper left x value bounding box |
| 452 |
uly Upper left y value bounding box |
| 453 |
lrx Lower right x value bounding box |
| 454 |
lry Lower right y value bounding box |
| 455 |
dx Resolution in x |
| 456 |
dy Resolution in y |
| 457 |
resample Resample algorithm used for reading pixel data in case of interpolation (default: GRIORA_NearestNeighbour). Check http://www.gdal.org/gdal_8h.html#a640ada511cbddeefac67c548e009d5a for available options. |
| 458 |
extent get boundary from extent from polygons in vector dataset |
| 459 |
noread Set this flag to True to not read data when opening |
| 460 |
======== =================================================== |
| 461 |
|
| 462 |
.. |
| 463 |
resample: (default: GRIORA_NearestNeighbour) Resample algorithm used for reading pixel data in case of interpolation GRIORA_NearestNeighbour | GRIORA_Bilinear | GRIORA_Cubic | GRIORA_CubicSpline | GRIORA_Lanczos | GRIORA_Average | GRIORA_Average | GRIORA_Gauss (check http://www.gdal.org/gdal_8h.html#a640ada511cbddeefac67c548e009d5a) |
| 464 |
|
| 465 |
Supported keys when creating new Jim image object not read from file: |
| 466 |
|
| 467 |
===== ================= |
| 468 |
ncol Number of columns |
| 469 |
nrow Number of rows |
| 470 |
nband (default: 1) Number of bands |
| 471 |
otype (default: Byte) Data type ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}) |
| 472 |
a_srs Assign the spatial reference for the output file, e.g., psg:3035 to use European projection and force to European grid |
| 473 |
===== ================= |
| 474 |
|
| 475 |
Supported keys used to initialize random pixel values in new Jim image object: |
| 476 |
|
| 477 |
======= ============================================ |
| 478 |
seed (default: 0) seed value for random generator |
| 479 |
mean (default: 0) Mean value for random generator |
| 480 |
stdev (default: 0) Standard deviation for Gaussian random generator |
| 481 |
uniform (default: 0) Start and end values for random value with uniform distribution |
| 482 |
======= ============================================ |
| 483 |
|
| 484 |
Returns: |
| 485 |
This instance of Jim object (self) |
| 486 |
|
| 487 |
Example: |
| 488 |
|
| 489 |
See also :py:func:`createJim` |
| 490 |
|
| 491 |
END |
| 492 |
|
| 493 |
METHOD close() |
| 494 |
Close a raster dataset, releasing resources such as memory and GDAL dataset handle. |
| 495 |
|
| 496 |
END |
| 497 |
|
| 498 |
|
| 499 |
METHOD write(dict) |
| 500 |
Write the raster dataset to file in a GDAL supported format |
| 501 |
|
| 502 |
Args: |
| 503 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 504 |
|
| 505 |
Supported keys in the dict: |
| 506 |
|
| 507 |
======== =================================================== |
| 508 |
filename output filename to write to: |
| 509 |
oformat (default: GTiff) Output image (GDAL supported) format |
| 510 |
co Creation option for output file. Multiple options can be specified as a list |
| 511 |
nodata Nodata value to put in image |
| 512 |
======== =================================================== |
| 513 |
|
| 514 |
Returns: |
| 515 |
This instance of Jim object (self) |
| 516 |
|
| 517 |
.. note:: |
| 518 |
Supported GDAL output formats are restricted to those that support creation (see http://www.gdal.org/formats_list.html#footnote1) |
| 519 |
The image data is kept in memory (unlike using method :py:func:`Jim:close`) |
| 520 |
|
| 521 |
Example: |
| 522 |
|
| 523 |
Create Jim image object by opening an existing file in jp2 format. Then write to a compressed and tiled file in the default GeoTIFF format:: |
| 524 |
|
| 525 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 526 |
jim=jl.createJim({'filename':ifn}) |
| 527 |
jim.write({'filename':'/tmp/test.tif','co':['COMPRESS=LZW','TILED=YES']}) |
| 528 |
jim.close() |
| 529 |
|
| 530 |
END |
| 531 |
|
| 532 |
METHOD dumpImg(dict) |
| 533 |
Dump the raster dataset to output (screen or ASCII file). |
| 534 |
|
| 535 |
Args: |
| 536 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 537 |
|
| 538 |
Supported keys in the dict: |
| 539 |
|
| 540 |
========= ============================================================= |
| 541 |
output Output ascii file (Default is empty: dump to standard output) |
| 542 |
oformat Output format: matrix or list (x,y,z) form. Default is matrix |
| 543 |
geo (bool) Set to True to dump x and y in spatial reference system of raster dataset (for list form only). Default is to dump column and row index (starting from 0) |
| 544 |
band Band index to crop |
| 545 |
srcnodata Do not dump these no data values (for list form only) |
| 546 |
force (bool) Set to True to force full dump even for large images (above 100 rows and cols) |
| 547 |
========= ============================================================= |
| 548 |
|
| 549 |
Returns: |
| 550 |
This instance of Jim object (self) |
| 551 |
|
| 552 |
|
| 553 |
Example: |
| 554 |
|
| 555 |
Open resampled raster dataset in reduced spatial resolution of 20 km by 20 km and dump to screen (first in matrix then in list format):: |
| 556 |
|
| 557 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 558 |
jim=jl.createJim({'filename':ifn, 'dx':20000,'dy':20000,'resample':'GRIORA_Bilinear'}) |
| 559 |
jim.dumpImg({'oformat':'matrix'}) |
| 560 |
|
| 561 |
2503 2794 3148 3194 3042 2892 |
| 562 |
2634 2792 2968 2864 2790 3171 |
| 563 |
2335 2653 2723 2700 2703 2836 |
| 564 |
2510 2814 3027 2946 2889 2814 |
| 565 |
2972 2958 3014 2983 2900 2899 |
| 566 |
2692 2711 2843 2755 2795 2823 |
| 567 |
|
| 568 |
jim.dumpImg({'oformat':'list'}) |
| 569 |
|
| 570 |
0 0 2503 |
| 571 |
1 0 2794 |
| 572 |
2 0 3148 |
| 573 |
3 0 3194 |
| 574 |
4 0 3042 |
| 575 |
5 0 2892 |
| 576 |
|
| 577 |
0 1 2634 |
| 578 |
1 1 2792 |
| 579 |
2 1 2968 |
| 580 |
3 1 2864 |
| 581 |
4 1 2790 |
| 582 |
5 1 3171 |
| 583 |
|
| 584 |
0 2 2335 |
| 585 |
1 2 2653 |
| 586 |
2 2 2723 |
| 587 |
3 2 2700 |
| 588 |
4 2 2703 |
| 589 |
5 2 2836 |
| 590 |
|
| 591 |
0 3 2510 |
| 592 |
1 3 2814 |
| 593 |
2 3 3027 |
| 594 |
3 3 2946 |
| 595 |
4 3 2889 |
| 596 |
5 3 2814 |
| 597 |
|
| 598 |
0 4 2972 |
| 599 |
1 4 2958 |
| 600 |
2 4 3014 |
| 601 |
3 4 2983 |
| 602 |
4 4 2900 |
| 603 |
5 4 2899 |
| 604 |
|
| 605 |
0 5 2692 |
| 606 |
1 5 2711 |
| 607 |
2 5 2843 |
| 608 |
3 5 2755 |
| 609 |
4 5 2795 |
| 610 |
5 5 2823 |
| 611 |
|
| 612 |
jim.close() |
| 613 |
|
| 614 |
END |
| 615 |
|
| 616 |
METHOD isEqual(*args) |
| 617 |
Test raster dataset for equality. |
| 618 |
|
| 619 |
Args: |
| 620 |
* ``Jim``: A reference Jim object |
| 621 |
|
| 622 |
Returns: |
| 623 |
True if raster dataset is equal to reference raster dataset, else False. |
| 624 |
|
| 625 |
END |
| 626 |
|
| 627 |
METHOD convert(dict) |
| 628 |
Convert Jim image with respect to data type, creation options (compression, interleave, etc.). |
| 629 |
|
| 630 |
Args: |
| 631 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 632 |
|
| 633 |
Supported keys in the dict: |
| 634 |
|
| 635 |
+------------------+---------------------------------------------------------------------------------+ |
| 636 |
| key | value | |
| 637 |
+==================+=================================================================================+ |
| 638 |
| otype | Data type for output image | |
| 639 |
+------------------+---------------------------------------------------------------------------------+ |
| 640 |
| scale | Scale output: output=scale*input+offset | |
| 641 |
+------------------+---------------------------------------------------------------------------------+ |
| 642 |
| offset | Apply offset: output=scale*input+offset | |
| 643 |
+------------------+---------------------------------------------------------------------------------+ |
| 644 |
| autoscale | Scale output to min and max, e.g., [0,255] | |
| 645 |
+------------------+---------------------------------------------------------------------------------+ |
| 646 |
| a_srs | Override the projection for the output file | |
| 647 |
+------------------+---------------------------------------------------------------------------------+ |
| 648 |
|
| 649 |
Returns: |
| 650 |
This converted Jim object |
| 651 |
|
| 652 |
Example: |
| 653 |
|
| 654 |
Convert data type of input image to byte, using autoscale and clipping respectively:: |
| 655 |
|
| 656 |
jim_scaled=jim.convert({'otype':'Byte','autoscale':[0,255]}) |
| 657 |
jim_clipped=jim.setThreshold({'min':0,'max':255,'nodata':0}).convert({'otype':'Byte'}) |
| 658 |
|
| 659 |
END |
| 660 |
|
| 661 |
METHOD crop(dict) |
| 662 |
Subset raster dataset according in spatial (subset region) or spectral/temporal domain (subset bands) |
| 663 |
|
| 664 |
Args: |
| 665 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 666 |
|
| 667 |
Returns: |
| 668 |
This subset of Jim object |
| 669 |
|
| 670 |
.. note:: |
| 671 |
Spatial subsetting only supports nearest neighbor interpolation. Use :py:func:`createJim` for more flexible interpolation options |
| 672 |
|
| 673 |
Supported keys in the dict: |
| 674 |
|
| 675 |
.. note:: |
| 676 |
In addition to the keys defined here, you can use all the keys defined in :py:func:`Jim:convert` |
| 677 |
|
| 678 |
**Subset spatial region in coordinates of the image geospatial reference system** |
| 679 |
|
| 680 |
+------------------+---------------------------------------------------------------------------------+ |
| 681 |
| key | value | |
| 682 |
+==================+=================================================================================+ |
| 683 |
| extent | Get boundary from extent from polygons in vector file | |
| 684 |
+------------------+---------------------------------------------------------------------------------+ |
| 685 |
| eo | Special extent options controlling rasterization | |
| 686 |
+------------------+---------------------------------------------------------------------------------+ |
| 687 |
| ln | Layer name of extent to crop | |
| 688 |
+------------------+---------------------------------------------------------------------------------+ |
| 689 |
| crop_to_cutline | True will crop the extent of the target dataset to the extent of the cutline | |
| 690 |
| | The outside area will be set to no data (the value defined by the key 'nodata') | |
| 691 |
+------------------+---------------------------------------------------------------------------------+ |
| 692 |
| crop_in_cutline | True: inverse operation to crop_to_cutline | |
| 693 |
| | The inside area will be set to no data (the value defined by the key 'nodata') | |
| 694 |
+------------------+---------------------------------------------------------------------------------+ |
| 695 |
| ulx | Upper left x value of bounding box to crop | |
| 696 |
+------------------+---------------------------------------------------------------------------------+ |
| 697 |
| uly | Upper left y value of bounding box to crop | |
| 698 |
+------------------+---------------------------------------------------------------------------------+ |
| 699 |
| lrx | Lower right x value of bounding box to crop | |
| 700 |
+------------------+---------------------------------------------------------------------------------+ |
| 701 |
| lry | Lower right y value of bounding box to crop | |
| 702 |
+------------------+---------------------------------------------------------------------------------+ |
| 703 |
| dx | Output resolution in x (default: keep original resolution) | |
| 704 |
+------------------+---------------------------------------------------------------------------------+ |
| 705 |
| dy | Output resolution in y (default: keep original resolution) | |
| 706 |
+------------------+---------------------------------------------------------------------------------+ |
| 707 |
| nodata | Nodata value to put in image if out of bounds | |
| 708 |
+------------------+---------------------------------------------------------------------------------+ |
| 709 |
| align | Align output bounding box to input image | |
| 710 |
+------------------+---------------------------------------------------------------------------------+ |
| 711 |
|
| 712 |
.. note:: |
| 713 |
Possible values for the key 'eo' are: ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG. For instance you can use 'eo':'ATTRIBUTE=fieldname' |
| 714 |
|
| 715 |
**Subset bands** |
| 716 |
|
| 717 |
+------------------+---------------------------------------------------------------------------------+ |
| 718 |
| key | value | |
| 719 |
+==================+=================================================================================+ |
| 720 |
| band | List of band indices to crop (index is 0 based) | |
| 721 |
+------------------+---------------------------------------------------------------------------------+ |
| 722 |
| startband | Start band sequence number (index is 0 based) | |
| 723 |
+------------------+---------------------------------------------------------------------------------+ |
| 724 |
| endband | End band sequence number (index is 0 based) | |
| 725 |
+------------------+---------------------------------------------------------------------------------+ |
| 726 |
|
| 727 |
.. |
| 728 |
| mask | Data type for output image | |
| 729 |
+------------------+---------------------------------------------------------------------------------+ |
| 730 |
| msknodata | Scale output: output=scale*input+offset | |
| 731 |
+------------------+---------------------------------------------------------------------------------+ |
| 732 |
| mskband | Apply offset: output=scale*input+offset | |
| 733 |
+------------------+---------------------------------------------------------------------------------+ |
| 734 |
|
| 735 |
Example: |
| 736 |
|
| 737 |
Convert data type of input image to byte, using autoscale and clipping respectively:: |
| 738 |
|
| 739 |
jim_scaled=jim.convert({'otype':'Byte','autoscale':[0,255]}) |
| 740 |
jim_clipped=jim.setThreshold({'min':0,'max':255,'nodata':0}).convert({'otype':'Byte'}) |
| 741 |
|
| 742 |
END |
| 743 |
|
| 744 |
METHOD warp(dict) |
| 745 |
Warp a raster dataset to a target spatial reference system |
| 746 |
|
| 747 |
Args: |
| 748 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 749 |
|
| 750 |
Returns: |
| 751 |
This warped Jim object in the target spatial reference system |
| 752 |
|
| 753 |
Supported keys in the dict: |
| 754 |
|
| 755 |
+------------------+---------------------------------------------------------------------------------+ |
| 756 |
| key | value | |
| 757 |
+==================+=================================================================================+ |
| 758 |
| s_srs | Source spatial reference system (default is to read from input) | |
| 759 |
+------------------+---------------------------------------------------------------------------------+ |
| 760 |
| t_srs | Target spatial reference system | |
| 761 |
+------------------+---------------------------------------------------------------------------------+ |
| 762 |
| resample | Resample algorithm used for reading pixel data in case of interpolation | |
| 763 |
| | (default: GRIORA_NearestNeighbour). | |
| 764 |
| | Check http://www.gdal.org/gdal_8h.html#a640ada511cbddeefac67c548e009d5a | |
| 765 |
| | or available options. | |
| 766 |
+------------------+---------------------------------------------------------------------------------+ |
| 767 |
| nodata | Nodata value to put in image if out of bounds | |
| 768 |
+------------------+---------------------------------------------------------------------------------+ |
| 769 |
| otype | Data type for output image | |
| 770 |
+------------------+---------------------------------------------------------------------------------+ |
| 771 |
|
| 772 |
.. note:: |
| 773 |
Possible values for the key 'otype' are: Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64 |
| 774 |
|
| 775 |
Example: |
| 776 |
|
| 777 |
Read a raster dataset from disk by selecting a bounding box in some target spatial reference system. Then warp the read raster dataset to the target spatial reference system:: |
| 778 |
|
| 779 |
jim=jl.createJim({'filename':'/path/to/file.tif','t_srs':'epsg:3035','ulx':1000000,'uly':4000000','lrx':1500000,'lry':3500000}) |
| 780 |
jim_warped=jim.warp({'t_srs':'epsg:3035}) |
| 781 |
|
| 782 |
END |
| 783 |
|
| 784 |
METHOD filter1d(dict) |
| 785 |
Filter Jim image in spectral/temporal domain performed on multi-band raster dataset. |
| 786 |
|
| 787 |
Args: |
| 788 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 789 |
|
| 790 |
|
| 791 |
Returns: |
| 792 |
This filtered of Jim object (self) |
| 793 |
|
| 794 |
Supported keys in the dict: |
| 795 |
|
| 796 |
|
| 797 |
+------------------+---------------------------------------------------------------------------------+ |
| 798 |
| key | value | |
| 799 |
+==================+=================================================================================+ |
| 800 |
| filter | filter function (see values for different filter types in tables below) | |
| 801 |
+------------------+---------------------------------------------------------------------------------+ |
| 802 |
| dz | filter kernel size in z (spectral/temporal dimension), must be odd (example: 3) | |
| 803 |
+------------------+---------------------------------------------------------------------------------+ |
| 804 |
| pad | Padding method for filtering (how to handle edge effects) | |
| 805 |
| | Possible values are: symmetric (default), replicate, circular, zero (pad with 0)| |
| 806 |
+------------------+---------------------------------------------------------------------------------+ |
| 807 |
| otype | Data type for output image | |
| 808 |
+------------------+---------------------------------------------------------------------------------+ |
| 809 |
|
| 810 |
|
| 811 |
**Morphological filters** |
| 812 |
|
| 813 |
+---------------------+------------------------------------------------------+ |
| 814 |
| filter | description | |
| 815 |
+=====================+======================================================+ |
| 816 |
| dilate | morphological dilation | |
| 817 |
+---------------------+------------------------------------------------------+ |
| 818 |
| erode | morphological erosion | |
| 819 |
+---------------------+------------------------------------------------------+ |
| 820 |
| close | morpholigical closing (dilate+erode) | |
| 821 |
+---------------------+------------------------------------------------------+ |
| 822 |
| open | morpholigical opening (erode+dilate) | |
| 823 |
+---------------------+------------------------------------------------------+ |
| 824 |
|
| 825 |
.. note:: |
| 826 |
The morphological filter uses a linear structural element with a size defined by the key 'dz' |
| 827 |
|
| 828 |
Example: |
| 829 |
|
| 830 |
Perform a morphological dilation with a linear structural element of size 5:: |
| 831 |
|
| 832 |
jim_filtered=jim.filter1d({'filter':'dilate','dz':5}) |
| 833 |
|
| 834 |
|
| 835 |
**Statistical filters** |
| 836 |
|
| 837 |
+--------------+------------------------------------------------------+ |
| 838 |
| filter | description | |
| 839 |
+==============+======================================================+ |
| 840 |
| smoothnodata | smooth nodata values (set nodata option!) | |
| 841 |
+--------------+------------------------------------------------------+ |
| 842 |
| nvalid | report number of valid (not nodata) values in window | |
| 843 |
+--------------+------------------------------------------------------+ |
| 844 |
| median | perform a median filter | |
| 845 |
+--------------+------------------------------------------------------+ |
| 846 |
| var | calculate variance in window | |
| 847 |
+--------------+------------------------------------------------------+ |
| 848 |
| min | calculate minimum in window | |
| 849 |
+--------------+------------------------------------------------------+ |
| 850 |
| max | calculate maximum in window | |
| 851 |
+--------------+------------------------------------------------------+ |
| 852 |
| sum | calculate sum in window | |
| 853 |
+--------------+------------------------------------------------------+ |
| 854 |
| mean | calculate mean in window | |
| 855 |
+--------------+------------------------------------------------------+ |
| 856 |
| stdev | calculate standard deviation in window | |
| 857 |
+--------------+------------------------------------------------------+ |
| 858 |
| percentile | calculate percentile value in window | |
| 859 |
+--------------+------------------------------------------------------+ |
| 860 |
| proportion | calculate proportion in window | |
| 861 |
+--------------+------------------------------------------------------+ |
| 862 |
|
| 863 |
.. note:: |
| 864 |
You can specify the no data value for the smoothnodata filter with the extra key 'nodata' and a list of no data values. The interpolation type can be set with the key 'interp' (check complete list of `values <http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html>`_, removing the leading "gsl_interp"). |
| 865 |
|
| 866 |
Example: |
| 867 |
|
| 868 |
Smooth the 0 valued pixel values using a linear interpolation in a spectral/temporal neighborhood of 5 bands:: |
| 869 |
|
| 870 |
jim_filtered=jim.filter1d({'filter':'smoothnodata','nodata':0,'interp':'linear','dz':5}) |
| 871 |
|
| 872 |
**Wavelet filters** |
| 873 |
|
| 874 |
Perform a wavelet transform (or inverse) in spectral/temporal domain. |
| 875 |
|
| 876 |
.. note:: |
| 877 |
The wavelet coefficients can be positive and negative. If the input raster dataset has an unsigned data type, make sure to set the output to a signed data type using the key 'otype'. |
| 878 |
|
| 879 |
You can use set the wavelet family with the key 'family' in the dictionary. The following wavelets are supported as values: |
| 880 |
|
| 881 |
* daubechies |
| 882 |
* daubechies_centered |
| 883 |
* haar |
| 884 |
* haar_centered |
| 885 |
* bspline |
| 886 |
* bspline_centered |
| 887 |
|
| 888 |
+----------+--------------------------------------+ |
| 889 |
| filter | description | |
| 890 |
+==========+======================================+ |
| 891 |
| dwt | discrete wavelet transform | |
| 892 |
+----------+--------------------------------------+ |
| 893 |
| dwti | discrete inverse wavelet transform | |
| 894 |
+----------+--------------------------------------+ |
| 895 |
| dwt_cut | DWT approximation in spectral domain | |
| 896 |
+----------+--------------------------------------+ |
| 897 |
|
| 898 |
.. note:: |
| 899 |
The filter 'dwt_cut' performs a forward and inverse transform, approximating the input signal. The approximation is performed by discarding a percentile of the wavelet coefficients that can be set with the key 'threshold'. A threshold of 0 (default) retains all and a threshold of 50 discards the lower half of the wavelet coefficients. |
| 900 |
|
| 901 |
Example: |
| 902 |
|
| 903 |
Approximate the multi-temporal raster dataset by discarding the lower 20 percent of the coefficients after a discrete wavelet transform. The input dataset has a Byte data type. We wavelet transform is calculated using an Int16 data type. The approximated image is then converted to a Byte dataset, making sure all values below 0 and above 255 are set to 0:: |
| 904 |
|
| 905 |
jim_approx=jim_multitemp.filter1d({'filter':'dwt_cut','threshold':20, 'otype':Int16}) |
| 906 |
jim_approx=jim_approx({'min':0,'max':255,'nodata':0}).convert({'otype':'Byte'}) |
| 907 |
|
| 908 |
**Hyperspectral filters** |
| 909 |
|
| 910 |
Hyperspectral filters assume the bands in the input raster dataset correspond to contiguous spectral bands. Full width half max (FWHM) and spectral response filters are supported. They converts an N band input raster dataset to an M (< N) band output raster dataset. |
| 911 |
|
| 912 |
The full width half max (FWHM) filter expects a list of M center wavelenghts and a corresponding list of M FWHM values. The M center wavelenghts define the output wavelenghts and must be provided with the key 'wavelengthOut'. For the FHWM, use the key 'fwhm' and a list of M values. The algorithm needs to know the N wavelenghts that correspond to the N bands of the input raster dataset. Use the key 'wavelengthIn' and a list of N values. The units of input, output and FWHM are arbitrary, but should be identical (e.g., nm). |
| 913 |
|
| 914 |
Example: |
| 915 |
|
| 916 |
Covert the hyperspectral input raster dataset, with the wavelengths defined in the list wavelenghts_in to a multispectral raster dataset with three bands, corresponding to Red, Green, and Blue:: |
| 917 |
|
| 918 |
wavelengths_in=[] |
| 919 |
#define the wavelenghts of the input raster dataset |
| 920 |
|
| 921 |
if len(wavelength_in) == jim_hyperspectral.nrOfBand(): |
| 922 |
jim_rgb=jim_hyperspectral.filter1d({'wavelengthIn:wavelenghts_in,'wavelengthOut':[650,510,475],'fwhm':[50,50,50]}) |
| 923 |
else: |
| 924 |
print("Error: number of input wavelengths must be equal to number of bands in input raster dataset") |
| 925 |
|
| 926 |
.. note:: |
| 927 |
The input wavelenghts are automatically interpolated. You can specify the interpolation using the key 'interp' and values as listed interpolation http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html |
| 928 |
|
| 929 |
The spectral response filter (SRF) |
| 930 |
|
| 931 |
The input raster dataset is filtered with M of spectral response functions (SRF). Each spectral response function must be provided by the user in an ASCII file that consists of two columns: wavelengths and response. Use the key 'srf' and a list of paths to the ASCII file(s). The algorithm automatically takes care of the normalization of the SRF. |
| 932 |
|
| 933 |
Example: |
| 934 |
|
| 935 |
Covert the hyperspectral input raster dataset, to a multispectral raster dataset with three bands, corresponding to Red, Green, and Blue as defined in the ASCII text files 'srf_red.txt', 'srf_green.txt', 'srf_blue.txt':: |
| 936 |
|
| 937 |
wavelengths_in=[] |
| 938 |
#specify the wavelenghts of the input raster dataset |
| 939 |
|
| 940 |
if len(wavelength_in) == jim_hyperspectral.nrOfBand(): |
| 941 |
jim_rgb=jim_hyperspectral.filter1d({'wavelengthIn:wavelenghts_in,'srf':['srf_red.txt','srf_green.txt','srf_blue.txt']}) |
| 942 |
else: |
| 943 |
print("Error: number of input wavelengths must be equal to number of bands in input raster dataset") |
| 944 |
|
| 945 |
.. note:: |
| 946 |
The input wavelenghts are automatically interpolated. You can specify the interpolation using the key 'interp' and values as listed interpolation http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html |
| 947 |
|
| 948 |
|
| 949 |
**Custom filters** |
| 950 |
|
| 951 |
For the custom filter, you can specify your own taps using the keyword 'tapz' and a list of filter tap values. The tap values are automatically normalized by the algorithm. |
| 952 |
|
| 953 |
Example: |
| 954 |
|
| 955 |
Perform a simple smoothing filter by defining three identical tap values:: |
| 956 |
|
| 957 |
jim_filtered=jim.filter1d({'tapz':[1,1,1]}) |
| 958 |
|
| 959 |
END |
| 960 |
|
| 961 |
METHOD filter2d(dict) |
| 962 |
Filter Jim image in spatial domain performed on single or multi-band raster dataset. |
| 963 |
|
| 964 |
Args: |
| 965 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 966 |
|
| 967 |
|
| 968 |
Returns: |
| 969 |
This filtered of Jim object (self) |
| 970 |
|
| 971 |
Supported keys in the dict: |
| 972 |
|
| 973 |
|
| 974 |
+------------------+---------------------------------------------------------------------------------+ |
| 975 |
| key | value | |
| 976 |
+==================+=================================================================================+ |
| 977 |
| filter | filter function (see values for different filter types in tables below) | |
| 978 |
+------------------+---------------------------------------------------------------------------------+ |
| 979 |
| dx | filter kernel size in x, use odd values only (default is 3) | |
| 980 |
+------------------+---------------------------------------------------------------------------------+ |
| 981 |
| dy | filter kernel size in y, use odd values only (default is 3) | |
| 982 |
+------------------+---------------------------------------------------------------------------------+ |
| 983 |
| pad | Padding method for filtering (how to handle edge effects) | |
| 984 |
| | Possible values are: symmetric (default), replicate, circular, zero (pad with 0)| |
| 985 |
+------------------+---------------------------------------------------------------------------------+ |
| 986 |
| otype | Data type for output image | |
| 987 |
+------------------+---------------------------------------------------------------------------------+ |
| 988 |
|
| 989 |
|
| 990 |
**Edge detection** |
| 991 |
|
| 992 |
+---------------------+-------------------------------------------------------------------------+ |
| 993 |
| filter | description | |
| 994 |
+=====================+=========================================================================+ |
| 995 |
| sobelx | Sobel operator in x direction | |
| 996 |
+---------------------+-------------------------------------------------------------------------+ |
| 997 |
| sobely | Sobel operator in y direction | |
| 998 |
+---------------------+-------------------------------------------------------------------------+ |
| 999 |
| sobelxy | Sobel operator in x and y direction | |
| 1000 |
+---------------------+-------------------------------------------------------------------------+ |
| 1001 |
| homog | binary value indicating if pixel is identical to all pixels in kernel | |
| 1002 |
+---------------------+-------------------------------------------------------------------------+ |
| 1003 |
| heterog | binary value indicating if pixel is different than all pixels in kernel | |
| 1004 |
+---------------------+-------------------------------------------------------------------------+ |
| 1005 |
|
| 1006 |
Example: |
| 1007 |
|
| 1008 |
Perform Sobel edge detection in both x and direction:: |
| 1009 |
|
| 1010 |
jim_filtered=jim.filter2d({'filter':'sobelxy'}) |
| 1011 |
|
| 1012 |
**Morphological filters** |
| 1013 |
|
| 1014 |
.. note:: |
| 1015 |
For a more comprehensive list morphological operators, please refer to :ref:`advanced spatial morphological operators <mia_morpho2d>`. |
| 1016 |
|
| 1017 |
+---------------------+------------------------------------------------------+ |
| 1018 |
| filter | description | |
| 1019 |
+=====================+======================================================+ |
| 1020 |
| dilate | morphological dilation | |
| 1021 |
+---------------------+------------------------------------------------------+ |
| 1022 |
| erode | morphological erosion | |
| 1023 |
+---------------------+------------------------------------------------------+ |
| 1024 |
| close | morpholigical closing (dilate+erode) | |
| 1025 |
+---------------------+------------------------------------------------------+ |
| 1026 |
| open | morpholigical opening (erode+dilate) | |
| 1027 |
+---------------------+------------------------------------------------------+ |
| 1028 |
|
| 1029 |
.. note:: |
| 1030 |
You can use the optional key 'class' with a list value to take only these pixel values into account. For instance, use 'class':[255] to dilate clouds in the raster dataset that have been flagged with value 255. In addition, you can use a circular disc kernel (set the key 'circular' to True). |
| 1031 |
|
| 1032 |
Example: |
| 1033 |
|
| 1034 |
Perform a morphological dilation using a circular kernel with size (diameter) of 5 pixels:: |
| 1035 |
|
| 1036 |
jim_filtered=jim.filter2d({'filter':'dilate','dx':5,'dy':5,'circular':True}) |
| 1037 |
|
| 1038 |
**Statistical filters** |
| 1039 |
|
| 1040 |
+--------------+------------------------------------------------------+ |
| 1041 |
| filter | description | |
| 1042 |
+==============+======================================================+ |
| 1043 |
| smoothnodata | smooth nodata values (set nodata option!) | |
| 1044 |
+--------------+------------------------------------------------------+ |
| 1045 |
| nvalid | report number of valid (not nodata) values in window | |
| 1046 |
+--------------+------------------------------------------------------+ |
| 1047 |
| median | perform a median filter | |
| 1048 |
+--------------+------------------------------------------------------+ |
| 1049 |
| var | calculate variance in window | |
| 1050 |
+--------------+------------------------------------------------------+ |
| 1051 |
| min | calculate minimum in window | |
| 1052 |
+--------------+------------------------------------------------------+ |
| 1053 |
| max | calculate maximum in window | |
| 1054 |
+--------------+------------------------------------------------------+ |
| 1055 |
| ismin | binary value indicating if pixel is minimum in kernel| |
| 1056 |
+--------------+------------------------------------------------------+ |
| 1057 |
| ismax | binary value indicating if pixel is maximum in kernel| |
| 1058 |
+--------------+------------------------------------------------------+ |
| 1059 |
| sum | calculate sum in window | |
| 1060 |
+--------------+------------------------------------------------------+ |
| 1061 |
| mode | calculate the mode (only for categorical values) | |
| 1062 |
+--------------+------------------------------------------------------+ |
| 1063 |
| mean | calculate mean in window | |
| 1064 |
+--------------+------------------------------------------------------+ |
| 1065 |
| stdev | calculate standard deviation in window | |
| 1066 |
+--------------+------------------------------------------------------+ |
| 1067 |
| percentile | calculate percentile value in window | |
| 1068 |
+--------------+------------------------------------------------------+ |
| 1069 |
| proportion | calculate proportion in window | |
| 1070 |
+--------------+------------------------------------------------------+ |
| 1071 |
|
| 1072 |
.. note:: |
| 1073 |
You can specify the no data value for the smoothnodata filter with the extra key 'nodata' and a list of no data values. The interpolation type can be set with the key 'interp' (check complete list of `values <http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html>`_, removing the leading "gsl_interp"). |
| 1074 |
|
| 1075 |
Example: |
| 1076 |
|
| 1077 |
Perform a median filter with kernel size of 5x5 pixels:: |
| 1078 |
|
| 1079 |
jim_filtered=jim.filter2d({'filter':'median','dz':5}) |
| 1080 |
|
| 1081 |
**Wavelet filters** |
| 1082 |
|
| 1083 |
Perform a wavelet transform (or inverse) in spatial domain. |
| 1084 |
|
| 1085 |
.. note:: |
| 1086 |
The wavelet coefficients can be positive and negative. If the input raster dataset has an unsigned data type, make sure to set the output to a signed data type using the key 'otype'. |
| 1087 |
|
| 1088 |
You can use set the wavelet family with the key 'family' in the dictionary. The following wavelets are supported as values: |
| 1089 |
|
| 1090 |
* daubechies |
| 1091 |
* daubechies_centered |
| 1092 |
* haar |
| 1093 |
* haar_centered |
| 1094 |
* bspline |
| 1095 |
* bspline_centered |
| 1096 |
|
| 1097 |
+----------+--------------------------------------+ |
| 1098 |
| filter | description | |
| 1099 |
+==========+======================================+ |
| 1100 |
| dwt | discrete wavelet transform | |
| 1101 |
+----------+--------------------------------------+ |
| 1102 |
| dwti | discrete inverse wavelet transform | |
| 1103 |
+----------+--------------------------------------+ |
| 1104 |
| dwt_cut | DWT approximation in spectral domain | |
| 1105 |
+----------+--------------------------------------+ |
| 1106 |
|
| 1107 |
.. note:: |
| 1108 |
The filter 'dwt_cut' performs a forward and inverse transform, approximating the input signal. The approximation is performed by discarding a percentile of the wavelet coefficients that can be set with the key 'threshold'. A threshold of 0 (default) retains all and a threshold of 50 discards the lower half of the wavelet coefficients. |
| 1109 |
|
| 1110 |
Example: |
| 1111 |
|
| 1112 |
Approximate the multi-temporal raster dataset by discarding the lower 20 percent of the coefficients after a discrete wavelet transform. The input dataset has a Byte data type. We wavelet transform is calculated using an Int16 data type. The approximated image is then converted to a Byte dataset, making sure all values below 0 and above 255 are set to 0:: |
| 1113 |
|
| 1114 |
jim_approx=jim_multitemp.filter2d({'filter':'dwt_cut','threshold':20, 'otype':Int16}) |
| 1115 |
jim_approx=jim_approx({'min':0,'max':255,'nodata':0}).convert({'otype':'Byte'}) |
| 1116 |
|
| 1117 |
END |
| 1118 |
|
| 1119 |
METHOD classify(dict) |
| 1120 |
Supervised classification of a raster dataset. The classifier must have been trained via the :py:func:`VectorOgr:train` method. |
| 1121 |
The classifier can be selected with the key 'method' and possible values 'svm' and 'ann': |
| 1122 |
|
| 1123 |
Args: |
| 1124 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1125 |
|
| 1126 |
|
| 1127 |
Returns: |
| 1128 |
The classified raster dataset. |
| 1129 |
|
| 1130 |
Supported keys in the dict (with more keys defined for the respective classication methods): |
| 1131 |
|
| 1132 |
+------------------+------------------------------------------------------------------------------------------------------+ |
| 1133 |
| key | value | |
| 1134 |
+==================+======================================================================================================+ |
| 1135 |
| method | Classification method (svm or ann) | |
| 1136 |
+------------------+------------------------------------------------------------------------------------------------------+ |
| 1137 |
| model | Model filename to save trained classifier | |
| 1138 |
+------------------+------------------------------------------------------------------------------------------------------+ |
| 1139 |
| band | Band index (starting from 0). The band order must correspond to the band names defined in the model. | |
| 1140 |
| | Leave empty to use all bands | |
| 1141 |
+------------------+------------------------------------------------------------------------------------------------------+ |
| 1142 |
|
| 1143 |
The support vector machine (SVM) supervised classifier is described `here <http://dx.doi.org/10.1007/BF00994018>`_. The implementation in JIPlib is based on the open source `libsvm <https://www.csie.ntu.edu.tw/~cjlin/libsvm/>`_. |
| 1144 |
|
| 1145 |
The artificial neural network (ANN) supervised classifier is based on the back propagation model as introduced by D. E. Rumelhart, G. E. Hinton, and R. J. Williams (Nature, vol. 323, pp. 533-536, 1986). The implementation is based on the open source C++ library fann (http://leenissen.dk/fann/wp/). |
| 1146 |
|
| 1147 |
**Prior probabilities** |
| 1148 |
|
| 1149 |
Prior probabilities can be set for each of the classes. The prior probabilities can be provided with the key 'prior' and a list of values for each of the (in ascending order). The priors are automatically normalized by the algorithm. Alternatively, a prior probability can be provided for each pixel, using the key 'priorimg' and a value pointing to the path of multi-band raster dataset. The bands of the raster dataset represent the prior probabilities for each of the classes. |
| 1150 |
|
| 1151 |
**Classifying parts of the input raster dataset** |
| 1152 |
|
| 1153 |
Parts of the input raster dataset can be classified only by using a vector or raster mask. To apply a vector mask, use the key 'extent' with the path of the vector dataset as a value. Optionally, a spatial extent option can be provided with the key 'eo' that controlls the rasterization process (values can be either one of: ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG). For instance, you can define 'eo':'ATTRIBUTE=fieldname' to rasterize only those features with an attribute equal to fieldname. |
| 1154 |
|
| 1155 |
To apply a raster mask, use the key 'mask' with the path of the raster dataset as a value. Mask value(s) not to consider for classification can be set as a list value with the key 'msknodata'. |
| 1156 |
|
| 1157 |
+------------------+---------------------------------------------------------------------------------+ |
| 1158 |
| key | value | |
| 1159 |
+==================+=================================================================================+ |
| 1160 |
| extent | Data type for output image | |
| 1161 |
+------------------+---------------------------------------------------------------------------------+ |
| 1162 |
| eo | Special extent options controlling rasterization | |
| 1163 |
+------------------+---------------------------------------------------------------------------------+ |
| 1164 |
| mask | Only classify within specified mask | |
| 1165 |
+------------------+---------------------------------------------------------------------------------+ |
| 1166 |
| msknodata | Mask value(s) in mask not to consider for classification | |
| 1167 |
+------------------+---------------------------------------------------------------------------------+ |
| 1168 |
| nodata | Nodata value to put where image is masked as no data | |
| 1169 |
+------------------+---------------------------------------------------------------------------------+ |
| 1170 |
|
| 1171 |
END |
| 1172 |
|
| 1173 |
METHOD classifySML(dict) |
| 1174 |
Supervised classification of a raster dataset using the symbolic machine learning algorithm `sml <https://doi.org/10.3390/rs8050399>`_. For training, one or more reference raster datasets with categorical values is expected as a JimList. The reference raster dataset is typically at a lower spatial resolution than the input raster dataset to be classified. Unlike the :py:func:`Jim:classify`, the training is performed not prior to the classification, but in the same process as the classification. |
| 1175 |
|
| 1176 |
Args: |
| 1177 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1178 |
|
| 1179 |
Returns: |
| 1180 |
A multiband raster dataset with one band for each class. The pixel values represent the respective frequencies of the classes (scaled to Byte). To create a hard classified output, obtain the maxindex of this output. The result will then contains the class indices (0-nclass-1). To obtain the same class numbers as defined in the reference dataset, use the :py:func:`Jim:reclass` method (see example below). |
| 1181 |
|
| 1182 |
Supported keys in the dict: |
| 1183 |
|
| 1184 |
+------------------+---------------------------------------------------------------------------------+ |
| 1185 |
| key | value | |
| 1186 |
+==================+=================================================================================+ |
| 1187 |
| band | List of band indices (starting from 0). Leave empty to use all bands | |
| 1188 |
+------------------+---------------------------------------------------------------------------------+ |
| 1189 |
| class | List of classes to extract from the reference. Leave empty to extract two | |
| 1190 |
| | classes only (1 against rest) | |
| 1191 |
+------------------+---------------------------------------------------------------------------------+ |
| 1192 |
| otype | Data type for output image | |
| 1193 |
+------------------+---------------------------------------------------------------------------------+ |
| 1194 |
|
| 1195 |
|
| 1196 |
**Classifying parts of the input raster dataset** |
| 1197 |
|
| 1198 |
See :py:func:`Jim:classify`. |
| 1199 |
|
| 1200 |
Example: |
| 1201 |
|
| 1202 |
Use the Corine land cover product as a reference to perform an SML classification of a Sentinel-2 image using the 10 m bands (B02, B03, B04 and B08). |
| 1203 |
|
| 1204 |
Import modules:: |
| 1205 |
|
| 1206 |
import os, sys |
| 1207 |
from osgeo import gdal |
| 1208 |
from osgeo import gdalconst |
| 1209 |
from osgeo import ogr |
| 1210 |
from osgeo import osr |
| 1211 |
import fnmatch |
| 1212 |
import time |
| 1213 |
import numpy as np |
| 1214 |
from scipy import misc |
| 1215 |
import operator |
| 1216 |
import jiplib as jl |
| 1217 |
from osgeo import gdal |
| 1218 |
|
| 1219 |
Preparation of input. Stack all input bands to single multiband input raster dataset. Scale input to Byte and adapt the dynamic range to chosen number of bits:: |
| 1220 |
|
| 1221 |
NBIT=7 |
| 1222 |
jimlist=jl.createJimList() |
| 1223 |
for file in sorted(fnmatch.filter(os.listdir(infolder), '*_B0[2348].jp2')): |
| 1224 |
file=os.path.join(infolder,file) |
| 1225 |
jim=jl.createJim({'filename':file,'dx':100,'dy':100}) |
| 1226 |
jim_convert=jim.convert({'autoscale':[2**(8-NBIT),2**8-1],'otype':'GDT_Byte'}).pointOpBitShift(8-NBIT) |
| 1227 |
jim.close() |
| 1228 |
jimlist.pushImage(jim_convert) |
| 1229 |
jim=jimlist.stack() |
| 1230 |
jimlist.close() |
| 1231 |
|
| 1232 |
Then prepare reference dataset. The reference Corine land cover is in the LAEA (EPSG:3035) coordinate reference system. We will only read the area corresponding to the input image Therefore, we need to calculate the transformed bounding box of the input image in LAEA:: |
| 1233 |
|
| 1234 |
corinefn='/eos/jeodpp/data/base/Landcover/EUROPE/CorineLandCover/CLC2012/VER18-5/Data/GeoTIFF/250m/g250_clc12_V18_5.tif' |
| 1235 |
jim_ref=jl.createJim({'filename':corinefn,'noread':True,'a_srs':'EPSG:3035'}) |
| 1236 |
print("bounding box input image:",jim.getUlx(), jim.getUly(), jim.getLrx(), jim.getLry()) |
| 1237 |
pointUL = ogr.Geometry(ogr.wkbPoint) |
| 1238 |
pointUL.AddPoint(jim.getUlx(), jim.getUly()) |
| 1239 |
pointLR = ogr.Geometry(ogr.wkbPoint) |
| 1240 |
pointLR.AddPoint(jim.getLrx(), jim.getLry()) |
| 1241 |
source = osr.SpatialReference() |
| 1242 |
source.ImportFromEPSG(32632) |
| 1243 |
target = osr.SpatialReference() |
| 1244 |
target.ImportFromEPSG(3035) |
| 1245 |
transform = osr.CoordinateTransformation(source, target) |
| 1246 |
pointUL.Transform(transform) |
| 1247 |
pointLR.Transform(transform) |
| 1248 |
|
| 1249 |
Now we can open the reference image for the region of interest. We will open it in a reduced spatial resolution of 500 m:: |
| 1250 |
|
| 1251 |
jim_ref=jl.createJim({'filename':corinefn,'dx':500,'dy':500.0,'ulx':pointUL.GetX(),'uly':pointUL.GetY(),'lrx':pointLR.GetX(),'lry':pointLR.GetY(),'a_srs':'EPSG:3035'}) |
| 1252 |
|
| 1253 |
Create a dictionary with the class names and corresponding values used in the classified raster map:: |
| 1254 |
|
| 1255 |
classDict={} |
| 1256 |
classDict['urban']=2 |
| 1257 |
classDict['agriculture']=12 |
| 1258 |
classDict['forest']=25 |
| 1259 |
classDict['water']=41 |
| 1260 |
classDict['rest']=50 |
| 1261 |
sorted(classDict.values()) |
| 1262 |
|
| 1263 |
Reclass the reference to the selected classes:: |
| 1264 |
|
| 1265 |
classFrom=range(0,50) |
| 1266 |
classTo=[50]*50 |
| 1267 |
for i in range(0,50): |
| 1268 |
if i>=1 and i<10: |
| 1269 |
classTo[i]=classDict['urban'] |
| 1270 |
elif i>=11 and i<22: |
| 1271 |
classTo[i]=classDict['agriculture'] |
| 1272 |
elif i>=23 and i<25: |
| 1273 |
classTo[i]=classDict['forest'] |
| 1274 |
elif i>=40 and i<45: |
| 1275 |
classTo[i]=classDict['water'] |
| 1276 |
else: |
| 1277 |
classTo[i]=classDict['rest'] |
| 1278 |
|
| 1279 |
jim_ref=jim_ref.reclass({'class':classFrom,'reclass':classTo}) |
| 1280 |
|
| 1281 |
The SML algorithm uses a JimList of reference raster datasets. Here we will create a list of a single reference only:: |
| 1282 |
|
| 1283 |
reflist=jl.createJimList([jim_ref]) |
| 1284 |
|
| 1285 |
For a multi-class problem, we must define the list of classes that should be taken into account by the SML algorithm:: |
| 1286 |
|
| 1287 |
sml=jim.classifySML(reflist,{'class':sorted(classDict.values())}).setNoData([0]) |
| 1288 |
|
| 1289 |
Preparation of output. The output is a multiband raster dataset with one band for each class. The pixels represent the respective frequencies of the classes (scaled to Byte) |
| 1290 |
|
| 1291 |
We can create a hard classified output by obtaining the maxindex of this output. The result contains the class indices (0-nclass-1). |
| 1292 |
To obtain the same class numbers as defined in the reference dataset, we can reclass accordingly:: |
| 1293 |
|
| 1294 |
sml_class=sml.statProfile({'function':'maxindex'}).reclass({'class':range(0,sml.nrOfBand()),'reclass':sorted(classDict.values())}) |
| 1295 |
|
| 1296 |
END |
| 1297 |
|
| 1298 |
METHOD reclass(dict) |
| 1299 |
Replace categorical pixel values in raster dataset |
| 1300 |
|
| 1301 |
Args: |
| 1302 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1303 |
|
| 1304 |
Returns: |
| 1305 |
Raster dataset with class values replaced according to corresponding class and reclass list values. |
| 1306 |
|
| 1307 |
Supported keys in the dict: |
| 1308 |
|
| 1309 |
+------------------+---------------------------------------------------------------------------------+ |
| 1310 |
| key | value | |
| 1311 |
+==================+=================================================================================+ |
| 1312 |
| class | List of input classes to reclass from | |
| 1313 |
+------------------+---------------------------------------------------------------------------------+ |
| 1314 |
| reclass | List of output classes to reclass to | |
| 1315 |
+------------------+---------------------------------------------------------------------------------+ |
| 1316 |
| otype | Data type for output image (default is type of input raster dataset) | |
| 1317 |
+------------------+---------------------------------------------------------------------------------+ |
| 1318 |
|
| 1319 |
.. note:: |
| 1320 |
The list size of the class and reclass should be identical. The value class[index] will be replaced with the value reclass[index]. |
| 1321 |
|
| 1322 |
Example: |
| 1323 |
|
| 1324 |
Reclass all pixel values 0 to 255:: |
| 1325 |
|
| 1326 |
jim_reclass=jim.reclass({'class':[0],'reclass':[255]}) |
| 1327 |
|
| 1328 |
END |
| 1329 |
|
| 1330 |
METHOD setThreshold(dict) |
| 1331 |
Apply minimum and maximum threshold to pixel values in raster dataset |
| 1332 |
|
| 1333 |
Args: |
| 1334 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1335 |
|
| 1336 |
Supported keys in the dict: |
| 1337 |
|
| 1338 |
+------------------+---------------------------------------------------------------------------------+ |
| 1339 |
| key | value | |
| 1340 |
+==================+=================================================================================+ |
| 1341 |
| min | Minimum threshold value (if pixel value < min set pixel value to no data) | |
| 1342 |
+------------------+---------------------------------------------------------------------------------+ |
| 1343 |
| max | Maximum threshold value (if pixel value < max set pixel value to no data) | |
| 1344 |
+------------------+---------------------------------------------------------------------------------+ |
| 1345 |
| value | value to be set if within min and max | |
| 1346 |
| | (if not set, valid pixels will remain their input value) | |
| 1347 |
+------------------+---------------------------------------------------------------------------------+ |
| 1348 |
| abs | Set to True to perform threshold test to absolute pixel values | |
| 1349 |
+------------------+---------------------------------------------------------------------------------+ |
| 1350 |
| nodata | Set pixel value to this no data if pixel value < min or > max | |
| 1351 |
+------------------+---------------------------------------------------------------------------------+ |
| 1352 |
|
| 1353 |
Returns: |
| 1354 |
Raster dataset with pixel threshold applied. |
| 1355 |
|
| 1356 |
Example: |
| 1357 |
|
| 1358 |
Mask all values not within [0,250] and set to 255 (no data):: |
| 1359 |
|
| 1360 |
jim_threshold=jim.setThreshold({'min':0,'max':250,'nodata':255}) |
| 1361 |
|
| 1362 |
END |
| 1363 |
|
| 1364 |
METHOD getMask(dict) |
| 1365 |
Create mask image based on values in input raster dataset. |
| 1366 |
|
| 1367 |
Args: |
| 1368 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1369 |
|
| 1370 |
Supported keys in the dict (more keys defined depending on the mask type) |
| 1371 |
|
| 1372 |
+------------------+---------------------------------------------------------------------------------+ |
| 1373 |
| key | value | |
| 1374 |
+==================+=================================================================================+ |
| 1375 |
| band | List of bands (0 indexed) user for mask. | |
| 1376 |
+------------------+---------------------------------------------------------------------------------+ |
| 1377 |
| min | List of minimum threshold values. | |
| 1378 |
+------------------+---------------------------------------------------------------------------------+ |
| 1379 |
| min | List of maximum threshold values. | |
| 1380 |
+------------------+---------------------------------------------------------------------------------+ |
| 1381 |
| operator | Boolean operator ("AND" or "OR") used to combine tests applied to list of bands | |
| 1382 |
| | or min/max thresholds. Default is OR. | |
| 1383 |
+------------------+---------------------------------------------------------------------------------+ |
| 1384 |
| data | List of pixel values to set if pixel value is within min and max. | |
| 1385 |
| | List of values correspond to the list of min/max values in min/max values | |
| 1386 |
+------------------+---------------------------------------------------------------------------------+ |
| 1387 |
| data | List of pixel values to set if pixel value is not within min and max. | |
| 1388 |
| | List of values correspond to the list of min/max values in min/max values | |
| 1389 |
+------------------+---------------------------------------------------------------------------------+ |
| 1390 |
|
| 1391 |
Returns: |
| 1392 |
Raster mask dataset. |
| 1393 |
|
| 1394 |
Example: |
| 1395 |
|
| 1396 |
Create a binary mask from a raster dataset. The mask will get a value 1 (defined by the key 'data') if pixels in the input image are between 1 and 20. Otherwise, the mask will have a 0 (defined by the key 'nodata') value:: |
| 1397 |
|
| 1398 |
jim_threshold=jim.setThreshold({'min':0,'max':250,'nodata':255}) |
| 1399 |
|
| 1400 |
END |
| 1401 |
|
| 1402 |
METHOD setMask(mask, dict) |
| 1403 |
Apply mask image based on values in vector or raster dataset. |
| 1404 |
|
| 1405 |
Args: |
| 1406 |
* ``mask`` Either a list of raster datasets (:py:class:`JimList`) or a vector dataset (:py:class:`VectorOgr`) |
| 1407 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1408 |
|
| 1409 |
Returns: |
| 1410 |
Raster dataset with pixel mask applied. |
| 1411 |
|
| 1412 |
Supported keys in the dict (more keys defined depending on the mask type) |
| 1413 |
|
| 1414 |
+------------------+---------------------------------------------------------------------------------+ |
| 1415 |
| key | value | |
| 1416 |
+==================+=================================================================================+ |
| 1417 |
| otype | Data type for output image | |
| 1418 |
+------------------+---------------------------------------------------------------------------------+ |
| 1419 |
| nodata | Set pixel value to this no data if pixel value not valid according to mask | |
| 1420 |
+------------------+---------------------------------------------------------------------------------+ |
| 1421 |
|
| 1422 |
Mask is a :py:class:`JimList` |
| 1423 |
|
| 1424 |
+------------------+---------------------------------------------------------------------------------+ |
| 1425 |
| key | value | |
| 1426 |
+==================+=================================================================================+ |
| 1427 |
| msknodata | List of mask values where raster dataset should be set to nodata. | |
| 1428 |
| | Use one value for each mask, or multiple values for a single mask. | |
| 1429 |
+------------------+---------------------------------------------------------------------------------+ |
| 1430 |
| mskband | List of mask bands to read (0 indexed). Provide band for each mask. | |
| 1431 |
+------------------+---------------------------------------------------------------------------------+ |
| 1432 |
| operator | List of operators used for testing pixel values against mask. | |
| 1433 |
| | Provide one operator for each msknodata value. | |
| 1434 |
+------------------+---------------------------------------------------------------------------------+ |
| 1435 |
|
| 1436 |
.. note:: |
| 1437 |
The mask raster datasets in the :py:class:`JimList` can be of a different spatial resolution than the input raster dataset to be masked. A nearest neighbor resampling is used. |
| 1438 |
|
| 1439 |
Mask is a :py:class:`VectorOgr` |
| 1440 |
|
| 1441 |
+------------------+---------------------------------------------------------------------------------+ |
| 1442 |
| key | value | |
| 1443 |
+==================+=================================================================================+ |
| 1444 |
| eo | Special extent options controlling rasterization | |
| 1445 |
+------------------+---------------------------------------------------------------------------------+ |
| 1446 |
| ln | List of layer names. | |
| 1447 |
+------------------+---------------------------------------------------------------------------------+ |
| 1448 |
|
| 1449 |
.. note:: |
| 1450 |
Possible values for the key 'eo' are: ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG. For instance you can use 'eo':'ATTRIBUTE=fieldname' |
| 1451 |
|
| 1452 |
Example: |
| 1453 |
|
| 1454 |
Apply vector mask to a raster dataset, masking all pixels that are touched by the vector to a value 255 (no data). You can reduce the memory footprint by not reading the vector dataset:: |
| 1455 |
|
| 1456 |
v0=jl.createVector() |
| 1457 |
v0.open({'filename':args.vm,'noread':True}) |
| 1458 |
jim1=jim0.setMask(v0,{'nodata':255,'eo':'ALL_TOUCHED'}) |
| 1459 |
|
| 1460 |
Apply list of raster masks that consists of a single raster dataset jim_mask (created from jim1 with :py:func:`Jim:getMask`) to a raster dataset jim. Set a value 255 (no data) to all values where the mask has a value 0 (msknodata):: |
| 1461 |
|
| 1462 |
jim_mask=jim1.getMask({'min':1,'max':20,'nodata':0,'data':1}) |
| 1463 |
jlist=jl.JimList([jim_mask]) |
| 1464 |
jim_masked=jim.setMask(jlist,{'nodata':255,'msknodata':0}) |
| 1465 |
|
| 1466 |
END |
| 1467 |
|
| 1468 |
METHOD getStats(dict) |
| 1469 |
Calculate statistics of a raster dataset. |
| 1470 |
|
| 1471 |
Args: |
| 1472 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1473 |
|
| 1474 |
Returns: |
| 1475 |
A dictionary with the results of the statistics, using the same keys as for the functions. |
| 1476 |
|
| 1477 |
Supported keys in the dict: |
| 1478 |
|
| 1479 |
+------------------+---------------------------------------------------------------------------------+ |
| 1480 |
| key | value | |
| 1481 |
+==================+=================================================================================+ |
| 1482 |
| function | Statistical function (see values for different functions in tables below) | |
| 1483 |
+------------------+---------------------------------------------------------------------------------+ |
| 1484 |
| cband | List of bands on which to calculate the statistics | |
| 1485 |
+------------------+---------------------------------------------------------------------------------+ |
| 1486 |
| down | Down sampling factor (in pixels x and y) to calculate the statistics on a subset| |
| 1487 |
+------------------+---------------------------------------------------------------------------------+ |
| 1488 |
| src_min | Do not take smaller values into account when calculating statistics | |
| 1489 |
+------------------+---------------------------------------------------------------------------------+ |
| 1490 |
| src_max | Do not take higher values into account when calculating statistics | |
| 1491 |
+------------------+---------------------------------------------------------------------------------+ |
| 1492 |
| nodata | Do not take these values into account when calculating statistics | |
| 1493 |
+------------------+---------------------------------------------------------------------------------+ |
| 1494 |
| otype | Data type for output image | |
| 1495 |
+------------------+---------------------------------------------------------------------------------+ |
| 1496 |
|
| 1497 |
.. note:: |
| 1498 |
For statistical functions requiring two sets of inputs, use a list of two values for cband (e.g., regression and histogram2d) |
| 1499 |
|
| 1500 |
**Supported statistical functions** |
| 1501 |
|
| 1502 |
+--------------+------------------------------------------------------+ |
| 1503 |
| function | description | |
| 1504 |
+=====================+===============================================+ |
| 1505 |
| invalid | report number of invalid (nodata) values | |
| 1506 |
+--------------+------------------------------------------------------+ |
| 1507 |
| nvalid | report number of valid (not nodata) values | |
| 1508 |
+--------------+------------------------------------------------------+ |
| 1509 |
| basic | Shows basic statistics | |
| 1510 |
| | (min,max, mean and stdDev of the raster datasets) | |
| 1511 |
+--------------+------------------------------------------------------+ |
| 1512 |
| gdal | Use the GDAL calculation of basic statistics | |
| 1513 |
+--------------+------------------------------------------------------+ |
| 1514 |
| mean | calculate the mean value | |
| 1515 |
+--------------+------------------------------------------------------+ |
| 1516 |
| median | calculate the median value | |
| 1517 |
+--------------+------------------------------------------------------+ |
| 1518 |
| var | calculate variance value | |
| 1519 |
+--------------+------------------------------------------------------+ |
| 1520 |
| stdev | calculate standard deviation | |
| 1521 |
+--------------+------------------------------------------------------+ |
| 1522 |
| skewness | calculate the skewness | |
| 1523 |
+--------------+------------------------------------------------------+ |
| 1524 |
| kurtosis | calculate the kurtosis | |
| 1525 |
+--------------+------------------------------------------------------+ |
| 1526 |
| sum | calculate sum of all values | |
| 1527 |
+--------------+------------------------------------------------------+ |
| 1528 |
| minmax | calculate minimum and maximum value | |
| 1529 |
+--------------+------------------------------------------------------+ |
| 1530 |
| min | calculate minimum value | |
| 1531 |
+--------------+------------------------------------------------------+ |
| 1532 |
| max | calculate maximum value | |
| 1533 |
+--------------+------------------------------------------------------+ |
| 1534 |
| histogram | calculate the histogram | |
| 1535 |
+--------------+------------------------------------------------------+ |
| 1536 |
| histogram2d | calculate the two-dimensional histogram for two bands| |
| 1537 |
+--------------+------------------------------------------------------+ |
| 1538 |
| rmse | calculate root mean square error for two bands | |
| 1539 |
+--------------+------------------------------------------------------+ |
| 1540 |
| regresssion | calculate the regression between two bands | |
| 1541 |
+--------------+------------------------------------------------------+ |
| 1542 |
|
| 1543 |
For the histogram function, the following key values can be set: |
| 1544 |
|
| 1545 |
+--------------+------------------------------------------------------+ |
| 1546 |
| key | description | |
| 1547 |
+=====================+===============================================+ |
| 1548 |
| nbin | Number of bins for the histogram | |
| 1549 |
+--------------+------------------------------------------------------+ |
| 1550 |
| relative | Set to True to report percentage values | |
| 1551 |
+--------------+------------------------------------------------------+ |
| 1552 |
| kde | Set to True to use Kernel density estimation when | |
| 1553 |
| | producing histogram. The standard deviation is | |
| 1554 |
| | estimated based on Silverman's rule of thumb | |
| 1555 |
+--------------+------------------------------------------------------+ |
| 1556 |
|
| 1557 |
Example: |
| 1558 |
|
| 1559 |
Get the histogram of the input raster dataset using 10 bins:: |
| 1560 |
|
| 1561 |
jim.getStats({'function':['histogram','nbin':10}) |
| 1562 |
|
| 1563 |
END |
| 1564 |
|
| 1565 |
METHOD statProfile(dict) |
| 1566 |
Obtain a statistical profile per pixel based on a multi-band input raster dataset. Multiple functions can be set, resulting in a multi-band raster dataset (one output band for each function). |
| 1567 |
|
| 1568 |
Args: |
| 1569 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1570 |
|
| 1571 |
Returns: |
| 1572 |
The statistical profile of the input raster dataset |
| 1573 |
|
| 1574 |
Supported keys in the dict: |
| 1575 |
|
| 1576 |
|
| 1577 |
+------------------+---------------------------------------------------------------------------------+ |
| 1578 |
| key | value | |
| 1579 |
+==================+=================================================================================+ |
| 1580 |
| function | Statistical function (see values for different functions in tables below) | |
| 1581 |
+------------------+---------------------------------------------------------------------------------+ |
| 1582 |
| nodata | Do not take these values into account when calculating statistics | |
| 1583 |
+------------------+---------------------------------------------------------------------------------+ |
| 1584 |
| otype | Data type for output image | |
| 1585 |
+------------------+---------------------------------------------------------------------------------+ |
| 1586 |
|
| 1587 |
|
| 1588 |
**Statistical profile functions** |
| 1589 |
|
| 1590 |
+--------------+------------------------------------------------------+ |
| 1591 |
| function | description | |
| 1592 |
+=====================+===============================================+ |
| 1593 |
| nvalid | report number of valid (not nodata) values in window | |
| 1594 |
+--------------+------------------------------------------------------+ |
| 1595 |
| median | perform a median filter | |
| 1596 |
+--------------+------------------------------------------------------+ |
| 1597 |
| var | calculate variance in window | |
| 1598 |
+--------------+------------------------------------------------------+ |
| 1599 |
| min | calculate minimum in window | |
| 1600 |
+--------------+------------------------------------------------------+ |
| 1601 |
| max | calculate maximum in window | |
| 1602 |
+--------------+------------------------------------------------------+ |
| 1603 |
| sum | calculate sum in window | |
| 1604 |
+--------------+------------------------------------------------------+ |
| 1605 |
| mode | calculate the mode (only for categorical values) | |
| 1606 |
+--------------+------------------------------------------------------+ |
| 1607 |
| mean | calculate mean in window | |
| 1608 |
+--------------+------------------------------------------------------+ |
| 1609 |
| stdev | calculate standard deviation in window | |
| 1610 |
+--------------+------------------------------------------------------+ |
| 1611 |
| percentile | calculate percentile value in window | |
| 1612 |
+--------------+------------------------------------------------------+ |
| 1613 |
| proportion | calculate proportion in window | |
| 1614 |
+--------------+------------------------------------------------------+ |
| 1615 |
|
| 1616 |
.. note:: |
| 1617 |
The 'percentile' function calculates the percentile value based on the pixel values in the multi-band input raster dataset. A number of percentiles can be calculated, e.g., 10th and 50th percentile, resulting in a multi-band output raster dataset (one band for each calculated percentile). The percentiles to be calculated can be set with the key 'perc' and a list of values. |
| 1618 |
|
| 1619 |
Example: |
| 1620 |
|
| 1621 |
Calculated the 10th and 50th percentiles for the multi-band input raster dataset jim:: |
| 1622 |
|
| 1623 |
jim_percentiles=jim.statProfile({'function':args.function,'perc':[10,50]}) |
| 1624 |
|
| 1625 |
END |
| 1626 |
|
| 1627 |
METHOD stretch(dict) |
| 1628 |
Stretch the input raster dataset. |
| 1629 |
|
| 1630 |
Args: |
| 1631 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1632 |
|
| 1633 |
Returns: |
| 1634 |
A dictionary with the results of the statistics, using the same keys as for the functions. |
| 1635 |
|
| 1636 |
Supported keys in the dict: |
| 1637 |
|
| 1638 |
+------------------+---------------------------------------------------------------------------------+ |
| 1639 |
| key | value | |
| 1640 |
+==================+=================================================================================+ |
| 1641 |
| function | Statistical function (see values for different functions in tables below) | |
| 1642 |
+------------------+---------------------------------------------------------------------------------+ |
| 1643 |
| down | Down sampling factor (in pixels x and y) to calculate the statistics on a subset| |
| 1644 |
+------------------+---------------------------------------------------------------------------------+ |
| 1645 |
| src_min | Clip source below this minimum value | |
| 1646 |
+------------------+---------------------------------------------------------------------------------+ |
| 1647 |
| src_max | Clip source above this minimum value | |
| 1648 |
+------------------+---------------------------------------------------------------------------------+ |
| 1649 |
| dst_min | Mininum value in output image | |
| 1650 |
+------------------+---------------------------------------------------------------------------------+ |
| 1651 |
| dst_max | Maximum value in output image | |
| 1652 |
+------------------+---------------------------------------------------------------------------------+ |
| 1653 |
| cc_min | Cumulative count cut from | |
| 1654 |
+------------------+---------------------------------------------------------------------------------+ |
| 1655 |
| cc_max | Cumulative count cut to | |
| 1656 |
+------------------+---------------------------------------------------------------------------------+ |
| 1657 |
| band | List of bands to stretch | |
| 1658 |
+------------------+---------------------------------------------------------------------------------+ |
| 1659 |
| eq | Set to True to perform histogram equalization | |
| 1660 |
+------------------+---------------------------------------------------------------------------------+ |
| 1661 |
| nodata | List of values not to take into account when stretching | |
| 1662 |
+------------------+---------------------------------------------------------------------------------+ |
| 1663 |
| otype | Data type for output image | |
| 1664 |
+------------------+---------------------------------------------------------------------------------+ |
| 1665 |
|
| 1666 |
Example: |
| 1667 |
|
| 1668 |
Stretch the input raster dataset using the cumulative counts of 5 and 95 percent. Then, the output is converted to Byte with a dynamic range that is calculated based on the number of user defined bits (NBIT=[1:8]):: |
| 1669 |
|
| 1670 |
CCMIN=5 |
| 1671 |
CCMAX=95 |
| 1672 |
NBIT=7 |
| 1673 |
jim_stretched=jim.({'cc_min':CCMIN,'cc_max':CCMAX,'dst_min':2**(8-NBIT),'dst_max':2**8-1,'otype':'GDT_Float32'}) |
| 1674 |
jim_byte=jim_stretched.convert({'otype':'GDT_Byte'}).pointOpBitShift(8-NBIT) |
| 1675 |
|
| 1676 |
END |
| 1677 |
|
| 1678 |
METHOD extractOgr(*args) |
| 1679 |
Extract pixel values from raster image using a vector dataset sample. |
| 1680 |
|
| 1681 |
Args: |
| 1682 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1683 |
|
| 1684 |
Returns: |
| 1685 |
A :py:class:`VectorOgr` with the same geometry as the sample vector dataset and an extra field for each of the calculated raster value (zonal) statistics. The same layer name(s) of the sample will be used for the output vector dataset. |
| 1686 |
|
| 1687 |
Supported keys in the dict: |
| 1688 |
|
| 1689 |
+------------------+---------------------------------------------------------------------------------+ |
| 1690 |
| key | value | |
| 1691 |
+==================+=================================================================================+ |
| 1692 |
| rule | Rule how to calculate zonal statistics per feature | |
| 1693 |
+------------------+---------------------------------------------------------------------------------+ |
| 1694 |
| copy | Copy these fields from the sample vector dataset (default is to copy all fields)| |
| 1695 |
+------------------+---------------------------------------------------------------------------------+ |
| 1696 |
| label | Create extra field named 'label' with this value | |
| 1697 |
+------------------+---------------------------------------------------------------------------------+ |
| 1698 |
| fid | Create extra field named 'fid' with this field identifier (sequence of features)| |
| 1699 |
+------------------+---------------------------------------------------------------------------------+ |
| 1700 |
| band | List of bands to extract (0 indexed). Default is to use extract all bands | |
| 1701 |
+------------------+---------------------------------------------------------------------------------+ |
| 1702 |
| bandname | List of band name corresponding to list of bands to extract | |
| 1703 |
+------------------+---------------------------------------------------------------------------------+ |
| 1704 |
| startband | Start band sequence number (0 indexed) | |
| 1705 |
+------------------+---------------------------------------------------------------------------------+ |
| 1706 |
| endband | End band sequence number (0 indexed) | |
| 1707 |
+------------------+---------------------------------------------------------------------------------+ |
| 1708 |
| output | Name of the output vector dataset in which the zonal statistics are saved | |
| 1709 |
+------------------+---------------------------------------------------------------------------------+ |
| 1710 |
| oformat | Output vector dataset format | |
| 1711 |
+------------------+---------------------------------------------------------------------------------+ |
| 1712 |
| co | Creation option for output vector dataset | |
| 1713 |
+------------------+---------------------------------------------------------------------------------+ |
| 1714 |
|
| 1715 |
**Supported rules for extraction** |
| 1716 |
|
| 1717 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1718 |
| rule | description | |
| 1719 |
+==================+===================================================================================================+ |
| 1720 |
| point | extract a single pixel within the polygon or on each point feature | |
| 1721 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1722 |
| allpoints | Extract all pixel values covered by the polygon | |
| 1723 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1724 |
| centroid | Extract pixel value at the centroid of the polygon | |
| 1725 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1726 |
| mean | Extract average of all pixel values within the polygon | |
| 1727 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1728 |
| stdev | Extract standard deviation of all pixel values within the polygon | |
| 1729 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1730 |
| median | Extract median of all pixel values within the polygon | |
| 1731 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1732 |
| min | Extract minimum value of all pixels within the polygon | |
| 1733 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1734 |
| max | Extract maximum value of all pixels within the polygon | |
| 1735 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1736 |
| sum | Extract sum of the values of all pixels within the polygon | |
| 1737 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1738 |
| mode | Extract the mode of classes within the polygon (classes must be set with the option class) | |
| 1739 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1740 |
| proportion | Extract proportion of class(es) within the polygon (classes must be set with the option class) | |
| 1741 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1742 |
| count | Extract count of class(es) within the polygon (classes must be set with the option class) | |
| 1743 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1744 |
| percentile | Extract percentile as defined by option perc (e.g, 95th percentile of values covered by polygon) | |
| 1745 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1746 |
|
| 1747 |
**Masking values from extract** |
| 1748 |
|
| 1749 |
To mask some pixels from the extraction process, there are some keys that can be used: |
| 1750 |
|
| 1751 |
+------------------+---------------------------------------------------------------------------------+ |
| 1752 |
| key | value | |
| 1753 |
+==================+=================================================================================+ |
| 1754 |
| srcnodata | List of nodata values not to extract | |
| 1755 |
+------------------+---------------------------------------------------------------------------------+ |
| 1756 |
| bndnodata | List of band in input image to check if pixel is valid (used for srcnodata) | |
| 1757 |
+------------------+---------------------------------------------------------------------------------+ |
| 1758 |
| mask | Use the the specified file as a validity mask | |
| 1759 |
+------------------+---------------------------------------------------------------------------------+ |
| 1760 |
| mskband | Use the the specified band of the mask file defined | |
| 1761 |
+------------------+---------------------------------------------------------------------------------+ |
| 1762 |
| msknodata | List of mask values not to extract | |
| 1763 |
+------------------+---------------------------------------------------------------------------------+ |
| 1764 |
| threshold | Maximum number of features to extract (use positive values for percentage value | |
| 1765 |
| | and negative value for absolute threshold) | |
| 1766 |
+------------------+---------------------------------------------------------------------------------+ |
| 1767 |
|
| 1768 |
Example: |
| 1769 |
|
| 1770 |
Open a raster sample dataset based on land cover map (e.g., Corine) and use it to extract a stratified sample of 100 points from an input raster dataset with four spectral bands ('B02', 'B03', 'B04', 'B08'). Only sample classes 2 (urban), 12 (agriculture), 25 (forest), 41 (water) and an aggregated (rest) class 50:: |
| 1771 |
|
| 1772 |
jim_ref=jl.createJim({'filename':'/path/to/landcovermap.tif'}) |
| 1773 |
|
| 1774 |
samplefn='path/to/sample.sqlite' |
| 1775 |
outputfn='path/to/output.sqlite' |
| 1776 |
|
| 1777 |
classDict={} |
| 1778 |
classDict['urban']=2 |
| 1779 |
classDict['agriculture']=12 |
| 1780 |
classDict['forest']=25 |
| 1781 |
classDict['water']=41 |
| 1782 |
classDict['rest']=50 |
| 1783 |
classFrom=range(0,50) |
| 1784 |
classTo=[50]*50 |
| 1785 |
for i in range(0,50): |
| 1786 |
if i>=1 and i<10: |
| 1787 |
classTo[i]=classDict['urban'] |
| 1788 |
elif i>=11 and i<22: |
| 1789 |
classTo[i]=classDict['agriculture'] |
| 1790 |
elif i>=23 and i<25: |
| 1791 |
classTo[i]=classDict['forest'] |
| 1792 |
elif i>=40 and i<45: |
| 1793 |
classTo[i]=classDict['water'] |
| 1794 |
else: |
| 1795 |
classTo[i]=classDict['rest'] |
| 1796 |
|
| 1797 |
|
| 1798 |
jim_ref=jl.createJim({'filename':args.reference,'dx':jim.getDeltaX(),'dy':jim.getDeltaY(),'ulx':jim.getUlx(),'uly':jim.getUly(),'lrx':jim.getLrx(),'lry':jim.getLry()}) |
| 1799 |
jim_ref=jim_ref.reclass({'class':classFrom,'reclass':classTo}) |
| 1800 |
|
| 1801 |
srcnodata=[0] |
| 1802 |
dict={'srcnodata':srcnodata} |
| 1803 |
dict.update({'output':output}) |
| 1804 |
dict.update({'class':sorted(classDict.values())}) |
| 1805 |
sampleSize=-100 #use negative values for absolute and positive values for percentage values |
| 1806 |
dict.update({'threshold':sampleSize}) |
| 1807 |
dict.update({'bandname':['B02','B03','B04','B08']}) |
| 1808 |
dict.update({'band':[0,1,2,3]}) |
| 1809 |
|
| 1810 |
sample=jim.extractImg(jim_ref,dict) |
| 1811 |
|
| 1812 |
END |
| 1813 |
|
| 1814 |
METHOD extractSample(dict) |
| 1815 |
Extract a random or grid sample from raster image. |
| 1816 |
|
| 1817 |
Args: |
| 1818 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1819 |
|
| 1820 |
Returns: |
| 1821 |
A :py:class:`VectorOgr` with fields for each of the calculated raster value (zonal) statistics. |
| 1822 |
|
| 1823 |
Supported keys in the dict: |
| 1824 |
|
| 1825 |
+------------------+---------------------------------------------------------------------------------+ |
| 1826 |
| key | value | |
| 1827 |
+==================+=================================================================================+ |
| 1828 |
| rule | Rule how to calculate zonal statistics per feature | |
| 1829 |
+------------------+---------------------------------------------------------------------------------+ |
| 1830 |
| buffer | Buffer for calculating statistics for point features (in number of pixels) | |
| 1831 |
+------------------+---------------------------------------------------------------------------------+ |
| 1832 |
| label | Create extra field named 'label' with this value | |
| 1833 |
+------------------+---------------------------------------------------------------------------------+ |
| 1834 |
| fid | Create extra field named 'fid' with this field identifier (sequence of features)| |
| 1835 |
+------------------+---------------------------------------------------------------------------------+ |
| 1836 |
| band | List of bands to extract (0 indexed). Default is to use extract all bands | |
| 1837 |
+------------------+---------------------------------------------------------------------------------+ |
| 1838 |
| bandname | List of band name corresponding to list of bands to extract | |
| 1839 |
+------------------+---------------------------------------------------------------------------------+ |
| 1840 |
| startband | Start band sequence number (0 indexed) | |
| 1841 |
+------------------+---------------------------------------------------------------------------------+ |
| 1842 |
| endband | End band sequence number (0 indexed) | |
| 1843 |
+------------------+---------------------------------------------------------------------------------+ |
| 1844 |
| output | Name of the output vector dataset in which the zonal statistics are saved | |
| 1845 |
+------------------+---------------------------------------------------------------------------------+ |
| 1846 |
| ln | Layer name of output vector dataset | |
| 1847 |
+------------------+---------------------------------------------------------------------------------+ |
| 1848 |
| oformat | Output vector dataset format | |
| 1849 |
+------------------+---------------------------------------------------------------------------------+ |
| 1850 |
| co | Creation option for output vector dataset | |
| 1851 |
+------------------+---------------------------------------------------------------------------------+ |
| 1852 |
|
| 1853 |
**Supported rules for extraction** |
| 1854 |
|
| 1855 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1856 |
| rule | description | |
| 1857 |
+==================+===================================================================================================+ |
| 1858 |
| point | extract a single pixel within the polygon or on each point feature | |
| 1859 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1860 |
| allpoints | Extract all pixel values covered by the polygon | |
| 1861 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1862 |
| centroid | Extract pixel value at the centroid of the polygon | |
| 1863 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1864 |
| mean | Extract average of all pixel values within the polygon | |
| 1865 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1866 |
| stdev | Extract standard deviation of all pixel values within the polygon | |
| 1867 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1868 |
| median | Extract median of all pixel values within the polygon | |
| 1869 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1870 |
| min | Extract minimum value of all pixels within the polygon | |
| 1871 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1872 |
| max | Extract maximum value of all pixels within the polygon | |
| 1873 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1874 |
| sum | Extract sum of the values of all pixels within the polygon | |
| 1875 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1876 |
| mode | Extract the mode of classes within the polygon (classes must be set with the option class) | |
| 1877 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1878 |
| proportion | Extract proportion of class(es) within the polygon (classes must be set with the option class) | |
| 1879 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1880 |
| count | Extract count of class(es) within the polygon (classes must be set with the option class) | |
| 1881 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1882 |
| percentile | Extract percentile as defined by option perc (e.g, 95th percentile of values covered by polygon) | |
| 1883 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1884 |
|
| 1885 |
.. note:: |
| 1886 |
For the rules mode, proportion and count, set the extra key 'class' with the list of class values in the input raster image to use. |
| 1887 |
|
| 1888 |
**Masking values from extract** |
| 1889 |
|
| 1890 |
To mask some pixels from the extraction process, there are some keys that can be used: |
| 1891 |
|
| 1892 |
+------------------+---------------------------------------------------------------------------------+ |
| 1893 |
| key | value | |
| 1894 |
+==================+=================================================================================+ |
| 1895 |
| srcnodata | List of nodata values not to extract | |
| 1896 |
+------------------+---------------------------------------------------------------------------------+ |
| 1897 |
| bndnodata | List of band in input image to check if pixel is valid (used for srcnodata) | |
| 1898 |
+------------------+---------------------------------------------------------------------------------+ |
| 1899 |
| mask | Use the the specified file as a validity mask | |
| 1900 |
+------------------+---------------------------------------------------------------------------------+ |
| 1901 |
| mskband | Use the the specified band of the mask file defined | |
| 1902 |
+------------------+---------------------------------------------------------------------------------+ |
| 1903 |
| msknodata | List of mask values not to extract | |
| 1904 |
+------------------+---------------------------------------------------------------------------------+ |
| 1905 |
| threshold | Maximum number of features to extract (use positive values for percentage value | |
| 1906 |
| | and negative value for absolute threshold) | |
| 1907 |
+------------------+---------------------------------------------------------------------------------+ |
| 1908 |
|
| 1909 |
Example: |
| 1910 |
|
| 1911 |
Extract a random sample of 100 points, calculating the mean value based on a 3x3 window (buffer value of 1 pixel neighborhood) in a vector dataset in memory:: |
| 1912 |
|
| 1913 |
v01=jim0.extractSample({'random':100,'buffer':1,'rule':['mean'],'output':'mem01','oformat':'Memory'}) |
| 1914 |
v01.close() |
| 1915 |
|
| 1916 |
Extract a sample of 100 points using a regular grid sampling scheme. For each grid point, calculate the median value based on a 3x3 window (buffer value of 1 pixel neighborhood). Write the result in a SQLite vector dataset on disk:: |
| 1917 |
|
| 1918 |
outputfn='/path/to/output.sqlite' |
| 1919 |
npoint=100 |
| 1920 |
gridsize=int(jim.nrOfCol()*jim.getDeltaX()/math.sqrt(npoint)) |
| 1921 |
v=jim.extractSample({'grid':gridsize,'buffer':1,'rule':['median'],'output':output,'oformat':'SQLite'}) |
| 1922 |
v.write() |
| 1923 |
v.close() |
| 1924 |
|
| 1925 |
END |
| 1926 |
|
| 1927 |
METHOD extractImg(dict) |
| 1928 |
Extract a pixel values from an input raster dataset based on a raster sample dataset. |
| 1929 |
|
| 1930 |
Args: |
| 1931 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 1932 |
|
| 1933 |
Returns: |
| 1934 |
A :py:class:`VectorOgr` with fields for each of the calculated raster value (zonal) statistics. |
| 1935 |
|
| 1936 |
Supported keys in the dict: |
| 1937 |
|
| 1938 |
+------------------+---------------------------------------------------------------------------------+ |
| 1939 |
| key | value | |
| 1940 |
+==================+=================================================================================+ |
| 1941 |
| rule | Rule how to calculate zonal statistics per feature | |
| 1942 |
+------------------+---------------------------------------------------------------------------------+ |
| 1943 |
| class | List of classes to extract from the raster sample dataset. | |
| 1944 |
| | Leave empty to extract all valid data pixels from thee sample | |
| 1945 |
+------------------+---------------------------------------------------------------------------------+ |
| 1946 |
| cname | Name of the class label in the output vector dataset (default is 'label') | |
| 1947 |
+------------------+---------------------------------------------------------------------------------+ |
| 1948 |
| fid | Create extra field named 'fid' with this field identifier (sequence of features)| |
| 1949 |
+------------------+---------------------------------------------------------------------------------+ |
| 1950 |
| band | List of bands to extract (0 indexed). Default is to use extract all bands | |
| 1951 |
+------------------+---------------------------------------------------------------------------------+ |
| 1952 |
| bandname | List of band name corresponding to list of bands to extract | |
| 1953 |
+------------------+---------------------------------------------------------------------------------+ |
| 1954 |
| startband | Start band sequence number (0 indexed) | |
| 1955 |
+------------------+---------------------------------------------------------------------------------+ |
| 1956 |
| endband | End band sequence number (0 indexed) | |
| 1957 |
+------------------+---------------------------------------------------------------------------------+ |
| 1958 |
| down | Down sampling factor to extract a subset of the sample based on a grid | |
| 1959 |
+------------------+---------------------------------------------------------------------------------+ |
| 1960 |
| output | Name of the output vector dataset in which the zonal statistics are saved | |
| 1961 |
+------------------+---------------------------------------------------------------------------------+ |
| 1962 |
| ln | Layer name of output vector dataset | |
| 1963 |
+------------------+---------------------------------------------------------------------------------+ |
| 1964 |
| oformat | Output vector dataset format | |
| 1965 |
+------------------+---------------------------------------------------------------------------------+ |
| 1966 |
| co | Creation option for output vector dataset | |
| 1967 |
+------------------+---------------------------------------------------------------------------------+ |
| 1968 |
|
| 1969 |
**Supported rules for extraction** |
| 1970 |
|
| 1971 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1972 |
| rule | description | |
| 1973 |
+==================+===================================================================================================+ |
| 1974 |
| point | extract a single pixel within the polygon or on each point feature | |
| 1975 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1976 |
| allpoints | Extract all pixel values covered by the polygon | |
| 1977 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1978 |
| centroid | Extract pixel value at the centroid of the polygon | |
| 1979 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1980 |
| mean | Extract average of all pixel values within the polygon | |
| 1981 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1982 |
| stdev | Extract standard deviation of all pixel values within the polygon | |
| 1983 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1984 |
| median | Extract median of all pixel values within the polygon | |
| 1985 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1986 |
| min | Extract minimum value of all pixels within the polygon | |
| 1987 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1988 |
| max | Extract maximum value of all pixels within the polygon | |
| 1989 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1990 |
| sum | Extract sum of the values of all pixels within the polygon | |
| 1991 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1992 |
| mode | Extract the mode of classes within the polygon (classes must be set with the option class) | |
| 1993 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1994 |
| proportion | Extract proportion of class(es) within the polygon (classes must be set with the option class) | |
| 1995 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1996 |
| count | Extract count of class(es) within the polygon (classes must be set with the option class) | |
| 1997 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 1998 |
| percentile | Extract percentile as defined by option perc (e.g, 95th percentile of values covered by polygon) | |
| 1999 |
+------------------+---------------------------------------------------------------------------------------------------+ |
| 2000 |
|
| 2001 |
.. note:: |
| 2002 |
For the rules mode, proportion and count, set the extra key 'class' with the list of class values in the input raster image to use. |
| 2003 |
|
| 2004 |
**Masking values from extract** |
| 2005 |
|
| 2006 |
To mask some pixels from the extraction process, there are some keys that can be used: |
| 2007 |
|
| 2008 |
+------------------+---------------------------------------------------------------------------------+ |
| 2009 |
| key | value | |
| 2010 |
+==================+=================================================================================+ |
| 2011 |
| srcnodata | List of nodata values not to extract | |
| 2012 |
+------------------+---------------------------------------------------------------------------------+ |
| 2013 |
| bndnodata | List of band in input image to check if pixel is valid (used for srcnodata) | |
| 2014 |
+------------------+---------------------------------------------------------------------------------+ |
| 2015 |
| mask | Use the the specified file as a validity mask | |
| 2016 |
+------------------+---------------------------------------------------------------------------------+ |
| 2017 |
| mskband | Use the the specified band of the mask file defined | |
| 2018 |
+------------------+---------------------------------------------------------------------------------+ |
| 2019 |
| msknodata | List of mask values not to extract | |
| 2020 |
+------------------+---------------------------------------------------------------------------------+ |
| 2021 |
| threshold | Maximum number of features to extract (use positive values for percentage value | |
| 2022 |
| | and negative value for absolute threshold) | |
| 2023 |
+------------------+---------------------------------------------------------------------------------+ |
| 2024 |
|
| 2025 |
Example: |
| 2026 |
|
| 2027 |
Extract a random sample of 100 points, calculating the mean value based on a 3x3 window (buffer value of 1 pixel neighborhood) in a vector dataset in memory:: |
| 2028 |
|
| 2029 |
v01=jim0.extractSample({'random':100,'buffer':1,'rule':['mean'],'output':'mem01','oformat':'Memory'}) |
| 2030 |
v01.close() |
| 2031 |
|
| 2032 |
Extract a sample of 100 points using a regular grid sampling scheme. For each grid point, calculate the median value based on a 3x3 window (buffer value of 1 pixel neighborhood). Write the result in a SQLite vector dataset on disk:: |
| 2033 |
|
| 2034 |
outputfn='/path/to/output.sqlite' |
| 2035 |
npoint=100 |
| 2036 |
gridsize=int(jim.nrOfCol()*jim.getDeltaX()/math.sqrt(npoint)) |
| 2037 |
v=jim.extractSample({'grid':gridsize,'buffer':1,'rule':['median'],'output':output,'oformat':'SQLite'}) |
| 2038 |
v.write() |
| 2039 |
v.close() |
| 2040 |
|
| 2041 |
END |
| 2042 |
|
| 2043 |
######### |
| 2044 |
# JimList |
| 2045 |
######### |
| 2046 |
|
| 2047 |
CLASS JimList |
| 2048 |
JimList class represents a list of Jim images. |
| 2049 |
|
| 2050 |
Notes: |
| 2051 |
A JimList can be created from a python list of Jim images:: |
| 2052 |
|
| 2053 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 2054 |
jim0=createJim() |
| 2055 |
jlist=jl.createJimList([jim0]) |
| 2056 |
#do stuff with jim ... |
| 2057 |
jlist.close() |
| 2058 |
|
| 2059 |
END |
| 2060 |
|
| 2061 |
METHOD pushImage(Jim) |
| 2062 |
Push a Jim image to this JimList object |
| 2063 |
|
| 2064 |
Args: |
| 2065 |
* A :py:class:`Jim` object. |
| 2066 |
|
| 2067 |
Returns: |
| 2068 |
The :py:class:`JimList` (self) with the extra image pushed to the end |
| 2069 |
|
| 2070 |
Push a :py:class:`Jim` image object to an empty :py:class:`JimList`:: |
| 2071 |
|
| 2072 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 2073 |
jim0=createJim() |
| 2074 |
jlist=jl.createJimList() |
| 2075 |
jlist.pushImage(jim0) |
| 2076 |
#do stuff with jim ... |
| 2077 |
jlist.close() |
| 2078 |
|
| 2079 |
END |
| 2080 |
|
| 2081 |
METHOD popImage(Jim) |
| 2082 |
Pop a Jim image from this JimList |
| 2083 |
|
| 2084 |
Returns: |
| 2085 |
The :py:class:`JimList` (self) without the last image (that has been removed) |
| 2086 |
|
| 2087 |
Pop a :py:class`Jim` image object to an empty :py:class:`JimList`:: |
| 2088 |
|
| 2089 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 2090 |
jim0=createJim() |
| 2091 |
jlist=jl.createJimList() |
| 2092 |
jlist.pushImage(jim0) |
| 2093 |
jlist.popImage() |
| 2094 |
jlist.close() |
| 2095 |
|
| 2096 |
END |
| 2097 |
|
| 2098 |
METHOD getImage(integer) |
| 2099 |
Get an image at the specified index (0 based) |
| 2100 |
|
| 2101 |
Args: |
| 2102 |
* ``Integer`` the index of the index to get (0 based). |
| 2103 |
|
| 2104 |
Returns: |
| 2105 |
The :py:class:`Jim` object at the specified index |
| 2106 |
|
| 2107 |
Push an image to an empty list and get it back:: |
| 2108 |
|
| 2109 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 2110 |
jim0=createJim() |
| 2111 |
jlist=jl.createJimList() |
| 2112 |
jlist.pushImage(jim0) |
| 2113 |
jim1=jlist.getImage(0) |
| 2114 |
#jim1 is a reference to jim0 |
| 2115 |
|
| 2116 |
END |
| 2117 |
|
| 2118 |
METHOD getSize() |
| 2119 |
Get number of images in list |
| 2120 |
|
| 2121 |
Returns: |
| 2122 |
The number of images in the list |
| 2123 |
|
| 2124 |
Push an image to an empty list and get it back:: |
| 2125 |
|
| 2126 |
ifn='/eos/jeodpp/data/SRS/Copernicus/S2/scenes/source/L1C/2017/08/05/065/S2A_MSIL1C_20170805T102031_N0205_R065_T32TNR_20170805T102535.SAFE/GRANULE/L1C_T32TNR_A011073_20170805T102535/IMG_DATA/T32TNR_20170805T102031_B08.jp2' |
| 2127 |
jim0=createJim() |
| 2128 |
jlist=jl.createJimList() |
| 2129 |
jlist.pushImage(jim0) |
| 2130 |
if jlist.getSize() != 1: |
| 2131 |
print("Error: size of list should be 1") |
| 2132 |
|
| 2133 |
END |
| 2134 |
|
| 2135 |
METHOD pushNoDataValue(float) |
| 2136 |
Push a no data value to this :py:class:`JimList` object. |
| 2137 |
|
| 2138 |
Args: |
| 2139 |
* ``Float`` the no data value |
| 2140 |
|
| 2141 |
Returns: |
| 2142 |
The :py:class:`JimList` (self) |
| 2143 |
|
| 2144 |
END |
| 2145 |
|
| 2146 |
|
| 2147 |
METHOD clearNoData(float) |
| 2148 |
Clear all no data values from this :py:class:`JimList` object. |
| 2149 |
|
| 2150 |
Returns: |
| 2151 |
The :py:class:`JimList` (self) |
| 2152 |
|
| 2153 |
END |
| 2154 |
|
| 2155 |
METHOD covers(*args) |
| 2156 |
Check if a geolocation is covered by this :py:class:`JimList` object. Only the coordinates of the point (variant 1) or region of interest (variant 2) are checked, irrespective of no data values. Set the additional flag to True if the region of interest must be entirely covered. |
| 2157 |
|
| 2158 |
Args (variant 1): |
| 2159 |
|
| 2160 |
* ``x`` (float): x coordinate in spatial reference system of the raster dataset |
| 2161 |
* ``y`` (float): y coordinate in spatial reference system of the raster dataset |
| 2162 |
|
| 2163 |
|
| 2164 |
Args (variant 2): |
| 2165 |
|
| 2166 |
* ``ulx`` (float): upper left x coordinate in spatial reference system of the raster dataset |
| 2167 |
* ``uly`` (float): upper left y coordinate in spatial reference system of the raster dataset |
| 2168 |
* ``lrx`` (float): lower right x coordinate in spatial reference system of the raster dataset |
| 2169 |
* ``lry`` (float): lower right x coordinate in spatial reference system of the raster dataset |
| 2170 |
* ``all`` (bool): set to True if the entire bounding box must be covered by the raster dataset |
| 2171 |
|
| 2172 |
Returns: |
| 2173 |
True if the raster dataset covers the point or region of interest. |
| 2174 |
|
| 2175 |
END |
| 2176 |
|
| 2177 |
METHOD selectGeo(*args) |
| 2178 |
Removes all images in this :py:class:`JimList` object if not covered by the coordinates of the point (variant 1) or region of interest (variant 2). |
| 2179 |
|
| 2180 |
Args (variant 1): |
| 2181 |
|
| 2182 |
* ``x`` (float): x coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2183 |
* ``y`` (float): y coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2184 |
|
| 2185 |
|
| 2186 |
Args (variant 2): |
| 2187 |
|
| 2188 |
* ``ulx`` (float): upper left x coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2189 |
* ``uly`` (float): upper left y coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2190 |
* ``lrx`` (float): lower right x coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2191 |
* ``lry`` (float): lower right x coordinate in spatial reference system of the this :py:class:`JimList` object |
| 2192 |
|
| 2193 |
|
| 2194 |
Returns: |
| 2195 |
A subset of the :py:class:`JimList` object that covers the point or region of interest. |
| 2196 |
|
| 2197 |
END |
| 2198 |
|
| 2199 |
METHOD getBoundingBox() |
| 2200 |
Get the bounding box of this :py:class:`JimList` object in georeferenced coordinates. |
| 2201 |
|
| 2202 |
Returns: |
| 2203 |
A list with the bounding box of this :py:class:`JimList` object in georeferenced coordinates. |
| 2204 |
|
| 2205 |
END |
| 2206 |
|
| 2207 |
METHOD getUlx() |
| 2208 |
Get the upper left corner x (georeferenced) coordinate of this :py:class:`JimList` object |
| 2209 |
|
| 2210 |
Returns: |
| 2211 |
The upper left corner x (georeferenced) coordinate of this :py:class:`JimList` object |
| 2212 |
|
| 2213 |
END |
| 2214 |
|
| 2215 |
METHOD getUly() |
| 2216 |
Get the upper left corner y (georeferenced) coordinate of this :py:class:`JimList` object |
| 2217 |
|
| 2218 |
Returns: |
| 2219 |
The upper left corner y (georeferenced) coordinate of this :py:class:`JimList` object |
| 2220 |
|
| 2221 |
END |
| 2222 |
|
| 2223 |
METHOD getLrx() |
| 2224 |
Get the lower left corner x (georeferenced) coordinate of this :py:class:`JimList` object |
| 2225 |
|
| 2226 |
Returns: |
| 2227 |
The lower left corner x (georeferenced) coordinate of this :py:class:`JimList` object |
| 2228 |
|
| 2229 |
END |
| 2230 |
|
| 2231 |
METHOD getLry() |
| 2232 |
Get the lower left corner y (georeferenced) coordinate of this :py:class:`JimList` object |
| 2233 |
|
| 2234 |
Returns: |
| 2235 |
The lower left corner y (georeferenced) coordinate of this :py:class:`JimList` object |
| 2236 |
|
| 2237 |
END |
| 2238 |
|
| 2239 |
METHOD composite(dict) |
| 2240 |
Composite overlapping :py:class:`Jim` raster datasets according to a composite rule. |
| 2241 |
This method can be used to mosaic and composite multiple (georeferenced) :py:class:`Jim` raster datasets. A mosaic can merge images with different geographical extents into a single larger image. Compositing resolves the overlapping pixels according to some rule (e.g, the median of all overlapping pixels). Input datasets can have a different bounding boxes and spatial resolution. |
| 2242 |
|
| 2243 |
Args: |
| 2244 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2245 |
|
| 2246 |
Supported keys in the dict: |
| 2247 |
|
| 2248 |
+------------------+---------------------------------------------------------------------------------+ |
| 2249 |
| key | value | |
| 2250 |
+==================+=================================================================================+ |
| 2251 |
| crule | Composite rule | |
| 2252 |
+------------------+---------------------------------------------------------------------------------+ |
| 2253 |
| band | band index(es) to crop (leave empty if all bands must be retained) | |
| 2254 |
+------------------+---------------------------------------------------------------------------------+ |
| 2255 |
| resample | Resampling method (near or bilinear) | |
| 2256 |
+------------------+---------------------------------------------------------------------------------+ |
| 2257 |
| otype | Data type for output image. Default is to inherit type from input image | |
| 2258 |
+------------------+---------------------------------------------------------------------------------+ |
| 2259 |
| a_srs | Override the projection for the output file | |
| 2260 |
+------------------+---------------------------------------------------------------------------------+ |
| 2261 |
| file | Create extra band in output representing number of observations (1) and/or | |
| 2262 |
| | sequence number of selected raster dataset in the list (2) for each pixel | |
| 2263 |
+------------------+---------------------------------------------------------------------------------+ |
| 2264 |
|
| 2265 |
Returns: |
| 2266 |
The composite :py:class:`Jim` raster dataset object |
| 2267 |
|
| 2268 |
**Managing no data values in input and output** |
| 2269 |
|
| 2270 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2271 |
| key | value | |
| 2272 |
+==================+=============================================================================================+ |
| 2273 |
| bndnodata | Band(s) in input image to check if pixel is valid (used for srcnodata, min and max options) | |
| 2274 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2275 |
| srcnodata | invalid value(s) for input raster dataset | |
| 2276 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2277 |
| bndnodata | Band(s) in input image to check if pixel is valid (used for srcnodata, min and max options) | |
| 2278 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2279 |
| min | flag values smaller or equal to this value as invalid | |
| 2280 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2281 |
| max | flag values larger or equal to this value as invalid | |
| 2282 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2283 |
| dstnodata | nodata value to put in output raster dataset if not valid or out of bounds | |
| 2284 |
+------------------+---------------------------------------------------------------------------------------------+ |
| 2285 |
|
| 2286 |
**Subset spatial region in coordinates of the image geospatial reference system** |
| 2287 |
|
| 2288 |
+------------------+---------------------------------------------------------------------------------+ |
| 2289 |
| key | value | |
| 2290 |
+==================+=================================================================================+ |
| 2291 |
| extent | Get boundary from extent from polygons in vector file | |
| 2292 |
+------------------+---------------------------------------------------------------------------------+ |
| 2293 |
| eo | Special extent options controlling rasterization | |
| 2294 |
+------------------+---------------------------------------------------------------------------------+ |
| 2295 |
| ln | Layer name of extent to crop | |
| 2296 |
+------------------+---------------------------------------------------------------------------------+ |
| 2297 |
| crop_to_cutline | True will crop the extent of the target dataset to the extent of the cutline | |
| 2298 |
| | The outside area will be set to no data (the value defined by the key 'nodata') | |
| 2299 |
+------------------+---------------------------------------------------------------------------------+ |
| 2300 |
| ulx | Upper left x value of bounding box to crop | |
| 2301 |
+------------------+---------------------------------------------------------------------------------+ |
| 2302 |
| uly | Upper left y value of bounding box to crop | |
| 2303 |
+------------------+---------------------------------------------------------------------------------+ |
| 2304 |
| lrx | Lower right x value of bounding box to crop | |
| 2305 |
+------------------+---------------------------------------------------------------------------------+ |
| 2306 |
| lry | Lower right y value of bounding box to crop | |
| 2307 |
+------------------+---------------------------------------------------------------------------------+ |
| 2308 |
| dx | Output resolution in x (default: keep original resolution) | |
| 2309 |
+------------------+---------------------------------------------------------------------------------+ |
| 2310 |
| dy | Output resolution in y (default: keep original resolution) | |
| 2311 |
+------------------+---------------------------------------------------------------------------------+ |
| 2312 |
| align | Align output bounding box to first input raster dataset in list | |
| 2313 |
+------------------+---------------------------------------------------------------------------------+ |
| 2314 |
|
| 2315 |
.. note:: |
| 2316 |
Possible values for the key 'eo' are: ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG. For instance you can use 'eo':'ATTRIBUTE=fieldname' |
| 2317 |
|
| 2318 |
**Supported composite rules** |
| 2319 |
|
| 2320 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2321 |
| composite rule | composite output | |
| 2322 |
+=================+=================================================================================+ |
| 2323 |
| overwrite | Overwrite overlapping pixels | |
| 2324 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2325 |
| maxndvi | Create a maximum NDVI (normalized difference vegetation index) composite | |
| 2326 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2327 |
| maxband | Select the pixel with a maximum value in the band specified by option cband | |
| 2328 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2329 |
| minband | Select the pixel with a minimum value in the band specified by option cband | |
| 2330 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2331 |
| mean | Calculate the mean (average) of overlapping pixels | |
| 2332 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2333 |
| stdev | Calculate the standard deviation of overlapping pixels | |
| 2334 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2335 |
| median | Calculate the median of overlapping pixels | |
| 2336 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2337 |
| mode | Select the mode of overlapping pixels (maximum voting): use for Byte images only| |
| 2338 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2339 |
| sum | Calculate the arithmetic sum of overlapping pixels | |
| 2340 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2341 |
| maxallbands | For each individual band, assign the maximum value found in all overlapping | |
| 2342 |
| | pixels. Unlike maxband, output band values cannot be attributed to a single | |
| 2343 |
| | (date) pixel in the input time series | |
| 2344 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2345 |
| minallbands | For each individual band, assign the minimum value found in all overlapping | |
| 2346 |
| | pixels. Unlike minband, output band values cannot be attributed to a single | |
| 2347 |
| | (date) pixel in the input time series | |
| 2348 |
+-----------------+---------------------------------------------------------------------------------+ |
| 2349 |
|
| 2350 |
.. note:: |
| 2351 |
Some rules require multiple input bands. For instance, the maxndvi rule calculates the NDVI per pixel based on two input bands. Use the extra key 'cband' to indicate the list of bands representing the red and near infrared band respectively. |
| 2352 |
|
| 2353 |
END |
| 2354 |
|
| 2355 |
METHOD stack(dict) |
| 2356 |
Stack all raster datasets in the list to a single multi-band raster dataset. |
| 2357 |
|
| 2358 |
Args: |
| 2359 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2360 |
|
| 2361 |
Supported keys in the dict: |
| 2362 |
|
| 2363 |
+------------------+---------------------------------------------------------------------------------+ |
| 2364 |
| key | value | |
| 2365 |
+==================+=================================================================================+ |
| 2366 |
| band | band index(es) to crop (leave empty if all bands must be retained) | |
| 2367 |
+------------------+---------------------------------------------------------------------------------+ |
| 2368 |
| otype | Data type for output image. Default is to inherit type from input image | |
| 2369 |
+------------------+---------------------------------------------------------------------------------+ |
| 2370 |
| a_srs | Override the projection for the output file | |
| 2371 |
+------------------+---------------------------------------------------------------------------------+ |
| 2372 |
|
| 2373 |
Returns: |
| 2374 |
Multi-band :py:class:`Jim` raster dataset object. |
| 2375 |
|
| 2376 |
END |
| 2377 |
|
| 2378 |
METHOD getStats(dict) |
| 2379 |
Calculate statistics of a raster dataset. |
| 2380 |
|
| 2381 |
Args: |
| 2382 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2383 |
|
| 2384 |
Returns: |
| 2385 |
A dictionary with the results of the statistics, using the same keys as for the functions. |
| 2386 |
|
| 2387 |
Supported keys in the dict: |
| 2388 |
|
| 2389 |
+------------------+---------------------------------------------------------------------------------+ |
| 2390 |
| key | value | |
| 2391 |
+==================+=================================================================================+ |
| 2392 |
| function | Statistical function (see values for different functions in tables below) | |
| 2393 |
+------------------+---------------------------------------------------------------------------------+ |
| 2394 |
| cband | List of bands on which to calculate the statistics | |
| 2395 |
+------------------+---------------------------------------------------------------------------------+ |
| 2396 |
| down | Down sampling factor (in pixels x and y) to calculate the statistics on a subset| |
| 2397 |
+------------------+---------------------------------------------------------------------------------+ |
| 2398 |
| src_min | Do not take smaller values into account when calculating statistics | |
| 2399 |
+------------------+---------------------------------------------------------------------------------+ |
| 2400 |
| src_max | Do not take higher values into account when calculating statistics | |
| 2401 |
+------------------+---------------------------------------------------------------------------------+ |
| 2402 |
| nodata | Do not take these values into account when calculating statistics | |
| 2403 |
+------------------+---------------------------------------------------------------------------------+ |
| 2404 |
| otype | Data type for output image | |
| 2405 |
+------------------+---------------------------------------------------------------------------------+ |
| 2406 |
|
| 2407 |
.. note:: |
| 2408 |
For statistical functions requiring two sets of inputs, use a list of two values for cband (e.g., regression and histogram2d) |
| 2409 |
|
| 2410 |
**Supported statistical functions** |
| 2411 |
|
| 2412 |
+--------------+------------------------------------------------------+ |
| 2413 |
| function | description | |
| 2414 |
+==============+======================================================+ |
| 2415 |
| invalid | report number of invalid (nodata) values | |
| 2416 |
+--------------+------------------------------------------------------+ |
| 2417 |
| nvalid | report number of valid (not nodata) values | |
| 2418 |
+--------------+------------------------------------------------------+ |
| 2419 |
| basic | Shows basic statistics | |
| 2420 |
| | (min,max, mean and stdDev of the raster datasets) | |
| 2421 |
+--------------+------------------------------------------------------+ |
| 2422 |
| gdal | Use the GDAL calculation of basic statistics | |
| 2423 |
+--------------+------------------------------------------------------+ |
| 2424 |
| mean | calculate the mean value | |
| 2425 |
+--------------+------------------------------------------------------+ |
| 2426 |
| median | calculate the median value | |
| 2427 |
+--------------+------------------------------------------------------+ |
| 2428 |
| var | calculate variance value | |
| 2429 |
+--------------+------------------------------------------------------+ |
| 2430 |
| stdev | calculate standard deviation | |
| 2431 |
+--------------+------------------------------------------------------+ |
| 2432 |
| skewness | calculate the skewness | |
| 2433 |
+--------------+------------------------------------------------------+ |
| 2434 |
| kurtosis | calculate the kurtosis | |
| 2435 |
+--------------+------------------------------------------------------+ |
| 2436 |
| sum | calculate sum of all values | |
| 2437 |
+--------------+------------------------------------------------------+ |
| 2438 |
| minmax | calculate minimum and maximum value | |
| 2439 |
+--------------+------------------------------------------------------+ |
| 2440 |
| min | calculate minimum value | |
| 2441 |
+--------------+------------------------------------------------------+ |
| 2442 |
| max | calculate maximum value | |
| 2443 |
+--------------+------------------------------------------------------+ |
| 2444 |
| histogram | calculate the histogram | |
| 2445 |
+--------------+------------------------------------------------------+ |
| 2446 |
| histogram2d | calculate the two-dimensional histogram for two bands| |
| 2447 |
+--------------+------------------------------------------------------+ |
| 2448 |
| rmse | calculate root mean square error for two bands | |
| 2449 |
+--------------+------------------------------------------------------+ |
| 2450 |
| regresssion | calculate the regression between two bands | |
| 2451 |
+--------------+------------------------------------------------------+ |
| 2452 |
|
| 2453 |
For the histogram function, the following key values can be set: |
| 2454 |
|
| 2455 |
+--------------+------------------------------------------------------+ |
| 2456 |
| key | description | |
| 2457 |
+==============+======================================================+ |
| 2458 |
| nbin | Number of bins for the histogram | |
| 2459 |
+--------------+------------------------------------------------------+ |
| 2460 |
| relative | Set to True to report percentage values | |
| 2461 |
+--------------+------------------------------------------------------+ |
| 2462 |
| kde | Set to True to use Kernel density estimation when | |
| 2463 |
| | producing histogram. The standard deviation is | |
| 2464 |
| | estimated based on Silverman's rule of thumb | |
| 2465 |
+--------------+------------------------------------------------------+ |
| 2466 |
|
| 2467 |
Example: |
| 2468 |
|
| 2469 |
Get the histogram of the input raster dataset using 10 bins:: |
| 2470 |
|
| 2471 |
jlist.getStats({'function':['histogram','nbin':10}) |
| 2472 |
|
| 2473 |
END |
| 2474 |
|
| 2475 |
METHOD statProfile(dict) |
| 2476 |
Obtain a statistical profile per pixel based on the data available in a :py:class:`JimList` object. Multiple functions can be set, resulting in a multi-band raster dataset (one output band for each function). |
| 2477 |
|
| 2478 |
Args: |
| 2479 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2480 |
|
| 2481 |
Returns: |
| 2482 |
The statistical profile of the input raster dataset |
| 2483 |
|
| 2484 |
Supported keys in the dict: |
| 2485 |
|
| 2486 |
|
| 2487 |
+------------------+---------------------------------------------------------------------------------+ |
| 2488 |
| key | value | |
| 2489 |
+==================+=================================================================================+ |
| 2490 |
| function | Statistical function (see values for different functions in tables below) | |
| 2491 |
+------------------+---------------------------------------------------------------------------------+ |
| 2492 |
| nodata | Do not take these values into account when calculating statistics | |
| 2493 |
+------------------+---------------------------------------------------------------------------------+ |
| 2494 |
| otype | Data type for output image | |
| 2495 |
+------------------+---------------------------------------------------------------------------------+ |
| 2496 |
|
| 2497 |
|
| 2498 |
**Statistical profile functions** |
| 2499 |
|
| 2500 |
+--------------+------------------------------------------------------+ |
| 2501 |
| function | description | |
| 2502 |
+==============+======================================================+ |
| 2503 |
| nvalid | report number of valid (not nodata) values in window | |
| 2504 |
+--------------+------------------------------------------------------+ |
| 2505 |
| median | perform a median filter | |
| 2506 |
+--------------+------------------------------------------------------+ |
| 2507 |
| var | calculate variance in window | |
| 2508 |
+--------------+------------------------------------------------------+ |
| 2509 |
| min | calculate minimum in window | |
| 2510 |
+--------------+------------------------------------------------------+ |
| 2511 |
| max | calculate maximum in window | |
| 2512 |
+--------------+------------------------------------------------------+ |
| 2513 |
| sum | calculate sum in window | |
| 2514 |
+--------------+------------------------------------------------------+ |
| 2515 |
| mode | calculate the mode (only for categorical values) | |
| 2516 |
+--------------+------------------------------------------------------+ |
| 2517 |
| mean | calculate mean in window | |
| 2518 |
+--------------+------------------------------------------------------+ |
| 2519 |
| stdev | calculate standard deviation in window | |
| 2520 |
+--------------+------------------------------------------------------+ |
| 2521 |
| percentile | calculate percentile value in window | |
| 2522 |
+--------------+------------------------------------------------------+ |
| 2523 |
| proportion | calculate proportion in window | |
| 2524 |
+--------------+------------------------------------------------------+ |
| 2525 |
|
| 2526 |
.. note:: |
| 2527 |
The 'percentile' function calculates the percentile value based on the pixel values in the multi-band input raster dataset. A number of percentiles can be calculated, e.g., 10th and 50th percentile, resulting in a multi-band output raster dataset (one band for each calculated percentile). The percentiles to be calculated can be set with the key 'perc' and a list of values. |
| 2528 |
|
| 2529 |
Example: |
| 2530 |
|
| 2531 |
Calculated the 10th and 50th percentiles for the multi-band input raster dataset jim:: |
| 2532 |
|
| 2533 |
jim_percentiles=jlist.statProfile({'function':args.function,'perc':[10,50]}) |
| 2534 |
|
| 2535 |
END |
| 2536 |
|
| 2537 |
########### |
| 2538 |
# VectorOgr |
| 2539 |
########### |
| 2540 |
|
| 2541 |
CLASS VectorOgr |
| 2542 |
VectorOgr class is the basis vector dataset class of the Joint image processing library. |
| 2543 |
|
| 2544 |
|
| 2545 |
END |
| 2546 |
|
| 2547 |
METHOD getLayerCount() |
| 2548 |
Get number of layers in this vector dataset |
| 2549 |
|
| 2550 |
Returns: |
| 2551 |
The number of layers in this vector dataset |
| 2552 |
END |
| 2553 |
|
| 2554 |
METHOD getFeatureCount() |
| 2555 |
Get number of features in this vector dataset |
| 2556 |
|
| 2557 |
Returns: |
| 2558 |
The number of features in this vector dataset |
| 2559 |
END |
| 2560 |
|
| 2561 |
METHOD getBoundingBox() |
| 2562 |
Get the bounding box of this dataset in georeferenced coordinates. |
| 2563 |
|
| 2564 |
Returns: |
| 2565 |
A list with the bounding box of this dataset in georeferenced coordinates. |
| 2566 |
|
| 2567 |
END |
| 2568 |
|
| 2569 |
METHOD getUlx() |
| 2570 |
Get the upper left corner x (georeferenced) coordinate of this dataset |
| 2571 |
|
| 2572 |
Returns: |
| 2573 |
The upper left corner x (georeferenced) coordinate of this dataset |
| 2574 |
|
| 2575 |
END |
| 2576 |
|
| 2577 |
METHOD getUly() |
| 2578 |
Get the upper left corner y (georeferenced) coordinate of this dataset |
| 2579 |
|
| 2580 |
Returns: |
| 2581 |
The upper left corner y (georeferenced) coordinate of this dataset |
| 2582 |
|
| 2583 |
END |
| 2584 |
|
| 2585 |
METHOD getLrx() |
| 2586 |
Get the lower left corner x (georeferenced) coordinate of this dataset |
| 2587 |
|
| 2588 |
Returns: |
| 2589 |
The lower left corner x (georeferenced) coordinate of this dataset |
| 2590 |
|
| 2591 |
END |
| 2592 |
|
| 2593 |
METHOD getLry() |
| 2594 |
Get the lower left corner y (georeferenced) coordinate of this dataset |
| 2595 |
|
| 2596 |
Returns: |
| 2597 |
The lower left corner y (georeferenced) coordinate of this dataset |
| 2598 |
|
| 2599 |
END |
| 2600 |
|
| 2601 |
METHOD open(dict) |
| 2602 |
Open a vector dataset |
| 2603 |
|
| 2604 |
Args: |
| 2605 |
|
| 2606 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2607 |
|
| 2608 |
Supported keys in the dict: |
| 2609 |
|
| 2610 |
======== =================================================== |
| 2611 |
filename Filename of the vector dataset |
| 2612 |
ln Layer name |
| 2613 |
======== =================================================== |
| 2614 |
|
| 2615 |
Returns: |
| 2616 |
This instance of VectorOgr object (self) |
| 2617 |
|
| 2618 |
**keys specific for reading vector datasets** |
| 2619 |
|
| 2620 |
=============== =================================================== |
| 2621 |
attributeFilter Set an attribute filter |
| 2622 |
noread Set this flag to True to not read data when opening |
| 2623 |
=============== =================================================== |
| 2624 |
|
| 2625 |
**keys specific for writing vector datasets** |
| 2626 |
|
| 2627 |
======== =================================================================== |
| 2628 |
a_srs Assign this projection (e.g., epsg:3035) |
| 2629 |
gtype Geometry type (default is wkbUnknown) |
| 2630 |
co Format dependent options controlling creation of the output file |
| 2631 |
oformat Output sample dataset format supported by OGR (default is "SQLite") |
| 2632 |
======== =================================================================== |
| 2633 |
|
| 2634 |
Example: |
| 2635 |
|
| 2636 |
Create a vector and open a dataset:: |
| 2637 |
|
| 2638 |
v0=jl.createVector() |
| 2639 |
v0.open({'filename':'/path/to/vector.sqlite'}) |
| 2640 |
|
| 2641 |
END |
| 2642 |
|
| 2643 |
METHOD close() |
| 2644 |
Close a vector dataset, releasing resources such as memory and OGR dataset handle. |
| 2645 |
|
| 2646 |
END |
| 2647 |
|
| 2648 |
METHOD write() |
| 2649 |
Write the vector dataset to file |
| 2650 |
|
| 2651 |
Returns: |
| 2652 |
This instance of Jim object (self) |
| 2653 |
|
| 2654 |
.. note:: |
| 2655 |
Unlike writing a raster dataset :py:class:`Jim` where the output filename and type can be defined at the time of writing, these parameters have already been set when opening the :py:class:`VectorOgr`. |
| 2656 |
|
| 2657 |
END |
| 2658 |
|
| 2659 |
METHOD train(dict) |
| 2660 |
Train a supervised classifier based on extracted data including label information (typically obtained via :py:func:`Jim:extractOgr`). |
| 2661 |
|
| 2662 |
Args: |
| 2663 |
|
| 2664 |
* ``dict`` (Python Dictionary) with key value pairs. Each key (a 'quoted' string) is separated from its value by a colon (:). The items are separated by commas and the dictionary is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}. A value can be a list that is also separated by commas and enclosed in square brackets []. |
| 2665 |
|
| 2666 |
Supported keys in the dict: |
| 2667 |
|
| 2668 |
======== ===================================================================================================================== |
| 2669 |
method Classification method: 'svm' (support vector machine), 'ann' (artificial neural network) |
| 2670 |
model Model filename to save trained classifier |
| 2671 |
label Attribute name for class label in training vector file (default: 'label') |
| 2672 |
bandname List of band names to use that correspond to the fields in the vector dataset. Leave empty to use all bands |
| 2673 |
class List of alpha numeric class names as defined in the label attribute (use only if labels contain not numerical values) |
| 2674 |
reclass List of numeric class values corresponding to the list defined by the class key |
| 2675 |
======== ===================================================================================================================== |
| 2676 |
|
| 2677 |
Returns: |
| 2678 |
|
| 2679 |
This instance of VectorOgr object (self) |
| 2680 |
|
| 2681 |
**Balancing the training sample** |
| 2682 |
|
| 2683 |
Keys used to balance the training sample: |
| 2684 |
|
| 2685 |
======== ================================================================================================ |
| 2686 |
balance Balance the input data to this number of samples for each class |
| 2687 |
random Randomize training data for balancing |
| 2688 |
min Set to a value to not take classes into account with a sample size that is lower than this value |
| 2689 |
======== ================================================================================================ |
| 2690 |
|
| 2691 |
**Support vector machine** |
| 2692 |
|
| 2693 |
The support vector machine (SVM) supervised classifier is described `here <http://dx.doi.org/10.1007/BF00994018>`_. The implementation in JIPlib is based on the open source `libsvm <https://www.csie.ntu.edu.tw/~cjlin/libsvm/>`_. |
| 2694 |
|
| 2695 |
Keys specific to the SVM: |
| 2696 |
|
| 2697 |
========== ====================================================================== |
| 2698 |
svmtype Type of SVM (C_SVC, nu_SVC,one_class, epsilon_SVR, nu_SVR)","C_SVC") |
| 2699 |
kerneltype Type of kernel function (linear,polynomial,radial,sigmoid) ","radial") |
| 2700 |
kd Degree in kernel function",3) |
| 2701 |
gamma Gamma in kernel function",1.0) |
| 2702 |
coef0 Coef0 in kernel function",0) |
| 2703 |
ccost The parameter C of C_SVC, epsilon_SVR, and nu_SVR",1000) |
| 2704 |
nu The parameter nu of nu_SVC, one_class SVM, and nu_SVR",0.5) |
| 2705 |
eloss The epsilon in loss function of epsilon_SVR",0.1) |
| 2706 |
cache Cache memory size in MB",100) |
| 2707 |
etol The tolerance of termination criterion",0.001) |
| 2708 |
shrink Whether to use the shrinking heuristics",false) |
| 2709 |
probest Whether to train a SVC or SVR model for probability estimates",true,2) |
| 2710 |
========== ====================================================================== |
| 2711 |
|
| 2712 |
**Artificial neural network** |
| 2713 |
|
| 2714 |
The artificial neural network (ANN) supervised classifier is based on the back propagation model as introduced by D. E. Rumelhart, G. E. Hinton, and R. J. Williams (Nature, vol. 323, pp. 533-536, 1986). The implementation is based on the open source C++ library fann (http://leenissen.dk/fann/wp/). |
| 2715 |
|
| 2716 |
|
| 2717 |
Keys specific to the ANN: |
| 2718 |
|
| 2719 |
========== ========================================================================== |
| 2720 |
nneuron List defining the number of neurons in each hidden layer in the neural network |
| 2721 |
connection Connection rate (default: 1.0 for a fully connected network |
| 2722 |
learning Learning rate (default: 0.7) |
| 2723 |
weights Weights for neural network. Apply to fully connected network only, starting from first input neuron to last output neuron, including the bias neurons (last neuron in each but last layer) |
| 2724 |
maxit Maximum epochs used for training the neural network (default: 500) |
| 2725 |
========== ========================================================================== |
| 2726 |
|
| 2727 |
.. note:: |
| 2728 |
To define two hidden layers with 3 and 5 neurons respectively, define a list of two values for the key 'nneuron': [3, 5]. |
| 2729 |
|
| 2730 |
END |