From 8d3a1a3487274977e3b4f01c79e889dfa4ef04f5 Mon Sep 17 00:00:00 2001 From: Josh Brinks Date: Wed, 3 Jan 2024 10:28:35 -0500 Subject: [PATCH] large files to git ignore --- .gitignore | 4 ++++ docs/LANCE_MODIS_NRT_GlobalFlood_MCDWD.html | 23 +++++++++++---------- docs/search.json | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index dcf1b7b..e70817d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ wsim-gldas-vis_files water-wsim-gldas-v1-composite-anom-one-month-netcdf water-wsim-gldas-v1-composite-one-month-netcdf +.Rproj.user +composite_anom_1mo.nc +modis_nrt_flood.nc +wsim_gldas_tex.nc diff --git a/docs/LANCE_MODIS_NRT_GlobalFlood_MCDWD.html b/docs/LANCE_MODIS_NRT_GlobalFlood_MCDWD.html index a380d48..431aff7 100644 --- a/docs/LANCE_MODIS_NRT_GlobalFlood_MCDWD.html +++ b/docs/LANCE_MODIS_NRT_GlobalFlood_MCDWD.html @@ -4478,7 +4478,7 @@ - + @@ -4625,14 +4625,15 @@

Load Data

download_link <- content_items$downloadsLink print(download_link) - - } else { - print("Request failed with status code", http_status(response)$status_code) - } - -} else{ - download_link <- "modis_nrt_flood.nc" -} + stars::write_stars(raster_df, "modis_nrt_flood.nc") + + } else { + print("Request failed with status code", http_status(response)$status_code) + } + +} else{ + download_link <- "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:

@@ -4754,8 +4755,8 @@

Create NRT
stars object downsampled to 1000 by 1000 cells. See tm_shape manual (argument raster.downsample)

-
- +
+
diff --git a/docs/search.json b/docs/search.json index a658811..37fc1d8 100644 --- a/docs/search.json +++ b/docs/search.json @@ -123,14 +123,14 @@ "href": "LANCE_MODIS_NRT_GlobalFlood_MCDWD.html", "title": "MODIS NRT Global Flood Product", "section": "", - "text": "The MODIS/Aqua+Terra Global Flood Product L3 Near Real Time (NRT) 250m Global Flood Product (MCDWD_L3_NRT) (beta) provides daily maps of flooding globally. The product is provided over 3 compositing periods (1-day, 2-day, and 3-day) to minimize the impact of clouds and more rigorously identify flood water (the best composite will depend on the cloudiness for a particular event).\n\nNASA EARTHDATA\nCRM SEARCH\n\npackages_to_check <- c(\"stars\", \"httr\", \"jsonlite\", \"tmap\")\n\n# Check and install packages\nfor (package_name in packages_to_check) {\n if (!package_name %in% rownames(installed.packages())) {\n install.packages(package_name)\n cat(paste(\"Package\", package_name, \"installed.\\n\"))\n } else {\n cat(paste(\"Package\", package_name, \"is already installed.\\n\"))\n }\n library(package_name, character.only = TRUE)\n}\n\nPackage stars is already installed.\nPackage httr is already installed.\nPackage jsonlite is already installed.\nPackage tmap is already installed.\n\n\n\n#in case tmap does not install\n#remotes::install_github('r-tmap/tmap')\n\n\n\n\n\n\nBased on availability, edit the year_day variable YYYY-DD. Example: ‘2022-01’\n\n#add the year and date you want to search for (YYYY-DD, 2022-01)\nyear_day <- '2023-336'\n\n\n\n\n\nBased on availability, edit the tile_code variable:\n\n#add tile code from the map above (written as h00v00)\ntile_code <- 'h05v05'\n\nThis is the NRT Flood F3 (MCDWD_L3_F3) API URL:\n\nAPI_URL <- paste0('https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=')\n\nWe can combine the API URL above with the year_day provided and print the available datasets:\n\n#pasting together URL and year_day\nurl <- paste0(API_URL, year_day)\nprint(url)\n\n[1] \"https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=2023-336\"\n\n\n\n\n\n\nAccess the NASA Earthdata with the GET function:\n\nif(!file.exists(\"modis_nrt_flood.nc\")) {\n # Make the GET request\n response <- httr::GET(url)\n # Check response status from the GET function and check the contents from the parsed data.\n print(response)\n if (http_status(response)$category == \"Success\") {\n # Parse the response JSON\n data <- content(response, as = \"text\", encoding = \"UTF-8\")\n data_parsed <- jsonlite::fromJSON(data)\n #filter for the tile code\n content_items <- data_parsed$content[grepl(tile_code, data_parsed$content$name, ignore.case = TRUE), ]\n #check the content items\n print(content_items)\n #Select the URL from the 'downloadsLink' column in the content_items list: \n download_link <- content_items$downloadsLink\n print(download_link)\n \n \n } else {\n print(\"Request failed with status code\", http_status(response)$status_code)\n }\n \n} else{\n download_link <- \"modis_nrt_flood.nc\"\n}\n\nUse the “read_stars()” function from the “stars” R Library to read the geoTiff raster. The raster is assigned to the “x” variable:\n\nraster_df <- stars::read_stars(download_link)\n\nSet the Coordinate reference system (CRS) to “EPSG:4326”\n\nmy_raster <- st_set_crs(raster_df, st_crs(\"EPSG:4326\"))\n\nWarning in `st_crs<-.dimensions`(`*tmp*`, value = value): replacing CRS does\nnot reproject data: use st_transform, or st_warp to warp to a new CRS\n\nst_crs(my_raster)\n\nCoordinate Reference System:\n User input: EPSG:4326 \n wkt:\nGEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]\n\n\n\n\n\nPlot the raster to quickly view it:\n\nplot(my_raster, axes = TRUE)\n\ndownsample set to 3\n\n\n\n\n\n\n\nRefer to the MODIS NRT Global Flood Product User Guide for more information.\nNRT Flood data has 5 classifications:\n\n\n\nCode\nDefinition\n\n\n\n\n0\nNo Water\n\n\n1\nSurface Water\n\n\n2\nRecurring flood1\n\n\n3\nFlood (unusual)\n\n\n255\nInsufficient data\n\n\n\nCreate 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:\n\nclass_breaks <- c(-Inf, 0.1, 1.1, 2.1, 3.1)\ncolors <- c( \"gray\", \"blue\", \"yellow\",\"red\")\n\nlabels = c(\"0: No Water\", \"1: Surface Water\", \"2: Recurring flood\", \"3: Flood (unusual)\")\n\nAdd a title for the plot that includes the year, day of year, and tile code:\n\ntitle = paste(\"NRT Flood\", year_day, tile_code)\n\nGenerate a plot from the tmap library using the tm_shape() function. With style as “cat,” meaning categorical. T\n\ntmap_mode(\"view\")\n\ntmap mode set to interactive viewing\n\n## tmap mode set to plotting\ntm_shape(my_raster, style=\"cat\" )+\n tm_raster(palette = c(colors), \n title = title, \n breaks = class_breaks,\n labels = labels )+\n tm_basemap(server = \"Esri.WorldImagery\") +\n tm_layout(legend.outside = TRUE)\n\nstars object downsampled to 1000 by 1000 cells. See tm_shape manual (argument raster.downsample)" + "text": "The MODIS/Aqua+Terra Global Flood Product L3 Near Real Time (NRT) 250m Global Flood Product (MCDWD_L3_NRT) (beta) provides daily maps of flooding globally. The product is provided over 3 compositing periods (1-day, 2-day, and 3-day) to minimize the impact of clouds and more rigorously identify flood water (the best composite will depend on the cloudiness for a particular event).\n\nNASA EARTHDATA\nCRM SEARCH\n\npackages_to_check <- c(\"stars\", \"httr\", \"jsonlite\", \"tmap\")\n\n# Check and install packages\nfor (package_name in packages_to_check) {\n if (!package_name %in% rownames(installed.packages())) {\n install.packages(package_name)\n cat(paste(\"Package\", package_name, \"installed.\\n\"))\n } else {\n cat(paste(\"Package\", package_name, \"is already installed.\\n\"))\n }\n library(package_name, character.only = TRUE)\n}\n\nPackage stars is already installed.\nPackage httr is already installed.\nPackage jsonlite is already installed.\nPackage tmap is already installed.\n\n\n\n#in case tmap does not install\n#remotes::install_github('r-tmap/tmap')\n\n\n\n\n\n\nBased on availability, edit the year_day variable YYYY-DD. Example: ‘2022-01’\n\n#add the year and date you want to search for (YYYY-DD, 2022-01)\nyear_day <- '2023-336'\n\n\n\n\n\nBased on availability, edit the tile_code variable:\n\n#add tile code from the map above (written as h00v00)\ntile_code <- 'h05v05'\n\nThis is the NRT Flood F3 (MCDWD_L3_F3) API URL:\n\nAPI_URL <- paste0('https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=')\n\nWe can combine the API URL above with the year_day provided and print the available datasets:\n\n#pasting together URL and year_day\nurl <- paste0(API_URL, year_day)\nprint(url)\n\n[1] \"https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=2023-336\"\n\n\n\n\n\n\nAccess the NASA Earthdata with the GET function:\n\nif(!file.exists(\"modis_nrt_flood.nc\")) {\n # Make the GET request\n response <- httr::GET(url)\n # Check response status from the GET function and check the contents from the parsed data.\n print(response)\n if (http_status(response)$category == \"Success\") {\n # Parse the response JSON\n data <- content(response, as = \"text\", encoding = \"UTF-8\")\n data_parsed <- jsonlite::fromJSON(data)\n #filter for the tile code\n content_items <- data_parsed$content[grepl(tile_code, data_parsed$content$name, ignore.case = TRUE), ]\n #check the content items\n print(content_items)\n #Select the URL from the 'downloadsLink' column in the content_items list: \n download_link <- content_items$downloadsLink\n print(download_link)\n \n stars::write_stars(raster_df, \"modis_nrt_flood.nc\")\n \n } else {\n print(\"Request failed with status code\", http_status(response)$status_code)\n }\n \n} else{\n download_link <- \"modis_nrt_flood.nc\"\n}\n\nUse the “read_stars()” function from the “stars” R Library to read the geoTiff raster. The raster is assigned to the “x” variable:\n\nraster_df <- stars::read_stars(download_link)\n\nSet the Coordinate reference system (CRS) to “EPSG:4326”\n\nmy_raster <- st_set_crs(raster_df, st_crs(\"EPSG:4326\"))\n\nWarning in `st_crs<-.dimensions`(`*tmp*`, value = value): replacing CRS does\nnot reproject data: use st_transform, or st_warp to warp to a new CRS\n\nst_crs(my_raster)\n\nCoordinate Reference System:\n User input: EPSG:4326 \n wkt:\nGEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]\n\n\n\n\n\nPlot the raster to quickly view it:\n\nplot(my_raster, axes = TRUE)\n\ndownsample set to 3\n\n\n\n\n\n\n\nRefer to the MODIS NRT Global Flood Product User Guide for more information.\nNRT Flood data has 5 classifications:\n\n\n\nCode\nDefinition\n\n\n\n\n0\nNo Water\n\n\n1\nSurface Water\n\n\n2\nRecurring flood1\n\n\n3\nFlood (unusual)\n\n\n255\nInsufficient data\n\n\n\nCreate 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:\n\nclass_breaks <- c(-Inf, 0.1, 1.1, 2.1, 3.1)\ncolors <- c( \"gray\", \"blue\", \"yellow\",\"red\")\n\nlabels = c(\"0: No Water\", \"1: Surface Water\", \"2: Recurring flood\", \"3: Flood (unusual)\")\n\nAdd a title for the plot that includes the year, day of year, and tile code:\n\ntitle = paste(\"NRT Flood\", year_day, tile_code)\n\nGenerate a plot from the tmap library using the tm_shape() function. With style as “cat,” meaning categorical. T\n\ntmap_mode(\"view\")\n\ntmap mode set to interactive viewing\n\n## tmap mode set to plotting\ntm_shape(my_raster, style=\"cat\" )+\n tm_raster(palette = c(colors), \n title = title, \n breaks = class_breaks,\n labels = labels )+\n tm_basemap(server = \"Esri.WorldImagery\") +\n tm_layout(legend.outside = TRUE)\n\nstars object downsampled to 1000 by 1000 cells. See tm_shape manual (argument raster.downsample)" }, { "objectID": "LANCE_MODIS_NRT_GlobalFlood_MCDWD.html#modis-nrt-global-flood-product", "href": "LANCE_MODIS_NRT_GlobalFlood_MCDWD.html#modis-nrt-global-flood-product", "title": "MODIS NRT Global Flood Product", "section": "", - "text": "The MODIS/Aqua+Terra Global Flood Product L3 Near Real Time (NRT) 250m Global Flood Product (MCDWD_L3_NRT) (beta) provides daily maps of flooding globally. The product is provided over 3 compositing periods (1-day, 2-day, and 3-day) to minimize the impact of clouds and more rigorously identify flood water (the best composite will depend on the cloudiness for a particular event).\n\nNASA EARTHDATA\nCRM SEARCH\n\npackages_to_check <- c(\"stars\", \"httr\", \"jsonlite\", \"tmap\")\n\n# Check and install packages\nfor (package_name in packages_to_check) {\n if (!package_name %in% rownames(installed.packages())) {\n install.packages(package_name)\n cat(paste(\"Package\", package_name, \"installed.\\n\"))\n } else {\n cat(paste(\"Package\", package_name, \"is already installed.\\n\"))\n }\n library(package_name, character.only = TRUE)\n}\n\nPackage stars is already installed.\nPackage httr is already installed.\nPackage jsonlite is already installed.\nPackage tmap is already installed.\n\n\n\n#in case tmap does not install\n#remotes::install_github('r-tmap/tmap')\n\n\n\n\n\n\nBased on availability, edit the year_day variable YYYY-DD. Example: ‘2022-01’\n\n#add the year and date you want to search for (YYYY-DD, 2022-01)\nyear_day <- '2023-336'\n\n\n\n\n\nBased on availability, edit the tile_code variable:\n\n#add tile code from the map above (written as h00v00)\ntile_code <- 'h05v05'\n\nThis is the NRT Flood F3 (MCDWD_L3_F3) API URL:\n\nAPI_URL <- paste0('https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=')\n\nWe can combine the API URL above with the year_day provided and print the available datasets:\n\n#pasting together URL and year_day\nurl <- paste0(API_URL, year_day)\nprint(url)\n\n[1] \"https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=2023-336\"\n\n\n\n\n\n\nAccess the NASA Earthdata with the GET function:\n\nif(!file.exists(\"modis_nrt_flood.nc\")) {\n # Make the GET request\n response <- httr::GET(url)\n # Check response status from the GET function and check the contents from the parsed data.\n print(response)\n if (http_status(response)$category == \"Success\") {\n # Parse the response JSON\n data <- content(response, as = \"text\", encoding = \"UTF-8\")\n data_parsed <- jsonlite::fromJSON(data)\n #filter for the tile code\n content_items <- data_parsed$content[grepl(tile_code, data_parsed$content$name, ignore.case = TRUE), ]\n #check the content items\n print(content_items)\n #Select the URL from the 'downloadsLink' column in the content_items list: \n download_link <- content_items$downloadsLink\n print(download_link)\n \n \n } else {\n print(\"Request failed with status code\", http_status(response)$status_code)\n }\n \n} else{\n download_link <- \"modis_nrt_flood.nc\"\n}\n\nUse the “read_stars()” function from the “stars” R Library to read the geoTiff raster. The raster is assigned to the “x” variable:\n\nraster_df <- stars::read_stars(download_link)\n\nSet the Coordinate reference system (CRS) to “EPSG:4326”\n\nmy_raster <- st_set_crs(raster_df, st_crs(\"EPSG:4326\"))\n\nWarning in `st_crs<-.dimensions`(`*tmp*`, value = value): replacing CRS does\nnot reproject data: use st_transform, or st_warp to warp to a new CRS\n\nst_crs(my_raster)\n\nCoordinate Reference System:\n User input: EPSG:4326 \n wkt:\nGEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]\n\n\n\n\n\nPlot the raster to quickly view it:\n\nplot(my_raster, axes = TRUE)\n\ndownsample set to 3\n\n\n\n\n\n\n\nRefer to the MODIS NRT Global Flood Product User Guide for more information.\nNRT Flood data has 5 classifications:\n\n\n\nCode\nDefinition\n\n\n\n\n0\nNo Water\n\n\n1\nSurface Water\n\n\n2\nRecurring flood1\n\n\n3\nFlood (unusual)\n\n\n255\nInsufficient data\n\n\n\nCreate 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:\n\nclass_breaks <- c(-Inf, 0.1, 1.1, 2.1, 3.1)\ncolors <- c( \"gray\", \"blue\", \"yellow\",\"red\")\n\nlabels = c(\"0: No Water\", \"1: Surface Water\", \"2: Recurring flood\", \"3: Flood (unusual)\")\n\nAdd a title for the plot that includes the year, day of year, and tile code:\n\ntitle = paste(\"NRT Flood\", year_day, tile_code)\n\nGenerate a plot from the tmap library using the tm_shape() function. With style as “cat,” meaning categorical. T\n\ntmap_mode(\"view\")\n\ntmap mode set to interactive viewing\n\n## tmap mode set to plotting\ntm_shape(my_raster, style=\"cat\" )+\n tm_raster(palette = c(colors), \n title = title, \n breaks = class_breaks,\n labels = labels )+\n tm_basemap(server = \"Esri.WorldImagery\") +\n tm_layout(legend.outside = TRUE)\n\nstars object downsampled to 1000 by 1000 cells. See tm_shape manual (argument raster.downsample)" + "text": "The MODIS/Aqua+Terra Global Flood Product L3 Near Real Time (NRT) 250m Global Flood Product (MCDWD_L3_NRT) (beta) provides daily maps of flooding globally. The product is provided over 3 compositing periods (1-day, 2-day, and 3-day) to minimize the impact of clouds and more rigorously identify flood water (the best composite will depend on the cloudiness for a particular event).\n\nNASA EARTHDATA\nCRM SEARCH\n\npackages_to_check <- c(\"stars\", \"httr\", \"jsonlite\", \"tmap\")\n\n# Check and install packages\nfor (package_name in packages_to_check) {\n if (!package_name %in% rownames(installed.packages())) {\n install.packages(package_name)\n cat(paste(\"Package\", package_name, \"installed.\\n\"))\n } else {\n cat(paste(\"Package\", package_name, \"is already installed.\\n\"))\n }\n library(package_name, character.only = TRUE)\n}\n\nPackage stars is already installed.\nPackage httr is already installed.\nPackage jsonlite is already installed.\nPackage tmap is already installed.\n\n\n\n#in case tmap does not install\n#remotes::install_github('r-tmap/tmap')\n\n\n\n\n\n\nBased on availability, edit the year_day variable YYYY-DD. Example: ‘2022-01’\n\n#add the year and date you want to search for (YYYY-DD, 2022-01)\nyear_day <- '2023-336'\n\n\n\n\n\nBased on availability, edit the tile_code variable:\n\n#add tile code from the map above (written as h00v00)\ntile_code <- 'h05v05'\n\nThis is the NRT Flood F3 (MCDWD_L3_F3) API URL:\n\nAPI_URL <- paste0('https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=')\n\nWe can combine the API URL above with the year_day provided and print the available datasets:\n\n#pasting together URL and year_day\nurl <- paste0(API_URL, year_day)\nprint(url)\n\n[1] \"https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/details?products=MCDWD_L3_F3_NRT&archiveSets=61&temporalRanges=2023-336\"\n\n\n\n\n\n\nAccess the NASA Earthdata with the GET function:\n\nif(!file.exists(\"modis_nrt_flood.nc\")) {\n # Make the GET request\n response <- httr::GET(url)\n # Check response status from the GET function and check the contents from the parsed data.\n print(response)\n if (http_status(response)$category == \"Success\") {\n # Parse the response JSON\n data <- content(response, as = \"text\", encoding = \"UTF-8\")\n data_parsed <- jsonlite::fromJSON(data)\n #filter for the tile code\n content_items <- data_parsed$content[grepl(tile_code, data_parsed$content$name, ignore.case = TRUE), ]\n #check the content items\n print(content_items)\n #Select the URL from the 'downloadsLink' column in the content_items list: \n download_link <- content_items$downloadsLink\n print(download_link)\n \n stars::write_stars(raster_df, \"modis_nrt_flood.nc\")\n \n } else {\n print(\"Request failed with status code\", http_status(response)$status_code)\n }\n \n} else{\n download_link <- \"modis_nrt_flood.nc\"\n}\n\nUse the “read_stars()” function from the “stars” R Library to read the geoTiff raster. The raster is assigned to the “x” variable:\n\nraster_df <- stars::read_stars(download_link)\n\nSet the Coordinate reference system (CRS) to “EPSG:4326”\n\nmy_raster <- st_set_crs(raster_df, st_crs(\"EPSG:4326\"))\n\nWarning in `st_crs<-.dimensions`(`*tmp*`, value = value): replacing CRS does\nnot reproject data: use st_transform, or st_warp to warp to a new CRS\n\nst_crs(my_raster)\n\nCoordinate Reference System:\n User input: EPSG:4326 \n wkt:\nGEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]\n\n\n\n\n\nPlot the raster to quickly view it:\n\nplot(my_raster, axes = TRUE)\n\ndownsample set to 3\n\n\n\n\n\n\n\nRefer to the MODIS NRT Global Flood Product User Guide for more information.\nNRT Flood data has 5 classifications:\n\n\n\nCode\nDefinition\n\n\n\n\n0\nNo Water\n\n\n1\nSurface Water\n\n\n2\nRecurring flood1\n\n\n3\nFlood (unusual)\n\n\n255\nInsufficient data\n\n\n\nCreate 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:\n\nclass_breaks <- c(-Inf, 0.1, 1.1, 2.1, 3.1)\ncolors <- c( \"gray\", \"blue\", \"yellow\",\"red\")\n\nlabels = c(\"0: No Water\", \"1: Surface Water\", \"2: Recurring flood\", \"3: Flood (unusual)\")\n\nAdd a title for the plot that includes the year, day of year, and tile code:\n\ntitle = paste(\"NRT Flood\", year_day, tile_code)\n\nGenerate a plot from the tmap library using the tm_shape() function. With style as “cat,” meaning categorical. T\n\ntmap_mode(\"view\")\n\ntmap mode set to interactive viewing\n\n## tmap mode set to plotting\ntm_shape(my_raster, style=\"cat\" )+\n tm_raster(palette = c(colors), \n title = title, \n breaks = class_breaks,\n labels = labels )+\n tm_basemap(server = \"Esri.WorldImagery\") +\n tm_layout(legend.outside = TRUE)\n\nstars object downsampled to 1000 by 1000 cells. See tm_shape manual (argument raster.downsample)" }, { "objectID": "LANCE_MODIS_NRT_GlobalFlood_MCDWD.html#footnotes",