xrf_explorer.server.routes package

Submodules

xrf_explorer.server.routes.color_segmentation module

get_color_cluster_bitmask(data_source: str, elem: int, k: int, elem_threshold: int)[source]

Returns the png bitmask for the color clusters over the whole painting/selected element.

Parameters:
  • data_source – data_source to get the bitmask from

  • elem – index of selected element (0 if whole painting, channel+1 if element)

  • k – number of color clusters to compute

  • elem_threshold – elemental threshold

:return bitmask PNG file for the whole image

get_color_clusters(data_source: str, elem: int, k: int, elem_threshold: int)[source]

Gets the colors corresponding to the image-wide/element-wise color clusters, and caches them as well as the corresponding bitmasks.

Parameters:
  • data_source – data source to get the clusters from

  • elem – index of selected element (0 if whole painting, channel+1 if element)

  • k – number of color clusters to compute

  • elem_threshold – elemental threshold

:return JSON containing the ordered list of colors

xrf_explorer.server.routes.dim_reduction module

get_dr_embedding(data_source: str, element: int, threshold: int)[source]

Generate the dimensionality reduction embedding of an element, given a threshold.

Parameters:
  • data_source – data source to generate the embedding from

  • element – element to generate the embedding for

  • threshold – threshold from which a pixel is selected

Returns:

string code indicating the status of the embedding generation. “success” when embedding was generated successfully, “downsampled” when successful and the number of data points was down sampled.

get_dr_embedding_mapping(data_source: str)[source]

Creates the image for polygon selection that decodes to which points in the embedding the pixels of the elemental data cube are mapped. Uses the current embedding and indices for the given data source to create the image.

Parameters:

data_source – data source to get the overlay from

Returns:

image that decodes to which points in the embedding the pixels of the elemental data cube are mapped

get_dr_overlay(data_source: str, overlay_type: str)[source]

Generate the dimensionality reduction overlay with a given type.

Parameters:
  • data_source – data source to get the overlay from

  • overlay_type – the overlay type. Images are prefixed with contextual_ and elements by elemental_

Returns:

overlay image file

xrf_explorer.server.routes.elemental_cube module

convert_elemental_cube(data_source: str)[source]

Converts all elemental data cubes of a data source to .dms format.

Parameters:

data_source – The name of the data source to convert the elemental data cube

Returns:

200 if the conversion was successful, 500 otherwise

data_cube_recipe(data_source: str)[source]

Get the registering recipe for the data cubes.

Parameters:

data_source – data source to get the recipe from

Returns:

the registering recipe of the data cubes

data_cube_size(data_source: str)[source]

Get the size of the data cubes.

Parameters:

data_source – data source to get the size from

Returns:

the size of the data cubes

elemental_map(data_source: str, channel: int)[source]

Get an elemental map.

Parameters:
  • data_source – data source to get the map from

  • channel – the channel to get the map from

Returns:

the elemental map

list_element_averages(data_source: str)[source]

Get the names and averages of the elements present in the painting.

Parameters:

data_source – data_source to get the element averages from

Returns:

JSON list of objects indicating average abundance for every element. Each object is of the form {

name: element name, channel: element channel, average: element abundance

}

list_element_averages_selection(data_source: str)[source]

Get the names and averages of the elements present in a rectangular selection of the painting.

Parameters:

data_source – data_source to get the element averages from

Returns:

JSON list of objects indicating average abundance for every element. Each object is of the form {

name: element name, average: element abundance

}

list_element_names(data_source: str)[source]

Get the short names of the elements stored in the elemental data cube.

Parameters:

data_source – data source to get the element names from

Returns:

JSON list of the short names of the elements.

xrf_explorer.server.routes.general module

api()[source]

Returns a list of all API endpoints.

Returns:

list of API endpoints

xrf_explorer.server.routes.helper module

encode_selection(selection_data: any, data_source: str, cube_type: CubeType) ndarray | tuple[str, int][source]

Creates a bitmask of the given cube from a selection in JSON format.

Parameters:
  • selection_data – the selection data in JSON format as extracted from a request

  • data_source – the name of the data source containing the cube

  • cube_type – the type of the cube on which to apply the selection

Returns:

bitmask of the cube encoding the selection or None if an error occurred

