eMODIS API

Table of Contents

GET GetDerivedAnnualMetricsList

This endpoint retrieves a list of all available eMODIS annual derived metrics 

URL:

https://devise.uwyo.edu/Umbraco/api/ErosApi/GetDerivedAnnualMetricsList

Parameters:

This endpoint does not require any parameters

Response:

[
    {
        "metric": "dur",
        "temporal": "Annual",
        "maxDate": "2021-01-01T00:00:00"
    },
    {
        "metric": "eost",
        "temporal": "Annual",
        "maxDate": "2021-01-01T00:00:00"
    },
    {
        "metric": "maxt",
        "temporal": "Annual",
        "maxDate": "2021-01-01T00:00:00"
    },
    {
        "metric": "sost",
        "temporal": "Annual",
        "maxDate": "2021-01-01T00:00:00"
    },
    {
        "metric": "tin",
        "temporal": "Annual",
        "maxDate": "2021-01-01T00:00:00"
    }
]

POST GetDerivedAnnualData

This endpoint retrieves filtered eMODIS derived annual data to facilitate downloading of files

URL:

https://devise.uwyo.edu/Umbraco/api/ErosApi/GetDerivedAnnualData

Parameters:

  • StartDate (string): The start date in YYYY-MM-DD format.
  • EndDate (string): The end date in YYYY-MM-DD format.
  • Years (json int array): A comma separated array of desired years
  • Months (json int array): A comma separated array of desired months
  • Metrics (json string array): A comma separated array of eMODIS metrics.
{
    "StartDate": null,
    "EndDate": null,
    "Years" : [2001],
    "Months": null,
    "Metrics": ["dur"]
}

Response:

[
    {
        "filename": "MODIS_dur_2001.tif",
        "temporal": "Annual",
        "metric": "dur",
        "sampDate": "2001-01-01T00:00:00",
        "sampYear": 2001,
        "sampMonth": 1,
        "sampDay": 1,
        "sampWeek": 1,
        "url": "https://pathfinder.arcc.uwyo.edu/devise/EROS_DerivedMetrics/EROS_dur_Annual/MODIS_dur_2001.tif",
        "resolution": "250 m",
        "source": "DEVISER MODIS",
        "crs": "epsg:5072"
    }
]

R Examples

The following is a collection of R examples to show how to utilize the eMODIS API to obtain data independent of the DEVISE app

Extract Data From Points:

    1. Create your point first if you do not already have it
      require(terra)
      require(sf)
      require(httr)
      require(jsonlite)
      require(tidyverse)
      
      points <- data.frame(id = c(1, 2), x = c(-108.36312, -109.36312),  y = c(45.54731, 45.54731)) %>%
        sf::st_as_sf(coords = c("x", "y"), crs = 4326)
      
    2. We also need to obtain the list of all available metrics. Since we are working with annual data, we'll get the annual metric list
      myEmodisMetrics<- httr::POST(
        "https://devise.uwyo.edu/umbraco/api/erosapi/GetDerivedAnnualMetricsList",
        content_type_json()
      ) %>%
        content()
      
      myEmodisMetrics <- do.call(rbind.data.frame, myEmodisMetrics)
      
    3. Now that we have a list of available metrics for the eMODIS annual dataset, let's pick one we're interested in. For this example we'll use the 'sost' metric which happens to be the 1st metric in our `myEmodisMetrics` list. We'll also need to pick dates. Here we will use the years 2005 - 2008
      dat<- httr::POST(
        "https://devise.uwyo.edu/umbraco/api/erosapi/GetDerivedAnnualData",
        httr::content_type_json(),
        body = jsonlite::toJSON(
          list(StartDate = jsonlite::unbox("2005-01-01"),
               EndDate = jsonlite::unbox("2008-01-01"),
               Metrics = myEmodisMetrics$metric[1]),
          auto_unbox = FALSE
        )
      ) %>%
        content()
      
      dat <- do.call(rbind.data.frame, dat)
      
    4. I've obtained a list of files representing 'sost' data annually for the years 2005 - 2008. We want to download these files so we can extract the data. First we want to pick a directory to save the files to.
      outDir <- "D:/examplePath"
      
      Then we want to loop through our list of files and download each one to the desired destination
      # loop through each file and download
      for(j in 1:nrow(dat)){
        try(utils::download.file(url = dat$url[j], destfile = paste0(outDir, "/", dat$filename[j]), quiet = TRUE, mode = "wb"), silent = TRUE)
      }
      
    5. Now that we've got all of our files downloaded, we can stack them into a single raster.
      # Get the newly downloaded files
      rfiles<- dir(outDir, pattern = ".tif$", full.names = TRUE)
      
      # Stack the rasters into one
      rs<- terra::rast(rfiles)
      
      # Change the names of the layers to something more meaningful
      names(rs) <- str_split(dat$filename, "\\.", simplify = TRUE)[,1]
      
    6. Before extracting the data from our raster, we have to ensure our points are in the correct format
      pts<- vect(as(points %>% st_transform(crs = 5072), "Spatial"))
      
    7. Now that our raster and points are in the correct format we can extract our data.
      ## Extract some sort of data here
      mySostData<- terra::extract(rs, pts, ID = FALSE)
      
    8. We have the data corresponding to our points. You can see it in R using view or we manipulate into a format that is easier to read and understand.
      # Use this to view the data as is
      View(mySostData)
      
      
      # Use this to manipulate data into an easier to read format and plot the trends    
      dfPts<- cbind(points, mySostData) %>% 
        st_drop_geometry() %>% 
        pivot_longer(cols = 2:ncol(.), names_to = "Raster", values_to = "Value") %>% 
        separate(Raster, into = c("Source", "Parameter", "SampYear"), sep = "_")
      # plot data
      dfPts %>% 
        ggplot(aes(x = SampYear, y = Value, group = as.factor(id), color = as.factor(id))) +
        geom_line()