Skip to content

0.7.0

Latest
Compare
Choose a tag to compare
@kyrylo-gr kyrylo-gr released this 10 Jun 13:56
· 25 commits to main since this release

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:

data = aqm.load_file("2023_01_31__12_34_56__simple_sine")

type(data) # -> 'AnalysisData'

Create a new file:

aq = aqm.create_acquisition()
aq['x'] = 123
aq.save_acquisition(y=456)

Save and load more than one file.

Acquisition cell:

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

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:

['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

def abc(a):
    return 3*a
param1 = 123

Saving:

aqm.set_default_config_files(["config1.py"]) # run ones on aqm initialization

Reading:

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.

aqm.data.parse_config_file('config1.py').eval_key('param1')

Functions can be saved

It's possible to save a simple function now.

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);
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

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.

data =  AttrDict({'param_1': 123.43})

data.output(["param_1"]) # -> param_1 = 123.43
data.output(["param_1__m/s__1f"]) # -> param_1 = 123.4 (m/s)

Short way to call enumerate(loop(...)) -> loop.enum(...)

As easy as the title says. No need to call enumerate on loop just use loop.enum(...)

aqm.acquisition_cell('simple_sine')

aqm['some_loop'] = loop = AcquisitionLoop()

for i, q in loop.enum(1, 5, .5):
    loop.append(x=i, y=q)
aqm.analysis_cell(acquisition_name=r"^simple_\w")
aqm.d.some_loop.x  # -> [0., 1., 2., 3.]
aqm.d.some_loop.y  # -> [1. , 1.5, 2. , 2.5]

Figures can again be saved inside h5 file.

Before, figures were saved with pickle library. But then figures cannot be opened on different systems. So a new library pltsave was used. This allows to save and open the figure on different systems.

Usage (as before):

To save a particular figure use inside_h5 keyword:

aqm.save_fig(fig, inside_h5=True)

To save every figure, set save_fig_inside_h5 keyword during init of AcquisitionAnalysisManager to True:

aqm = AcquisitionAnalysisManager(..., save_fig_inside_h5=True)

Minor features

  • Fix saving complex numbers inside AcquisitionLoop