Skip to content

Commit

Permalink
Merge pull request #191 from tylere:issue_190
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697703491
  • Loading branch information
Xee authors committed Nov 18, 2024
2 parents 9c34203 + 5182b88 commit 5ce8db6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ cython_debug/

# MacOS
.DS_Store

# pixi environments
.pixi
11 changes: 6 additions & 5 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,12 @@ def open_dataset(
if ee.data.getUserAgent() != user_agent:
ee.data.setUserAgent(user_agent)

collection = (
filename_or_obj
if isinstance(filename_or_obj, ee.ImageCollection)
else ee.ImageCollection(self._parse(filename_or_obj))
)
if isinstance(filename_or_obj, ee.ImageCollection):
collection = filename_or_obj
elif isinstance(filename_or_obj, ee.Image):
collection = ee.ImageCollection(filename_or_obj)
else:
collection = ee.ImageCollection(self._parse(filename_or_obj))

store = EarthEngineStore.open(
collection,
Expand Down
8 changes: 8 additions & 0 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ def test_open_dataset__n_images(self):

self.assertLen(ds.time, 1)

def test_open_dataset_image_to_imagecollection(self):
"""Ensure that opening an ee.Image is the same as opening a single image ee.ImageCollection."""
img = ee.Image('CGIAR/SRTM90_V4')
ic = ee.ImageCollection(img)
ds1 = xr.open_dataset(img, engine='ee')
ds2 = xr.open_dataset(ic, engine='ee')
self.assertTrue(ds1.identical(ds2))

def test_can_chunk__opened_dataset(self):
ds = xr.open_dataset(
'NASA/GPM_L3/IMERG_V07',
Expand Down

0 comments on commit 5ce8db6

Please sign in to comment.