-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feat/Data handler to save data #188
Conversation
The tests are failing because I haven't added xarray as a required package but as an optional package. @yomach @TheoLaudatQM any recommendations? Should I skip tests if xarray isn't installed? |
You can tell the tests to build with these packages, I'll take a look next week |
@nulinspiratie |
Wait, I don't see you added xarray as a required package at all? |
@yomach yeah just noticed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add it also to the CHANGELOG.md
and to the main README.md
file (in the root directory)
Done @yomach ! |
@TheoLaudatQM @yonatanrqm any comments? If possible, I'm hoping to have this merged tomorrow |
Data handler
This PR is made because a standardized method is needed in Qualibrate to save data.
Introduction
The
DataHandler
is used to easily save data once a measurement has been performed.It saves data into an automatically generated folder with folder structure:
{root_data_folder}/%Y-%m-%d/#{idx}_{name}_%H%M%S
.root_data_folder
is the root folder for all data, defined once at the start%Y-%m-%d
: All datasets are first ordered by date{idx}
: Datasets are identified by an incrementer (starting at#1
).Whenever a save is performed, the index of the last saved dataset is determined and
increased by 1.
name
: Each data folder has a name%H%M%S
: The time is also specified.This structure can be changed in
DataHandler.folder_structure
.Data is generally saved using the command
data_handler.save_data("msmt_name", data)
,where
data
is a dictionary.The data is saved to the json file
data.json
in the data folder, but nonserialisabletypes are saved into separate files. The following nonserialisable types are currently
supported:
Basic example
After calling
data_handler.save_data()
, three files are created indata_folder
:T1_figure.png
arrays.npz
containing all the numpy arraysdata.json
which contains:Creating a data folder
A data folder can be created in two ways:
Note that the methods return different results.
The method
DataHandler.save_data
simply returns the path to the newly-created data folder, whereasDataHandler.create_data_folder
returns a dict with additional information on the data folder such as theidx
.This additional information can also be accessed after calling
DataHandler.save_data
through the attributeDataHandler.path_properties
.Manually adding additional files to data folder
After a data folder has been created, its path can be accessed from
DataHandler.path
.This allows you to add additional files:
Auto-saving additional files to data folder
In many cases certain files need to be added every time a data folder is created.
Instead of having to manually add these files each time, they can be specified beforehand:
Each key is a path from the current working directory, and the corresponding value is the target filepath w.r.t. the data folder.
The key does not have to be a relative filepath, it can also be an absolute path.
This can be useful if you want to autosave a specific file on a fixed location somewhere on your hard drive.