gingerbread.central_processing_handler.utils package#

Submodules#

gingerbread.central_processing_handler.utils.db_helpers module#

gingerbread.central_processing_handler.utils.db_helpers.correct_label_format(labels: Dict[str, int]) List[Dict[str, str | int | bool]]#

This function corrects the label format to the correct format for MQ. :param labels: This is the labels of the data :type labels: Dict[str, int]

Returns:

  • labels (List[Dict[str, Union[int, str, bool]]])

  • The list of dictionaries containing the labels

gingerbread.central_processing_handler.utils.db_helpers.generate_cls_meta_records(version_uid: str, cls_name: str, labels: Dict[str, int], cls_type: str, measure_unit: str) Dict[str, Tuple]#

This function generates a dictionary with the cls records for cls_meta_table table in MQ. :param version_uid: This is the version uid of the data :type version_uid: str :param cls_name: This is the cls name of the data :type cls_name: str :param measure_unit: This is the measure unit of the data :type measure_unit: str

Returns:

  • cls_record (Dict[str, Tuple])

  • The dictionary containing the cls record

gingerbread.central_processing_handler.utils.db_helpers.generate_cls_predicted_table_records(pcls_uid: str, cls_uid: str, model_id: str, model_version: str) Dict[str, Tuple]#

This function generates a dictionary with the prediction records. :param pcls_uid: This is the prediction uid of the data :type pcls_uid: str :param cls_uid: This is the cls uid of the data :type cls_uid: str :param model_id: This is the model id of the data :type model_id: str :param model_version: This is the model version of the data :type model_version: str

Returns:

  • prediction_record (Dict[str, Tuple])

  • The dictionary containing the prediction record

gingerbread.central_processing_handler.utils.db_helpers.generate_cls_records(series_uid: str | None, project_uid: str, study_uid: str, cls_uid: str) Dict[str, Tuple]#

This function generates a dictionary with the prediction records. :param series_uid: This is the series uid of the data :type series_uid: str :param study_uid: This is the study uid of the data :type study_uid: str :param cls_uid: This is the cls uid of the data :type cls_uid: str

Returns:

  • cls_record (Dict[str, Tuple])

  • The dictionary containing the cls record

gingerbread.central_processing_handler.utils.db_helpers.generate_cls_version_records(version_uid: str, cls_uid: str, pcls: ndarray) Dict[str, Tuple]#

This function generates a dictionary with the mask version records for mask_version_table in MQ. :param version_uid: This is the version uid of the prediction. :type version_uid: str :param cls_uid: This is the cls uid of the data :type cls_uid: str :param pcls: This is the actual image of the cls :type pcls: np.ndarray

Returns:

  • cls_version_record (Dict[str, Tuple])

  • The dictionary containing the cls version record

gingerbread.central_processing_handler.utils.db_helpers.generate_imported_records(project_uid: str, project_name: str, description: str) Dict[str, Tuple]#

This function generates a dictionary with the imported records for imported_table table in MQ. :param project_uid: This is the project uid of the data :type project_uid: str :param project_name: This is the project name of the data :type project_name: str :param description: This is the description of the data :type description: str

Returns:

  • imported_record (Dict[str, Tuple])

  • The dictionary containing the imported record

gingerbread.central_processing_handler.utils.db_helpers.generate_mask_meta_table(version_uid: str, mask_name: str, labels: Dict[str, int], mask_type: str, measure_unit: str) Dict[str, Tuple]#

This function generates a dictionary with the mask records for mask_predicted_table table in MQ. :param version_uid: This is the version uid of the data :type version_uid: str :param mask_name: This is the mask name of the data :type mask_name: str :param labels: This is the labels of the data :type labels: Dict[str, int] :param mask_type: This is the mask type of the data :type mask_type: str :param measure_unit: This is the measure unit of the data :type measure_unit: str

Returns:

  • mask_record (Dict[str, Tuple])

  • The dictionary containing the mask record

