resurfemg.data_connector.config module

Copyright 2022 Netherlands eScience Center and Twente University. Licensed under the Apache License, version 2.0. See LICENSE for details.

This file contains methods to let the user configure all paths for data instead of hard-coding them, as well as methods to check data integrity. The data integrity can be checked because this file contains hash functions to track data. Synthetic data can be made with several methods.

class Config(location=None, configure=False, verbose=False, force=False)

Bases: object

A configuration class for ResurfEMG data paths, allowing to specify paths in a JSON file instead of hardcoding them within the code. A typical workflow would be: 1. Create a Config object, which loads the configuration file (config.json) from the provided location or from default locations: config = Config(verbose=True) 2. Extract a configured directory using the get_directory method: base_path = config.get_directory(‘root_data’)

If no location is specified it will try to load the configuration file from the default locations in the following order: - ./config.json (current working directory) - PROJECT_ROOT/config.json (project root directory, if located) - ~/.resurfemg/config.json (user config in Windows) - /etc/resurfemg/config.json (system-wide config in Linux or OSX)

If ‘configure’ is set to True, a new configuration file will be created at the first available location in the above list. If ‘force’ is set to True, any existing configuration file will be overwritten.

For details on how to set up the configuration file, see: - print(config.usage()): instructions on where to create a config file. - print(config.config_file_help()): details on the config file structure. ———————————————————————–

config_file_help()

This function provides help on how to set up the configuration file.

create_config_from_example(location: str, force=False)

This function creates a config file from an example file.

param location:

The location of the example file.

type location:

str

get_config()

This function returns the configuration file.

return:

The configuration file.

rtype:

dict

get_default_layout()

This function returns the default layout of the configuration file.

return:

The default layout of the configuration file.

rtype:

dict

get_directory(directory, value=None)

This function returns the directory specified in the configuration file. If the directory is not specified, it will return the value. ———————————————————————– :param directory: The directory to return. :type directory: str :param value: The value to return if the directory is not specified. :type value: str :return: The directory specified in the configuration file. :rtype: str

load(location, verbose=False)

This function loads the configuration file. If no location is specified it will try to load the configuration file from the default locations: - ./config.json - ~/.resurfemg/config.json - /etc/resurfemg/config.json - PROJECT_ROOT/config.json ———————————————————————– :param location: The location of the configuration file. :type location: str :param verbose: A boolean to print the loaded configuration. :type verbose: bool :raises ValueError: If the configuration file is not found.

parse_paths(_path)

This function parses the paths in the configuration file.

print_config()

This function prints the current configuration.

required_directories = ['root_data']
setup_config(location=None, force=False)
usage()

Provide feedback if the paths are not configured or not configured correctly. It contains instructions on how to configure the paths. ———————————————————————–

validate(_path, force=False)

This function validates the configuration file. It checks if the required directories exist. ———————————————————————– :raises LoggingError: If the required directories do not exist.

convert_to_os_path(path: str)

This function converts a path to a os readable path.

param path:

The path to convert.

type path:

str

find_project_root(current_dir=PosixPath('/home/runner/work/ReSurfEMG/ReSurfEMG'), marker_file=None, prefer_build_markers=True)

Walks upward from current_dir to find a plausible Python project root. Returns the path if found, else None. If marker_file is provided, it is uses the marker_file in favor of looking for standard build/ VCS markers. If prefer_build_markers is True, prioritize pyproject/setup files over .git. Markers checked are: Build-markers: pyproject.toml, setup.cfg, setup.py, poetry.lock, Pipfile, requirements.txt, tox.ini VCS-markers: .git :param current_dir: The directory to start searching from. :type current_dir: Path :param marker_file: Look for a specific marker file. :type marker_file: Optional[str] :param prefer_build_markers: Whether to prefer build markers over VCS markers. :type prefer_build_markers: bool :return: The absolute path to the root directory of the repository. :rtype: Optional[Path]

hash_it_up_right_all(origin_directory, file_extension)

Hashing function to check files are not corrupted or to assure files are changed. This function hashes all files in a directory. ———————————————————————– :param origin_directory: The string of the directory with files to hash :type origin_directory: str :param file_extension: File extension :type file_extension: str

Returns df:

The hash values of the files

Rtype df:

pandas.DataFrame