mlreflect.xrrloader.dataloader package

Submodules

mlreflect.xrrloader.dataloader.fioloader module

mlreflect.xrrloader.dataloader.scans module

class mlreflect.xrrloader.dataloader.scans.ReflectivityScan(scan_number: int, scattering_angle: numpy.ndarray, intensity: numpy.ndarray, wavelength: float, beam_width: float, sample_length: float, beam_shape: str = 'gauss', normalize_to: str = 'max', timestamp: Optional[str] = None)[source]

Bases: object

Store information about a loaded scan and perform a basic footprint correction.

Parameters
  • scan_number – Scan number for identification (usually derived from SPEC scan number).

  • scattering_angle – Full scattering angle (2theta) in degrees for each intensity value.

  • intensity – Continuous raw intensity values (including attenuator correction).

  • wavelength – Wavelength in units of angstroms.

  • beam_width – Beam width for a rectangular approximation or FWHM of a Gaussian approximation in units of mm.

  • sample_length – Sample length in beam direction in units of mm.

  • beam_shape – Beam shape approximation. Either ‘box’ or ‘gauss’ (default).

  • normalize_to – To what intensity value the curve is normalized to after footprint correction. Either

‘first’ or ‘max’ (default). :param timestamp: Timestamp of when the scan was taken in the SPEC format (e.g. “Wed Apr 28 09:32:45 2010”).

property corrected_intensity
get_corrected_intensity_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get corrected intensity between q_min and q_max.

get_interpolated_intensity(new_q: numpy.ndarray)[source]

Interpolate log10 values of the corrected intensity to new values new_q.

get_q_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get q values between q_min and q_max.

get_raw_intensity_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get raw intensity between q_min and q_max.

