Skip to content
Snippets Groups Projects
Commit 60786d84 authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

Merge remote-tracking branch 'origin/roelo008-main-patch-53941' into working_20230227

Nog n X nu met hopelijk laatste commit
parents f5c7ca9b e5205a5b
No related branches found
No related tags found
1 merge request!2Working 202302378b
......@@ -13,15 +13,16 @@ Left and center are two integer arrays, called 'beheertypen' and 'top10'. These
|value|beheertypen|top10|
|-----|-----|-----|
|1|10|160|
|2|10|100
|3|10|143|
|4|11|142|
|5|11|143|
|6|11|144|
|7|11|100|
|8|12|161|
|9|13|144|
|1|11|142|
|2|13|160|
|3|11|143|
|4|13|144|
|5|10|100|
|6|10|143|
|7|10|160|
|8|11|144|
|9|12|161|
|10|11|100|
The combine tool is designed for use in conjunction with the [Multi-Reclass Tool](https://git.wur.nl/roelo008/mrt).
......@@ -84,35 +85,38 @@ Possible future developments include:
## How the Combine tool works
This section explains how the Combine tool works. Let's look at the two intput categorical rasters again:
![combined_raster](resources/demo_combined_raster.JPG)
![combined_raster](resources/input_rasters.JPG)
Firstly, the tool designs Windows of equal size that subdivide the input rasters. The default Window size in the tool is 2.000 x 2.000 (rows x columns). In this example we take two windows of size 4 rows * 2 columns. The position of the Window within the image is recorded as the top-left index. For Window01: `row 0, column 0` and for Window02: `row 0, column 2`.
Firstly, the tool designs Windows of equal size that subdivide the input rasters. Let's assume two windows of size 4 rows * 2 columns. The position of the Window within the image is recorded as the top-left index. For Window01: `row 0, column 0` and for Window02: `row 0, column 2`.
![Windows](resources/windows.JPG)
The following occurs for each window, and is processed in parallel.
The chunk of the input rasters as specified by the Window are read into memory. They are 'stacked' along the third-dimension, so that the input-raster-combinations can be determined.
A chunk of each input raster, as specified by the Window, is read into memory. These sub-arrays are 'stacked' along the third-dimension, so that the combinations of values in the input-rasters can be determined.
For Window01:
For Window01 the combinations are:
`combinations = (11, 142), (11, 142), (11, 143), (10, 100), (13, 144), (10, 143)`
`combinations = (11, 142), (11, 142), (13, 160), (11, 143), (13, 144), (10, 100), (13, 144), (10, 143)`
Removing duplicates, the following unique combinations remain:
`unique_combinations = (11, 142), (11, 143), (10, 100), (13, 144), (10, 143)`
`unique_combinations = (11, 142), (13, 160), (11, 143), (13, 144), (10, 100), (10, 143)`
A dictionary is built where the unique combinations are the _keys_ and their enumeration the values.
|key|value|
|-----|-----|
(11, 142)|1
(11, 143)|2
(10, 100)|3
(13, 160)|2
(11, 143)|3
(13, 144)|4
(10, 143)|5
(10, 100)|5
(10, 143)|6
Applying this dictionary to the _stack_ of sub-arrays, yields a `4x2`array:
!Image
![W01Reclassed.JPG](resources/W01_reclassed.JPG)
Applying the same procedure to the second window yields the following dictionary and array:
......@@ -122,53 +126,66 @@ Applying the same procedure to the second window yields the following dictionary
(11, 144)|2
(12, 161)|3
(10, 100)|4
(11, 142)|5
(11, 100)|5
(11, 142)|6
!Image
![W02Reclassed](resources/W02_reclassed.JPG)
The resulting arrays are written to file as `*.npz` files. The dictionaries linking combinations to enurations are stored in memory as property of the Window.
Once all Windows are processed, all combinations occuring in the input rasters are known (as the keys of the dictionaries). Repeated occurences are reduced to a single entry, creating a list of unique combinations. In the example, there area 8 unique combinations. A new dictionary is construed to map combinations to an output value:
Once all Windows are processed, all combinations occuring in the input rasters are known (as the keys of the dictionaries). In the example, there are 10 unique combinations. A new dictionary is construed to map the unique combinations to an output value:
|key|value|
|-----|-----|
(11, 142)|1
(11, 143)|2
(10, 100)|3
(13, 160)|2
(11, 143)|3
(13, 144)|4
(10, 143)|5
(10, 160)|6
(11, 144)|7
(12, 161)|8
(10, 100)|5
(10, 143)|6
(10, 160)|7
(11, 144)|8
(12, 161)|9
(11, 100)|10
The dictionary of each Window is updated to map the Window-specific output value to the joint output value. For Window01:
The dictionary of each Window is updated to map the Window-specific output value to the Joint-output value. For Window01:
|key|value|
|Output Value Window01|Joint-Output value|
|-----|-----|
1|1
2|2
3|3
4|4
5|5
6|6
and for Window02:
|key|value|
|Output Value Window02|Joint-Output value|
|-----|-----|
1|6
2|7
3|8
4|3
5|1
1|7
2|8
3|9
4|5
5|10
6|1
The temporay array of each Window is read from file and remapped according to the updated dictionary.
The temporary array of each Window is re-read from file and remapped according to the updated dictionary.
Writing the output to file occurs in a single Task that loops over all Windows. This is because writing to a GeoTiff from multiple processes is not possible.
For Window01:
![Window01 to joint](resources/W01_reclassed.JPG)
and Window02:
The remapped array is writting to file and positioned within the larger image according to the Window specs.
![Window02 to joint](resources/W02_reclassed_to_joint.JPG)
Writing the output to file occurs in a single Task that loops over all Windows. This is because writing to a GeoTiff from multiple processes is not possible.
The remapped array is positioned within the overall image according to the Window specs and then written to file. This creates the output array:
![Output](resources/JointOutputArray.JPG)
## Support
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment