paidiverpy.metadata_parser.ifdo_tools#

Utility functions for metadata parsing.

Functions#

validate_ifdo(→ list[dict[str, Any]])

validate_ifdo method.

load_json_schema(→ dict[str, Any])

Load iFDO JSON schema.

convert_to_ifdo(→ None)

Convert metadata to iFDO format.

parse_ifdo_items(→ tuple[dict[str, Any], list[str]])

Parse iFDO items from metadata.

parse_ifdo_header(→ tuple[dict[str, Any], list[str]])

Parse iFDO header from dataset metadata.

map_fields_to_ifdo(→ dict[str, Any])

Map fields from dataset metadata to iFDO header.

map_exif_to_ifdo(→ str | None | dict[str, Any])

Map EXIF metadata to iFDO format.

format_ifdo_validation_error(→ str)

Format error message.

parse_validation_errors(→ list[dict[str, Any]])

Parse validation errors.

get_ifdo_fields(→ tuple[dict[str, Any], list[str], ...)

Get required fields from iFDO schema.

Module Contents#

paidiverpy.metadata_parser.ifdo_tools.validate_ifdo(file_path: str | None = None, ifdo_data: dict[str, Any] | None = None) list[dict[str, Any]][source]#

validate_ifdo method.

Validates input data against iFDO scheme. Raises an exception if the data is invalid.

Parameters:
  • file_path (str) – Path to the iFDO file. If not provided, ifdo_data must be.

  • ifdo_data (dict) – parsed iFDO data from the file. If not provided, file_path must be.

Returns:

List of validation errors.

Return type:

list

paidiverpy.metadata_parser.ifdo_tools.load_json_schema(ifdo_version: str) dict[str, Any][source]#

Load iFDO JSON schema.

Parameters:

ifdo_version (str) – iFDO version to load.

Returns:

Loaded JSON schema.

Return type:

dict

paidiverpy.metadata_parser.ifdo_tools.convert_to_ifdo(dataset_metadata: dict[str, Any], metadata: pandas.DataFrame, output_path: str) None[source]#

Convert metadata to iFDO format.

Parameters:
  • dataset_metadata (dict) – Dataset metadata.

  • metadata (pd.DataFrame) – Metadata to convert.

  • output_path (str) – Path to save the converted metadata.

paidiverpy.metadata_parser.ifdo_tools.parse_ifdo_items(metadata: pandas.DataFrame, ifdo_schema: dict[str, Any]) tuple[dict[str, Any], list[str]][source]#

Parse iFDO items from metadata.

Parameters:
  • metadata (pd.DataFrame) – Metadata to parse.

  • ifdo_schema (dict) – iFDO schema.

Returns:

Parsed iFDO items and list of missing fields.

Return type:

tuple

paidiverpy.metadata_parser.ifdo_tools.parse_ifdo_header(dataset_metadata: dict[str, Any], ifdo_schema: dict[str, Any], metadata: pandas.DataFrame) tuple[dict[str, Any], list[str]][source]#

Parse iFDO header from dataset metadata.

Parameters:
  • dataset_metadata (dict) – Dataset metadata.

  • ifdo_schema (dict) – iFDO schema.

  • metadata (pd.DataFrame) – Metadata to parse.

Returns:

Parsed iFDO header and list of missing fields.

Return type:

tuple

paidiverpy.metadata_parser.ifdo_tools.map_fields_to_ifdo(data: dict[str, Any], ifdo_data: dict[str, Any], schema: dict[str, Any], fields: list[str] | set[str], missing_fields: list[str], missing_fields_suffix: str = '', required: bool = False) dict[str, Any][source]#

Map fields from dataset metadata to iFDO header.

Parameters:
  • data (dict) – Dataset metadata.

  • ifdo_data (dict) – iFDO data to populate.

  • schema (dict) – iFDO schema.

  • fields (list) – List of fields to map.

  • missing_fields (list) – List of missing fields.

  • missing_fields_suffix (str) – Suffix to append to missing fields.

  • required (bool) – Whether the fields are required.

Returns:

Mapped iFDO header.

Return type:

dict

paidiverpy.metadata_parser.ifdo_tools.map_exif_to_ifdo(metadata: dict[str, Any]) str | None | dict[str, Any][source]#

Map EXIF metadata to iFDO format.

Parameters:

metadata (dict) – Metadata to convert.

Returns:

Converted metadata in iFDO format.

Return type:

str | None

paidiverpy.metadata_parser.ifdo_tools.format_ifdo_validation_error(text: list[str]) str[source]#

Format error message.

Parameters:

text (list) – List of error messages.

Returns:

Formatted error message.

Return type:

str

paidiverpy.metadata_parser.ifdo_tools.parse_validation_errors(errors: list[dict[str, Any]], schema: dict[str, Any]) list[dict[str, Any]][source]#

Parse validation errors.

Parameters:
  • errors (list) – List of validation errors.

  • schema (dict) – JSON schema.

Returns:

Parsed validation errors.

Return type:

list

paidiverpy.metadata_parser.ifdo_tools.get_ifdo_fields(schema: dict[str, Any], section: str) tuple[dict[str, Any], list[str], set[str]][source]#

Get required fields from iFDO schema.

Parameters:
  • schema (dict) – JSON schema.

  • section (str) – Section of the schema to get fields from.

Returns:

iFDO fields, required fields, non-required fields.

Return type:

tuple