Skip to content

Commit ba2848e

Browse files
committed
PR feedback.
1 parent e4e8bcb commit ba2848e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pyrasterframes/src/main/python/docs/raster-read.pymd

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,24 @@ display(tile)
5555

5656
## Multiple Singleband Rasters
5757

58-
In this example, we show reading [two bands](https://en.wikipedia.org/wiki/Multispectral_image) of [Landsat 8](https://landsat.gsfc.nasa.gov/landsat-8/) imagery (red and near-infrared), combining them with `rf_normalized_difference` to compute NDVI. As described in the section on @ref:[catalogs](raster-catalogs.md), image URIs in a single row are assumed to be from the same scene/granule, and therefore compatible. This pattern is commonly used when multiple bands are stored in separate files.
58+
In this example, we show the reading @ref:[two bands](concepts.md#band) of [Landsat 8](https://landsat.gsfc.nasa.gov/landsat-8/) imagery (red and near-infrared), combining them with `rf_normalized_difference` to compute [NDVI](https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index), a common measure of vegetation health. As described in the section on @ref:[catalogs](raster-catalogs.md), image URIs in a single row are assumed to be from the same scene/granule, and therefore compatible. This pattern is commonly used when multiple bands are stored in separate files.
5959

6060
```python, multi_singleband
6161
bands = [f'B{b}' for b in [4, 5]]
6262
uris = [f'https://landsat-pds.s3.us-west-2.amazonaws.com/c1/L8/014/032/LC08_L1TP_014032_20190720_20190731_01_T1/LC08_L1TP_014032_20190720_20190731_01_T1_{b}.TIF' for b in bands]
6363
catalog = ','.join(bands) + '\n' + ','.join(uris)
6464

65-
rf = spark.read.raster(catalog, bands) \
66-
.withColumnRenamed('B4', 'red').withColumnRenamed('B5', 'NIR') \
67-
.withColumn('longitude_latitude', st_reproject(st_centroid(rf_geometry('red')), rf_crs('red'), lit('EPSG:4326'))) \
68-
.withColumn('NDVI', rf_normalized_difference('NIR', 'red')) \
69-
.where(rf_tile_sum('NDVI') > 10000) \
70-
.select('longitude_latitude', 'red', 'NIR', 'NDVI')
65+
rf = (spark.read.raster(catalog, bands)
66+
# Adding semantic names
67+
.withColumnRenamed('B4', 'red').withColumnRenamed('B5', 'NIR')
68+
# Adding tile center point for reference
69+
.withColumn('longitude_latitude', st_reproject(st_centroid(rf_geometry('red')), rf_crs('red'), lit('EPSG:4326')))
70+
# Compute NDVI
71+
.withColumn('NDVI', rf_normalized_difference('NIR', 'red'))
72+
# For the purposes of inspection, filter out rows where there's not much vegetation
73+
.where(rf_tile_sum('NDVI') > 10000)
74+
# Order output
75+
.select('longitude_latitude', 'red', 'NIR', 'NDVI'))
7176
display(rf)
7277
```
7378

0 commit comments

Comments
 (0)