Global -> AWS Handlers

AWS API

tardis_em.utils.aws.get_benchmark_aws() dict

Fetch benchmark data from a specified AWS endpoint.

This function sends a GET request to the specified AWS S3 URL to fetch the latest network benchmark data. If the request is successful (HTTP status code 200), it decodes the JSON content from the response and returns it as a Python dictionary. The function handles the request with a specific timeout configuration.

Returns:

A dictionary containing the benchmark data fetched from the AWS endpoint if the request is successful and content is valid JSON.

Return type:

dict

tardis_em.utils.aws.put_benchmark_aws(data: dict, network: str | None = '', model=None) bool

Sends benchmark data and optional model weights to an AWS S3 bucket.

This function uploads provided benchmark data as a JSON file to a predefined location in an AWS S3 bucket. Optionally, if a model file is provided, it uploads the model weights to a corresponding directory in the bucket based on the network name. The function ensures appropriate HTTP status codes are checked to confirm successful uploads.

Parameters:
  • data – The benchmark data to upload. It should be a dictionary containing the relevant information.

  • network – The name of the network associated with the uploaded model. This serves as part of the model file name. Defaults to an empty string if not provided.

  • model – The path to the model’s file to upload. If provided, the function will attempt to upload the model to the AWS S3 bucket.

Returns:

A boolean value indicating whether the data upload (and optionally, the model upload) was successful.

tardis_em.utils.aws.get_all_version_aws(network: str, subtype: str, model: str)

Fetches all available version strings of a specific model from the AWS Tardis weights bucket.

This function communicates with an AWS S3 bucket to retrieve version information for specified network, subtype, and model. It parses the response to extract all relevant versions that match the expected format.

Parameters:
  • network (str) – The name of the network being queried.

  • subtype (str) – The specific subtype of the network.

  • model (str) – The model identifier within the specified network and subtype.

Returns:

A list of version strings that match the query parameters, starting with “V”.

Return type:

list[str]

tardis_em.utils.aws.get_model_aws(https: str)

Fetches a model from AWS by sending a GET request to the provided URL.

Parameters:

https (str) – The HTTPS URL string to fetch the model from.

Returns:

The response object from the GET request.

Return type:

requests.Response

tardis_em.utils.aws.get_weights_aws(network: str, subtype: str, model: str | None = None, version: int | None = None)

Retrieve the weights of a specified deep learning model architecture and subtype, optionally specifying the model and version, from AWS or locally cached storage if available. The function handles directory setup, input validation, and either fetching or downloading the required weights.

Parameters:
  • network (str) – Name of the neural network model to retrieve. Must be one of the predefined valid model types from ‘ALL_MODELS’.

  • subtype (str) – Specific subtype or configuration of the network. Must be one of the predefined valid subtype values from ‘ALL_SUBTYPE’.

  • model (Optional[str]) – Dataset or model specification for the given network and subtype. Defaults to None. Relevant only for certain network types.

  • version (Optional[int]) – Version of the model to retrieve. Defaults to None, which automatically selects the latest version available for the given network, subtype, and model.

Returns:

Path to the weights file if available locally or a file-like buffer containing the downloaded weights if fetched from AWS.

tardis_em.utils.aws.aws_check_with_temp(model_name: list) bool

Check the availability and validity of local model weights and headers compared to the version stored on AWS.

Parameters:

model_name – A list containing identifiers for the model. It is expected to contain at least four elements where each corresponds to specific attributes or subdirectories of the model.

Returns:

A boolean value indicating whether the locally stored model weights are up-to-date (True) or require a download/update (False).

tardis_em.utils.aws.aws_check_pkg_with_temp() bool

Checks the existence and validity of a local Tardis package and compares it with the latest version available on AWS.

Returns:

A boolean indicating whether the local package exists and is up-to-date. If False is returned, the caller is expected to download the package from AWS.

Return type:

bool

Over-the-Air Update API

tardis_em.utils.ota_update.ota_update(status=False)

Check for Over-The-Air (OTA) updates and handle notifications for available updates.

This function performs a check to determine whether a new version of the application is available. The function periodically checks for updates based on a saved timestamp. If an update check has not occurred in the last 24 hours, it consults AWS for new updates. Based on the status parameter, it either returns a simple message or displays a detailed notification about the availability of a new version.

Parameters:

status (bool) – A boolean indicating the type of response. If True, returns a simple notification message. If False, displays a graphical notification about the update.

Returns:

If status is True and a new version is available, returns a string indicating that a new version is available. Otherwise, returns an empty string.

Return type:

str

tardis_em.utils.ota_update.main()

The main function performs an Over-The-Air (OTA) update for the Tardis-EM package. It checks or creates a directory for the update, retrieves the new package, saves the package locally, uninstalls previous versions of the package, installs the new one, and provides update-related instructions to the user via a visual display.

Returns:

None