Labmate

Latest version: v0.10.2

Safety actively analyzes 682361 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

123.54321

aqm.parse_config_str(["k__ms__2f"]) -> 'k = 123.54 (ms)'

aqm.parse_config_str(["k__ms"]) -> 'a = 123.54321 (ms)'

123.54

aqm.parse_config_str(["k__2e"]) -> 'a = 1.23e+02'


Warning when analyzing old data

Now when you're analyzing old files using aqm.analysis_cell inside the Jupyter notebook you will see a warning.

Linting!

Now analysis cell is parsed in the search for a classical error.

It happens a lot that you use by mistake global variables inside analysis_cell, now you can prevent it.

How to setup

You can set explicitly which external variables you are allowed to use inside analysis_cell

python
aqm.linting(allowed_variables=['aqm', 'plt'])


Or you can parse the init_analyse file. (Normally this is a file which is run before running the analysis cell so you are allowed to use any variables from it)

python
aqm.linting(init_file="files/init_analyse.py")


Note that this function will not look inside if you use import of type `from module import *`

How to use

After running `aqm.linting` there is nothing more to do, just run the usual `aqm.analysis_cell` and see if there are any warnings.

If some usage of global variables should be ignored add ` noqa` at the end of the line.

AttrDict

Now there is a new class available: `AttrDict`. It's a classical dictionary but allows to access it by attributes.

Simple example:

python
data = AttrDict({'a': 123})
print(data.a) -> 123


Recursive example:

python
data = AttrDict({'a':{'b': 456}})
print(data.a.b) -> 456


Feature:
Now parsed data from the config files are returned as an instance of `AttrDict`, so it can be easily accessed.

Minor features

- SyncData.asdict() -> dict
- more tests

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(...)`

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


python
aqm.analysis_cell(acquisition_name=r"^simple_\w")
aqm.d.some_loop.x -> [0., 1., 2., 3.]

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:

python
aqm.save_fig(fig, inside_h5=True)


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

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


Minor features

- Fix saving complex numbers inside AcquisitionLoop

0.7.0

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

0.6.1

Version 0.6.1. What's new?

This is a minor update with important features.

Features added:

- Short way to call enumerate(loop(...)) -> loop.enum(...)
- List of strings or objects can be now saved. It's saved as json string.

Minor features

- Fix saving complex numbers inside AcquisitionLoop

Page 1 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.