pyCGM2.Utils#

files functions#

concatenateExcelFiles(DATA_PATH_OUT, ...)

Concatenate multiple Excel files into a single Excel file.

copyPaste(src, dst)

Copy and paste a file from a source to a destination.

copyPasteDirectory(src, dst[, overwriteFlag])

Copy and paste a directory from a source to a destination.

copySessionFolder(folderPath, folder2copy, ...)

Copy a session folder, optionally including only selected files.

createDir(fullPathName)

Create a new directory.

deleteDirectory(dir)

Delete a directory.

getC3dFiles(path[, text, ignore])

Retrieve all C3D files from a directory, optionally filtering by text within filenames.

getDirname(fullname)

Extract the directory path from a full path.

getDirs(folderPath[, contain, pattern])

Get all subdirectories within a folder.

getFileCreationDate(file)

Get the creation date of a file.

getFilename(fullname)

Extract the filename from a full path.

getFiles(path, extension[, ignore, ...])

Retrieve all files with a specific extension from a directory.

getIKweightSet(DATA_PATH, ikwf)

Retrieve marker weights for kinematic fitting from a specified file.

getMp(mpInfo[, resetFlag])

Return required and optional anthropometric parameters from a given dictionary.

getMpFileContent(DATA_PATH, file, subject)

Retrieve anthropometric data from a specified file.

getTranslators(DATA_PATH[, translatorType])

Retrieve CGM marker translators from a specified file.

is_json(s)

Check if a string is valid JSON.

is_yaml(s)

Check if a string is valid YAML.

loadAnalysis(path, FilenameNoExt)

Load a pyCGM2 analysis instance from a file.

loadModel(path, FilenameNoExt)

Load a pyCGM2 model instance from a file.

loadModelSettings(DATA_PATH, ...)

Load pyCGM2 model settings from a specified file.

loadMp(path, filename)

Load a set of anthropometric parameters (mp file).

loadSettings(DATA_PATH, settingFile[, subfolder])

Load settings from a specified file.

openFile(path, filename)

Open a JSON or YAML file and return its contents as a dictionary.

openJson(path, filename)

Open a JSON file and return its contents as a dictionary.

openPickleFile(path, filename)

Open a serialized (pickle) file and return its contents.

openYaml(path, filename)

Open a YAML file and return its contents as a dictionary.

readContent(stringContent)

Read a string content in JSON or YAML format and return it as a dictionary.

readXml(DATA_PATH, filename)

Read an XML file and parse its contents.

renameFile(fileToRename, renamedFile)

Rename a file.

saveAnalysis(analysisInstance, path, ...)

Save a pyCGM2 analysis instance to a file.

saveJson(path, filename, content[, ensure_ascii])

Save a dictionary as a JSON file.

saveModel(model, path, FilenameNoExt)

Save a pyCGM2 model instance to a file.

saveMp(mpInfo, model, DATA_PATH, mpFilename)

Save anthropometric parameters as a JSON file.

savePickleFile(instance, path, filename)

Serialize an object and save it as a pickle file.

saveYaml(path, filename, content)

Save a dictionary as a YAML file.

try_as(loader, s, on_error)

Attempt to parse a string with a given loader and catch specific errors.

utils functions#

checkSimilarElement(listData)

Check if all elements in a list are similar.

getSimilarElement(listData)

Get a similar element from a list.

homogeneizeArguments(argv, kwargs)

Homogenize arguments by merging positional and keyword arguments into a single dictionary.

isInRange(val, min, max)

Check if a value is within a specified range.

str(unicodeVariable)

Encode a unicode variable to a specified encoding format.

toBool(text)

Convert a text string to a boolean value.

Additional files functions#

count_directories(data_directory)

count the number of directory in 'data_directory'

count_directories_with_label(data_directory, ...)

count the number of directory containing a specific label in 'data_directory'

delete_all_files(root_dir, extension[, verbose])

Delete all .h5 files found in a directory and all its subdirectories, with optional logging.

get_parent_directory(path_str)

Return the parent directory of the given path, ensuring a trailing separator.

moveDirectory(src, dst)

Move a directory 'src' into the directory 'dst'.

moveFile(src, dst)

Move a file from a source to a destination.

Additional utils functions#

FrameConverter(firstFrame, lastFrame, nppf)

A class for converting frame numbers between point and analog data formats.

cleanStringSpacing(param1)

clean spacing in a string

getNumberFromStr(input_string)

extract number from a string

is_valid_session_name(name)

Check that a name strictly follows the Session <integer> pattern.

removeDuplicate(listData)

remove duplicated item from a list

timeRange(startTime, sampleRate, numberOfFrames)

Calculate the time range for a given set of values.

Readers#

ExcelReader(file_path)

Reader of cell values of an Excel workbook (computed values).

is_json(s)

Check if a string is valid JSON.

is_yaml(s)

Check if a string is valid YAML.

openFile(path, filename)

Open a JSON or YAML file and return its contents as a dictionary.

openJson(path, filename)

Open a JSON file and return its contents as a dictionary.

openYaml(path, filename)

Open a YAML file and return its contents as a dictionary.

try_as(loader, s, on_error)

Attempt to parse a string with a given loader and catch specific errors.

Prettifier#

RegExSub(pattern[, flags, replace_with])

Dict factory for regex and corresponding substitution expression.

apply_re_subs(string, RegExSub_list[, debug])

Apply multiple regex substitutions to a string.

prettify_html(html_string[, debug])

Restore inline HTML tag format of BeautifulSoup.prettify() output.

prettify_xml(xml_string[, indent, debug])

Prettify XML with intelligent inline tags.

Timer#

Timer([name, verbose])

A quick tic-toc timer, used as a context manager.

Visualisation#

displayFrame(acq, frameInstance[, labels, ...])

Append the origin and axes of a frame as constant points to an acquisition.

Testing utilities#

test_offset(value, acq, viconLabel[, decimal])

Assert that a value equals a Vicon offset (degrees) stored in the PROCESSING metadata.

test_point(acq, RefLabel, LabelToTest[, ...])

Assert that two points of an acquisition are almost equal.

test_point_rms(acq, RefLabel, LabelToTest, ...)

Assert that the rms difference between two points of an acquisition is below a threshold.

test_point_compareToRef(acqRef, acqToTest, ...)

Assert that a point is almost equal in two acquisitions.

test_point_rms_compareToRef(acqRef, ...)

Assert that the rms difference of a point between two acquisitions is below a threshold.

print_offset(value, acq, viconLabel[, decimal])

Log a value and the corresponding Vicon offset (degrees) stored in the PROCESSING metadata.

plotComparisonOfPoint(acq, label, suffix[, ...])

Plot the three components of a point and of its suffixed version.

plotValuesComparison(values0, values1)

Plot the three components of two arrays.

plotComparison_MomentPanel(acq, suffix1, ...)

Plot the joint moments of a side for two output suffixes.

plotComparison_ForcePanel(acq, suffix1, ...)

Plot the joint forces of a side for two output suffixes.