Skip to content

Simplify pixel grid params #224

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ cython_debug/

# pixi environments
.pixi
*.egg-info

# temporary work files
temp/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
75 changes: 40 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Now, in your Python environment, make the following imports:

```python
import ee
import xarray
import xarray as xr
```

Next, specify your EE-registered cloud project ID and initialize the EE client
Expand All @@ -48,68 +48,73 @@ ee.Initialize(
opt_url='https://earthengine-highvolume.googleapis.com')
```

Open any Earth Engine ImageCollection by specifying the Xarray engine as `'ee'`:

We specify the desired pixel grid using three parameters: `crs`, `crs_transform`, and `shape_2d`. Xee contains a helper function `extract_grid_params` that can extract these parameters from an Earth Engine Image or ImageCollection object.
```python
ds = xarray.open_dataset('ee://ECMWF/ERA5_LAND/HOURLY', engine='ee')
ic = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY')
grid_params = helpers.extract_grid_params(ic)
```

Open all bands in a specific projection (not the Xee default):
Open any Earth Engine ImageCollection by specifying the Xarray engine as `'ee'`:

```python
ds = xarray.open_dataset('ee://ECMWF/ERA5_LAND/HOURLY', engine='ee',
crs='EPSG:4326', scale=0.25)
ds = xr.open_dataset(
'ee://ECMWF/ERA5_LAND/HOURLY',
engine='ee',
**grid_params
)
```

Open an ImageCollection (maybe, with EE-side filtering or processing):
Open all bands in a specific projection:

```python
ic = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate(
'1992-10-05', '1993-03-31')
ds = xarray.open_dataset(ic, engine='ee', crs='EPSG:4326', scale=0.25)
ds = xr.open_dataset(
'ee://ECMWF/ERA5_LAND/HOURLY',
engine='ee',
crs="EPSG:32610",
crs_transform=[30, 0, 448485+103000, 0, -30, 4263915-84000], # In San Francisco, California
shape_2d=(64, 64),
)
```

Open an ImageCollection with a specific EE projection or geometry:
Open an ImageCollection (maybe, with EE-side filtering or processing):

```python
ic = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate(
'1992-10-05', '1993-03-31')
leg1 = ee.Geometry.Rectangle(113.33, -43.63, 153.56, -10.66)
ds = xarray.open_dataset(
ds = xr.open_dataset(
ic,
engine='ee',
projection=ic.first().select(0).projection(),
geometry=leg1
crs="EPSG:32610",
crs_transform=[30, 0, 448485+103000, 0, -30, 4263915-84000], # In San Francisco, California
shape_2d=(64, 64),
)
```

Open multiple ImageCollections into one `xarray.Dataset`, all with the same
projection:
Open an ImageCollection with a specific EE projection or geometry:

```python
ds = xarray.open_mfdataset(
['ee://ECMWF/ERA5_LAND/HOURLY', 'ee://NASA/GDDP-CMIP6'],
engine='ee', crs='EPSG:4326', scale=0.25)
```
import shapely

Open a single Image by passing it to an ImageCollection:
grid_params = helpers.fit_geometry(
geometry=shapely.geometry.box(113.33, -43.63, 153.56, -10.66),
grid_crs='EPSG:4326',
grid_shape=(256, 256)
)

```python
i = ee.ImageCollection(ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318'))
ds = xarray.open_dataset(i, engine='ee')
ds = xr.open_dataset(
ic,
engine='ee',
**grid_params
)
```

Open any Earth Engine ImageCollection to match an existing transform:
Open a single Image:

```python
raster = rioxarray.open_rasterio(...) # assume crs + transform is set
img = ee.Image("LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318")
grid_params = helpers.extract_grid_params(img)
ds = xr.open_dataset(
'ee://ECMWF/ERA5_LAND/HOURLY',
img,
engine='ee',
geometry=tuple(raster.rio.bounds()), # must be in EPSG:4326
projection=ee.Projection(
crs=str(raster.rio.crs), transform=raster.rio.transform()[:6]
),
**grid_params
)
```

Expand Down
4,600 changes: 4,600 additions & 0 deletions pixi.lock

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "xee"
dynamic = ["version"]
description = "A Google Earth Engine extension for Xarray."
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.8,<3.13"
license = {text = "Apache-2.0"}
authors = [
{name = "Google LLC", email = "noreply@google.com"},
Expand Down Expand Up @@ -40,6 +40,7 @@ tests = [
"pyink",
"rasterio",
"rioxarray",
"shapely",
]
dataflow = [
"absl-py",
Expand All @@ -65,5 +66,28 @@ preview = true
pyink-indentation = 2
pyink-use-majority-quotes = true

[tool.setuptools]
packages = ["xee"]

[tool.setuptools_scm]
fallback_version = "9999"

[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["osx-arm64"]

[tool.pixi.pypi-dependencies]
xee = { path = ".", editable = true }

[tool.pixi.environments]
default = { solve-group = "default" }
dataflow = { features = ["dataflow"], solve-group = "default" }
examples = { features = ["examples", "dataflow"], solve-group = "default" }
tests = { features = ["tests"], solve-group = "default" }

[tool.pixi.tasks]

[tool.pixi.dependencies]
proj = ">=9.5.1,<10"
gdal = ">=3.10.1,<4"
pytest = ">=8.3.4,<9"
Loading