Skip to content

Commit

Permalink
update readers to match new file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Aug 27, 2024
1 parent e9d2633 commit 695f7e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 8 additions & 1 deletion virtualizarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@
Any,
Hashable,
Optional,
TypeAlias,
cast,
)

import xarray as xr
from xarray.backends import AbstractDataStore, BackendArray
from xarray.coding.times import CFDatetimeCoder
from xarray.conventions import decode_cf_variables
from xarray.core.indexes import Index, PandasIndex
from xarray.core.variable import IndexVariable
from xarray.core.variable import IndexVariable, Variable

from virtualizarr.manifests import ManifestArray
from virtualizarr.utils import _fsspec_openfile_from_filepath

XArrayOpenT = str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore

T_Attrs = MutableMapping[Any, Any]
T_Variables = Mapping[Any, Variable]
# alias for (dims, data, attrs, encoding)
T_VariableExpanded: TypeAlias = tuple[Hashable, Any, dict[Any, Any], dict[Any, Any]]


class AutoName(Enum):
# Recommended by official Python docs for auto naming:
Expand Down
16 changes: 8 additions & 8 deletions virtualizarr/readers/kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from xarray.core.indexes import Index
from xarray.core.variable import Variable

from virtualizarr.backend import FileType, separate_coords
from virtualizarr.backend import (
FileType,
construct_virtual_dataset,
determine_cf_coords,
)
from virtualizarr.manifests import ChunkManifest, ManifestArray
from virtualizarr.types.kerchunk import (
KerchunkArrRefs,
Expand Down Expand Up @@ -176,14 +180,10 @@ def dataset_from_kerchunk_refs(

if indexes is None:
indexes = {}
data_vars, coords = separate_coords(vars, indexes, coord_names)

vds = Dataset(
data_vars,
coords=coords,
# indexes={}, # TODO should be added in a later version of xarray
attrs=ds_attrs,
)
decoded_vars, decoded_attrs, coord_names = determine_cf_coords(vars, ds_attrs)

vds = construct_virtual_dataset(decoded_vars, indexes, decoded_attrs, coord_names)

return vds

Expand Down
2 changes: 1 addition & 1 deletion virtualizarr/readers/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xarray.core.indexes import Index
from xarray.core.variable import Variable

from virtualizarr.backend import determine_cf_coords, construct_virtual_dataset
from virtualizarr.backend import construct_virtual_dataset, determine_cf_coords
from virtualizarr.manifests import ChunkManifest, ManifestArray
from virtualizarr.zarr import ZArray

Expand Down

0 comments on commit 695f7e9

Please sign in to comment.