2

I am trying to clip an xarray dataset using rioxarray.clip with geometry from a geodataframe. I am running the code on a cloud platform built on kubernetes clusters in a distributed manner using Dask. From what I can tell, my code is correct and should be performing the clip. However, when I graph the clip result the clipped dataset has the same extents as the parent.

First, the data is brought in using the intake library and the to_dask function.

url = 'https://raw.githubusercontent.com/USGS-python/hytest-catalogs/main/hytest_intake_catalog.yml'
cat = intake.open_catalog(url)

dataset = 'conus404-40year-cloud'

ds = cat[dataset].to_dask()

This is what the dataset looks like. enter image description here The dataset is then trimmed to variables and time of interest. The clipping geography is also created.

# restrict variables to those of interest
c404_variables = ["PREC_ACC_NC", "TK", "ACSWDNB", "I_ACSWDNB", "ACSWDNB", "I_ACSWDNB", "ACLWDNB", "I_ACLWDNB", "ACLWUPB", "I_ACLWUPB"]
c404 = ds[c404_variables]

# use slice to filter by time 
start_time = "1990-01-01 00:00"
end_time = "1990-12-31 00:00"
c404 = c404.sel(time=slice(start_time, end_time))

#WGS84 = EPSG:4326
c404.rio.write_crs("epsg:4326", inplace=True)

# bring in boundaries of the Deleware River Basing (DRB) and create single polygon
drb = pygeohydro.WBD("huc6", outfields=["huc6", "name"]).byids("huc6", ["020401", "020402"])
# create a column where all entries have the same value
drb["name"] = "DRB"

#dissolve by that column to create a single geometry
drb = drb.dissolve(by="name")

At this point, I've matched the CRS between the xarray dataset and the geodataframe. I then perform the clip and visualize the result.

# clip data to precise geometry of Delaware River Basin
c404_drb = c404.rio.clip(drb.geometry, drop=True, invert=False, from_disk=True)

# make data smaller 
c404_drb_check = c404_drb["TK"].sel(time="1990-01-01 07:00").load()

c404_drb_check.hvplot.quadmesh(x='lon', y='lat', rasterize=True, 
                             geo=True, tiles='OSM', alpha=0.7, cmap='turbo')

And the resulting image has an extent of CONUS rather than the Delaware River Basin.

After reviewing the rioxarray usage examples and API references, I wonder if there are issues with the coordinates of the dataset or that it was created through intake.to_dask, though it is an xarray.dataset so rioxarray should still work. Any insight someone would have would be most helpful. TYIA

1 Answer 1

1

rioxarray clip has not been designed/tested to work with dask yet. It may or may not work. If you are interested in collaborating to add support, opening a ticket on GitHub would be a good next step.

2
  • Thank you, I will open a ticket on Github. I'll do so then report there and here on a couple of work arounds I'm going to try. Thank you! Commented Sep 6, 2022 at 14:11
  • Sounds good. Thanks 👍
    – snowman2
    Commented Sep 7, 2022 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.