Skip to content

compatibility

Description

This module contains the functions used to ensure the compatibility of file formats saved with previous versions of openhdemg with the most recent versions of the library.


convert_json_output(old='', new='', old_version='0.1.0-beta.2', new_version='0.1.0-beta.3', append_name='converted', compresslevel=4, gui=True, ignore_safety_checks=False)

Convert .json files saved from previous openhdemg versions to the desired format (target openhdemg version).

PARAMETER DESCRIPTION
old

A path pointing to a .json file, or to a folder containing multiple .json files, saved from the openhdemg version specified in old_version. The path can be a simple string, the use of Path() is not necessary. If old points to a folder, all the .json files contained in that folder will be converted. Make sure that the folder contains only .json files from the openhdemg version specified in old_version.

TYPE: str DEFAULT: ""

new

A path pointing to the folder where the converted .json file/files will be saved. The path can be a simple string, the use of Path() is not necessary.

TYPE: str DEFAULT: ""

old_version

The openhdemg version used to save the old files. Only "0.1.0-beta.2" is currently supported.

TYPE: str {0.1.0-beta.2} DEFAULT: 0.1.0-beta.2

new_version

The target openhdemg version for which you want to convert the files. Only "0.1.0-beta.3" is currently supported.

TYPE: str {0.1.0-beta.3} DEFAULT: 0.1.0-beta.3

append_name

String to append to the name of the converted file. Use append_name="" to don't append any name.

TYPE: str DEFAULT: "converted"

compresslevel

An int from 0 to 9, where 0 is no compression and nine maximum compression. Compressed files will take less space, but will require more computation. The relationship between compression level and time required for the compression is not linear. For optimised performance, we suggest values between 2 and 6, with 4 providing the best balance.

TYPE: int DEFAULT: 4

gui

If true, the user will be able to select one or multiple .json files to convert and the output folder with a convenient graphical interface. If true, old and new can be ignored.

TYPE: bool DEFAULT: True

ignore_safety_checks

Safety checks are performed to avoid overwriting the original file. If ignore_safety_checks=True, the original file could be overwritten without asking user permission. The risk of overwriting files happens when converted files are saved in their original directory and with append_name="".

TYPE: bool DEFAULT: False

Examples:

Convert the file/s with a practical GUI.

>>> from openhdemg.compatibility import convert_json_output
>>> convert_json_output(gui=True, append_name="converted")

Convert all the files in a folder without GUI. Save them in the same location with a different name.

>>> from openhdemg.compatibility import convert_json_output
>>> old = "C:/Users/.../test conversions/"
>>> new = "C:/Users/.../test conversions/"
>>> convert_json_output(
...     old=old,
...     new=new,
...     append_name="converted",
...     gui=False,
... )

Convert a file in a folder without GUI and overwrite it.

>>> from openhdemg.compatibility import convert_json_output
>>> old = "C:/Users/.../test conversions/old_testfile.json"
>>> new = "C:/Users/.../test conversions/"
>>> convert_json_output(
...     old=old,
...     new=new,
...     append_name="",
...     gui=False,
...     ignore_safety_checks=True,
... )

load_0_1_0_b2(filepath)

save_0_1_0_b3(emgfile, filepath, compresslevel)