refnx.reduce

class refnx.reduce.BatchReducer(filename, data_folder=None, verbose=True, persistent=True, **kwds)[source]

Bases: object

Batch reduction of reflectometry data based on spreadsheet metadata.

Example

>>> from refnx.reduce import BatchReducer
>>> data_folder = r'V:\data\current'
>>> b = BatchReducer('reduction.xls', data_folder=data_folder)
>>> b.reduce()

The spreadsheet must have columns:

reduce name scale refl1 refl2 refl3 dir1 dir2 dir3

Only rows where the value of the reduce column is 1 and where the sample name is set will be processed.

load_runs()[source]
reduce(show=True)[source]

Batch reduce data based on metadata from a spreadsheet

Parameters

show (bool (optional, default=True)) – display a summary table of the rows that were reduced

select_runs(all_runs)[source]
class refnx.reduce.Catalogue(h5d)[source]

Bases: object

Extract relevant parts of a NeXus file for reflectometry reduction

property datafile_number
class refnx.reduce.PlatypusNexus(h5data)[source]

Bases: refnx.reduce.platypusnexus.ReflectNexus

Processes Platypus NeXus files to produce an intensity vs wavelength spectrum

Parameters

h5data (HDF5 NeXus file or str) – An HDF5 NeXus file for Platypus, or a str containing the path to one

chod(omega=0.0, twotheta=0.0, scanpoint=0)[source]

Calculates the flight length of the neutrons in the Platypus instrument.

Parameters
  • omega (float, optional) – Rough angle of incidence

  • twotheta (float, optional) – Rough 2 theta angle

  • scanpoint (int, optional) – Which dataset is being considered

Returns

chod, d_cx – Flight distance (mm), distance between chopper discs (mm)

Return type

float, float

correct_for_gravity(detector, detector_sd, m_lambda, lo_wavelength, hi_wavelength)[source]
create_detector_norm(h5norm)[source]

Produces a detector normalisation array for a neutron detector. Here we average over N, T and X to provide a relative efficiency for each y wire.

Parameters

h5norm (hdf5 file) – Containing a flood field run (water)

Returns

norm, norm_sd – 1D array containing the normalisation data for each y pixel

Return type

array_like

detector_average_unwanted_direction(detector)[source]

Averages over non-collimated beam direction

estimated_beam_width_at_detector(scanpoint)[source]
phase_angle(scanpoint=0)[source]

Calculates the phase angle for a given scanpoint

Parameters

scanpoint (int) – The scanpoint you’re interested in

Returns

phase_angle, master_opening – The phase angle in degrees, and the angular opening of the master chopper in radians

Return type

float

time_offset(master_phase_offset, master_opening, freq, phase_angle, z0, flight_distance, tof_hist)[source]

Timing offsets for Platypus chopper system, includes a gravity correction for phase angle

class refnx.reduce.PlatypusReduce(direct, data_folder=None, **kwds)[source]

Bases: refnx.reduce.reduce.ReflectReduce

Reduces Platypus reflectometer data to give the specular reflectivity. Offspecular data maps are also produced.

Parameters
  • direct (string, hdf5 file-handle or PlatypusNexus object) – A string containing the path to the direct beam hdf5 file, the hdf5 file itself, or a PlatypusNexus object.

  • data_folder (str, optional) – Where is the raw data stored?

Examples

>>> from refnx.reduce import PlatypusReduce
>>> reducer = PlatypusReduce('PLP0000711.nx.hdf')
>>> datasets, reduced = reducer.reduce('PLP0000711.nx.hdf',
...                                    rebin_percent=2)
refnx.reduce.accumulate_HDF_files(files)[source]

Accumulates HDF files together, writing an accumulated file in the current directory. The accumulated datafile is written in the current directory (os.getcwd()) and has a filename based on the first file, prepended by ‘ADD_’. For example, if the first file is PLP0000708.nx.hdf then the accumulated file is ADD_PLP0000708.nx.hdf.

Parameters

files (list) – Strings specifying NeXUS filenames to be added together.

refnx.reduce.basename_datafile(pth)[source]

Given a NeXUS path return the basename minus the file extension. :param pth: :type pth: str

Returns

basename

Return type

str

Examples

