Skip to content

Commit

Permalink
WIP working roundtrip for only multiindex
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Sep 14, 2023
1 parent aa95aca commit b1f81a6
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions qcodes/dataset/data_set_in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def _load_from_netcdf(

loaded_data = xr.load_dataset(path, engine="h5netcdf")

# todo replace with check that type(xr_ds.indexes["multi_index"])
# is a MultiIndex
if "multi_index" in loaded_data.coords:
loaded_data = cfxr.coding.decode_compress_to_multi_index(
loaded_data, "multi_index"
Expand Down Expand Up @@ -398,14 +400,28 @@ def _from_xarray_dataset_to_qcodes_raw_data(
output[str(datavar)] = {}
data = xr_data[datavar]
output[str(datavar)][str(datavar)] = data.data
coords_unexpanded = []
# this logic only applies if gridded
# for multi_index we want to skip that one and
for coord_name in data.dims:
coords_unexpanded.append(xr_data[coord_name].data)
coords_arrays = np.meshgrid(*coords_unexpanded, indexing="ij")
for coord_name, coord_array in zip(data.dims, coords_arrays):
output[str(datavar)][str(coord_name)] = coord_array

all_coords = []
for index_name in data.dims:
index = data.indexes[index_name]

coords = {name: data.coords[name] for name in index.names}
all_coords.append(coords)

if len(all_coords) > 1:
coords_unexpanded = []
# this logic only applies if gridded
# for multi_index we want to skip that one and
for coord_name in data.dims:
coords_unexpanded.append(xr_data[coord_name].data)
coords_arrays = np.meshgrid(*coords_unexpanded, indexing="ij")
for coord_name, coord_array in zip(data.dims, coords_arrays):
output[str(datavar)][str(coord_name)] = coord_array
else:
coords = all_coords[0]
for coord_name, coord in coords.items():
output[str(datavar)][str(coord_name)] = coord.data

return output

def prepare(
Expand Down

0 comments on commit b1f81a6

Please sign in to comment.