gingerbread.central_processing_handler.utils.db_helpers.generate_mask_records(series_uid: str, project_uid: str, study_uid: str, mask_uid: str, orientation: str) Dict[str, Tuple]#

This function generates a dictionary with the mask records for mask_predicted_table table in MQ. :param series_uid: This is the series uid of the data :type series_uid: str :param study_uid: This is the study uid of the data :type study_uid: str :param mask_uid: This is the mask uid of the data :type mask_uid: str :param orientation: This is the orientation of the data :type orientation: str

Returns:

  • mask_record (Dict[str, Tuple])

  • The dictionary containing the mask record

gingerbread.central_processing_handler.utils.db_helpers.generate_mask_table_records(pmask_uid: str, mask_uid: str, model_id: str, is_empty: bool, model_version: str) Dict[str, Tuple]#

This function generates a dictionary with the mask records for mask_predicted_table table in MQ. :param p_mask: :type p_mask: np.ndarray :param This is the mask that you want to store in the database: :param mask_uid: :type mask_uid: str :param This is the mask id that you want to store in the database: :param model_version: :type model_version: str :param This is the model version that you want to store in the database:

Returns:

  • mask_record (Dict[str, Tuple])

  • The dictionary containing the mask record

gingerbread.central_processing_handler.utils.db_helpers.generate_mask_version_records(mask_version_uid: str, mask_uid: str, pmask: ndarray) Dict[str, Tuple]#

This function generates a dictionary with the mask version records for mask_version_table in MQ. :param mask_version_uid: This is the version uid of the mask generated. A mask can have many versions :type mask_version_uid: str :param mask_uid: This is the mask uid of the data :type mask_uid: str :param pmask: This is the actual image of the mask :type pmask: np.ndarray

Returns:

  • mask_version_record (Dict[str, Tuple])

  • The dictionary containing the mask version record

gingerbread.central_processing_handler.utils.db_helpers.generate_meta_records(project_id: str, model_version: str, series_uid: str, version_uid: str, analytics: Dict[str, float]) Dict[str, Tuple]#

This function generates a dictionary for meta data. :returns: * meta_record (Dict[str, Tuple])

  • The dictionary containing the meta record

gingerbread.central_processing_handler.utils.db_helpers.generate_pastel_color(idx: int) str#

Generate a random pastel hex color. :param idx: The index of the color up to 4 (0-4) :type idx: int

Returns:

output

Return type:

str

gingerbread.central_processing_handler.utils.db_helpers.generate_project_series_meta_records(series_uid: str, project_uid: str, description: str, status: str) Dict[str, Tuple]#

This function generates a dictionary with the project series records for project_series_table table in MQ. :param series_uid: This is the series uid of the data :type series_uid: str :param project_uid: This is the project uid of the data :type project_uid: str :param description: This is the description of the data :type description: str :param signed_by: This is the signed_by of the data :type signed_by: str :param status: This is the status of the data :type status: str

Returns:

  • project_series_record (Dict[str, Tuple])

  • The dictionary containing the project series record

gingerbread.central_processing_handler.utils.db_helpers.generate_thumb_mask_version_records(thumbnail_mask_uid: str, version_uid: str, thumbnail: ndarray) Dict[str, Tuple[str, ndarray]]#

generate_thumb_mask_version_records for storing thumbnails.

Parameters:
  • thumbnail_mask_uid (str) – thumbnail_mask_uid

  • version_uid (str) – version_uid

  • thumbnail (np.ndarray) – thumbnail

Return type:

Dict[str, Tuple[str, np.ndarray]]

gingerbread.central_processing_handler.utils.db_helpers.prepare_for_classification_upload(response: Dict[str, Any], model_id: str, series_uid: str, study_uid: str, project_series_uid: str | None = None) Dict[str, Any]#

Prepare the response from the model for upload to the database. :param response: The response from the model :type response: Dict[str, Any] :param model_id: The model id :type model_id: str :param series_uid: The series uid :type series_uid: str :param study_uid: The study uid :type study_uid: str :param project_series_uid: The project series uid :type project_series_uid: Optional[str | None]

