refnx.util

refnx.util.EPadd(a, da, b, db, covar=0)[source]

C = A + B

refnx.util.EPcos(a, da)[source]

C = cos (A)

refnx.util.EPdiv(a, da, b, db, covar=0)[source]

C = A / B

refnx.util.EPexp(a, da, k=1, n=1)[source]

C = n * exp(k * A)

refnx.util.EPlog(a, da, k=1, n=1)[source]

C = n * log(k * A )

refnx.util.EPlog10(a, da, k=1, n=1)[source]

C = n * log10(k * A)

refnx.util.EPmul(a, da, b, db, covar=0)[source]

C = A * B

refnx.util.EPmulk(a, da, k)[source]

C = A * k

refnx.util.EPpow(a, da, b, db, covar=0)[source]

C = A ** B

refnx.util.EPpowk(a, da, k, n=1)[source]

C = pow(k, A * n)

refnx.util.EPsin(a, da)[source]

C = sin (A)

refnx.util.EPsub(a, da, b, db, covar=0)[source]

C = A - B

refnx.util.EPtan(a, da)[source]

C = tan (A)

refnx.util.actual_footprint(d1, d2, L12, L2S, angle)[source]

Calculate the actual footprint on a reflectivity sample.

Parameters
  • d1 (float) – opening of first collimation slit

  • d2 (float) – opening of second collimation slit

  • L12 (float) – distance between first and second collimation slits

  • L2S (float) – distance from second collimation slit to sample

  • angle (float) – angle of incidence of sample (degrees)

Returns

(umbra_footprint, penumbra_footprint) – Footprint of the umbra and penumbra

Return type

float, float

refnx.util.angle(q, wavelength)[source]

calculate angle given Q and wavelength

Parameters
  • q (float) – Wavevector (A**-1)

  • wavelength (float) – Wavelength of radiation (A)

Returns

angle – angle of incidence (degrees)

Return type

float

refnx.util.beamfrac(FWHM, length, angle)[source]

Calculate the beam fraction intercepted by a sample.

Parameters
  • FWHM (float) – The FWHM of the beam height

  • length (float) – Length of the sample in mm

  • angle (float) – Angle that the sample makes w.r.t the beam (degrees)

Returns

beamfrac – The fraction of the beam that intercepts the sample

Return type

float

refnx.util.beamfrackernel(kernelx, kernely, length, angle)[source]

The beam fraction intercepted by a sample, used for calculating footprints.

Parameters
  • kernelx (array-like) – x axis for the probability kernel

  • kernely (array-like) – probability kernel describing the intensity distribution of the beam

  • length (float) – length of the sample

  • angle (float) – angle of incidence (degrees)

Returns

fraction – The fraction of the beam intercepted by a sample.

Return type

float

refnx.util.div(d1, d2, L12=2859)[source]

Calculate the angular resolution for a set of collimation conditions

Parameters
  • d1 (float) – slit 1 opening

  • d2 (float) – slit 2 opening

  • L12 (float) – distance between slits

Returns

  • dtheta, alpha, beta – dtheta is the FWHM of the Gaussian approximation to the trapezoidal resolution function alpha is the angular divergence of the penumbra beta is the angular divergence of the umbra

  • When calculating dtheta / theta values for resolution, then dtheta is the

  • value you need to use.

  • See equations 11-14 in [1]_.

  • .. [1] de Haan, V.-O.; de Blois, J.; van der Ende, P.; Fredrikze, H.;

  • van der Graaf, A.; Schipper, M.; van Well, A. A. & J., v. d. Z. ROG, the

  • neutron reflectometer at IRI Delft Nuclear Instruments and Methods in

  • Physics Research A, 1995, 362, 434-453

refnx.util.double_chopper_frequency(min_wavelength, max_wavelength, L, N=1)[source]

Calculates the maximum frequency available for a given wavelength band without getting frame overlap in a chopper spectrometer.

Parameters
  • min_wavelength (float) – minimum wavelength to be used

  • max_wavelength (float) – maximum wavelength to be used

  • L (float) – Flight length of instrument (m)

  • N (float, optional) – number of windows in chopper pair

Returns

max_freq – The maximum frequency a double chopper system can use to avoid frame overlap.

Return type

float

refnx.util.energy_wavelength(energy)[source]

Converts wavelength to energy in meV

Parameters

energy (float) – Energy in meV.

Returns

wavelength – Wavelength in Angstrom.

Return type

float

refnx.util.get_scaling_in_overlap(x0, y0, dy0, x1, y1, dy1)[source]

Obtain vertical scaling factor that splices the second dataset onto the first.

