r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

Dataset property values not displaying correctly #193

Closed obaines closed 2 years ago

obaines commented 2 years ago

At submit an issue, please attached the following information of your rgee session:

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

# Print metadata for a DEM dataset.
print(ee$Image('USGS/SRTMGL1_003')$getInfo())

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()

Description

I'm trying to use the terraClimate dataset (ee.ImageCollection("IDAHO_EPSCOR/TERRACLIMATE")) to produce yearly means for different climate variables. After some transformations (e.g. adding images together), Earth Engine requires metadata to be re-added (e.g. for 'system:time_start' so I can continue to filter variables by month or year).

The 'system:time_start' variable (and potentially others) are not displaying correctly however. When I run a $getInfo() command on an image from the terraClimate dataset, I get a value of -1 for system:time_start, yet I still am able to filter the dataset correctly. What's more, if I use this value, e.g. converting to a date object and then formatting as a YYYY-MM-dd string, the correct date appears, even though the input value was supposedly -1.

Hope this is clear enough - happy to add more info if reqired!

What I Did

terraClim <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE")$filterDate('1979-01-01', '2020-12-31')

#Printing the system:time_start property which returns -1
print(terraClim$first()$get('system:time_start')$getInfo())

#We can then convert this to a date (which also returns -1 when printing)
print(ee$Date(terraClim$first()$get('system:time_start'))$getInfo())

#But when we format this as a string, it returns the right date rather than -1
print(ee$Date(terraClim$first()$get('system:time_start'))$format('YYYY-MM-dd')$getInfo())
csaybar commented 2 years ago

Hi @obaines

This problem was described in https://r-spatial.github.io/rgee/articles/considerations.html#be-careful-with-eedate

library(rgee)
ee_Initialize()

terraClim <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE")$filterDate('1979-01-01', '2020-12-31')

#Printing the system:time_start property which returns -1
print(
  terraClim$first()$get('system:time_start') %>% eedate_to_rdate()
)

#We can then convert this to a date (which also returns -1 when printing)
print(
  ee$Date(terraClim$first()$get('system:time_start')) %>% eedate_to_rdate(timestamp = TRUE)
)

#But when we format this as a string, it returns the right date rather than -1
print(
  ee$Date(terraClim$first()$get('system:time_start'))$format('YYYY-MM-dd') %>% 
    eedate_to_rdate()
)
obaines commented 2 years ago

Ah great - thought it was odd I didn't see an issue regarding this already! Thanks for your help @csaybar