You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pyrasterframes/src/main/python/docs/nodata-handling.pymd
+72-35Lines changed: 72 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -146,6 +146,37 @@ And the original SCL data. The bright yellow is a cloudy region in the original
146
146
display(sample[1])
147
147
```
148
148
149
+
## NoData and Local Arithmatic
150
+
151
+
Let's now explore how the presence of NoData affects local arithmatic operations. To demonstrate the behaviour, lets create two tiles. One tile will have values of 0 and 1, and the other will have values of just 0.
152
+
153
+
154
+
```python
155
+
tile_size = 100
156
+
x = np.zeros((tile_size, tile_size), dtype='int16')
157
+
x[:,tile_size//2:] = 1
158
+
x = Tile(x)
159
+
y = Tile(np.zeros((tile_size, tile_size), dtype='int16'))
160
+
161
+
rf = spark.createDataFrame([Row(x=x, y=y)])
162
+
print('x')
163
+
display(x)
164
+
print('y')
165
+
display(y)
166
+
```
167
+
168
+
Now, let's create a new column from `x` with the value of 1 changed to NoData. Then, we will add this new column with NoData to the `y` column. As shown below, the result of the sum also has NoData (represented in white). In general for arithmatic operations, Data + NoData = NoData. To see more information about possible operations on Tile columns, see the @ref:[local map algebra](local-algebra.md) doc.
One way to mask a tile is to make a new tile with a user defined NoData value. We will explore this method below. First, lets create a rasterframe from a tile with values of 0, 1, 2, and 3. We will use numpy to create a 100x100 Tile with columns of 0, 1, 2, and 3.
@@ -191,36 +222,6 @@ And the tile named `tile_nd_2` has the values of 1 and 2 masked out. This is bec
191
222
display(collected[0].tile_nd_2)
192
223
```
193
224
194
-
## Nodata Values in Aggregation
195
-
196
-
Let's use the same tile as before to demonstrate how NoData values affect tile aggregations
197
-
198
-
```python
199
-
tile_size = 100
200
-
x = np.zeros((tile_size, tile_size), dtype='int16')
201
-
for i in range(4):
202
-
x[:, i*tile_size//4:(i+1)*tile_size//4] = i
203
-
x = Tile(x)
204
-
205
-
rf = spark.createDataFrame([Row(tile=x)])
206
-
display(x)
207
-
```
208
-
209
-
First we create the two new masked tile columns as before. One with only the value of 1 masked, and the other with and values of 1 and 2 masked.
The results of `rf_tile_sum` vary on the tiles that were masked. This is because any cells with NoData values are ignored in the aggregation. Note that `tile_nd_2` has the lowest sum, since it has the fewest amount of data cells.
Combining tile columns of different cell types gets a little trickier when user defined NoData cell types are involved. Let's create 3 tile columns: one without a defined NoData value, one with a NoData value of 1, and one with a NoData value of 2.
246
246
247
+
Combining tile columns of different cell types gets a little trickier when user defined NoData cell types are involved. Let's create 2 tile columns: one with a NoData value of 1, and one with a NoData value of 2.
Let's try adding the tile column without a defined NoData value to a tile column with a defined NoData value. When there is an inconsistent NoData value in the two columns, the NoData value of the right-hand side of the sum is kept. In this case, this means the result has no defined NoData value.
257
+
Let's try adding the tile columns with different NoData values. When there is an inconsistent NoData value in the two columns, the NoData value of the right-hand side of the sum is kept. In this case, this means the result has a NoData value of 1.
The results of `rf_tile_sum` vary on the tiles that were masked. This is because any cells with NoData values are ignored in the aggregation. Note that `tile_nd_2` has the lowest sum, since it has the fewest amount of data cells.
0 commit comments