gingerbread.central_processing_handler.utils.db_helpers.prepare_for_segmentation_upload(response: Dict[str, Any], image: ndarray, affine: ndarray, series_uid: str, model_id: str, study_uid: str, project_series_uid: str | None = None) Tuple[Dict[str, Dict[str, float | int | str | bool | Tuple]], str]#

Prepare the response from the model for upload to the database.

gingerbread.central_processing_handler.utils.db_helpers.upload_to_mq(records: Dict[str, Tuple], table_name: str, ignore_conflict: bool = False) NoReturn#

This function records to tables in MQ.

gingerbread.central_processing_handler.utils.helpers module#

gingerbread.central_processing_handler.utils.helpers.copy_obj(obj: any)#
gingerbread.central_processing_handler.utils.helpers.decode_payload(payload: str, blosc_compression: bool = True) ndarray#

the function decodes a payload/response from the RadiomPipe API by first converting the hexstring to bytes and decompressing + decoding the buffer. The payload is then converted back to a dictionary from bytes. :param payload: the payload is the response from the RadiomPipe application :type payload: str

Returns:

  • The dictionary contains two dataframes with radiomic features and diagnostic from the process as well

  • as two dictionaries with masks from the segmentation and nested radiomics features.

gingerbread.central_processing_handler.utils.helpers.decode_weights_pickled(encoded_weights: bytes) OrderedDict#

the function decodes a encoded weights loaded from MQ. :param encoded_model: encoded weights loaded from MQ as decompressed gzip bytes and then pickled. :type encoded_model: bytes

Returns:

weights – the weights of pre-trained model.

Return type:

OrderedDict

gingerbread.central_processing_handler.utils.helpers.encode_payload(payload: ndarray, blosc_compression: bool = True) str | bytes#

This functions make the payload ready for the post request by converting the payload to bytes then compression and placing it in an IO buffer. :param payload: This is the payload containing the data that you want to ship

as a HTTPS post request to the REST APi.

Returns:

buffer – The buffer containing the payload in compressed bytes

Return type:

BytesIO()

gingerbread.central_processing_handler.utils.helpers.encode_weights(weights: OrderedDict) bytes#

This functions make the weights of pre-trained model ready for uploading to MQ. :param model: The model we want to encode and upload to MQ. :type model: OrderedDict

Returns:

buffer – The bytes which represents the compressed and encoded weights.

Return type:

bytes

gingerbread.central_processing_handler.utils.helpers.get_img_info(img: ndarray) int#

get_img_info is very simple helper that returns the dimension of image volume. :param img: this is the image volume that you need to know the dimension for :type img: np.ndarray

gingerbread.central_processing_handler.utils.helpers.hash_function(uuid: str, uuid_type: str, make_unique: bool) str#

The function hashes uuids, which is to anonymize, by a pepper value setting. The algorithm uses a SHA512 and iterates enough times to create approximately random hashes. The function is as of now written to work on the most used uuids. :param uuid: Provide the string value for the uuid that has to hashed. Use it as the salt secret

which is the way to decode the value againg. The value is also going to be same for the salt secret.

Parameters:
  • uuid_type (str) – Specifiy which uuid type to hash. The three types as of now are: (i) patient, (ii) study and (iii) series.

  • make_unique (bool) – Specify if the uuid should be made unique. Uses time to make it unique

Returns:

The returned value is an unique identifier string which is not possible to use for back tracing to the original source.

Return type:

str

gingerbread.central_processing_handler.utils.helpers.nested_dict()#

Reacursive dict function for making nested dicts.

gingerbread.central_processing_handler.utils.helpers.str2bool(string_value: str) bool#

str2bool will return True if the value is in the string tuple and False otherwise. :param string_value: string_value :type string_value: str

Return type:

bool

gingerbread.central_processing_handler.utils.helpers.timer(orig_func: Callable)#

This is custom timer decorator. :param orig_func: The orig_func is the python function which is decorated. :type orig_func: object

Returns:

elapsed runtime for the function.

Return type:

type

Module contents#