Parameters
  • x0 (np.ndarray) – abscissae for the first dataset

  • y0 (np.ndarray) – y values for the first dataset

  • dy0 (np.ndarray) – dy (standard deviation) values for the first dataset

  • x1 (np.ndarray) – abscissae values for the second dataset

  • y1 (np.ndarray) – y values for the second dataset

  • dy1 (np.ndarray) – dy (standard deviation) values for the second dataset

Returns

(scale, dscale, overlap_points)scale and dscale are the scaling and uncertainty in scaling factor. They are np.nan if the abscissae ranges don’t overlap. overlap_points indicates the points in the first dataset that are in the overlap region.

Return type

float, float, array-like

refnx.util.height_of_beam_after_dx(d1, d2, L12, distance)[source]

Calculate the total widths of beam a given distance away from a collimation slit.

if distance >= 0, then it’s taken to be the distance after d2. if distance < 0, then it’s taken to be the distance before d1.

Parameters
  • d1 (float) – opening of first collimation slit

  • d2 (float) – opening of second collimation slit

  • L12 (float) – distance between first and second collimation slits

  • distance (float) – distance from first or last slit to a given position

Notes

Units - equivalent distances (inches, mm, light years)

Returns

(umbra, penumbra) – full width of umbra and penumbra

Return type

float, float

refnx.util.neutron_transmission(formula, density, wavelength, thickness, xs_type='abs_incoh')[source]

Calculates the transmission of neutrons through a material.

Parameters
  • formula (str) – Chemical formula of the material.

  • density (float) – material density in g/cm^3

  • wavelength (float, np.ndarray) – wavelength of neutron in Angstrom

  • thickness (float) – thickness of material in mm

  • xs_type ({'abs', 'abs_incoh', 'abs_incoh_coh'}) – Cross section to use for penetration depth calculation

Returns

transmission – transmission of material

Return type

float or np.ndarray

Notes

The periodictable notes (and the NCNR activation calculator) advise the use of abs_incoh for absorption with respect to the beam.

refnx.util.penetration_depth(qq, rho)[source]

Calculates the penetration depth of a neutron/xray beam

Parameters
  • qq (float) – Q values to calculate the penetration depth at

  • rho (float or complex) – Complex SLD of material

Returns

penetration_depth

Return type

float

refnx.util.q(angle, wavelength)[source]

Calculate Q given angle of incidence and wavelength

Parameters
  • angle (float) – angle of incidence (degrees)

  • wavelength (float) – wavelength of radiation (Angstrom)

Returns

Q – Momentum transfer (A**-1)

Return type

float

refnx.util.q2(omega, twotheta, phi, wavelength)[source]

Convert angles and wavelength (lambda) to Q vector.

Parameters
  • omega (float) – angle of incidence of beam (with respect to xy plane).

  • twotheta (float) – angle between direct beam and the projection of the reflected beam onto xz plane.

  • phi (float) – azimuthal angle between reflected beam and xz plane.

  • wavelength (float) –

Returns

Qx, Qy, Qz – Momentum transfer.

Return type

float, float, float

Notes

All angles are assumed to be in degrees.

coordinate system: The beam is incident in the xz plane. x - along beam direction (in small angle approximation) y - transverse to beam direction, in plane of sample z - normal to sample plane.

The xy plane is equivalent to the sample plane.

refnx.util.qcrit(SLD1, SLD2)[source]

calculate critical Q vector given SLD of super and subphases

Parameters
  • SLD1 (float) – SLD of superphase (10^-6 A^-2)

  • SLD2 (float) – SLD of subphase (10^-6 A^-2)

Returns

qc – Critical Q vector for a reflectivity system.

Return type

float

refnx.util.refplot(datasets)[source]

Quickly plot a lot of datasets

Parameters

datasets (iterable) – {str, file, Data1D} specifying the datasets to plot

Returns

fig – The figure. Use fig.show() to display

Return type

matplotlib.figure.Figure

refnx.util.resolution_double_chopper(wavelength, z0=0.358, R=0.35, freq=24, H=0.005, xsi=0, L=7.5, tau_da=0)[source]

Calculates the fractional resolution of a double chopper pair, dl/l.

Parameters
  • wavelength (float) – wavelength in Angstroms

  • z0 (float) – distance between chopper pair (m)

  • R (float) – radius of chopper discs (m)

  • freq (float) – rotation frequency of choppers (Hz)

  • N (float) – number of windows in chopper pair

  • H (float) – height of beam (m)

  • xsi (float) – phase opening of chopper pair (degrees)

  • L (float) – Flight length of instrument (m)

  • tau_da (float) – Width of timebin (s)

Returns

res – Fractional wavelength resolution of a double chopper system.

Return type

