Skip to content

Commit c19a2a0

Browse files
committed
Little tweaks to wording and code style for nodata page
Signed-off-by: Jason T. Brown <[email protected]>
1 parent c7a850e commit c19a2a0

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

pyrasterframes/src/main/python/docs/nodata-handling.pymd

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ display(sample[1])
148148

149149
## NoData and Local Arithmatic
150150

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.
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.
152152

153153

154154
```python
@@ -161,27 +161,34 @@ y = Tile(np.zeros((tile_size, tile_size), dtype='int16'))
161161
rf = spark.createDataFrame([Row(x=x, y=y)])
162162
print('x')
163163
display(x)
164+
```
165+
166+
```python
164167
print('y')
165168
display(y)
166169
```
167170

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.
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.
169172

170173
```python
171174
masked_rf = rf.withColumn('x_nd', rf_mask_by_value('x', 'x', lit(1)) )
172175
masked_rf = masked_rf.withColumn('x_nd_y_sum', rf_local_add('x_nd', 'y'))
173176
row = masked_rf.collect()[0]
174177
print('x with NoData')
175178
display(row.x_nd)
176-
print('x with NoData and y sum')
179+
```
180+
181+
```python
182+
print('x with NoData plus y')
177183
display(row.x_nd_y_sum)
178184
```
185+
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).
179186

180187
## Changing a Tile's NoData Values
181188

182-
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.
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.
183190

184-
```python create_dummy_tile
191+
```python create_dummy_tile, caption='Dummy Tile'
185192
tile_size = 100
186193
x = np.zeros((tile_size, tile_size), dtype='int16')
187194

@@ -225,7 +232,7 @@ display(collected[0].tile_nd_2)
225232

226233
## Combining Tiles with Different Data Types
227234

228-
RasterFrames supports having Tile columns with multiple cell types in a single RasterFrame. It is important to understand how these different cell types interact.
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.
229236

230237
Let's first create a RasterFrame that has columns of `float` and `int` cell type.
231238

@@ -234,24 +241,25 @@ x = Tile((np.ones((100, 100))*2).astype('float'))
234241
y = Tile((np.ones((100, 100))*3.0).astype('int32'))
235242
rf = spark.createDataFrame([Row(x=x, y=y)])
236243

237-
rf.select(rf_cell_type('y'), rf_cell_type('x')).distinct().show()
244+
rf.select(rf_cell_type('x'), rf_cell_type('y')).distinct().show()
238245
```
239246

240-
When performing a local operation between tile columns with cell types `int` and type `float`, the resulting tile cell type will be `float`. If two tiles of different sized integer cell types are added together in the same way, the resulting cell type will be the same as the largest of the two integer cell types.
247+
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.
241248

242249
```python
243-
rf_added = rf.withColumn('xy_sum', rf_local_add('y', 'x'))
244-
rf_added.select(rf_cell_type('xy_sum'), rf_cell_type('y'), rf_cell_type('x')).distinct().show()
250+
rf.select(
251+
rf_cell_type('x'),
252+
rf_cell_type('y'),
253+
rf_cell_type(rf_local_add('x', 'y').alias('xy_sum')),
254+
).show(1)
245255
```
246256

247257
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.
248258

249259
```python
250-
x = Tile((np.ones((100, 100))*3).astype('int16'))
251-
rf = spark.createDataFrame([Row(x=x)])
252-
253-
rf_nd = rf.withColumn('x_nd_1', rf_convert_cell_type('x', get_nodata_ct(1))) \
254-
.withColumn('x_nd_2', rf_convert_cell_type('x', get_nodata_ct(2)))
260+
x_nd_1 = Tile((np.ones((100, 100))*3), get_nodata_ct(1))
261+
x_nd_2 = Tile((np.ones((100, 100))*3), get_nodata_ct(2))
262+
rf_nd = spark.createDataFrame([Row(x_nd_1=x_nd_1, x_nd_2=x_nd_2)])
255263
```
256264

257265
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.
@@ -268,9 +276,9 @@ rf_nd_sum = rf_nd.withColumn('x_nd_sum', rf_local_add('x_nd_1', 'x_nd_2'))
268276
rf_nd_sum.select(rf_cell_type('x_nd_sum')).distinct().show()
269277
```
270278

271-
## Nodata Values in Aggregation
279+
## NoData Values in Aggregation
272280

273-
Let's use the same tile as before to demonstrate how NoData values affect tile aggregations
281+
Let's use the same tile as before to demonstrate how NoData values affect tile aggregations.
274282

275283
```python
276284
tile_size = 100

0 commit comments

Comments
 (0)