magmap.settings.profiles module

Profile settings to setup common configurations.

Each profile has a default set of settings, which can be modified through “modifier” sub-profiles with groups of settings that overwrite the given default settings.

class magmap.settings.profiles.RegKeys(value)[source]

Bases: Enum

Register setting enumerations.

ACTIVE = 1
DBSCAN_EPS = 10
DBSCAN_MINPTS = 11
EDGE_AWARE_REANNOTATION = 8
KNN_N = 12
MARKER_EROSION = 2
MARKER_EROSION_MIN = 3
MARKER_EROSION_USE_MIN = 4
METRICS_CLUSTER = 9
SAVE_STEPS = 7
SKELETON_EROSION = 5
WATERSHED_MASK_FILTER = 6
class magmap.settings.profiles.SettingsDict(*args, **kwargs)[source]

Bases: dict

Profile dictionary, which contains collections of settings.

Allows modification by applying additional groups of settings specified in this dictionary. Supports saving and loading settings from a YAML file.

This class is being migrated to a data class, which supports type hints and attribute access. It will also reduce the need for Enums as keys.

Variables:
  • PATH_PROFILES (str) – Path to profiles directory.

  • NAME_KEY (str) – Key for profile name.

  • DEFAULT_NAME (str) – Default profile modifier name.

  • profiles (dict) – Dictionary of profiles to modify the default values, where each key is the profile name and the value is a nested dictionary that will overwrite or update the current values.

  • timestamps (dict) – Dictionary of profile files to last modified time.

  • delimiter (str) – Profile names delimiter; defaults to ,.

DEFAULT_NAME = 'default'
NAME_KEY = 'settings_name'
PATH_PROFILES = 'profiles'
__repr__()[source]

Represent with dict items and data class attributes.

add_profiles(names_str)[source]

Add profiles by names and files.

Layers profiles on top of one another so that any settings in the next profile take precedence over those in the prior profiles. For example, “lightsheet_5x” will give one profile, while “lightsheet_5x_contrast” will layer additional settings on top of the original lightsheet profile.

Parameters:

names_str (str) – The name of the settings profile to apply, with individual profiles separated by “,”. Profiles will be applied in order of appearance.

check_file_changed()[source]

Check whether any profile files have changed since last loaded.

Returns:

True if any file has changed.

Return type:

bool

static get_files(profiles_dir=None, filename_prefix='')[source]

Get profile files.

Parameters:
  • profiles_dir (str) – Directory from which to get files; defaults to None to use PATH_PROFILES.

  • filename_prefix (str) – Only get files starting with this string; defaults to an empty string.

Returns:

List of files in profiles_dir matching the given filename_prefix and ending with an extension in _EXT_YAML.

Return type:

List[str]

get_profile(profile_name)[source]

Get the dictionary for a given profile.

Profiles may either match an existing profile in profiles or specify a path to a YAML configuration file. YAML filenames will first be checked in PATH_PROFILES, followed by profile_name as the full path. If _add_mod_directly is True, the value at profile_name will be added or replaced with the found modifier value.

The profile in profiles whose name matches profile_name will be applied over the current settings. If both the current and new values are dictionaries, the current dictionary will be updated with the new values. Otherwise, the corresponding current value will be replaced by the new value.

Parameters:

profile_name (str) – Profile name.

Return type:

Optional[Dict[Union[str, Enum], Union[Dict, str]]]

Returns:

The loaded dictionary, or None if not found.

static is_identical_settings(profs, keys)[source]

Check whether the given settings are identical across profiles.

Parameters:
  • profs (Sequence[ROIProfile]) – Sequence of ROI profiles.

  • keys (Sequence[str]) – Sequence of setting keys to check.

Returns:

True if the settings are identical, otherwise False.

Return type:

bool

modify_settings(mods)[source]

Modify dictionary or data class items from another dictionary.

If corresponding values are sub-dictionaries, the existing sub-dict will be updated rather than replaced with the new sub-dict.

Priority is given to updated existing dictionary keys. If unavailable, data class attributes are updated.

Parameters:

mods (Dict[Union[str, Enum], Union[Dict, str]]) – Dictionary to update this class’ dictionary.

refresh_profile(check_timestamp=False)[source]

Refresh the profile.

Parameters:

check_timestamp (bool) – True to refresh only if a loaded profile file has changed; defaults to False.

save_settings(path)[source]

Save current settings to YAML file.

Parameters:

path (Union[str, Path]) – Output path.

Return type:

Dict

Returns:

Saved dictionary, including any modifications