Skip to content

Commit c7ae7b7

Browse files
author
Leah Wasser
authored
Merge pull request #858 from earthlab/uncertainty-lessons
Uncertainty lessons & landing page fix
2 parents 53cd859 + e1edf01 commit c7ae7b7

File tree

9 files changed

+46
-46
lines changed

9 files changed

+46
-46
lines changed

_posts/courses/earth-analytics-python/04-raster-vector-extract-data/2018-06-15-lidar-remote-sensing-uncertainty-landing-page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ category: courses
44
title: "Lidar Remote Sensing Uncertainty - Compare Ground to Lidar Measurements of Tree Height in Python"
55
permalink: /courses/earth-analytics-python/lidar-remote-sensing-uncertainty/
66
week-landing: 4
7-
modified: 2020-02-06
7+
modified: 2020-02-11
88
week: 4
99
sidebar:
1010
nav:

_posts/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: "Extract Raster Values at Point Locations in Python"
44
excerpt: "For many scientific analyses, it is helpful to be able to select raster pixels based on their relationship to a vector dataset (e.g. locations, boundaries). Learn how to extract data from a raster dataset using a vector dataset."
55
authors: ['Leah Wasser', 'Chris Holdgraf', 'Carson Farmer']
66
dateCreated: 2016-12-06
7-
modified: 2020-02-05
7+
modified: 2020-02-11
88
category: [courses]
99
class-lesson: ['remote-sensing-uncertainty-python-tb']
1010
permalink: /courses/use-data-open-source-python/spatial-data-applications/lidar-remote-sensing-uncertainty/extract-data-from-raster/
@@ -65,7 +65,7 @@ import rasterstats as rs
6565
import earthpy as et
6666
import earthpy.plot as ep
6767

68-
# Setting consistent plotting style throughout notebook
68+
# Set consistent plotting style
6969
sns.set_style("white")
7070
sns.set(font_scale=1.5)
7171

@@ -74,6 +74,12 @@ data = et.data.get_data("spatial-vector-lidar")
7474
os.chdir(os.path.join(et.io.HOME, 'earth-analytics'))
7575
```
7676

77+
{:.output}
78+
Downloading from https://ndownloader.figshare.com/files/12459464
79+
Extracted output to /root/earth-analytics/data/spatial-vector-lidar/.
80+
81+
82+
7783
## Import Canopy Height Model
7884

7985
First, you will import a canopy height model created by the National Ecological Observatory Network (NEON). In the
@@ -93,30 +99,33 @@ sjer_lidar_chm_path = os.path.join("data", "spatial-vector-lidar",
9399
"2013", "lidar", "SJER_lidarCHM.tif")
94100

95101
with rio.open(sjer_lidar_chm_path) as sjer_lidar_chm_src:
102+
# Masked = True sets no data values to np.nan if they are in the metadata
96103
SJER_chm_data = sjer_lidar_chm_src.read(1, masked=True)
97104
sjer_chm_meta = sjer_lidar_chm_src.profile
98105

99-
fig, ax = plt.subplots(figsize=(8, 8))
100-
101-
ax.hist(SJER_chm_data.ravel(),
102-
color="purple")
106+
```
103107

104-
ax.set(xlabel="Lidar Estimated Tree Height (m)",
105-
ylabel="Total Pixels",
106-
title="Distribution of Pixel Values \n Lidar Canopy Height Model")
108+
{:.input}
109+
```python
110+
# Explore the data by plotting a histogram with earthpy
111+
ax=ep.hist(SJER_chm_data,
112+
figsize=(8,8),
113+
colors="purple",
114+
xlabel="Lidar Estimated Tree Height (m)",
115+
ylabel="Total Pixels",
116+
title="Distribution of Pixel Values \n Lidar Canopy Height Model")
107117

108118
# Turn off scientific notation
109-
ax.ticklabel_format(useOffset=False,
110-
style='plain')
119+
ax[1].ticklabel_format(useOffset=False,
120+
style='plain')
111121
```
112122

113123
{:.output}
114124
{:.display_data}
115125

116126
<figure>
117127

118-
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_5_0.png" alt = "Bar plot showing the distribution of lidar canopy height model pixel values.">
119-
<figcaption>Bar plot showing the distribution of lidar canopy height model pixel values.</figcaption>
128+
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_6_0.png">
120129

121130
</figure>
122131

@@ -125,14 +134,15 @@ ax.ticklabel_format(useOffset=False,
125134

126135
{:.input}
127136
```python
128-
# View summary statistics of canopy height model
129-
print('Mean:', SJER_chm_data.mean())
130-
print('Max:', SJER_chm_data.max())
131-
print('Min:', SJER_chm_data.min())
137+
# EXPLORE: View summary statistics of canopy height model
138+
# Notice the mean value with 0's included in the data
139+
print('Mean:', np.nanmean(SJER_chm_data))
140+
print('Max:', np.nanmax(SJER_chm_data))
141+
print('Min:', np.nanmin(SJER_chm_data))
132142
```
133143

134144
{:.output}
135-
Mean: 1.935586243204776
145+
Mean: 1.9355862
136146
Max: 45.879997
137147
Min: 0.0
138148

@@ -146,10 +156,10 @@ Set all pixel values `==0` to `nan` as they will impact calculation of plot mean
146156

147157
{:.input}
148158
```python
149-
# Set CHM values of 0 to NAN (no data or not a number)
159+
# CLEANUP: Set CHM values of 0 to NAN (no data or not a number)
150160
SJER_chm_data[SJER_chm_data == 0] = np.nan
151161

152-
# View summary statistics of canopy height model
162+
# View summary statistics of canopy height model after cleaning up the data
153163
print('Mean:', np.nanmean(SJER_chm_data))
154164
print('Max:', np.nanmax(SJER_chm_data))
155165
print('Min:', np.nanmin(SJER_chm_data))
@@ -162,39 +172,29 @@ print('Min:', np.nanmin(SJER_chm_data))
162172

163173

164174

165-
Look at the histogram of the data with the 0's removed. Now you can see the true distribution of heights in the data.
166-
Notice that below to plot the histogram an additional step is taken to remove `nan` values from the data. There are several ways to do this but here, we simply subset the data using
167-
168-
`SJER_chm_data[~np.isnan(SJER_chm_data)])`
169-
170-
Then the data are flattened into a 1-dimensional array to create the histogram:
171-
172-
`SJER_chm_data[~np.isnan(SJER_chm_data)].ravel()`
173-
175+
Look at the histogram of the data with the 0's removed. Now you can see the true distribution of heights in the data without the 0's.
174176

175177
{:.input}
176178
```python
177-
# Remove nans, flatten the data & plot historgram
178-
SJER_chm_data_no_na = SJER_chm_data[~np.isnan(SJER_chm_data)].ravel()
179+
# Explore the data by plotting a histogram with earthpy
180+
ax=ep.hist(SJER_chm_data,
181+
figsize=(8,8),
182+
colors="purple",
183+
xlabel="Lidar Estimated Tree Height (m)",
184+
ylabel="Total Pixels",
185+
title="Distribution of Pixel Values \n Lidar Canopy Height Model")
179186

180-
fig, ax = plt.subplots(figsize=(10, 10))
181-
182-
ax.hist(SJER_chm_data_no_na, color="purple")
183-
184-
ax.set(xlabel='Lidar Estimated Tree Height (m)',
185-
ylabel='Total Pixels',
186-
title='Distribution of Pixel Values \n Lidar Canopy Height Model')
187-
188-
ax.ticklabel_format(useOffset=False,
189-
style='plain')
187+
# Turn off scientific notation
188+
ax[1].ticklabel_format(useOffset=False,
189+
style='plain')
190190
```
191191

192192
{:.output}
193193
{:.display_data}
194194

195195
<figure>
196196

197-
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_10_0.png" alt = "Bar plot showing the distribution of lidar chm values with 0's removed.">
197+
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_11_0.png" alt = "Bar plot showing the distribution of lidar chm values with 0's removed.">
198198
<figcaption>Bar plot showing the distribution of lidar chm values with 0's removed.</figcaption>
199199

200200
</figure>
@@ -293,7 +293,7 @@ plt.show()
293293

294294
<figure>
295295

296-
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_15_0.png" alt = "Map showing SJER plot location points overlayed on top of the SJER Canopy Height Model.">
296+
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_16_0.png" alt = "Map showing SJER plot location points overlayed on top of the SJER Canopy Height Model.">
297297
<figcaption>Map showing SJER plot location points overlayed on top of the SJER Canopy Height Model.</figcaption>
298298

299299
</figure>
@@ -623,7 +623,7 @@ plt.show()
623623

624624
<figure>
625625

626-
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_25_0.png" alt = "Bar plot showing maximum tree height per plot in SJER.">
626+
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_26_0.png" alt = "Bar plot showing maximum tree height per plot in SJER.">
627627
<figcaption>Bar plot showing maximum tree height per plot in SJER.</figcaption>
628628

629629
</figure>
@@ -780,7 +780,7 @@ plt.show()
780780

781781
<figure>
782782

783-
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_29_0.png" alt = "Bar plots showing pixel value distribution for all SJER sites.">
783+
<img src = "{{ site.url }}/images/courses/intermediate-earth-data-science-textbook/04-spatial-data-applications/remote-sensing-uncertainty/2016-12-06-uncertainty02-extract-raster-values/2016-12-06-uncertainty02-extract-raster-values_30_0.png" alt = "Bar plots showing pixel value distribution for all SJER sites.">
784784
<figcaption>Bar plots showing pixel value distribution for all SJER sites.</figcaption>
785785

786786
</figure>

0 commit comments

Comments
 (0)