-
I am trying to export the percentile fields for a specific time range of all years from MERRA2 dataset. ds = xr.concat(ds, "percentile")
ds.to_netcdf("output.nc") The code # Load MERRA/slv/2 dataset
dataset = ee.ImageCollection('NASA/GSFC/MERRA/slv/2')
# Define the desired date range (Jan 1st to Jan 15th)
start_day = 1
end_day = 15
# Filter by day-of-year range (using server-side filtering)
filtered_dataset = dataset.filter(ee.Filter.dayOfYear(start_day, end_day))
lonlim = [-(88+39/60), -(30+40/60)]
latlim = [-(41+23/60), 12+58/60]
bbox = ee.Geometry.BBox(lonlim[0], latlim[0], lonlim[1], latlim[1])
variables = ["PS", "T10M", "TQV", "U10M", "V10M"]
ds = []
for percentile in tqdm(np.arange(10, 100, 10)):
percentile_image = filtered_dataset.select(variables).reduce(ee.Reducer.percentile([int(percentile)]))
dsi = geemap.ee_to_xarray(
percentile_image.clip(bbox)
).squeeze().transpose("lat","lon").sel(lon=slice(*lonlim), lat=slice(*latlim))
dsi = dsi.rename({var: var.split("_")[0] for var in list(dsi)})
dsi = dsi.assign_coords(percentile=percentile)
ds.append(dsi)
ds = xr.concat(ds, "percentile")
ds.to_netcdf("output.nc") The idea is to have a final data that each variable varies in Anyone has any idea on how to perform this efficiently? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Use the map function on the image collection. Never use a for loop on an image collection. It is computationally expensive. |
Beta Was this translation helpful? Give feedback.
-
Export the images to Google Drive, then use Xarray to deal with dimensions. filtered_dataset = dataset.filter(ee.Filter.dayOfYear(start_day, end_day)).select(variables)
precentiles = ee.List.sequence(10, 100, 10)
collection = precentiles.map(lambda p: filtered_dataset.reduce(ee.Reducer.percentile([p])).clip(bbox))
image = ee.ImageCollection(collection).toBands()
image |
Beta Was this translation helpful? Give feedback.
Use the map function on the image collection. Never use a for loop on an image collection. It is computationally expensive.
https://developers.google.com/earth-engine/guides/ic_mapping