Version 0.7.0. What's new?
Quickly:
- Cleaner usage of `aqm`. Save and load more than one file.
- List of str and object can also be saved.
- Saved config files can be imported. Parsing of multiline values.
- Functions can be saved.
- `ConfigFile` has find and output methods.
- Short way to call enumerate(loop(...)) -> loop.enum(...).
- Figures can again be saved inside h5 file.
Cleaner usage of `aqm`. Save and load more than one file.
Cleaner usage of `aqm`.
Now it's easy to create and analyze data outside of acquisition_cell and analysis_cell
Load file:
python
data = aqm.load_file("2023_01_31__12_34_56__simple_sine")
type(data) -> 'AnalysisData'
Create a new file:
python
aq = aqm.create_acquisition()
aq['x'] = 123
aq.save_acquisition(y=456)
Save and load more than one file.
Acquisition cell:
python
aqm.acquisition_cell('list')
files = []
for i in range(5):
aq = aqm.create_acquisition()
x, y = take_some_data(param=i)
aq.save_acquisition(
x=x, y=y,
func_code=take_some_data, keep track of the function you used
parent=aqm.current_filepath.str) optional, but good to keep a trace of the files
files.append(aq.filepath)
aqm['files'] = files
aqm.save_acquisition() optional, but good practice
Analysis cell
python
aqm.analysis_cell(acquisition_name=r"^list")
for file in aqm.data.files:
data = aqm.load_file(file)
data.x, data.y
List of str and object can also be saved
Any list that can be converted to json can be saved now.
Examples:
python
['a', 'b', 'c']
['a', 'b', {'p1': 'c', 'p2': 'd'}]
['a', 'b', [1, 2, 3]]
Saved config files can be imported.
If you need to import a module that you have saved as a string inside the file, you can do so.
While the use of the eval function can be debatable, it is still very explicit.
Example of a config file `config1.py`
python
def abc(a):
return 3*a
param1 = 123
Saving:
python
aqm.set_default_config_files(["config1.py"]) run ones on aqm initialization
Reading:
python
cfg = aqm.data.parse_config_file('config1.py')
cfg.param1 -> 123 file is parsed by default without being evaluated
cfg_module = cfg.eval_as_module()
now cfg_module works as if you imported config1.py
cfg_module.abc(2) -> 4
cfg_module.param1 -> 123
Multiline parsing
Values that are written in multiple lines inside config files are well parsed. But still, there are not evaluated, so if you saved a dictionary it will be a string when parsed.
To convert a string to a dictionary you can use `eval_key` method that evaluates the string.
python
aqm.data.parse_config_file('config1.py').eval_key('param1')
Functions can be saved
It's possible to save a simple function now.
python
aqm.acquisition_cell('simple_sine')
def acquire_data(size):
import numpy as np
x = np.linspace(0, 10*np.pi, size)
y = np.sin(x)
return x, y
aqm.save_acquisition(acquire_data=acquire_data);
python
aqm.analysis_cell(acquisition_name=r"^simple_\w")
aqm.d.acquire_data.code return code of the function
aqm.d.acquire_data.eval(101) evaluate the function with given args and kwds
Functions are saved as a string inside the h5 file and are evaluated on the first eval method call. Not when the file is loaded. Therefore, use of eval function is still explicit.
ConfigFile has find and output methods
`ConfigFile`(subclass of an `AttrDict`) is a class used when a config file is loaded. It's a classical dict, but with possibility to access items as attributes.
Now you can find items inside dict and output values.
Find
python
data = AttrDict({'param_1': 'value1', 'param_2': 'value2'})
data.find('param') -> ('param_1', 'value1')
data.find_all('param') -> [('param_1', 'value1'), ('param_2', 'value2')]
Output
The syntax is the same as `parse_config_str` function.
python