Skip to content

Dset units attr #147

Closes #147 (closed)

It seems there was a typo in our implementation that crippled some plotting builtin functionalities of xarray. We used "unit" instead of "units". This MR fixes that.

For reference here is the snippet to update all datasets so that they can be used after this breaking change:

from quantify.data.handling import (
    load_dataset,
    set_datadir,
    get_tuids_containing,
    _locate_experiment_file
)
import xarray as xr
from quantify.utilities._tests_helpers import get_test_data_dir


set_datadir("username/quantify-data") # set your datadir here! 

tuids = get_tuids_containing("")
for i, tuid in enumerate(tuids):
    print(f"\rProcessing {tuid} ({i+1}/{len(tuids)})", end="")
    try:
        path = _locate_experiment_file(tuid, None, "dataset.hdf5")
        dset = xr.load_dataset(path)        
        for key, value in dset.items():
            if 'unit' in value.attrs:
                cur_unit = value.attrs['unit']
                value.attrs.update({"units": cur_unit})
                _ = value.attrs.pop("unit")
        dset.to_netcdf(path)
    except FileNotFoundError as e:
        # empy dirs might raise exceptions
        print("\n")
        print(e)

print('\nDONE')
Edited by Victor Negîrneac

Merge request reports

Loading