Module riid.data
This sub-package contains all utilities for synthesizing, reading, writing, and converting data.
Expand source code Browse git
# Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
"""This sub-package contains all utilities for synthesizing, reading, writing, and converting data.
"""
import numpy as np
def get_expected_spectra(seeds: np.ndarray, expected_counts: np.ndarray) -> np.ndarray:
"""Multiply a 1-D array of expected counts by either a 1-D array or 2-D
matrix of seed spectra.
The dimension(s) of the seed array(s), `seeds`, is expanded to be `(m, n, 1)` where:
- m = # of seeds
- n = # of channels
and the final dimension is added in order to facilitate proper broadcasting.
The dimension of the `expected_counts` must be 1, but the length `p` can be
any positive number.
The resulting expected spectra will be of shape `(m x p, n)`.
This represents the same number of channels `n`, but each expected count
value, of which there are `p`, will be me multiplied through each seed spectrum,
of which there are `m`.
All expected spectra matrices for each seed are then concatenated together
(stacked), eliminating the 3rd dimension.
"""
if expected_counts.ndim != 1:
raise ValueError("Expected counts array must be 1-D.")
if expected_counts.shape[0] == 0:
raise ValueError("Expected counts array cannot be empty.")
if seeds.ndim > 2:
raise InvalidSeedError("Seeds array must be 1-D or 2-D.")
expected_spectra = np.concatenate(
seeds * expected_counts[:, np.newaxis, np.newaxis]
)
return expected_spectra
class InvalidSeedError(Exception):
"""Seed spectra data structure is not 1- or 2-dimensional."""
pass
Sub-modules
riid.data.converters-
This module contains utilities for converting known datasets into
SampleSets. riid.data.labeling-
This module contains utility functions for managing ground truth information.
riid.data.sampleset-
This module contains the
SampleSetclass and otherSampleSet-related functions. riid.data.synthetic-
This module contains utilities for synthesizing gamma spectra.
Functions
def get_expected_spectra(seeds: numpy.ndarray, expected_counts: numpy.ndarray) ‑> numpy.ndarray-
Multiply a 1-D array of expected counts by either a 1-D array or 2-D matrix of seed spectra.
The dimension(s) of the seed array(s),
seeds, is expanded to be(m, n, 1)where:- m = # of seeds
- n = # of channels
and the final dimension is added in order to facilitate proper broadcasting. The dimension of the
expected_countsmust be 1, but the lengthpcan be any positive number.The resulting expected spectra will be of shape
(m x p, n). This represents the same number of channelsn, but each expected count value, of which there arep, will be me multiplied through each seed spectrum, of which there arem. All expected spectra matrices for each seed are then concatenated together (stacked), eliminating the 3rd dimension.Expand source code Browse git
def get_expected_spectra(seeds: np.ndarray, expected_counts: np.ndarray) -> np.ndarray: """Multiply a 1-D array of expected counts by either a 1-D array or 2-D matrix of seed spectra. The dimension(s) of the seed array(s), `seeds`, is expanded to be `(m, n, 1)` where: - m = # of seeds - n = # of channels and the final dimension is added in order to facilitate proper broadcasting. The dimension of the `expected_counts` must be 1, but the length `p` can be any positive number. The resulting expected spectra will be of shape `(m x p, n)`. This represents the same number of channels `n`, but each expected count value, of which there are `p`, will be me multiplied through each seed spectrum, of which there are `m`. All expected spectra matrices for each seed are then concatenated together (stacked), eliminating the 3rd dimension. """ if expected_counts.ndim != 1: raise ValueError("Expected counts array must be 1-D.") if expected_counts.shape[0] == 0: raise ValueError("Expected counts array cannot be empty.") if seeds.ndim > 2: raise InvalidSeedError("Seeds array must be 1-D or 2-D.") expected_spectra = np.concatenate( seeds * expected_counts[:, np.newaxis, np.newaxis] ) return expected_spectra
Classes
class InvalidSeedError (*args, **kwargs)-
Seed spectra data structure is not 1- or 2-dimensional.
Expand source code Browse git
class InvalidSeedError(Exception): """Seed spectra data structure is not 1- or 2-dimensional.""" passAncestors
- builtins.Exception
- builtins.BaseException