mcareader API documentation

Contents:

A minimal python interface to read Amptek’s mca files

class mcareader.Mca(file, encoding='iso-8859-15', calibration=None)[source]

A mca file.

raw

str – The text of the file.

calibration_points

numpy.ndarray – The 2D array with the calibration data or None if there is no such information.

__init__(file, encoding='iso-8859-15', calibration=None)[source]

Load the content of a mca file.

Parameters:
  • file (str) – The path to the file.
  • encoding (str) – The encoding to use to read the file.
  • calibration (str or list) – A path with a file used to read calibration or a 2D matrix describing it.
__weakref__

list of weak references to the object (if defined)

get_calibration_function(method=None)[source]

Get a calibration function from the file.

Parameters:method (str) –

The method to use. Available methods include:

  • ‘bestfit’: A linear fit in the sense of least-squares (default).
  • ‘interpolation’: Use a linear interpolation.
Returns:A function mapping channel number to energy. Note the first channel is number 0.
Return type:(Callable)
get_calibration_points()[source]

Get the calibration points from the MCA file, regardless of the calibration parameter used to create the object.

Returns:The 2D array with the data or None if there is no calibration data.
Return type:(numpy.ndarray)
get_counts(calibration_method=None, background=None)[source]

Get the number of counts in the spectrum.

Parameters:
  • calibration_method (str) – The method used for the calibration. See get_calibration_function.
  • background (Mca) – An spectrum describing a background to subtract from the returned points. The background is scaled using the REAL_TIME parameters.
Returns:

Number of counts in the spectrum.

Return type:

(float)

get_points(calibration_method=None, trim_zeros=True, background=None)[source]

Get the points of the spectrum.

Parameters:
  • calibration_method (str) – The method used for the calibration. See get_calibration_function.
  • trim_zeros (bool) – Whether to remove values with no counts.
  • background (Mca) – An spectrum describing a background to subtract from the returned points. The background is scaled using the REAL_TIME parameters.
Returns:

tuple containing:

x (List[float]): The list of x coordinates (mean bin energy).

y (List[float]): The list of y coordinates (counts in each bin).

Return type:

(tuple)

get_section(section)[source]

Find the str representing a section in the MCA file.

Parameters:section (str) – The name of the section to search for.
Returns:The text of the section or “” if not found.
Return type:(str)
get_total_energy(calibration_method=None, background=None)[source]

Get the total energy in the spectrum.

Parameters:
  • calibration_method (str) – The method used for the calibration. See get_calibration_function.
  • background (Mca) – An spectrum describing a background to subtract from the returned points. The background is scaled using the REAL_TIME parameters.
Returns:

Total energy of counts in the spectrum, in the units set in the calibration. If there is no calibration available, a meaningless number is returned.

Return type:

(float)

get_variable(variable)[source]

Find the str representing a variable in the MCA file.

Parameters:variable (str) – The name of the variable to search for.
Returns:The text of the value or “” if not found.
Return type:(str)
plot(log_y=False, log_x=False, calibration_method=None, background=None)[source]

Show a plot of the spectrum.

Parameters:
  • log_y (bool) – Whether the y-axis is in logarithmic scale.
  • log_x (bool) – Whether the x-axis is in logarithmic scale.
  • calibration_method (str) – The method used for the calibration. See get_calibration_function.
  • background (Mca) – An spectrum describing a background to subtract from the returned points. The background is scaled using the REAL_TIME parameters.

Indices and tables