Search code examples
rterra

Luna getNASA command not working for product MCD19A3D


I wanted to download files for the NASA product MCD19A3D v061. When looking for products, it is only listed as MCD19A3, without a D. If I look up files available, it says none available, possibly because the D is missing. I have attached my code below, based on the tutorial on rspatial.org/modis/2-download.html and the getNASA() function description page.

How can I change something to make it work? Or should I try to write my own function to download files based on the URLs at https://e4ftl01.cr.usgs.gov/MOTA/MCD19A3D.061/

    library(luna)
    library(terra)
    library(geodata)
    senegal <- geodata::gadm("Senegal", level=1, path=".")

    available <- getNASA(product = "MCD19A3", version = "061", 
                         start_date = "2024-01-01", 
                         end_date = "2024-03-01",
                         aoi = senegal, 
                         download = FALSE,
                         path = path)

Solution

  • Took me a while to find my EODIS logon info (you'll need yours), but this is a package that (should) simplify many steps that previously could prove quite frustrating, like creating a proper LDAAP url.

    library(luna)
    library(terra)
    
    nasa_products[which(nasa_products$short_name == 'MCD19A3'), ][2,]
            provider             concept_id short_name version
    46699 LPDAAC_ECS C1620265482-LPDAAC_ECS    MCD19A3     061
    
    

    provider 'LDAAC_ECS' is the getNASA server that the query will be directed to (default value), short_name is product and version is version.

    All of which sounds very nice, but, due to how selection of version(s) is coded, you won't get to version '061' as in the presence of multiple version, the first is used, in this case '006'.

    f_list = luna::getNASA(product = 'MCD19A3', start_date = sdate, end_date = edate, aoi = senegal, version = '006', download = FALSE, username = usr, password = pwd,  server = 'LPDAAC_ECS')
    [1] "No results found"
    
    debugonce(getNASA)
    
    f_list = luna::getNASA(product = 'MCD19A3', start_date = sdate, end_date = edate, aoi = senegal, version = '006', download = FALSE, username = usr, password = pwd,  server = 'LPDAAC_ECS')
    # enter n 6 times
    Browse[2]> h
            provider             concept_id short_name version
    1912  LPDAAC_ECS C1000000540-LPDAAC_ECS    MCD19A3     006
    46699 LPDAAC_ECS C1620265482-LPDAAC_ECS    MCD19A3     061
    
    # now, entering s (for step), we see what code is going to be run
    Browse[2]> s
    debug: if (nrow(pp) < 1) {
        if (nrow(h) < 1) {
            stop("The requested product is not available for this through this function")
        }
        else {
            cat("Options for this product:\n")
            print(head(h, 10))
            cat("\n")
            stop("The requested product is not available for this product version or server")
        }
    } else if (nrow(pp) > 1) {
        warning("Multiple sources available, using first one")
        print(pp)
        pp <- pp[1, ]
    # and 1 is not 2
    Browse[2]> h
            provider             concept_id short_name version
    1912  LPDAAC_ECS C1000000540-LPDAAC_ECS    MCD19A3     006
    46699 LPDAAC_ECS C1620265482-LPDAAC_ECS    MCD19A3     061
    

    This will likely be fixed. The CMR STAC API in R as presented in NASA tutorial.