float

refnx.util.resolution_single_chopper(wavelength, R=0.35, freq=24, H=0.005, phi=60, L=7.5)[source]

Calculates the fractional resolution of a single chopper, dl/l.

Parameters
  • wavelength (float) – wavelength in Angstroms

  • R (float) – radius of chopper discs (m)

  • freq (float) – rotation frequency of choppers (Hz)

  • N (float) – number of windows in chopper

  • H (float) – height of beam (m)

  • phi (float) – angular opening of chopper window (degrees)

  • L (float) – Flight length of instrument (m)

Returns

transmission – Transmission of a single chopper system.

Return type

float

refnx.util.slit_optimiser(footprint, resolution, angle=1.0, L12=2859.5, L2S=180, LS3=290.5, LSD=2500, verbose=True)[source]

Optimise slit settings for a given angular resolution, and a given footprint.

footprint: float

maximum footprint onto sample (mm)

resolution: float

fractional dtheta/theta resolution (FWHM)

angle: float, optional

angle of incidence in degrees

refnx.util.tauC(wavelength, xsi=0, z0=0.358, freq=24)[source]

Calculates the burst time of a double chopper pair

Parameters
  • wavelength (float) – wavelength in Angstroms

  • z0 (float) – distance between chopper pair (m)

  • freq (float) – rotation frequency of choppers (Hz)

  • xsi (float) – phase opening of chopper pair (degrees)

Returns

tauC – The burst time of a double chopper pair (s)

Return type

float

References

[1] A. A. van Well and H. Fredrikze, On the resolution and intensity of a time-of-flight neutron reflectometer, Physica B 357 (2005) 204-207 [2] A. Nelson and C. Dewhurst, Towards a detailed resolution smearing kernel for time-of-flight neutron reflectometers, J. Appl. Cryst. (2013) 46, 1338-1343

refnx.util.transmission_double_chopper(wavelength, z0=0.358, R=0.35, freq=24, N=1, H=0.005, xsi=0)[source]

Calculates the transmission of a double chopper pair

Parameters
  • wavelength (float) – wavelength in Angstroms

  • z0 (float) – distance between chopper pair (m)

  • R (float) – radius of chopper discs (m)

  • freq (float) – rotation frequency of choppers (Hz)

  • N (float) – number of windows in chopper pair

  • H (float) – height of beam (m)

  • xsi (float) – phase opening of chopper pair (degrees)

Returns

transmission – The transmission of a double chopper system.

Return type

float

References

[1] A. A. van Well and H. Fredrikze, On the resolution and intensity of a time-of-flight neutron reflectometer, Physica B 357 (2005) 204-207 [2] A. Nelson and C. Dewhurst, Towards a detailed resolution smearing kernel for time-of-flight neutron reflectometers, J. Appl. Cryst. (2013) 46, 1338-1343

refnx.util.transmission_single_chopper(R=0.35, phi=60, N=1, H=0.005)[source]

Calculates the transmission of a single chopper

Parameters
  • R (float) – radius of chopper discs (m)

  • phi (float) – angular opening of chopper disc (degrees)

  • N (float) – number of windows in chopper pair

  • H (float) – height of beam (m)

References

[1] A. A. van Well and H. Fredrikze, On the resolution and intensity of a time-of-flight neutron reflectometer, Physica B 357 (2005) 204-207 [2] A. Nelson and C. Dewhurst, Towards a detailed resolution smearing kernel for time-of-flight neutron reflectometers, J. Appl. Cryst. (2013) 46, 1338-1343

refnx.util.velocity_wavelength(velocity)[source]

Converts neutron velocity to wavelength

Parameters

velocity (float) – velocity of neutron in m/s

Returns

wavelength – wavelength of neutron in A

Return type

float

refnx.util.wavelength(q, angle)[source]

calculate wavelength given Q vector and angle

Parameters
  • q (float) – Wavevector (A**-1)

  • angle (float) – angle of incidence (degrees)

Returns

wavelength – Wavelength of radiation (A)

Return type

float

refnx.util.wavelength_energy(wavelength)[source]

Converts wavelength to energy in meV

Parameters

wavelength (float) – Wavelength in Angstrom.

Returns

energy – Energy in meV.

Return type

float

refnx.util.wavelength_velocity(wavelength)[source]

Converts wavelength to neutron velocity

Parameters

wavelength (float) – wavelength of neutron in Angstrom.

Returns

velocity – velocity of neutron in ms**-1

Return type

float

refnx.util.xray_energy(wavelength)[source]

convert energy (keV) to wavelength (angstrom)

refnx.util.xray_wavelength(energy)[source]

convert energy (keV) to wavelength (angstrom)