>>> basename_datafile('a/b/c.nx.hdf')
'c'
refnx.reduce.catalogue(start, stop, data_folder=None, prefix='PLP')[source]

Extract interesting information from Platypus NeXUS files.

Parameters
  • start (int) – start cataloguing from this run number

  • stop (int) – stop cataloguing at this run number

  • data_folder (str, optional) – path specifying location of NeXUS files

  • prefix ({'PLP', 'SPZ'}, optional) – str specifying whether you want to catalogue Platypus or Spatz files

Returns

catalog – Dataframe containing interesting parameters from Platypus Nexus files

Return type

pd.DataFrame

refnx.reduce.datafile_number(fname, prefix='PLP')[source]

From a filename figure out what the run number was

Parameters

fname (str) – The filename to be processed

Returns

run_number – The run number

Return type

int

Examples

>>> datafile_number('PLP0000708.nx.hdf')
708
refnx.reduce.gui()[source]
refnx.reduce.main()[source]
refnx.reduce.number_datafile(run_number, prefix='PLP')[source]

Given a run number figure out what the file name is. Given a file name, return the filename with the .nx.hdf extension

Parameters
  • run_number (int or str) –

  • prefix (str, optional) – The instrument prefix. Only used if run_number is an int

Returns

file_name

Return type

str

Examples

>>> number_datafile(708)
'PLP0000708.nx.hdf'
>>> number_datafile(708, prefix='QKK')
'QKK0000708.nx.hdf'
>>> number_datafile('PLP0000708.nx.hdf')
'PLP0000708.nx.hdf'
refnx.reduce.reduce_stitch(reflect_list, direct_list, background_list=None, norm_file_num=None, data_folder=None, prefix='PLP', trim_trailing=True, save=True, **kwds)[source]

Reduces a list of reflected beam run numbers and a list of corresponding direct beam run numbers from the Platypus reflectometer. If there are multiple reflectivity files they are spliced together.

Parameters
  • reflect_list (list) – Reflected beam run numbers, e.g. [708, 709, 710] 708 corresponds to the file PLP0000708.nx.hdf.

  • direct_list (list) – Direct beam run numbers, e.g. [711, 711, 711]

  • background_list (list, optional) – List of bool to control whether background subtraction is used for each reduction, e.g. [False, True, True]. The default is to do a background subtraction on all runs.

  • norm_file_num (int, optional) – The run number for the water flood field correction.

  • data_folder (str, optional) – Where is the raw data stored?

  • prefix (str, optional) – The instrument filename prefix.

  • trim_trailing (bool, optional) – When datasets are spliced together do you want to remove points in the overlap region from the preceding dataset?

  • save (bool, optional) – If True then the spliced file is written to a file (in the working directory) with a name like: c_PLP0000708.dat.

  • kwds (dict, optional) – Options passed directly to refnx.reduce.platypusnexus.process, for processing of individual spectra. Look at that method docstring for specification of options.

Returns

combined_dataset, reduced_filename – The combined dataset and the file name of the reduced data, if it was saved. If it wasn’t saved reduced_filename is None.

Return type

refnx.dataset.ReflectDataset, str

Notes

If background is in the supplied kwds it is ignored. The prefix is used to specify the run numbers to a filename. For example a run number of 10, and a prefix of PLP resolves to a NeXus filename of ‘PLP0000010.nx.hdf’.

Examples

>>> from refnx.reduce import reduce_stitch
>>> dataset, fname = reduce_stitch([708, 709, 710],
...                                [711, 711, 711],
...                                 rebin_percent=2)
refnx.reduce.reduce_xrdml(f, bkg=None, scale=1, sample_length=None)[source]

Reduces a Panalytical XRDML file

Parameters
  • f (file-like object or string) – The specular reflectivity (XRDML) file of interest

  • bkg (list) – A list of file-like objects or strings that contain background measurements. The background is assumed to have the same number of points as the specular reflectivity curve. The backgrounds are averaged and subtracted from the specular reflectivity

  • scale (float) – The direct beam intensity (cps)

  • sample_length (None or float) – If None then no footprint correction is done. Otherwise the transverse footprint of the sample (mm).

Returns

specular_q, specular_r, specular_dr – The specular reflectivity as a function of momentum transfer, Q.

Return type

np.ndarray