xrf_explorer.server.file_system.cubes package

Submodules

xrf_explorer.server.file_system.cubes.convert_csv module

get_elemental_data_cube_from_csv(path: str | Path) ndarray[source]

Get the elemental data cube from the csv file at the given path. Can raise error if file could not be read.

Parameters:

path – Path to the csv file containing the elemental data cube.

Returns:

3-dimensional numpy array containing the elemental data cube. First dimension is channel, and last two for x, y coordinates.

get_elemental_map_from_csv(element: int, path: str | Path) ndarray[source]

Get the elemental map of the given element from the csv file. Can raise error if file could not be read.

Parameters:
  • element – Index of the element in the elemental data cube.

  • path – Path to the dms file containing the elemental data cube.

Returns:

2-dimensional numpy array containing the elemental map. Dimensions are the x, y coordinates.

get_elements_from_csv(path: str | Path) list[str][source]

Get the names of the elements stored in the elemental data cube. Can raise error if file could not be read.

Parameters:

path – Path to the csv file containing the elemental data cube.

Returns:

List of the names of the elements.

xrf_explorer.server.file_system.cubes.convert_dms module

get_elemental_data_cube_from_dms(path: str | Path) ndarray[source]

Get the elemental data cube from the dms file. Can raise error if file could not be read.

Parameters:

path – Path to the dms file containing the elemental data cube.

Returns:

3-dimensional numpy array containing the elemental data cube. First dimension is channel, and last two for x, y coordinates

get_elemental_datacube_dimensions(data_source: str) tuple[int, int, int, int] | None[source]

Get the dimensions of the elemental datacube. Can raise error if file could not be read.

Parameters:

data_source – Name of the data source containing the raw data file in the server

Returns:

4-tuple of the dimensions of the raw elemental data and the header size (in bytes). Tuple is as follows (width, height, channels, header size)

get_elemental_map_from_dms(element: int, path: str | Path) ndarray[source]

Get the elemental map of the given element from the dms file. Can raise error if file could not be read.

Parameters:
  • element – Index of the element in the elemental data cube.

  • path – Path to the dms file containing the elemental data cube.

Returns:

2-dimensional numpy array containing the elemental map. Dimensions are the x, y coordinates.

get_elements_from_dms(path: str | Path) list[str][source]

Get the names of the elements stored in the elemental data cube. Can raise error if file could not be read.

Parameters:

path – Path to the dms file containing the elemental data cube.

Returns:

List of the names of the elements.

to_dms(folder_path: str, name_cube: str, cube: ndarray, elements: list[str]) bool[source]

Saves a numpy array and list of elements to a DMS file.

Parameters:
  • folder_path – Path to the folder where the DMS file will be saved.

  • name_cube – Name of the elemental data cube. Without file extension, e.g. ‘cube’.

  • cube – 3-dimensional numpy array containing the elemental data cube. First dimension is channel, and last two for x, y coordinates.

  • elements – List of the names of the elements.

Returns:

True if the cube was saved successfully, False otherwise.

xrf_explorer.server.file_system.cubes.elemental module

convert_elemental_cube_to_dms(data_source: str, cube_name: str) bool[source]

Converts an elemental data cube to .dms format. Updates the workspace accordingly and removes the old elemental data cube.

Parameters:
  • data_source – Name of the data source.

  • cube_name – Name of the elemental data cube. Should be present in the workspace.

Returns:

True if the cube was converted successfully, False otherwise.

get_element_averages(data_source: str) list[dict[str, str | float]][source]

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

Parameters:

data_source – Name of the data source.

Returns:

List of the names, channels and average composition of the elements.

get_element_averages_selection(data_source: str, mask: ndarray) list[dict[str, str | float]][source]

Get the names and averages of the elements present in (a subarea of) the painting.

Parameters:
  • data_source – The data source to get the selection averages from.

  • mask – A 2D mask of the selected pixels

Returns:

List of the names, channels and average composition of the elements.

get_element_names(data_source: str) list[str][source]

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

Parameters:

data_source – Data source folder name.

Returns:

List of the names of the elements. Empty list if error occurred.

get_elemental_data_cube(data_source: str) ndarray[source]

Get the elemental data cube at the given path.

Parameters:

data_source – the path to the .raw file

Returns:

3-dimensional numpy array containing the elemental data cube. First dimension is channel, and last two for x, y coordinates.

get_elemental_map(element: int, path: str) ndarray[source]

Get the elemental map of element index at the given path.

Parameters:
  • element – Index of the element in the elemental data cube.

  • path – Path to data cube.

Returns:

2-dimensional numpy array containing the elemental data cube. Dimensions are the x, y coordinates.

get_short_element_names(data_source: str) list[str][source]

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

Parameters:

data_source – Data source folder name.

Returns:

List of the names of the elements. Empty list if error occurred.

normalize_elemental_cube_per_layer(raw_cube: ndarray) ndarray[source]

Normalize the raw elemental data cube.

Parameters:

raw_cube – 3-dimensional numpy array containing the normalized elemental data. First dimension is channel, and last two for x, y coordinates.

Returns:

3-dimensional numpy array containing the normalized elemental data. First dimension is channel, and last two for x, y coordinates.

normalize_ndarray_to_grayscale(array: ndarray, upper_bound: int = 255) ndarray[source]

Map all values in the given array to the interval [0, upper_bound].

Parameters:
  • upper_bound – upper bound of the normalization interval.

  • array – n-dimensional numpy array.

Returns:

a copy of the array with values mapped to the interval [0, upper_bound].

xrf_explorer.server.file_system.cubes.spectral module

bin_data(data_source: str, low: int, high: int, bin_size: int)[source]

Reduces the raw data of a data source to channels in range [low:high] and averages channels per bin.

Parameters:
  • data_source – the name of the data source containing the raw data

  • low – the lower channel boundary

  • high – the higher channel boundary

  • bin_size – the number of channels per bin

get_raw_data(data_source: str, level: int = 0) memmap | ndarray[source]

Parse the raw data cube of a data source as a 3-dimensional numpy array.

Parameters:
  • data_source – the path to the .raw file

  • level – the mipmap level of the data to get

Returns:

memory map of the 3-dimensional array containing the raw data in format {x, y, channel}

get_spectra_params(data_source: str) dict[str, int][source]

Returns the spectrum parameters (low/high boundaries and bin size) of a data source.

Parameters:

data_source – Name of the data source.

Raises:

FileNotFoundError – There is no workspace in the data source

Returns:

dictionary with the low, high, bin size and binned values.

mipmap_exists(data_source: str, level: int) bool[source]

Checks if a specific mipmap level exists for a data source.

Parameters:
  • data_source – The datasource to check

  • level – The mipmap level to check

Returns:

Whether the specified mipmap level exists

mipmap_raw_cube(data_source: str, level: int)[source]

Generates the mipmaps of the raw data in the data source up to the selected level.

Parameters:
  • data_source – The data source to mipmap the data for

  • level – The level to mipmap the data to, 0 is original resolution

parse_rpl(path: str) dict[source]
Parse the rpl file of a data source as a dictionary, containing the following info:
  • width

  • height

  • depth

  • offset

  • data length

  • data type

  • byte order

  • record by

  • depth bin size

  • depth1

  • depth2

  • depth scale origin

  • depth scale increment

  • depth scale units

Parameters:

path – path to the rpl file

Returns:

Dictionary containing the attributes’ name and value

update_bin_params(data_source: str)[source]

Converts the low, high and binsize parameters in the workspace from energy to channel.

Parameters:

data_source – Name of the data source containing the workspace to modify.

Module contents

Module that handles everything related to the raw and elemental data cubes.