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
And the original SCL data. The bright yellow is a cloudy region in the original image.
141
144
142
-
```python show_scl
145
+
```python, caption='SCL tile for above'
143
146
display(sample[1])
144
147
```
145
148
146
-
## NoData in Arithmetic Operations
149
+
## NoData and Local Arithmatic
147
150
148
-
local algebra example; same celltype what happens to nodata
149
-
Possibly use st_geomFromWkt and rf_rasterize to create something to work from
151
+
Let's now explore how the presence of NoData affects @ref:[local map algebra](local-algebra.md) 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.
150
152
151
-
agg
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
+
```
165
+
166
+
```python
167
+
print('y')
168
+
display(y)
169
+
```
170
+
171
+
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 local algebra operations, Data + NoData = NoData.
To see more information about possible operations on Tile columns, see the @ref:[local map algebra](local-algebra.md) page and @ref:[function reference](reference.md#local-map-algebra).
186
+
187
+
## Changing a Tile's NoData Values
188
+
189
+
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 DataFrame from a tile with values of 0, 1, 2, and 3. We will use numpy to create a 100x100 Tile with vertical bands containing values 0, 1, 2, and 3.
190
+
191
+
```python create_dummy_tile, caption='Dummy Tile'
192
+
tile_size = 100
193
+
x = np.zeros((tile_size, tile_size), dtype='int16')
194
+
195
+
# setting the values of the columns
196
+
for i in range(4):
197
+
x[:, i*tile_size//4:(i+1)*tile_size//4] = i
198
+
x = Tile(x)
199
+
200
+
rf = spark.createDataFrame([Row(tile=x)])
201
+
display(x)
202
+
```
203
+
204
+
First, we mask the value of 1 by making a new column with the user defined cell type 'uint16ud1'. Then, we mask out the value of two by making a tile with the cell type 'uint16ud2'.
Let's look at the new Tiles we created. The tile named `tile_nd_1` has the 1 values masked out as expected.
221
+
222
+
```python
223
+
display(collected[0].tile_nd_1)
224
+
```
225
+
226
+
And the tile named `tile_nd_2` has the values of 1 and 2 masked out. This is because we created the tile by setting a new user defined NoData value to `tile_nd_1` the values previously masked out in `tile_nd_1` stayed masked when creating `tile_nd_2`.
227
+
228
+
```python
229
+
display(collected[0].tile_nd_2)
230
+
```
152
231
153
232
154
-
## Dealing with Multiple Cell Types
233
+
## Combining Tiles with Different Data Types
155
234
156
-
Quick demo of one ND tile one raw tile
235
+
RasterFrames supports having Tile columns with multiple cell types in a single DataFrame. It is important to understand how these different cell types interact.
157
236
158
-
Quick demo of ND in two different cell types
237
+
Let's first create a RasterFrame that has columns of `float` and `int` cell type.
159
238
239
+
```python
240
+
x = Tile((np.ones((100, 100))*2).astype('float'))
241
+
y = Tile((np.ones((100, 100))*3.0).astype('int32'))
When performing a local operation between tile columns with cell types `int` and type `float`, the resulting tile cell type will be `float`. In local algebra over two tiles of different "sized" cell types, the resulting cell type will be the largest of the two input tiles' cell types.
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 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