flip.core.base

FLIP Base Classes.

This module contains the abstract base class for all FLIP implementations.

Classes

FLIPBase

Abstract base class for FLIP functionality across all job types.

Module Contents

class flip.core.base.FLIPBase[source]

Bases: abc.ABC

Abstract base class for FLIP functionality across all job types.

This class defines the interface that all FLIP implementations must follow. Concrete implementations handle the differences between development and production environments, as well as job-type-specific behavior.

logger[source]
abstractmethod get_dataframe(project_id: str, query: str) pandas.DataFrame[source]

Returns a dataframe for the project/query.

Parameters:
  • project_id (str) – The project identifier

  • query (str) – SQL query string

Returns:

pd.DataFrame – Dataframe containing the query results

abstractmethod get_by_accession_number(project_id: str, accession_id: str, resource_type: flip.constants.flip_constants.ResourceType | List[flip.constants.flip_constants.ResourceType] = ResourceType.NIFTI) pathlib.Path[source]

Returns the path to the data for the given accession number.

Parameters:
  • project_id (str) – The project identifier

  • accession_id (str) – The accession ID of the imaging study

  • resource_type (Union[ResourceType, List[ResourceType]]) – Type(s) of resources to download

Returns:

Path – Path to the downloaded data

abstractmethod add_resource(project_id: str, accession_id: str, scan_id: str, resource_id: str, files: List[str]) None[source]

Adds specific image to XNAT for an accession ID.

Parameters:
  • project_id (str) – The project identifier

  • accession_id (str) – The accession ID

  • scan_id (str) – The scan ID

  • resource_id (str) – The resource type ID

  • files (List[str]) – List of file paths to upload

abstractmethod update_status(model_id: str, new_model_status: flip.constants.flip_constants.ModelStatus) None[source]

Updates training status in Central Hub.

Parameters:
  • model_id (str) – The model UUID

  • new_model_status (ModelStatus) – The new status to set

abstractmethod send_metrics(client_name: str, model_id: str, label: str, value: float, round: int) None[source]

Sends a metric value to the Central Hub.

Parameters:
  • client_name (str) – The client name sending the metric

  • model_id (str) – The model UUID

  • label (str) – The label of the metric

  • value (float) – The value of the metric

  • round (int) – The local round number

abstractmethod send_handled_exception(formatted_exception: str, client_name: str, model_id: str) None[source]

Sends a training-related exception to Central Hub.

Parameters:
  • formatted_exception (str) – The formatted exception message

  • client_name (str) – The client name that raised the exception

  • model_id (str) – The model UUID

abstractmethod upload_results_to_s3(results_folder: pathlib.Path, model_id: str) None[source]

Uploads results to S3 bucket.

Parameters:
  • results_folder (Path) – The folder containing results to upload

  • model_id (str) – The model UUID for which results are being uploaded

abstractmethod cleanup(path: pathlib.Path) None[source]

Cleans up local files.

Parameters:

path (Path) – The path to the file or directory to clean up

check_query(query: str) None[source]

Check whether the query is a string type.

Parameters:

query (str) – The query to validate

Raises:

TypeError – If query is not a string

check_project_id(project_id: str) None[source]

Checks whether the project id is a string type.

Parameters:

project_id (str) – The project ID to validate

Raises:

TypeError – If project_id is not a string

check_accession_id(accession_id: str) None[source]

Checks whether accession_id is a string type.

Parameters:

accession_id (str) – The accession ID to validate

Raises:

TypeError – If accession_id is not a string

check_resource_type(resource_type: flip.constants.flip_constants.ResourceType | List[flip.constants.flip_constants.ResourceType]) List[flip.constants.flip_constants.ResourceType][source]

Check whether resource type is valid and returns them reformatted.

Parameters:

resource_type (Union[ResourceType, List[ResourceType]]) – Single ResourceType or list of ResourceTypes

Returns:

List[ResourceType] – List of validated resource types

Raises:

TypeError – If resource_type is not valid