plot_corrected_intensity(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Plot corrected intensity within given q range.

plot_raw_intensity(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Plot raw intensity within given q range.

property q
class mlreflect.xrrloader.dataloader.scans.ScanSeries(iterable=(), /)[source]

Bases: list

Store a series of Scan objects in a list-like object.

append(scan: mlreflect.xrrloader.dataloader.scans.ReflectivityScan)[source]

Append object to the end of the list.

plot_series(scan_range: Optional[Iterable] = None, q_min: Optional[float] = None, q_max: Optional[float] = None, legend: bool = True)[source]

Plot all or a subset of scans of the series within the given q range.

property stats
to_array()[source]

Convert corrected intensity to numpy array with each scan as a row.

mlreflect.xrrloader.dataloader.specloader module

mlreflect.xrrloader.dataloader.transform module

mlreflect.xrrloader.dataloader.transform.angle_to_q(scattering_angle: numpy.ndarray, wavelength: float)[source]

Conversion from full scattering angle (degrees) to scattering vector (inverse angstroms)

mlreflect.xrrloader.dataloader.transform.energy_to_wavelength(energy: float)[source]

Conversion from photon energy (eV) to photon wavelength (angstroms)

mlreflect.xrrloader.dataloader.transform.q_to_angle(q: numpy.ndarray, wavelength: float)[source]

Conversion from scattering vector (inverse angstroms) to full scattering angle (degrees)

mlreflect.xrrloader.dataloader.transform.wavelength_to_energy(wavelength: float)[source]

Conversion from photon wavelength (angstroms) to photon energy (eV)

Module contents

class mlreflect.xrrloader.dataloader.FioLoader(file_stem: str, beam_width: float, sample_length: float, two_theta_counter='tt', default_roi_name='p100k_roi1', beam_shape='gauss', normalize_to='max', attenuator_counter='atten_position', division_counter=None)[source]

Bases: mlreflect.xrrloader.dataloader.reflectivity_loader.ReflectivityLoader

Read .fio files and associated detector images and extract reflectivity scans.

Parameters
  • file_stem – The name of the experiment including the preceding folder structure. E.g. if you’re experiment name is 'my_data' and in the folder 'user/data/', the file stem would be 'user/data/my_data'. This will look for all scans in the folder 'user/data/' that begin with 'my_data'.

  • two_theta_counter – Name of the counter that contains the full scattering angle (default: 'tt').

  • default_roi_name – Counter name of the default region of interest that is extracted as reflectivity (default:

  • 'p100k').

  • beam_width – Beam width for a rectangular approximation or FWHM of a Gaussian approximation in units of mm.

  • sample_length – Sample length in beam direction in units of mm.

  • beam_shape – Beam shape approximation. Either 'box' or 'gauss' (default).

  • normalize_to – To what intensity value the curve is normalized to after footprint correction. Either 'first' or 'max' (default).

  • attenuator_counter – Optional column name of the attenuator values for intensity correction.

  • division_counter – Optional name of a column that the intensity is divided by after attenuator correction.

load_scan(scan_number: int, trim_front: Optional[int] = None, trim_back: Optional[int] = None, roi: Optional[list] = None, detector_name='p100k') mlreflect.xrrloader.dataloader.scans.ReflectivityScan[source]

Read .fio files and associated detector images, trim it and return it in a ReflectivityScan object.

Parameters
  • scan_number – Number of the scan to extract.

  • trim_front – Number of measurement points that are cut off at the beginning of the scan (e.g. to remove the direct beam).

  • trim_back – Number of measurement points that are cut off at the end of the scan.

  • roi – Alternative region of interest in the raw detector image that will be converted to a reflectivity curve. The roi specifications must be a list of integers that specify the pixel boundaries in the format [left, bottom, right, top], e.g. roi=[241, 106, 247, 109]. This will override the default roi counter.

  • detector_name – Name of the detector from which the roi is extracted.

Returns: ReflectivityScan

load_scans(scan_numbers: Iterator, trim_front: Optional[int] = None, trim_back: Optional[int] = None, roi: Optional[list] = None) mlreflect.xrrloader.dataloader.scans.ScanSeries[source]

Read several reflectivity scans and return them in a ScanSeries object.

exception mlreflect.xrrloader.dataloader.NotReflectivityScanError[source]

Bases: Exception

Exception if a scan is not a theta2theta or reflectivity scan.

class mlreflect.xrrloader.dataloader.ReflectivityScan(scan_number: int, scattering_angle: numpy.ndarray, intensity: numpy.ndarray, wavelength: float, beam_width: float, sample_length: float, beam_shape: str = 'gauss', normalize_to: str = 'max', timestamp: Optional[str] = None)[source]

Bases: object

Store information about a loaded scan and perform a basic footprint correction.

Parameters
  • scan_number – Scan number for identification (usually derived from SPEC scan number).

  • scattering_angle – Full scattering angle (2theta) in degrees for each intensity value.

  • intensity – Continuous raw intensity values (including attenuator correction).

  • wavelength – Wavelength in units of angstroms.

  • beam_width – Beam width for a rectangular approximation or FWHM of a Gaussian approximation in units of mm.

  • sample_length – Sample length in beam direction in units of mm.

  • beam_shape – Beam shape approximation. Either ‘box’ or ‘gauss’ (default).

  • normalize_to – To what intensity value the curve is normalized to after footprint correction. Either

‘first’ or ‘max’ (default). :param timestamp: Timestamp of when the scan was taken in the SPEC format (e.g. “Wed Apr 28 09:32:45 2010”).

property corrected_intensity
get_corrected_intensity_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get corrected intensity between q_min and q_max.

get_interpolated_intensity(new_q: numpy.ndarray)[source]

Interpolate log10 values of the corrected intensity to new values new_q.

get_q_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get q values between q_min and q_max.

get_raw_intensity_range(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Get raw intensity between q_min and q_max.

plot_corrected_intensity(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Plot corrected intensity within given q range.

plot_raw_intensity(q_min: Optional[float] = None, q_max: Optional[float] = None)[source]

Plot raw intensity within given q range.

property q
class mlreflect.xrrloader.dataloader.ScanSeries(iterable=(), /)[source]

Bases: list

Store a series of Scan objects in a list-like object.

append(scan: mlreflect.xrrloader.dataloader.scans.ReflectivityScan)[source]

Append object to the end of the list.

plot_series(scan_range: Optional[Iterable] = None, q_min: Optional[float] = None, q_max: Optional[float] = None, legend: bool = True)[source]

Plot all or a subset of scans of the series within the given q range.

property stats
to_array()[source]

Convert corrected intensity to numpy array with each scan as a row.

class mlreflect.xrrloader.dataloader.SpecLoader(file_path: str, angle_columns: list, intensity_column: str, wavelength: float, beam_width: float, sample_length: float, beam_shape='gauss', normalize_to='max', attenuator_column=None, division_column=None)[source]

Bases: mlreflect.xrrloader.dataloader.reflectivity_loader.ReflectivityLoader

Read SPEC file and extract reflectivity scans.

Parameters
  • file_path – Full file path of the SPEC file.

  • angle_columns – List of column names of the angles in the SPEC file. If multiple are given, their absolute values are summed up to form the full scattering angle 2theta.

  • intensity_column – Column name of the reflected intensity. Attenuator and monitor correction must already be performed.

  • wavelength – Photon wavelength in units of angstroms.

  • beam_width – Beam width for a rectangular approximation or FWHM of a Gaussian approximation in units of mm.

  • sample_length – Sample length in beam direction in units of mm.

  • beam_shape – Beam shape approximation. Either 'box' or 'gauss' (default).

  • normalize_to – To what intensity value the curve is normalized to after footprint correction. Either 'first' or 'max' (default).

  • attenuator_column – Optional column name of the attenuator values for intensity correction.

  • division_column – Optional name of a column that the intensity is divided by after attenuator correction.

load_scan(scan_number: int, trim_front: Optional[int] = None, trim_back: Optional[int] = None) mlreflect.xrrloader.dataloader.scans.ReflectivityScan[source]

Read reflectivity scan from SPEC file, trim it and return it in a ReflectivityScan object.

load_scans(scan_numbers: Iterator, trim_front: Optional[int] = None, trim_back: Optional[int] = None) mlreflect.xrrloader.dataloader.scans.ScanSeries[source]

Read several reflectivity scans from SPEC file, trim them and return them in a ScanSeries object.