AFL.automation.APIServer.Driver#

Functions

ceil(x, /)

Return the ceiling of x as an Integral.

from_uri(uri[, structure_clients, cache, ...])

Connect to a Node on a local or remote server.

jsonify(*args, **kwargs)

Serialize the given arguments as JSON, and return a Response object with the application/json mimetype.

listify(obj)

makeRegistrar()

render_template(template_name_or_list, **context)

Render a template by name with the given context.

sqrt(x, /)

Return the square root of x.

Classes

Driver(name[, defaults, overrides, useful_links])

PersistentConfig(path[, defaults, ...])

A dictionary-like class that serializes changes to disk

AFL.automation.APIServer.Driver.makeRegistrar()[source]#
class AFL.automation.APIServer.Driver.Driver(name, defaults=None, overrides=None, useful_links=None)[source]#
unqueued()#
queued()#
quickbar()#
__init__(name, defaults=None, overrides=None, useful_links=None)[source]#
static_dirs = {'tiled_browser_css': PosixPath('/github/workspace/AFL/automation/driver_templates/tiled_browser/css'), 'tiled_browser_js': PosixPath('/github/workspace/AFL/automation/driver_templates/tiled_browser/js')}#
classmethod gather_defaults()[source]#

Gather all inherited static class-level dictionaries called default.

classmethod gather_static_dirs()[source]#

Gather all inherited class-level dictionaries named static_dirs.

This method walks through the Method Resolution Order (MRO) to collect static_dirs definitions from all parent classes. Child class definitions override parent definitions for the same subpath key.

Returns:

Dictionary mapping subpaths to pathlib.Path objects for directories containing static files to be served by the API server.

Return type:

dict

set_config(**kwargs)[source]#
get_config(name, print_console=False)[source]#
get_configs(print_console=False)[source]#
clean_config()[source]#

Remove any config keys that are not present in defaults.

This method gathers all defaults from the class hierarchy, makes a copy of the current config, and removes any keys that don’t exist in the defaults. The cleaned config is then saved back to the persistent config.

Returns:

Dictionary containing the keys that were removed from config

Return type:

dict

set_sample(sample_name, sample_uuid=None, **kwargs)[source]#
get_sample()[source]#
reset_sample()[source]#
status()[source]#
pre_execute(**kwargs)[source]#

Executed before each call to execute

All of the kwargs passed to execute are also pass to this method. It is expected that this method be overridden by subclasses.

post_execute(**kwargs)[source]#

Executed after each call to execute

All of the kwargs passed to execute are also pass to this method. It is expected that this method be overridden by subclasses.

execute(**kwargs)[source]#
set_object(serialized=True, **kw)[source]#
get_object(name, serialize=True)[source]#
set_data(data: dict)[source]#

Set data in the DataPacket object

Parameters:
  • data (dict) – Dictionary of data to store in the driver object

  • variables (Note! if the keys in data are not system or sample)

:param : :param they will be erased at the end of this function call.:

retrieve_obj(uid, delete=True)[source]#

Retrieve an object from the dropbox

Parameters:

uid (str) – The uuid of the file to retrieve

deposit_obj(obj, uid=None)[source]#

Store an object in the dropbox

Parameters:
  • obj (object) – The object to store in the dropbox

  • uid (str) – The uuid to store the object under

tiled_browser(**kwargs)[source]#

Serve the Tiled database browser HTML interface.

tiled_plot(**kwargs)[source]#

Serve the Tiled plotting interface for selected entries.

tiled_gantt(**kwargs)[source]#

Serve the Tiled Gantt chart interface for selected entries.

tiled_config(**kwargs)[source]#

Return Tiled server configuration from shared config file.

Reads tiled_server and tiled_api_key from ~/.afl/config.json. Returns dict with status and config values or helpful error message.

Proxy endpoint for Tiled metadata search to avoid CORS issues.

Parameters:
  • queries – JSON string of query list: [{“field”: “field_name”, “value”: “search_value”}, …]

  • offset – Result offset for pagination

  • limit – Number of results to return

Returns:

dict with status, data, total_count, or error message

tiled_get_data(entry_id, **kwargs)[source]#

Proxy endpoint to get xarray HTML representation from Tiled.

Parameters:

entry_id – Tiled entry ID

Returns:

dict with status and html, or error message

tiled_get_metadata(entry_id, **kwargs)[source]#

Proxy endpoint to get metadata from Tiled.

Parameters:

entry_id – Tiled entry ID

Returns:

dict with status and metadata, or error message

tiled_get_distinct_values(field, **kwargs)[source]#

Get distinct/unique values for a metadata field using Tiled’s distinct() method.

Parameters:

field – Metadata field name (e.g., ‘sample_name’, ‘sample_uuid’, ‘AL_campaign_name’, ‘AL_uuid’)

Returns:

dict with status and list of unique values, or error message

tiled_concat_datasets(entry_ids, concat_dim='index', variable_prefix='')[source]#

Gather datasets from Tiled entries and concatenate them along a dimension.

This method fetches multiple datasets from a Tiled server, extracts metadata (sample_name, sample_uuid, sample_composition), and concatenates them along the specified dimension. It also supports prefixing variable names.

For a single entry, the dataset is returned as-is without concatenation, and the sample dimension is auto-detected from existing dimensions.

Parameters:
  • entry_ids (List[str]) – List of Tiled entry IDs to fetch and concatenate

  • concat_dim (str, default="index") – Dimension name along which to concatenate the datasets (ignored for single entry)

  • variable_prefix (str, default="") – Optional prefix to prepend to variable, coordinate, and dimension names (except the concat_dim itself)

Returns:

For single entry: The original dataset with metadata added as attributes For multiple entries: Concatenated dataset with: - All original data variables and coordinates from individual datasets - Additional coordinates along concat_dim:

  • sample_name: Sample name from metadata or entry_id

  • sample_uuid: Sample UUID from metadata or empty string

  • entry_id: The Tiled entry ID for each dataset

  • If sample_composition metadata exists:
    • composition: DataArray with dims [concat_dim, “components”] containing composition values for each sample

Return type:

xr.Dataset

Raises:

ValueError – If entry_ids is empty If any entry_id is not found in Tiled If datasets cannot be fetched or concatenated

tiled_get_combined_plot_data(entry_ids, **kwargs)[source]#

Get concatenated xarray datasets from multiple Tiled entries.

Parameters:

entry_ids – JSON string array of entry IDs to concatenate

Returns:

dict with combined dataset structure ready for plotting

tiled_get_gantt_metadata(entry_ids, **kwargs)[source]#

Get metadata for Gantt chart from multiple Tiled entries.

This is a lightweight endpoint that only fetches metadata without loading or combining the actual datasets.

Parameters:

entry_ids – JSON string array of entry IDs

Returns:

dict with list of metadata for each entry

tiled_download_combined_dataset(entry_ids, **kwargs)[source]#

Download the concatenated xarray dataset as NetCDF file.

Parameters:

entry_ids – JSON string array of entry IDs (to regenerate dataset if needed)

Returns:

NetCDF file download with appropriate headers