Unexpected Keyword Argument in Xarray #315
Replies: 1 comment
-
|
Hi! It looks like you have encountered the changes introduced in Xee v0.1.0. In this version, the library transitioned to a new grid parameter system, which is why your code is failing with an "unexpected keyword argument" error for What Changed?
For more details, please see the Xee v0.1.0 Migration Guide. Updated Code SnippetHere is how you can update your workflow using the new !pip install -q xee
import ee
import shapely
import xarray as xr
from xee import helpers # Import the xee helpers module
import matplotlib.pyplot as plt
# 1. Authentication and Initialization
ee.Authenticate()
project_id = 'PROJECT_ID' # Replace with your project ID
ee.Initialize(project=project_id)
# 2. Define your AOI and helper
# The 'fit_geometry' helper replaces the old direct arguments
def get_grid_params(roi, grid_crs, grid_scale):
# This generates the required 'crs', 'crs_transform', and 'shape_2d'
# arguments automatically for xr.open_dataset
grid_params = helpers.fit_geometry(
geometry=roi,
geometry_crs='EPSG:4326',
grid_crs=grid_crs,
grid_scale=grid_scale # Note: Y-scale should be negative for north-up
)
return grid_params
# A rectangle in Washington State for testing
roi = shapely.geometry.box(-122.5, 46.5, -121.5, 47.5)
# 3. Prepare your data
lst = ee.ImageCollection("MODIS/061/MOD11A2").filterDate('2020','2021').select('LST_Day_1km').mean().multiply(0.02).subtract(273.15)
ndvi = ee.ImageCollection("MODIS/061/MOD13Q1").filterDate('2020','2021').select('NDVI').mean().multiply(0.0001)
stack = ee.Image.cat([lst, ndvi]).select([0,1],['lst','ndvi'])
# 4. Generate grid parameters using the helper
# grid_scale is (x_scale, y_scale)
grid_1km = get_grid_params(roi, 'EPSG:4326', (0.01, -0.01))
grid_250m = get_grid_params(roi, 'EPSG:4326', (0.0025, -0.0025))
# 5. Open dataset using the new engine call
# We unpack the dictionary returned by the helper
ds1km = xr.open_dataset(stack, engine='ee', **grid_1km)
ds250m = xr.open_dataset(stack, engine='ee', **grid_250m)
print(ds1km)
# 6. Plotting
# Note: No .transpose() is needed as v0.1.0 uses (time, y, x) order by default
fig, axes = plt.subplots(1, 2, figsize=(15, 6))
ds1km.lst.isel(time=0).plot(ax=axes[0])
axes[0].set_title('MODIS LST (1km Scale)')
ds250m.lst.isel(time=0).plot(ax=axes[1])
axes[1].set_title('MODIS LST (250m Scale)')
plt.tight_layout()
plt.show()
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
!pip install earthengine-api -q
!pip install xee -q
!pip install geemap -q
import ee
import geemap
import xarray as xr
import xee
!pip install -U xee xarray earthengine-api geemap
import ee
import geemap
import xarray as xr
ee.Authenticate()
ee.Initialize(project='ee-sabbirhossainshah')
import geemap
map = geemap.Map(basemap = 'SATELLITE')
map
roi = map.draw_last_feature.geometry()
roi
lst = ee.ImageCollection("MODIS/061/MOD11A2").filterDate('2020','2021').select('LST_Day_1km').mean().multiply(0.02).subtract(273.15)
ndvi = ee.ImageCollection("MODIS/061/MOD13Q1").filterDate('2020','2021').select('NDVI').mean().multiply(0.0001)
stack = ee.Image.cat([lst, ndvi]).select([0,1],['lst','ndvi'])
stack
ds1km = xr.open_dataset(stack, engine = 'ee', crs = 'EPSG:4326', scale = 0.01, geometry = roi)
ds250m = xr.open_dataset(stack, engine ='ee', crs = 'EPSG:4326', scale = 0.0025, geometry = roi)
ds1km
While running the code in google collab why shows error
TypeError Traceback (most recent call last)
/tmp/ipykernel_2657/2152062775.py in <cell line: 0>()
----> 1 ds1km = xr.open_dataset(stack, engine = 'ee', crs = 'EPSG:4326', scale = 0.01, geometry = roi)
2 ds250m = xr.open_dataset(stack, engine ='ee', crs = 'EPSG:4326', scale = 0.0025, geometry = roi)
3
4 ds1km
/usr/local/lib/python3.12/dist-packages/xarray/backends/api.py in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, create_default_indexes, inline_array, chunked_array_type, from_array_kwargs, backend_kwargs, **kwargs)
604
605 overwrite_encoded_chunks = kwargs.pop("overwrite_encoded_chunks", None)
--> 606 backend_ds = backend.open_dataset(
607 filename_or_obj,
608 drop_variables=drop_variables,
TypeError: EarthEngineBackendEntrypoint.open_dataset() got an unexpected keyword argument 'scale' or geometry
please help me as soon as possible
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions