Skip to content
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

Is it required to chunk selections? #40

Closed
andhuang-CLGX opened this issue Sep 28, 2021 · 3 comments
Closed

Is it required to chunk selections? #40

andhuang-CLGX opened this issue Sep 28, 2021 · 3 comments

Comments

@andhuang-CLGX
Copy link

import xarray as xr
import xoak
ds = xr.tutorial.open_dataset('rasm').isel(time=0)

ds.xoak.set_index(['yc', 'xc'], "scipy_kdtree")

ds.xoak.sel(yc=16.91, xc=27.51)

AttributeError: 'float' object has no attribute 'chunks'

@willirath
Copy link
Contributor

Currently, selections are only possible with xarray.DataArrays. These don't need to be chunked, but they do always have a degenerate single chunk:

print(xarray.DataArray([16.91, ]).chunks)
None

So you should be able to do something like:

import xarray as xr
import xoak
ds = xr.tutorial.open_dataset('rasm').isel(time=0)

ds.xoak.set_index(['yc', 'xc'], "scipy_kdtree")

print(ds.xoak.sel(yc=xr.DataArray([16.91, ]), xc=xr.DataArray([27.51, ])))
<xarray.Dataset>
Dimensions:  (dim_0: 1)
Coordinates:
    time     object 1980-09-16 12:00:00
    xc       (dim_0) float64 16.91
    yc       (dim_0) float64 27.51
Dimensions without coordinates: dim_0
Data variables:
    Tair     (dim_0) float64 ...
Attributes:
    title:                     /workspace/jhamman/processed/R1002RBRxaaa01a/l...
    institution:               U.W.
    source:                    RACM R1002RBRxaaa01a
    output_frequency:          daily
    output_mode:               averaged
    convention:                CF-1.4
    references:                Based on the initial model of Liang et al., 19...
    comment:                   Output from the Variable Infiltration Capacity...
    nco_openmp_thread_number:  1
    NCO:                       netCDF Operators version 4.7.9 (Homepage = htt...
    history:                   Fri Aug  7 17:57:38 2020: ncatted -a bounds,,d...

@andhuang-CLGX
Copy link
Author

Do you think xoak should automatically do that internally to mimic xarray.Dataset.sel() behavior?

@andhuang-CLGX
Copy link
Author

Oh I guess duplicate of #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants