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

Backend opener refactor #4429

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
except ImportError:
Delayed = None


DATAARRAY_NAME = "__xarray_dataarray_name__"
DATAARRAY_VARIABLE = "__xarray_dataarray_variable__"

Expand Down Expand Up @@ -446,6 +445,7 @@ def open_dataset(

if backend_kwargs is None:
backend_kwargs = {}
extra_kwargs = {}

def maybe_decode_store(store, lock=False):
ds = conventions.decode_cf(
Expand Down Expand Up @@ -504,28 +504,24 @@ def maybe_decode_store(store, lock=False):

if engine is None:
engine = _get_default_engine(filename_or_obj, allow_remote=True)
if engine == "netcdf4":
store = backends.NetCDF4DataStore.open(
filename_or_obj, group=group, lock=lock, **backend_kwargs
)
elif engine == "scipy":
store = backends.ScipyDataStore(filename_or_obj, **backend_kwargs)
elif engine == "pydap":
store = backends.PydapDataStore.open(filename_or_obj, **backend_kwargs)
elif engine == "h5netcdf":
store = backends.H5NetCDFStore.open(
filename_or_obj, group=group, lock=lock, **backend_kwargs
)
elif engine == "pynio":
store = backends.NioDataStore(filename_or_obj, lock=lock, **backend_kwargs)
elif engine == "pseudonetcdf":
store = backends.PseudoNetCDFDataStore.open(
filename_or_obj, lock=lock, **backend_kwargs
)
elif engine == "cfgrib":
store = backends.CfGribDataStore(
filename_or_obj, lock=lock, **backend_kwargs
)

backend_switch = {
"netcdf4": backends.NetCDF4DataStore.open,
"scipy": backends.ScipyDataStore,
"pydap": backends.PydapDataStore.open,
"h5netcdf": backends.H5NetCDFStore.open,
"pynio": backends.NioDataStore,
"pseudonetcdf": backends.PseudoNetCDFDataStore.open,
"cfgrib": backends.CfGribDataStore,
}
if engine in ["netcdf4", "h5netcdf"]:
extra_kwargs["group"] = group
extra_kwargs["lock"] = lock
elif engine in ["pynio", "pseudonetcdf", "cfgrib"]:
extra_kwargs["lock"] = lock
store = backend_switch.get(engine)(
filename_or_obj, **backend_kwargs, **extra_kwargs
)

else:
if engine not in [None, "scipy", "h5netcdf"]:
Expand Down