Skip to content

Commit

Permalink
compiled modis nrt with proper styling
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrinks committed Dec 21, 2023
1 parent 1539ced commit c6f4172
Show file tree
Hide file tree
Showing 18 changed files with 9,186 additions and 187 deletions.
29 changes: 15 additions & 14 deletions LANCE_MODIS_NRT_GlobalFlood_MCDWD.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The MODIS/Aqua+Terra Global Flood Product L3 Near Real Time (NRT) 250m Global Fl

[CRM SEARCH](https://cmr.earthdata.nasa.gov/search/concepts/C2018599131-LANCEMODIS.html)

```{r}
```{r message=FALSE, warning=FALSE}
packages_to_check <- c("stars", "httr", "jsonlite", "tmap")
# Check and install packages
Expand Down Expand Up @@ -99,6 +99,7 @@ if(!file.exists("modis_nrt_flood.nc")) {
download_link <- content_items$downloadsLink
print(download_link)
stars::write_stars(raster_df, "modis_nrt_flood.nc")
} else {
print("Request failed with status code", http_status(response)$status_code)
Expand All @@ -110,16 +111,15 @@ if(!file.exists("modis_nrt_flood.nc")) {
```


Use the "read_stars()" function from the "stars" R Library to read the geoTiff raster.
The raster is assigned to the "x" variable:
Use the "read_stars()" function from the "stars" R Library to read the geoTiff raster. The raster is assigned to the "x" variable:

```{r}
raster_df <- stars::read_stars(download_link)
```

Set the Coordinate reference system (CRS) to "EPSG:4326"

```{r}
my_raster <- st_set_crs(raster_df, st_crs("EPSG:4326"))
st_crs(my_raster)
Expand All @@ -139,17 +139,18 @@ Refer to the [MODIS NRT Global Flood Product User Guide](https://www.earthdata.n

NRT Flood data has 5 classifications:

| Code | Definition |
|:----:|:------------------------------------------------------|
| 0 | No Water |
| 1 | Surface Water |
| 2 | Recurring flood[^lance_modis_nrt_globalflood_mcdwd-1] |
| 3 | Flood (unusual) |
| 255 | Insufficient data |
| Code | Definition |
|:----:|:--------------------|
| 0 | No Water |
| 1 | Surface Water |
| 2 | Recurring flood[^1] |
| 3 | Flood (unusual) |
| 255 | Insufficient data |

[^lance_modis_nrt_globalflood_mcdwd-1]: Value 2 (Recurring flood) is not populated in the beta release.
[^1]: Value 2 (Recurring flood) is not populated in the beta release.

Create a classified legend; however, the NRT Flood data is stored in decimal numbers (aka floating-point). Create class breaks dividing the data by these breaks, and corresponding colors and labels:

```{r}
class_breaks <- c(-Inf, 0.1, 1.1, 2.1, 3.1)
colors <- c( "gray", "blue", "yellow","red")
Expand All @@ -159,11 +160,13 @@ labels = c("0: No Water", "1: Surface Water", "2: Recurring flood", "3: Flood (u
```

Add a title for the plot that includes the year, day of year, and tile code:

```{r}
title = paste("NRT Flood", year_day, tile_code)
```

Generate a plot from the tmap library using the tm_shape() function. With style as "cat," meaning categorical. T

```{r}
tmap_mode("view")
## tmap mode set to plotting
Expand All @@ -178,5 +181,3 @@ tm_shape(my_raster, style="cat" )+
```


Loading

0 comments on commit c6f4172

Please sign in to comment.