I'm running in to a LOT of frustration with trying to use xarray for data sets that it, shall we say, hasn't been designed for.
In particular, results from the FVCOM triangular mesh ocean model. But it's not just that.
IIRC, xarray (maybe when it was called xray) was essentially an implementation of the netcdf Data model. Since then, it's grown to do a lot of nifty stuff for you, with fancy indexing features, etc. But as a result, if you try to load a file it doesn't understand, it raises an Error and you are dead in the water.
If you think of xarray as a data analysis tool, this makes sense -- try to load the file, if xarray doesn't understand it, then fix your file, and reload it -- all good.
However, if you want to use xarray as a lower level library, then you might want to use TO FIX those issues it doesn't understand, and then if you can't even load the file, you're dead.
I guess what I'm looking for is a "load-all-the-arrays-even-if-you-can't-figure-out-all-the-coordinates" mode.
Does such a mode exist?
-CHB
The problem at hand:
This file:
Is results from an operational FVCOM model.
When I try to load it with xarray, I get:
File ~/miniforge3/envs/gnome/lib/python3.11/site-packages/xarray/core/dataset.py:696, in Dataset.__init__(self, data_vars, coords, attrs)
693 if isinstance(coords, Dataset):
694 coords = coords._variables
--> 696 variables, coord_names, dims, indexes, _ = merge_data_and_coords(
697 data_vars, coords
698 )
700 self._attrs = dict(attrs) if attrs is not None else None
701 self._close = None
File ~/miniforge3/envs/gnome/lib/python3.11/site-packages/xarray/core/dataset.py:421, in merge_data_and_coords(data_vars, coords)
419 coords = coords.copy()
420 else:
--> 421 coords = create_coords_with_default_indexes(coords, data_vars)
423 # exclude coords from alignment (all variables in a Coordinates object should
424 # already be aligned together) and use coordinates' indexes to align data_vars
425 return merge_core(
426 [data_vars, coords],
427 compat="broadcast_equals",
(...)
432 skip_align_args=[1],
433 )
File ~/miniforge3/envs/gnome/lib/python3.11/site-packages/xarray/core/coordinates.py:957, in create_coords_with_default_indexes(coords, data_vars)
955 all_variables = dict(coords)
956 if data_vars is not None:
--> 957 all_variables.update(data_vars)
959 indexes: dict[Hashable, Index] = {}
960 variables: dict[Hashable, Variable] = {}
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Clearly, it's not getting what it's expecting for coordinates, but I"d really like ot to give me a warning and move on, rather than erroring out :-)
-CHB