-
I'm having trouble figuring out what steps I'm missing to implement a custom backend to return a dataset which displays all non-indexed variables as expected. I already have methods to collect and transform the data into a xarray The challenge is I can't figure out what steps I'm missing which result in The examples below show differences between a dataset manually created, and the same dataset returned by a custom backend. The dataset includes:
Example 1: Simple dataset import xarray as xr
xr.Dataset(
data_vars={
"x": xr.DataArray(
data=[1,1,1,1],
dims="a"
),
"y": xr.DataArray(
data=[2,2,2,2],
dims="a"
)
},
coords={
"a": [1,2,3,4],
"b": ("a", [1,2,3,4])
}
) If the same dataset is returned via Example2: "Opening" dataset using custom backend. import numpy as np
import xarray as xr
from xarray.backends import BackendEntrypoint
# Simple backend that returns a fixed dataset with two variables, one dimension, and one non-dimension
class SimpleBackend(BackendEntrypoint):
description = "Simple backend"
def open_dataset(
self,
filename_or_obj,
*,
drop_variables=None,
):
return xr.Dataset(
data_vars={
"x": xr.DataArray(
data=[1,1,1,1],
dims="a"
),
"y": xr.DataArray(
data=[2,2,2,2],
dims="a"
)
},
coords={
"a": [1,2,3,4],
"b": ("a", [1,2,3,4])
}
)
xr.open_dataset("test", engine=SimpleBackend) What am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
this is normal, you need to call |
Beta Was this translation helpful? Give feedback.
this is normal, you need to call
ds.load()
ords.compute()
to get the same result:open_dataset
only reads the metadata of a file into memory, which allows opening files that are too big to fit into memory. As a second step you can (implicitly or explicitly) load the data into memory (or usedask
to allow computing with larger-than-memory arrays).