Skip to content

Commit

Permalink
minor updates in epi 7, 8 and 10. Also exercise added in epi 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Morrizzzzz committed May 8, 2024
1 parent 0fe77f7 commit e5d65d2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
10 changes: 5 additions & 5 deletions episodes/07-vector-data-in-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ questions:

In the preceding episodes, we have prepared, selected and downloaded raster data from before and after the wildfire event in the summer of 2023 on the Greek island of Rhodes. To evaluate the impact of this wildfire on the vital infrastructure and built-up areas we are going to create a subset of vector data representing these assets. In this episode you will learn how to extract vector data with specific characteristics like the type of attributes or their locations. The dataset that we will generate in this episode can lateron be confronted with scorched areas which we determine by analyzing the satellite images [Episode 9: Raster Calculations in Python](09-raster-calculations.md).

We'll be examining vector datasets that represent the valuable assests of Rhodes. As mentioned in [Episode 2: Introduction to Vector Data](02-intro-vector-data.md), vector data uses points, lines, and polygons to depict specific features on the Earth's surface. These geographic elements can have one or more attributes, like 'name' and 'population' for a city. In this epidoe we'll be using two open data sources: the Database of Global Administrative Areas (GADM) dataset to generate a polygon for the island of Rhodes and and Open Street Map data for the vital infrastructure and valuable assets.
We'll be examining vector datasets that represent the valuable assests of Rhodes. As mentioned in [Episode 2: Introduction to Vector Data](02-intro-vector-data.md), vector data uses points, lines, and polygons to depict specific features on the Earth's surface. These geographic elements can have one or more attributes, like 'name' and 'population' for a city. In this episode we'll be using two open data sources: the Database of Global Administrative Areas (GADM) dataset to generate a polygon for the island of Rhodes and and Open Street Map data for the vital infrastructure and valuable assets.

To handle the vector data in python we use the package [`geopandas`](https://geopandas.org/en/stable/). This package allows us to open, manipulate, and write vector dataset through python.

Expand Down Expand Up @@ -308,16 +308,16 @@ Now it will be up to you to create a dataset with valueable assets. You should b
:::challenge
## Exercise: Get the built-up regions

Create a `builtup_buffer` from the file `data/osm_landuse.gpkg` by the following steps:
Create a `builtup_buffer` from the file `data/osm/osm_landuse.gpkg` by the following steps:

1. Load the land use data from `data/osm_landuse.gpkg` and mask it with the administrative boundary of Rhodes Island (`gdf_rhodes`).
1. Load the land use data from `data/osm/osm_landuse.gpkg` and mask it with the administrative boundary of Rhodes Island (`gdf_rhodes`).
2. Select the land use data for "commercial", "industrial", and "residential".
3. Create a 10m buffer around the land use data.
4. Visualize the results.

After completing the exercise, answer the following questions:

1. How many unique land use types are there in `landuse.gpkg`?
1. How many unique land use types are there in `osm_landuse.gpkg`?
2. After selecting the three types of land use, how many entries (rows) are there in the results?

Hints:
Expand All @@ -329,7 +329,7 @@ Hints:
::::solution
```python
# Read data with a mask of Rhodes
gdf_landuse = gpd.read_file('../data/osm/landuse.gpkg', mask=gdf_rhodes)
gdf_landuse = gpd.read_file('./data_workshop/osm/osm_landuse.gpkg', mask=gdf_rhodes)

# Find number of unique landuse types
print(len(gdf_landuse['fclass'].unique()))
Expand Down
52 changes: 50 additions & 2 deletions episodes/08-crop-raster-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,57 @@ visual_clip.plot.imshow()

![](fig/E08/visual_clip.png){alt="Clip results"}

:::challenge
## Exercise: Get the red band for the Rhodes

Now that you have seen how clip a raster using a polygon, we want you to do this for the red band of the sattelite image. Use the shape of Rhodes from GADM and clip the red band with it. Furthermore, make sure to transform the no data values to Not a Number values.

::::solution
```python
# Solution

# Step 1 - Load the datasets - Vector data

import geopandas as gpd
gdf_greece = gpd.read_file('./data_workshop/gadm/ADM_ADM_3.gpkg')
gdf_rhodes = gdf_greece.loc[gdf_greece['NAME_3']=='Rhodos']

# Step 2 - Load the raster red band
import rioxarray
path_red = './data_workshop/sentinel2/red.tif'
red = rioxarray.open_rasterio(path_red, overview_level=1)

# Step 3 - It will not work, since it is not projected yet

gdf_rhodes = gdf_rhodes.to_crs(red.rio.crs)

# Step 4 - Clip the two

red_clip = red.rio.clip(gdf_rhodes["geometry"])

# Step 5 - assing nan values to no data

red_clip_nan = red_clip.where(red_clip!=red_clip.rio.nodata)

# Step 6 - Visualize the result

red_clip_nan.plot()

```

![](fig/E08/solution_excercise.png){alt="rhodes_builtup_buffer"}

::::
:::






### Match two rasters

Sometimes you need to match two rasters with different extents, resolutions, or CRS. The `reproject_match` function can be used for this purpose. We will demonstrate this by matching the cropped raster `visual_clip` with the Digital Elevation Model (DEM),`rhodes_dem.tif` of Rhodes.
Sometimes you need to match two rasters with different extents, resolutions, or CRS. For this you can use the [`reproject_match`](https://corteva.github.io/rioxarray/stable/examples/reproject_match.html#Reproject-Match) function . We will demonstrate this by matching the cropped raster `visual_clip` with the Digital Elevation Model (DEM),`rhodes_dem.tif` of Rhodes.

First, let's load the DEM:

Expand Down Expand Up @@ -196,7 +244,7 @@ As we can see, `reproject_match` does a lot of helpful things in one line of cod
Finally, we can save the matched DEM for later use. We save it as a Cloud-Optimized GeoTIFF (COG) file:

```python
dem_match.rio.to_raster('dem_rhodes_match.tif', driver='COG')
dem_matched.rio.to_raster('dem_rhodes_match.tif', driver='COG')
```

:::callout
Expand Down
2 changes: 1 addition & 1 deletion episodes/10-zonal-statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exercises: 0
- Calculate raster statistics over zones
:::




## Introduction
Expand Down
Binary file added episodes/fig/E08/solution_exercise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5d65d2

Please sign in to comment.