Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with ee_as_rast create raster with NaN #356

Open
rpkamakura opened this issue Feb 16, 2024 · 0 comments
Open

Issue with ee_as_rast create raster with NaN #356

rpkamakura opened this issue Feb 16, 2024 · 0 comments

Comments

@rpkamakura
Copy link

  • rgee version: 1.1.7
  • R version: 4.3.2
  • Operating System: Windows 10

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

  • [ Yes] You have the Python API installed (from terminal):
earthengine -h
  • [ NO] You can find the credentials file on your system:
library(rgee)
ee_path <- path.expand("~/.config/earthengine/credentials")
file.exists(ee_path)
  • [ Yes] You can run a simple EE command from R:
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()

python:         C:/Users/rep31/AppData/Local/anaconda3/python.exe
libpython:      C:/Users/rep31/AppData/Local/anaconda3/python310.dll
pythonhome:     C:/Users/rep31/AppData/Local/anaconda3
version:        3.10.9 | packaged by Anaconda, Inc. | (main, Mar  1 2023, 18:18:15) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/rep31/AppData/Local/anaconda3/Lib/site-packages/numpy
numpy_version:  1.23.5
ee:             C:\Users\rep31\AppData\Local\ANACON~1\lib\site-packages\ee\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON

Description

I'm trying to save several images as rasters via drive. Whenever I try, it doesn't give me any errors but returns rasters with only NaN values. The ideal images I want to save are mostly empty with just a few areas with values (clipped to smaller polygons) that are disjoint, but I also tried saving them while clipping to a larger geometry (geeBbox below) and had the same problem.

The issue doesn't seem to be on the earth engine side because I can do Map$addLayer(image) for the version of the images right before I run ee_as_rast(image) and the images look great before conversion.

I'm going to put the simpler code here that just pulls NAIP imagery since that is easier to reproduce, but I have the same problem with some processed Sentinel-2 imagery.

What I Did

#create our focal region (for output geometry, is from a shapefile)
Region <- st_read("../01Data/ChicagoS23/FocalRegion/FocalRegion.shp")
bbox <- st_bbox(Region)
bbox_Poly <- st_as_sfc(bbox)
geeBbox <- ee$Geometry$Rectangle(bbox)

NAIP <- ee$ImageCollection("USDA/NAIP/DOQQ")$
  filterBounds(geeBbox)$
  filterDate("2019-01-01", "2023-12-31")

#to use to filter the images
randomPts_center <- ee$FeatureCollection$randomPoints(region=geeBbox, points= 100, seed= 0, maxError= 1)
randomPoints <- randomPts_center$map(function(f) {f$buffer(60, 10)})

#get NAIP Imagery
N19 <- ee$ImageCollection(NAIP)$filterDate("2019-08-01", "2019-08-10")$mosaic()$clip(randomPoints)
N21<- ee$ImageCollection(NAIP)$filterDate("2021-09-01", "2021-09-15")$mosaic()$clip(randomPoints)

#switch them to terra rasters
rastN19 <- ee_as_rast(N19, region=geeBbox, via = "drive")
rastN21 <- ee_as_rast(N21, region=geeBbox, via = "drive")

##write the rasters
writeRaster(rastN19, "../01Data/QualityCheck/NAIP_2019.tiff")
writeRaster(rastN21, "../01Data/QualityCheck/NAIP_2021.tiff")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant