Skip to content

Commit

Permalink
Simpler URL parsing scheme for remote EE assets.
Browse files Browse the repository at this point in the history
@mahrsee1997 pointed out that there's an even simpler way to represent the parsing scheme for EE. Thanks, Rahul.

PiperOrigin-RevId: 570410561
  • Loading branch information
Xee authors authored and alxmrs committed Oct 3, 2023
1 parent 55df6d9 commit 024263e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,11 @@ class EarthEngineBackendEntrypoint(backends.BackendEntrypoint):
"""Backend for Earth Engine."""

def _parse(self, filename_or_obj: Union[str, os.PathLike[Any]]) -> str:
input_ = str(filename_or_obj).removeprefix('ee::')
parsed = parse.urlparse(input_)
parsed = parse.urlparse(str(filename_or_obj))
if parsed.scheme and parsed.scheme != 'ee':
raise ValueError(
'uri must follow the format `ee://<image/collection/path>` or '
'`ee::<image/collection/path>`.'
'`ee:<image/collection/path>`.'
)
return f'{parsed.netloc}{parsed.path}'

Expand Down
5 changes: 3 additions & 2 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def test_guess_can_open__collection_name(self):
self.entry.guess_can_open('LANDSAT/SomeRandomCollection/C01/T1')
)
self.assertTrue(self.entry.guess_can_open('ee://LANDSAT/LC08/C01/T1'))
self.assertTrue(self.entry.guess_can_open('ee::LANDSAT/LC08/C01/T1'))
self.assertTrue(self.entry.guess_can_open('ee:LANDSAT/LC08/C01/T1'))
self.assertFalse(self.entry.guess_can_open('ee::LANDSAT/LC08/C01/T1'))

def test_guess_can_open__image_collection(self):
ic = ee.ImageCollection('LANDSAT/LC08/C01/T1').filterDate(
Expand Down Expand Up @@ -339,7 +340,7 @@ def test_parses_ee_url(self):
dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 8}
)
ds = self.entry.open_dataset(
'ee::LANDSAT/LC08/C01/T1',
'ee:LANDSAT/LC08/C01/T1',
drop_variables=tuple(f'B{i}' for i in range(3, 12)),
scale=25.0, # in degrees
n_images=3,
Expand Down

0 comments on commit 024263e

Please sign in to comment.