Identification

Tools to find the response for each gamma line from a source.

Example

Load an event list, choose a clustering algorithm, and identify the specific gamma source:

data = np.loadtxt("imager-event-list.txt")
cluster_method = sklearn.cluster.KMeans()  # Or some other algorithm
source = SourceParams.get_source('Am241')

Then identify that sources lines:

responses = find_lines(data, cluster_method, source, gain_range=(1.0, 4.0))
for i, line in enumerate(responses):
    print(f"Line {i}: {line}")
x_ray_imager_bagriff.identify_lines._identify.find_lines(X, cluster_method, source, gain_range=None, diagnostic=None)

Finds the mean value associated with every source gamma line.

Parameters:
  • X (NDArray[int64]) – Array of measurements. Shape is (n events, n detectors). Integer values are expected from the detectors. Noise up to 1 is added to each point when converted to a float for clustering.

  • cluster_method (ClusterMixin) – Clustering algorithm from scikit-learn.clustering or otherwise compatible with ClusterMixin. fit() is called to assign labels, ideally with one cluster plus lines and background points as -1. If more labels are assigned, match_energy() selects the best fit.

  • source (SourceParams) – Parameters for the gamma source used. Should contain all peaks in the gamma spectrum, even if they’re not from decays directly, like a Compton edge.

  • gain_range (tuple[float, float] | None) – The max and min reasonable gain (detector units / keV).

  • diagnostic (GenericIdentifyDiagnostic | None) – Figure type object with a plot_diagnostic(X, labels). Useful to check that the cluster_method is accurately assigning gamma lines to the measurements.

Returns:

Array of mean detector responses. Shape is (n_lines, n_detectors)

Return type:

NDArray[float64]

x_ray_imager_bagriff.identify_lines._identify.line_means(X, labels)

Find mean for each point group.

Parameters:
  • X (NDArray[int64]) – Array of measurements. See find_lines() for more.

  • labels (NDArray[int64]) – Integer index of cluster identified for each measurement. Negative labels may be included, but will be ignored. Numpy warnings raised if non-zero labels < max(labels) are skipped.

Returns:

Array of the mean value for each detector in each labeled group. Shape is (max(labels), n detectors).

Raises:

ValueError – len(labels) != measurements in X.

Return type:

NDArray[float64]

x_ray_imager_bagriff.identify_lines._identify.match_energy(mean_response, energies, gain_range=None)

Matches a set of energies with best fit detector response.

For each mean response, the sum of all detectors should be proportional to the energy absorbed. The association of responses that best fit the energies with a linear gain, in the provided gain_range, are selected.

Parameters:
  • mean_response (NDArray[float64]) – An array of detector values associated with the mean of some feature in a calibration set. len(energies) of these are from the gamma spectral lines listed there, and rest are other features.

  • energies (NDArray[float64]) – An array listing some of the spectral lines captured. There should be fewer than the number of mean responses. Specific units are not required, but will change the meaning of the gain returned.

  • gain_range (tuple[float, float] | None) – Tuple setting the minimum and maximum gain that will be accepted as for the returned association.

Returns:

Array of indexes that selects best matched mean_response.

Raises:

RuntimeError – If no fit between responses and energies is found.

Return type:

tuple[NDArray[int64], float]