Utilities#
The hastegeo.core.utils package provides shared utility modules used across the HASTE platform.
Logging (hastegeo.core.utils.logs)#
Static logger utility for consistent logging across all HASTE components.
Logger— Configurable logger with file and console handlers
- class hastegeo.core.utils.logs.Logger[source]#
Bases:
object- static add_console_handler(logger, level=logging.ERROR)[source]#
Adds a console handler to the logger.
- static add_file_handler(logger, log_file, level=logging.INFO)[source]#
Adds a file handler to the logger.
- static get_logger(name, log_file='app.log', log_dir=None, level=logging.INFO)[source]#
Creates and returns a logger instance.
- Parameters:
- formatter = logging.Formatter(
‘%(asctime)s - %(name)s - %(levelname)s - %(message)s - %(funcName)s - %(lineno)d’
)
Metadata (hastegeo.core.utils.metadata)#
Utility functions for ID generation, timestamps, and hashing.
MetadataUtils— Static methods:generate_id(),generate_int_id(),get_timestamp(),get_short_date(),hash_string(),append_status_message()
Queue Handler (hastegeo.core.utils.queues)#
Azure Queue Storage client for sending and receiving async task messages.
AzureQueueHandler— Queue operations:put_message(),get_messages(),delete_message()
Imagery (hastegeo.core.utils.imagery)#
Geospatial imagery processing utilities using GDAL, rasterio, and OpenCV.
ImageryUtils— Static methods for mosaic creation, COG generation, reprojection, and tile creation
Downloader (hastegeo.core.utils.downloader)#
Multi-source imagery download client.
ImageryDownloader— Downloads from HTTP URLs, Azure Blob Storage, and AWS S3 with retry logic
Data Utilities (hastegeo.core.utils.data)#
Data transformation and file management helpers.
extract_from_url()— Extract substring from URL using regexconvert_json_to_geojson()— Transform JSON to GeoJSON FeatureCollectionget_distinct_label_classes()— Extract unique classification labelsdirectory_cleanup()— Delete directory and contentsfilter_roles()— Filter out anonymous/authenticated roles
TensorBoard Parser (hastegeo.core.utils.tbparser)#
Parse TensorBoard event logs to extract training metrics.
parse_tb_event_logs()— Parse event logs into epochs, accuracy, losscalculate_metrics()— Calculate training progress metrics
- hastegeo.core.utils.tbparser.calculate_metrics(logs, maxEpochs, time_field='elapsedDurationInMinutes', epoch_field='epoch')[source]#
Calculate completion metrics from TensorBoard logs.
- Parameters:
logs (str) – JSON string of logs containing epoch and time information.
maxEpochs (int) – Maximum number of epochs.
time_field (str) – The field name in logs that contains elapsed time information. Default is ‘elapsedDurationInMinutes’.
epoch_field (str) – The field name in logs that contains epoch information. Default is ‘epoch’.
- Returns:
- A dictionary containing the following keys:
’completed_epochs’ (int): The number of completed epochs.
’approx_time_to_complete’ (float): The approximate time to complete the remaining epochs.
’total_elapsed_time’ (float): The total elapsed time.
’time_per_epoch’ (float): The average time per epoch.
- Return type:
- hastegeo.core.utils.tbparser.parse_tb_event_logs(log_file_path)[source]#
Parses TensorBoard event logs to extract epoch, accuracy, and loss information.
- Parameters:
log_file_path (str) – The file path to the TensorBoard event log file.
- Returns:
- A tuple containing:
start_timestamp (str): The start timestamp of the events in UTC formatted as ‘%Y-%m-%d %H:%M:%S’.
- result (str): A JSON string containing a list of dictionaries, each representing an epoch with the following keys:
’epoch’ (int): The epoch number.
’elapsedDurationInMinutes’ (float): The duration of the epoch in minutes.
’multiclassAccuracy’ (float): The multiclass accuracy for the epoch.
’loss’ (float): The loss for the epoch.
’wallTime’ (str): The wall time of the epoch event in UTC formatted as ‘%Y-%m-%d %H:%M:%S’.
- Return type:
User Management (hastegeo.core.utils.user)#
User invitation and email notification utilities.
InvitationManager— Manage invitations via Azure Static Web Apps API and send emails via Azure Communication ServicesEmailSendResponse/CreateInvitationResponse— Response types
- class hastegeo.core.utils.user.CreateInvitationResponse(email_id, invitation_link, error)[source]#
Bases:
NamedTuple
- class hastegeo.core.utils.user.EmailSendResponse(email_id, sent, error)[source]#
Bases:
NamedTuple
- class hastegeo.core.utils.user.InvitationManager(emails, roles=None, invite_config=None, invite_expire_hours=168, delete_existing=False)[source]#
Bases:
object- __init__(emails, roles=None, invite_config=None, invite_expire_hours=168, delete_existing=False)[source]#
Initialize the InvitationManager with email addresses, user roles, and invitation expiration.
- Parameters:
- Raises:
EnvironmentError – If required environment variables are missing.
- create_invitation(email)[source]#
Create an invitation for a single email address using Azure Static Web Apps REST API.
- send_invitations()[source]#
Validates emails, creates invitations, sends invitation emails, and returns the results.
- For each email:
If invalid, adds an Invite with error.
- If valid, attempts to create an invitation link via Azure Static Web Apps API.
If invitation creation fails, adds an Invite with error.
If invitation creation succeeds, sends an email with the link and records the send status.
- Returns:
An Invites object containing Invite objects for all processed emails, with status and errors.
- Return type:
- class hastegeo.core.utils.user.UserManager(invite_config=None)[source]#
Bases:
objectManages user operations for Azure Static Web Apps including listing, deleting, and updating users.
- __init__(invite_config=None)[source]#
Initialize the UserManager with configuration.
- Parameters:
invite_config (InviteConfig) – Configuration for Static Web App connection
Exceptions (hastegeo.core.utils.exceptions)#
Custom exception types.
UnsupportedFormatError— Raised for unsupported file formats