brain_pipe.save.default.DefaultSaveMetadata

class DefaultSaveMetadata(key_fn: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], str] = <function default_metadata_key_fn>, filename: str = '.save_metadata.json')

Bases: OldMetadataCompliant, SaveMetadata

Implementation of SaveMetadata to work with DefaultSave.

Attributes

FEATURE_NAME_STR

FILENAME_STR

OLD_FORMAT_STR

SET_NAME_STR

lock

Retrieve the lock to use for the metadata file.

__init__(key_fn: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], str] = <function default_metadata_key_fn>, filename: str = '.save_metadata.json')

Create a new DefaultSaveMetadata.

Parameters:
  • key_fn (Callable[[Dict[str, Any]], str]) – The function to use to get the key from the data dict.

  • filename (str) – The filename to use for the metadata.

Methods

__init__([key_fn, filename])

Create a new DefaultSaveMetadata.

add(data_dict, filepath, feature_name, set_name)

Add metadata for a file.

attach_saver(saver)

Attach a saver to the metadata.

clear()

Clear the metadata.

convert_old_format(metadata_item, data_dict)

Convert the metadata item from the old format.

get()

Load the metadata.

get_metadata_for_savepath(path, ...[, ...])

Get the metadata associated for path where data is saved.

get_path()

Get the path to the metadata file.

get_relpath(path)

Construct a relative path with regard to save folder.

is_old_format(metadata_item)

Check if the metadata item is in the old format.

write(metadata_dict)

Write the metadata to disk.

add(data_dict: Dict[str, Any], filepath: str, feature_name: str | None, set_name: str | None)

Add metadata for a file.

Parameters:
  • data_dict (Dict[str, Any]) – The data dictionary.

  • filepath (str) – The path to the file.

  • feature_name (Optional[str]) – The name of the feature.

  • set_name (Optional[str]) – The name of the set.

attach_saver(saver)

Attach a saver to the metadata.

Parameters:

saver (DefaultSave) – The saver to attach.

clear()

Clear the metadata.

convert_old_format(metadata_item: str, data_dict: Dict[str, Any])

Convert the metadata item from the old format.

Parameters:
  • metadata_item (str) – The metadata item to convert.

  • data_dict (Dict[str, Any]) – The data dict containing the data to save.

Returns:

The converted metadata item.

Return type:

Dict[str, Any]

get()

Load the metadata.

Returns:

The metadata.

Return type:

Dict[str, Any]

get_metadata_for_savepath(path: str, feature_name: str | None, set_name: str | None, from_old_format=False)

Get the metadata associated for path where data is saved.

Parameters:
  • path (str) – The path to the data.

  • feature_name (Optional[str]) – The name of the feature.

  • set_name (Optional[str]) – The name of the set.

  • from_old_format (bool) – Whether the metadata is in the old format.

Returns:

The metadata associated with the path.

Return type:

Dict[str, Any]

get_path()

Get the path to the metadata file.

Returns:

The path to the metadata file.

Return type:

str

get_relpath(path: str)

Construct a relative path with regard to save folder.

Parameters:

path (str) – The path to make relative. If no saver is attached, this is returned as is.

Returns:

The relative path.

Return type:

str

classmethod is_old_format(metadata_item: str | Dict[str, Any])

Check if the metadata item is in the old format.

Parameters:

metadata_item (Union[str, Dict[str, Any]]) – The metadata item to check.

Returns:

Whether the metadata item is in the old format.

Return type:

bool

property lock

Retrieve the lock to use for the metadata file.

Returns:

The lock to use for the metadata file.

Return type:

multiprocessing.Lock

write(metadata_dict: Dict[str, Any])

Write the metadata to disk.

Parameters:

metadata_dict (Dict[str, Any]) – A dictionary containing the metadata.