parse_selection(selection_data: dict[slice(<class 'str'>, <class 'str'>, None)]) tuple[SelectionType, list[tuple[int, int]]] | tuple[str, int][source]

Parses a selection in JSON format and extracts the information therein.

Parameters:

selection_data – the selection data in JSON format

Returns:

The selection type and points or an error message and the HTTP response status code if an error occurred

validate_config(config: dict | None) tuple[str, int] | None[source]

Checks that the configuration has a valid format.

Parameters:

config – the configuration to verify

Returns:

None if the configuration is valid, otherwise a tuple with an error message and the HTTP response status code

xrf_explorer.server.routes.images module

contextual_image(data_source: str, name: str)[source]

Get a contextual image.

Parameters:
  • data_source – data source to get the image from

  • name – the name of the image in workspace.json

Returns:

the contextual image converted to png

contextual_image_recipe(data_source: str, name: str)[source]

Get the registering recipe of a contextual image.

Parameters:
  • data_source – data source to get the image recipe from

  • name – the name of the image in workspace.json

Returns:

the registering recipe of the contextual image

contextual_image_size(data_source: str, name: str)[source]

Get the size of a contextual image.

Parameters:
  • data_source – data source to get the image from

  • name – the name of the image in workspace.json

Returns:

the size of the contextual image

xrf_explorer.server.routes.project module

create_data_source_dir(data_source: str)[source]

Create a directory for a new data source.

Parameters:

data_source – The name of the data source to create

Returns:

JSON with directory name

datasource_files(data_source: str)[source]

Return a list of all available files for a data source.

Parameters:

data_source – The name of the data source to get the files for

Returns:

JSON list of strings representing the file names

delete_data_source(data_source: str)[source]

Completely deletes and removes all files from data source.

Parameters:

data_source – The data source to delete.

Returns:

JSON with directory name

get_workspace(data_source: str)[source]

Gets the workspace content for the specified data source or writes to it if a POST request is made.

Parameters:

data_source – The name of the data source to get the workspace content for

Returns:

If a GET request is made, the workspace content is sent as a json file. If a POST request is made, a confirmation message is sent

list_accessible_data_sources()[source]

Return a list of all available data sources stored in the data folder on the remote server as specified in the project’s configuration.

Returns:

JSON list of strings representing the data sources names

remove_data_source(data_source: str)[source]

Removes workspace.json from a data source,

Parameters:

data_source – The name of the data source to be aborted

Returns:

JSON with directory name

upload_chunk(data_source: str, file_name: str, start: int)[source]

Upload a chunk of bytes to a file in specified data source.

Parameters:
  • data_source – The name of the data source to upload the chunk to

  • file_name – The name of the file to upload the chunk to

  • start – The start index of the chunk in the specified file

Returns:

A message indicating the success of the upload

xrf_explorer.server.routes.spectral_cube module

bin_raw_data(data_source: str)[source]

Bins the raw data files channels to compress the file.

Parameters:

data_source – the data source containing the raw data to bin

Returns:

A boolean indicating if the binning was successful

get_average_data(data_source: str)[source]

Computes the average of the raw data for each bin of channels in range [low, high] on the whole painting.

Returns:

json list of tuples containing the bin number and the average intensity for this bin

get_element_spectra(data_source: str, element: str, excitation: float)[source]

Compute the theoretical spectrum in channel range [low, high] for an element with a bin size, as well as the element’s peaks energies and intensity.

Parameters:
  • data_source – the name of the data source, used for getting the spectrum boundaries and bin size

  • element – the chemical element to get the theoretical spectra of

  • excitation – the excitation energy

Returns:

JSON list of tuples containing the bin number and the theoretical intensity for this bin, the peak energies and the peak intensities

get_offset(data_source: str)[source]

Returns the depth offset energy of the raw data, that is the energy level of channel 0.

Parameters:

data_source – the data source containing the raw data

Returns:

The depth offset

get_selection_spectra(data_source: str)[source]

Get the average spectrum of the selected pixels of a rectangle selection.

Parameters:

data_source – the name of the data source

Returns:

JSON array where the index is the channel number and the value is the average intensity of that channel

Module contents

This module routes all incoming front-end requests to the appropriate backend functions