# probe - Instrument probe¶

 NeutronProbe Neutron probe. PolarizedNeutronProbe Polarized neutron probe PolarizedNeutronQProbe alias of PolarizedQProbe PolarizedQProbe Probe Defines the incident beam used to study the material. ProbeSet QProbe A pure Q, R probe Qmeasurement_union Determine the unique Q, dQ across all datasets. XrayProbe X-Ray probe. load4 Load in four column data Q, R, dR, dQ. make_probe Return a reflectometry measurement object of the given resolution. measurement_union Determine the unique (T, dT, L, dL) across all datasets. spin_asymmetry Compute spin asymmetry for R++, R–.

Experimental probe.

The experimental probe describes the incoming beam for the experiment. Scattering properties of the sample are dependent on the type and energy of the radiation.

See Data Representation for details.

class refl1d.probe.NeutronProbe(T=None, dT=0, L=None, dL=0, data=None, intensity=1, background=0, back_absorption=1, theta_offset=0, back_reflectivity=False, name=None, filename=None)[source]

Neutron probe.

By providing a scattering factor calculator for X-ray scattering, model components can be defined by mass density and chemical composition.

Aguide = 270
Q
alignment_uncertainty(w, I, d=0)

Compute alignment uncertainty.

Parameters:

w : float | degrees
Rocking curve full width at half max.
I : float | counts
Rocking curve integrated intensity.
d = 0: float | degrees
Motor step size

Returns:

dtheta : float | degrees
uncertainty in alignment angle
apply_beam(calc_Q, calc_R, resolution=True, interpolation=0)

Apply factors such as beam intensity, background, backabsorption, resolution to the data.

calc_Q
critical_edge(substrate=None, surface=None, n=51, delta=0.25)

Oversample points near the critical edge.

The critical edge is defined by the difference in scattering potential for the substrate and surface materials, or the reverse if back_reflectivity is true.

n is the number of $$Q$$ points to compute near the critical edge.

delta is the relative uncertainty in the material density, which defines the range of values which are calculated.

The $$n$$ points $$Q_i$$ are evenly distributed around the critical edge in $$Q_c \pm \delta Q_c$$ by varying angle $$\theta$$ for a fixed wavelength $$< \lambda >$$, the average of all wavelengths in the probe.

Specifically:

$\begin{split}Q_c^2 &= 16 \pi (\rho - \rho_\text{incident}) \\ Q_i &= Q_c - \delta_i Q_c (i - (n-1)/2) \qquad \text{for} \; i \in 0 \ldots n-1 \\ \lambda_i &= < \lambda > \\ \theta_i &= \sin^{-1}(Q_i \lambda_i / 4 \pi)\end{split}$

If $$Q_c$$ is imaginary, then $$-|Q_c|$$ is used instead, so this routine can be used for reflectivity signals which scan from back reflectivity to front reflectivity. For completeness, the angle $$\theta = 0$$ is added as well.

fresnel(substrate=None, surface=None)

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

label(prefix=None, gloss='', suffix='')
log10_to_linear()

Convert data from log to linear.

Older reflectometry reduction code stored reflectivity in log base 10 format. Call probe.log10_to_linear() after loading this data to convert it to linear for subsequent display and fitting.

oversample(n=20, seed=1)

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()
plot(view=None, **kwargs)

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)

Plot the Q**4 reflectivity associated with the probe.

Note that Q**4 reflectivity has the intensity and background applied so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / ( (100*Q)^{-4} I + B) \Delta R' = \Delta R / ( (100*Q)^{-4} I + B )$

where $$B$$ is the background.

plot_fft(theory=None, suffix='', label=None, substrate=None, surface=None, **kwargs)

FFT analysis of reflectivity signal.

plot_fresnel(substrate=None, surface=None, **kwargs)

Plot the Fresnel-normalized reflectivity associated with the probe.

Note that the Fresnel reflectivity has the intensity and background applied before normalizing so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / (F(Q) I + B) \Delta R' = \Delta R / (F(Q) I + B)$

where $$I$$ is the intensity and $$B$$ is the background.

plot_linear(**kwargs)

Plot the data associated with probe.

plot_log(**kwargs)

Plot the data associated with probe.

plot_logfresnel(*args, **kw)

Plot the log Fresnel-normalized reflectivity associated with the probe.

plot_residuals(theory=None, suffix='', label=None, plot_shift=None, **kwargs)
plot_resolution(suffix='', label=None, **kwargs)
plot_shift = 0
polarized = False
radiation = 'neutron'
residuals_shift = 0
resolution_guard()

Make sure each measured $$Q$$ point has at least 5 calculated $$Q$$ points contributing to it in the range $$[-3\Delta Q, 3\Delta Q]$$.

Not Implemented

restore_data()

Restore the original data.

resynth_data()

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)

Save the data and theory to a file.

scattering_factors(material, density)[source]

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

simulate_data(theory, noise=None)

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

subsample(dQ)

Select points at most every dQ.

Use this to speed up computation early in the fitting process.

This changes the data object, and is not reversible.

The current algorithm is not picking the “best” Q value, just the nearest, so if you have nearby Q points with different quality statistics (as happens in overlapped regions from spallation source measurements at different angles), then it may choose badly. Simple solutions based on the smallest relative error dR/R will be biased toward peaks, and smallest absolute error dR will be biased toward valleys.

view = 'fresnel'
write_data(filename, columns=('Q', 'R', 'dR'), header=None)

Save the data to a file.

header is a string with trailing n containing the file header. columns is a list of column names from Q, dQ, R, dR, L, dL, T, dT.

The default is to write Q, R, dR data.

class refl1d.probe.PolarizedNeutronProbe(xs=None, name=None, Aguide=270, H=0)[source]

Bases: object

Polarized neutron probe

xs (4 x NeutronProbe) is a sequence pp, pm, mp and mm.

Aguide (degrees) is the angle of the applied field relative to the plane of the sample, with angle 270º in the plane of the sample.

H (tesla) is the magnitude of the applied field

apply_beam(Q, R, resolution=True, interpolation=0)[source]

Apply factors such as beam intensity, background, backabsorption, and footprint to the data.

calc_Q
fresnel(*args, **kw)[source]

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

mm
mp
oversample(n=6, seed=1)[source]

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()[source]
plot(view=None, **kwargs)[source]

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)[source]
plot_SA(theory=None, label=None, plot_shift=None, **kwargs)[source]
plot_fresnel(**kwargs)[source]
plot_linear(**kwargs)[source]
plot_log(**kwargs)[source]
plot_logfresnel(**kwargs)[source]
plot_residuals(**kwargs)[source]
plot_resolution(**kwargs)[source]
pm
polarized = True
pp
restore_data()[source]

Restore the original data.

resynth_data()[source]

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)[source]

Save the data and theory to a file.

scattering_factors(material, density)[source]

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

select_corresponding(theory)[source]

Select theory points corresponding to the measured data.

Since we have evaluated theory at every Q, it is safe to interpolate measured Q into theory, since it will land on a node, not in an interval.

shared_beam(intensity=1, background=0, back_absorption=1, theta_offset=0)[source]

Share beam parameters across all four cross sections.

New parameters are created for intensity, background, theta_offset and back_absorption and assigned to the all cross sections. These can be replaced in an individual cross section if for some reason one of the parameters is independent.

simulate_data(theory, noise=2)[source]

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

substrate = None
surface = None
view = None
xs
refl1d.probe.PolarizedNeutronQProbe

alias of PolarizedQProbe

class refl1d.probe.PolarizedQProbe(xs=None, name=None, Aguide=270, H=0)[source]
apply_beam(Q, R, resolution=True, interpolation=0)

Apply factors such as beam intensity, background, backabsorption, and footprint to the data.

calc_Q
fresnel(*args, **kw)

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

mm
mp
oversample(n=6, seed=1)

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()
plot(view=None, **kwargs)

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)
plot_SA(theory=None, label=None, plot_shift=None, **kwargs)
plot_fresnel(**kwargs)
plot_linear(**kwargs)
plot_log(**kwargs)
plot_logfresnel(**kwargs)
plot_residuals(**kwargs)
plot_resolution(**kwargs)
pm
polarized = True
pp
restore_data()

Restore the original data.

resynth_data()

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)

Save the data and theory to a file.

scattering_factors(material, density)

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

select_corresponding(theory)

Select theory points corresponding to the measured data.

Since we have evaluated theory at every Q, it is safe to interpolate measured Q into theory, since it will land on a node, not in an interval.

shared_beam(intensity=1, background=0, back_absorption=1, theta_offset=0)

Share beam parameters across all four cross sections.

New parameters are created for intensity, background, theta_offset and back_absorption and assigned to the all cross sections. These can be replaced in an individual cross section if for some reason one of the parameters is independent.

simulate_data(theory, noise=2)

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

substrate = None
surface = None
view = None
xs
class refl1d.probe.Probe(T=None, dT=0, L=None, dL=0, data=None, intensity=1, background=0, back_absorption=1, theta_offset=0, back_reflectivity=False, name=None, filename=None)[source]

Bases: object

Defines the incident beam used to study the material.

For calculation purposes, probe needs to return the values $$Q_\text{calc}$$ at which the model is evaluated. This is normally going to be the measured points only, but for some systems, such as those with very thick layers, oversampling is needed to avoid aliasing effects.

A measurement point consists of incident angle, angular resolution, incident wavelength, FWHM wavelength resolution, reflectivity and uncertainty in reflectivity.

A probe is a set of points, defined by vectors for point attribute. For convenience, the attribute can be initialized with a scalar if it is constant throughout the measurement, but will be set to a vector in the probe. The attributes are initialized as follows:

T : float or [float] | degrees
Incident angle
dT : float or [float] | degrees
FWHM angular resolution
L : float or [float] | Å
Incident wavelength
dL : float or [float] | Å
FWHM wavelength dispersion
data : ([float], [float])
R, dR reflectivity measurement and uncertainty

Measurement properties:

intensity : float or Parameter
Beam intensity
background : float or Parameter
Constant background
back_absorption : float or Parameter
Absorption through the substrate relative to beam intensity. A value of 1.0 means complete transmission; a value of 0.0 means complete absorption.
theta_offset : float or Parameter
Offset of the sample from perfect alignment
back_reflectivity : True or False
True if the beam enters through the substrate

Measurement properties are fittable parameters. theta_offset in particular should be set using probe.theta_offset.dev(dT), with dT equal to the FWHM uncertainty in the peak position for the rocking curve, as measured in radians. Changes to theta_offset will then be penalized in the cost function for the fit as if it were another measurement. Use alignment_uncertainty() to compute dT from the shape of the rocking curve.

intensity and back_absorption are generally not needed — scaling the reflected signal by an appropriate intensity measurement will correct for both of these during reduction. background may be needed, particularly for samples with significant hydrogen content due to its large isotropic incoherent scattering cross section.

View properties:

view : string
One of ‘fresnel’, ‘logfresnel’, ‘log’, ‘linear’, ‘q4’, ‘residuals’
plot_shift : float
The number of pixels to shift each new dataset so datasets can be seen separately
residuals_shift :
The number of pixels to shift each new set of residuals so the residuals plots can be seen separately.

Normally view is set directly in the class rather than the instance since it is not specific to the view. Fresnel and Q4 views are corrected for background and intensity; log and linear views show the uncorrected data.

Aguide = 270
Q
static alignment_uncertainty(w, I, d=0)[source]

Compute alignment uncertainty.

Parameters:

w : float | degrees
Rocking curve full width at half max.
I : float | counts
Rocking curve integrated intensity.
d = 0: float | degrees
Motor step size

Returns:

dtheta : float | degrees
uncertainty in alignment angle
apply_beam(calc_Q, calc_R, resolution=True, interpolation=0)[source]

Apply factors such as beam intensity, background, backabsorption, resolution to the data.

calc_Q
critical_edge(substrate=None, surface=None, n=51, delta=0.25)[source]

Oversample points near the critical edge.

The critical edge is defined by the difference in scattering potential for the substrate and surface materials, or the reverse if back_reflectivity is true.

n is the number of $$Q$$ points to compute near the critical edge.

delta is the relative uncertainty in the material density, which defines the range of values which are calculated.

The $$n$$ points $$Q_i$$ are evenly distributed around the critical edge in $$Q_c \pm \delta Q_c$$ by varying angle $$\theta$$ for a fixed wavelength $$< \lambda >$$, the average of all wavelengths in the probe.

Specifically:

$\begin{split}Q_c^2 &= 16 \pi (\rho - \rho_\text{incident}) \\ Q_i &= Q_c - \delta_i Q_c (i - (n-1)/2) \qquad \text{for} \; i \in 0 \ldots n-1 \\ \lambda_i &= < \lambda > \\ \theta_i &= \sin^{-1}(Q_i \lambda_i / 4 \pi)\end{split}$

If $$Q_c$$ is imaginary, then $$-|Q_c|$$ is used instead, so this routine can be used for reflectivity signals which scan from back reflectivity to front reflectivity. For completeness, the angle $$\theta = 0$$ is added as well.

fresnel(substrate=None, surface=None)[source]

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

label(prefix=None, gloss='', suffix='')[source]
log10_to_linear()[source]

Convert data from log to linear.

Older reflectometry reduction code stored reflectivity in log base 10 format. Call probe.log10_to_linear() after loading this data to convert it to linear for subsequent display and fitting.

oversample(n=20, seed=1)[source]

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()[source]
plot(view=None, **kwargs)[source]

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)[source]

Plot the Q**4 reflectivity associated with the probe.

Note that Q**4 reflectivity has the intensity and background applied so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / ( (100*Q)^{-4} I + B) \Delta R' = \Delta R / ( (100*Q)^{-4} I + B )$

where $$B$$ is the background.

plot_fft(theory=None, suffix='', label=None, substrate=None, surface=None, **kwargs)[source]

FFT analysis of reflectivity signal.

plot_fresnel(substrate=None, surface=None, **kwargs)[source]

Plot the Fresnel-normalized reflectivity associated with the probe.

Note that the Fresnel reflectivity has the intensity and background applied before normalizing so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / (F(Q) I + B) \Delta R' = \Delta R / (F(Q) I + B)$

where $$I$$ is the intensity and $$B$$ is the background.

plot_linear(**kwargs)[source]

Plot the data associated with probe.

plot_log(**kwargs)[source]

Plot the data associated with probe.

plot_logfresnel(*args, **kw)[source]

Plot the log Fresnel-normalized reflectivity associated with the probe.

plot_residuals(theory=None, suffix='', label=None, plot_shift=None, **kwargs)[source]
plot_resolution(suffix='', label=None, **kwargs)[source]
plot_shift = 0
polarized = False
residuals_shift = 0
resolution_guard()[source]

Make sure each measured $$Q$$ point has at least 5 calculated $$Q$$ points contributing to it in the range $$[-3\Delta Q, 3\Delta Q]$$.

Not Implemented

restore_data()[source]

Restore the original data.

resynth_data()[source]

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)[source]

Save the data and theory to a file.

scattering_factors(material, density)[source]

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

simulate_data(theory, noise=None)[source]

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

subsample(dQ)[source]

Select points at most every dQ.

Use this to speed up computation early in the fitting process.

This changes the data object, and is not reversible.

The current algorithm is not picking the “best” Q value, just the nearest, so if you have nearby Q points with different quality statistics (as happens in overlapped regions from spallation source measurements at different angles), then it may choose badly. Simple solutions based on the smallest relative error dR/R will be biased toward peaks, and smallest absolute error dR will be biased toward valleys.

view = 'fresnel'
write_data(filename, columns=('Q', 'R', 'dR'), header=None)[source]

Save the data to a file.

header is a string with trailing n containing the file header. columns is a list of column names from Q, dQ, R, dR, L, dL, T, dT.

The default is to write Q, R, dR data.

class refl1d.probe.ProbeSet(probes, name=None)[source]
Aguide = 270
Q
alignment_uncertainty(w, I, d=0)

Compute alignment uncertainty.

Parameters:

w : float | degrees
Rocking curve full width at half max.
I : float | counts
Rocking curve integrated intensity.
d = 0: float | degrees
Motor step size

Returns:

dtheta : float | degrees
uncertainty in alignment angle
apply_beam(calc_Q, calc_R, interpolation=0, **kw)[source]
calc_Q
critical_edge(substrate=None, surface=None, n=51, delta=0.25)

Oversample points near the critical edge.

The critical edge is defined by the difference in scattering potential for the substrate and surface materials, or the reverse if back_reflectivity is true.

n is the number of $$Q$$ points to compute near the critical edge.

delta is the relative uncertainty in the material density, which defines the range of values which are calculated.

The $$n$$ points $$Q_i$$ are evenly distributed around the critical edge in $$Q_c \pm \delta Q_c$$ by varying angle $$\theta$$ for a fixed wavelength $$< \lambda >$$, the average of all wavelengths in the probe.

Specifically:

$\begin{split}Q_c^2 &= 16 \pi (\rho - \rho_\text{incident}) \\ Q_i &= Q_c - \delta_i Q_c (i - (n-1)/2) \qquad \text{for} \; i \in 0 \ldots n-1 \\ \lambda_i &= < \lambda > \\ \theta_i &= \sin^{-1}(Q_i \lambda_i / 4 \pi)\end{split}$

If $$Q_c$$ is imaginary, then $$-|Q_c|$$ is used instead, so this routine can be used for reflectivity signals which scan from back reflectivity to front reflectivity. For completeness, the angle $$\theta = 0$$ is added as well.

fresnel(*args, **kw)[source]

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

label(prefix=None, gloss='', suffix='')
log10_to_linear()

Convert data from log to linear.

Older reflectometry reduction code stored reflectivity in log base 10 format. Call probe.log10_to_linear() after loading this data to convert it to linear for subsequent display and fitting.

oversample(**kw)[source]

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()[source]
parts(theory)[source]
plot(theory=None, **kw)[source]

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(theory=None, **kw)[source]

Plot the Q**4 reflectivity associated with the probe.

Note that Q**4 reflectivity has the intensity and background applied so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / ( (100*Q)^{-4} I + B) \Delta R' = \Delta R / ( (100*Q)^{-4} I + B )$

where $$B$$ is the background.

plot_fft(theory=None, suffix='', label=None, substrate=None, surface=None, **kwargs)

FFT analysis of reflectivity signal.

plot_fresnel(theory=None, **kw)[source]

Plot the Fresnel-normalized reflectivity associated with the probe.

Note that the Fresnel reflectivity has the intensity and background applied before normalizing so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / (F(Q) I + B) \Delta R' = \Delta R / (F(Q) I + B)$

where $$I$$ is the intensity and $$B$$ is the background.

plot_linear(theory=None, **kw)[source]

Plot the data associated with probe.

plot_log(theory=None, **kw)[source]

Plot the data associated with probe.

plot_logfresnel(theory=None, **kw)[source]

Plot the log Fresnel-normalized reflectivity associated with the probe.

plot_residuals(theory=None, **kw)[source]
plot_resolution(**kw)[source]
plot_shift = 0
polarized = False
residuals_shift = 0
resolution_guard()

Make sure each measured $$Q$$ point has at least 5 calculated $$Q$$ points contributing to it in the range $$[-3\Delta Q, 3\Delta Q]$$.

Not Implemented

restore_data()[source]

Restore the original data.

resynth_data()[source]

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)[source]

Save the data and theory to a file.

scattering_factors(material, density)[source]

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

shared_beam(intensity=1, background=0, back_absorption=1, theta_offset=0)[source]

Share beam parameters across all segments.

New parameters are created for intensity, background, theta_offset and back_absorption and assigned to the all segments. These can be replaced in an individual segment if that parameter is independent.

simulate_data(theory, noise=2)[source]

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

stitch(same_Q=0.001, same_dQ=0.001)[source]

Stitch together multiple datasets into a single dataset.

Points within tol of each other and with the same resolution are combined by interpolating them to a common $$Q$$ value then averaged using Gaussian error propagation.

Returns: probe | Probe Combined data set.

To interpolate a set of points to a common value, first find the common $$Q$$ value:

$\hat Q = \sum{Q_k} / n$

Then for each dataset $$k$$, find the interval $$[i, i+1]$$ containing the value $$Q$$, and use it to compute interpolated value for $$R$$:

$\begin{split}w &= (\hat Q - Q_i)/(Q_{i+1} - Q_i) \\ \hat R &= w R_{i+1} + (1-w) R_{i+1} \\ \hat \sigma_{R} &= \sqrt{ w^2 \sigma^2_{R_i} + (1-w)^2 \sigma^2_{R_{i+1}} } / n\end{split}$

Average the resulting $$R$$ using Gaussian error propagation:

$\begin{split}\hat R &= \sum{\hat R_k}/n \\ \hat \sigma_R &= \sqrt{\sum \hat \sigma_{R_k}^2}/n\end{split}$
subsample(dQ)

Select points at most every dQ.

Use this to speed up computation early in the fitting process.

This changes the data object, and is not reversible.

The current algorithm is not picking the “best” Q value, just the nearest, so if you have nearby Q points with different quality statistics (as happens in overlapped regions from spallation source measurements at different angles), then it may choose badly. Simple solutions based on the smallest relative error dR/R will be biased toward peaks, and smallest absolute error dR will be biased toward valleys.

unique_L
view = 'fresnel'
write_data(filename, columns=('Q', 'R', 'dR'), header=None)

Save the data to a file.

header is a string with trailing n containing the file header. columns is a list of column names from Q, dQ, R, dR, L, dL, T, dT.

The default is to write Q, R, dR data.

class refl1d.probe.QProbe(Q, dQ, data=None, name=None, filename=None, intensity=1, background=0, back_absorption=1, back_reflectivity=False)[source]

A pure Q, R probe

This probe with no possibility of tricks such as looking up the scattering length density based on wavelength, or adjusting for alignment errors.

Aguide = 270
Q
alignment_uncertainty(w, I, d=0)

Compute alignment uncertainty.

Parameters:

w : float | degrees
Rocking curve full width at half max.
I : float | counts
Rocking curve integrated intensity.
d = 0: float | degrees
Motor step size

Returns:

dtheta : float | degrees
uncertainty in alignment angle
apply_beam(calc_Q, calc_R, resolution=True, interpolation=0)

Apply factors such as beam intensity, background, backabsorption, resolution to the data.

calc_Q
critical_edge(substrate=None, surface=None, n=51, delta=0.25)

Oversample points near the critical edge.

The critical edge is defined by the difference in scattering potential for the substrate and surface materials, or the reverse if back_reflectivity is true.

n is the number of $$Q$$ points to compute near the critical edge.

delta is the relative uncertainty in the material density, which defines the range of values which are calculated.

The $$n$$ points $$Q_i$$ are evenly distributed around the critical edge in $$Q_c \pm \delta Q_c$$ by varying angle $$\theta$$ for a fixed wavelength $$< \lambda >$$, the average of all wavelengths in the probe.

Specifically:

$\begin{split}Q_c^2 &= 16 \pi (\rho - \rho_\text{incident}) \\ Q_i &= Q_c - \delta_i Q_c (i - (n-1)/2) \qquad \text{for} \; i \in 0 \ldots n-1 \\ \lambda_i &= < \lambda > \\ \theta_i &= \sin^{-1}(Q_i \lambda_i / 4 \pi)\end{split}$

If $$Q_c$$ is imaginary, then $$-|Q_c|$$ is used instead, so this routine can be used for reflectivity signals which scan from back reflectivity to front reflectivity. For completeness, the angle $$\theta = 0$$ is added as well.

fresnel(substrate=None, surface=None)

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

label(prefix=None, gloss='', suffix='')
log10_to_linear()

Convert data from log to linear.

Older reflectometry reduction code stored reflectivity in log base 10 format. Call probe.log10_to_linear() after loading this data to convert it to linear for subsequent display and fitting.

oversample(n=20, seed=1)

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()
plot(view=None, **kwargs)

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)

Plot the Q**4 reflectivity associated with the probe.

Note that Q**4 reflectivity has the intensity and background applied so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / ( (100*Q)^{-4} I + B) \Delta R' = \Delta R / ( (100*Q)^{-4} I + B )$

where $$B$$ is the background.

plot_fft(theory=None, suffix='', label=None, substrate=None, surface=None, **kwargs)

FFT analysis of reflectivity signal.

plot_fresnel(substrate=None, surface=None, **kwargs)

Plot the Fresnel-normalized reflectivity associated with the probe.

Note that the Fresnel reflectivity has the intensity and background applied before normalizing so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / (F(Q) I + B) \Delta R' = \Delta R / (F(Q) I + B)$

where $$I$$ is the intensity and $$B$$ is the background.

plot_linear(**kwargs)

Plot the data associated with probe.

plot_log(**kwargs)

Plot the data associated with probe.

plot_logfresnel(*args, **kw)

Plot the log Fresnel-normalized reflectivity associated with the probe.

plot_residuals(theory=None, suffix='', label=None, plot_shift=None, **kwargs)
plot_resolution(suffix='', label=None, **kwargs)
plot_shift = 0
polarized = False
residuals_shift = 0
resolution_guard()

Make sure each measured $$Q$$ point has at least 5 calculated $$Q$$ points contributing to it in the range $$[-3\Delta Q, 3\Delta Q]$$.

Not Implemented

restore_data()

Restore the original data.

resynth_data()

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)

Save the data and theory to a file.

scattering_factors(material, density)

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

simulate_data(theory, noise=None)

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

subsample(dQ)

Select points at most every dQ.

Use this to speed up computation early in the fitting process.

This changes the data object, and is not reversible.

The current algorithm is not picking the “best” Q value, just the nearest, so if you have nearby Q points with different quality statistics (as happens in overlapped regions from spallation source measurements at different angles), then it may choose badly. Simple solutions based on the smallest relative error dR/R will be biased toward peaks, and smallest absolute error dR will be biased toward valleys.

view = 'fresnel'
write_data(filename, columns=('Q', 'R', 'dR'), header=None)

Save the data to a file.

header is a string with trailing n containing the file header. columns is a list of column names from Q, dQ, R, dR, L, dL, T, dT.

The default is to write Q, R, dR data.

refl1d.probe.Qmeasurement_union(xs)[source]

Determine the unique Q, dQ across all datasets.

class refl1d.probe.XrayProbe(T=None, dT=0, L=None, dL=0, data=None, intensity=1, background=0, back_absorption=1, theta_offset=0, back_reflectivity=False, name=None, filename=None)[source]

X-Ray probe.

By providing a scattering factor calculator for X-ray scattering, model components can be defined by mass density and chemical composition.

Aguide = 270
Q
alignment_uncertainty(w, I, d=0)

Compute alignment uncertainty.

Parameters:

w : float | degrees
Rocking curve full width at half max.
I : float | counts
Rocking curve integrated intensity.
d = 0: float | degrees
Motor step size

Returns:

dtheta : float | degrees
uncertainty in alignment angle
apply_beam(calc_Q, calc_R, resolution=True, interpolation=0)

Apply factors such as beam intensity, background, backabsorption, resolution to the data.

calc_Q
critical_edge(substrate=None, surface=None, n=51, delta=0.25)

Oversample points near the critical edge.

The critical edge is defined by the difference in scattering potential for the substrate and surface materials, or the reverse if back_reflectivity is true.

n is the number of $$Q$$ points to compute near the critical edge.

delta is the relative uncertainty in the material density, which defines the range of values which are calculated.

The $$n$$ points $$Q_i$$ are evenly distributed around the critical edge in $$Q_c \pm \delta Q_c$$ by varying angle $$\theta$$ for a fixed wavelength $$< \lambda >$$, the average of all wavelengths in the probe.

Specifically:

$\begin{split}Q_c^2 &= 16 \pi (\rho - \rho_\text{incident}) \\ Q_i &= Q_c - \delta_i Q_c (i - (n-1)/2) \qquad \text{for} \; i \in 0 \ldots n-1 \\ \lambda_i &= < \lambda > \\ \theta_i &= \sin^{-1}(Q_i \lambda_i / 4 \pi)\end{split}$

If $$Q_c$$ is imaginary, then $$-|Q_c|$$ is used instead, so this routine can be used for reflectivity signals which scan from back reflectivity to front reflectivity. For completeness, the angle $$\theta = 0$$ is added as well.

fresnel(substrate=None, surface=None)

Returns a Fresnel reflectivity calculator given the surface and and substrate. The calculated reflectivity includes The Fresnel reflectivity for the probe reflecting from a block of material with the given substrate.

Returns F = R(probe.Q), where R is magnitude squared reflectivity.

label(prefix=None, gloss='', suffix='')
log10_to_linear()

Convert data from log to linear.

Older reflectometry reduction code stored reflectivity in log base 10 format. Call probe.log10_to_linear() after loading this data to convert it to linear for subsequent display and fitting.

oversample(n=20, seed=1)

Generate an over-sampling of Q to avoid aliasing effects.

Oversampling is needed for thick layers, in which the underlying reflectivity oscillates so rapidly in Q that a single measurement has contributions from multiple Kissig fringes.

Sampling will be done using a pseudo-random generator so that accidental structure in the function does not contribute to the aliasing. The generator will usually be initialized with a fixed seed so that the point selection will not change from run to run, but a seed of None will choose a different set of points each time oversample is called.

The value n is the number of points that should contribute to each Q value when computing the resolution. These will be distributed about the nominal measurement value, but varying in both angle and energy according to the resolution function. This will yield more points near the measurement and fewer farther away. The measurement point itself will not be used to avoid accidental bias from uniform Q steps. Depending on the problem, a value of n between 20 and 100 should lead to stable values for the convolved reflectivity.

parameters()
plot(view=None, **kwargs)

Plot theory against data.

Need substrate/surface for Fresnel-normalized reflectivity

plot_Q4(**kwargs)

Plot the Q**4 reflectivity associated with the probe.

Note that Q**4 reflectivity has the intensity and background applied so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / ( (100*Q)^{-4} I + B) \Delta R' = \Delta R / ( (100*Q)^{-4} I + B )$

where $$B$$ is the background.

plot_fft(theory=None, suffix='', label=None, substrate=None, surface=None, **kwargs)

FFT analysis of reflectivity signal.

plot_fresnel(substrate=None, surface=None, **kwargs)

Plot the Fresnel-normalized reflectivity associated with the probe.

Note that the Fresnel reflectivity has the intensity and background applied before normalizing so that hydrogenated samples display more cleanly. The formula to reproduce the graph is:

$R' = R / (F(Q) I + B) \Delta R' = \Delta R / (F(Q) I + B)$

where $$I$$ is the intensity and $$B$$ is the background.

plot_linear(**kwargs)

Plot the data associated with probe.

plot_log(**kwargs)

Plot the data associated with probe.

plot_logfresnel(*args, **kw)

Plot the log Fresnel-normalized reflectivity associated with the probe.

plot_residuals(theory=None, suffix='', label=None, plot_shift=None, **kwargs)
plot_resolution(suffix='', label=None, **kwargs)
plot_shift = 0
polarized = False
radiation = 'xray'
residuals_shift = 0
resolution_guard()

Make sure each measured $$Q$$ point has at least 5 calculated $$Q$$ points contributing to it in the range $$[-3\Delta Q, 3\Delta Q]$$.

Not Implemented

restore_data()

Restore the original data.

resynth_data()

Generate new data according to the model R ~ N(Ro, dR).

The resynthesis step is a precursor to refitting the data, as is required for certain types of monte carlo error analysis.

save(filename, theory, substrate=None, surface=None)

Save the data and theory to a file.

scattering_factors(material, density)[source]

Returns the scattering factors associated with the material given the range of wavelengths/energies used in the probe.

simulate_data(theory, noise=None)

Set the data for the probe to R, adding random noise dR.

If noise is None, then use the uncertainty in the probe.

As a hack, if noise<0, use the probe uncertainty but don’t add noise to the data. Don’t depend on this behavior.

subsample(dQ)

Select points at most every dQ.

Use this to speed up computation early in the fitting process.

This changes the data object, and is not reversible.

The current algorithm is not picking the “best” Q value, just the nearest, so if you have nearby Q points with different quality statistics (as happens in overlapped regions from spallation source measurements at different angles), then it may choose badly. Simple solutions based on the smallest relative error dR/R will be biased toward peaks, and smallest absolute error dR will be biased toward valleys.

view = 'fresnel'
write_data(filename, columns=('Q', 'R', 'dR'), header=None)

Save the data to a file.

header is a string with trailing n containing the file header. columns is a list of column names from Q, dQ, R, dR, L, dL, T, dT.

The default is to write Q, R, dR data.

refl1d.probe.load4(filename, keysep=':', sep=None, comment='#', name=None, intensity=1, background=0, back_absorption=1, back_reflectivity=False, Aguide=270, H=0, theta_offset=0, sample_broadening=0, L=None, dL=None, T=None, dT=None, FWHM=False, radiation=None)[source]

Load in four column data Q, R, dR, dQ.

The file is loaded with bumps.data.parse_multi. keysep defaults to ‘:’ so that header data looks like JSON key: value pairs. sep is None so that the data uses white-space separated columns. comment is the standard ‘#’ comment character, used for “# key: value” lines, for commenting out data lines using “#number number number number”, and for adding comments after individual data lines. The parser isn’t very sophisticated, so be nice.

intensity is the overall beam intensity, background is the overall background level, and back_absorption is the relative intensity of data measured at negative Q compared to positive Q data. These can be values or a bumps Parameter objects.

back_reflectivity is True if reflectivity was measured through the substrate. This allows you to arrange the model from substrate to surface regardless of whether you are measuring through the substrate or reflecting off the surface.

theta_offset indicates sample alignment. In order to use theta offset you need to be able to convert from Q to wavelength and angle by providing values for the wavelength or the angle, and the associated resolution.

For monochromatic sources you can supply L, dLoL when you call load4, or you can store it in the header of the file:

# wavelength: 4.75  # Ang
# wavelength_resolution: 0.02  # Ang (1-sigma)


For time of flight sources, angle is fixed and wavelength is varying, so you can supply T, dT in degrees when you call load4, or you can store it in the header of the file:

# angle: 2  # degrees
# angular_resolution: 0.2  # degrees (1-sigma)


If both angle and wavelength are varying in the data, you can specify a separate value for each point, such the following:

# wavelength: [1, 1.2, 1.5, 2.0, ...]
# wavelength_resolution: [0.02, 0.02, 0.02, ...]


sample_broadening in degrees (1-$$\sigma$$) adds to the angular_resolution.

Aguide and H are parameters for polarized beam measurements indicating the magnitude and direction of the applied field.

Polarized data is represented using a multi-section data file, with blank lines separating each section. Each section must have a polarization keyword, with value “++”, “+-”, “-+” or “–”.

FWHM is True if dQ, dT, dL are given as FWHM rather than 1-$$\sigma$$. dR is always 1-$$\sigma$$.

radiation is ‘xray’ or ‘neutron’, depending on whether X-ray or neutron scattering length density calculator should be used for determining the scattering length density of a material.

refl1d.probe.make_probe(**kw)[source]

Return a reflectometry measurement object of the given resolution.

refl1d.probe.measurement_union(xs)[source]

Determine the unique (T, dT, L, dL) across all datasets.

refl1d.probe.spin_asymmetry(Qp, Rp, dRp, Qm, Rm, dRm)[source]

Compute spin asymmetry for R++, R–.

Parameters:

Qp, Rp, dRp : vector
Measured ++ cross section and uncertainty.
Qm, Rm, dRm : vector
Measured – cross section and uncertainty.

If dRp, dRm are None then the returned uncertainty will also be None.

Returns:

Q, SA, dSA : vector
Computed spin asymmetry and uncertainty.

Algorithm:

Spin asymmetry, $$S_A$$, is:

$S_A = \frac{R_{++} - R_{--}}{R_{++} + R_{--}}$

Uncertainty $$\Delta S_A$$ follows from propagation of error:

$\Delta S_A^2 = \frac{4(R_{++}^2\Delta R_{--}^2+R_{--}^2\Delta R_{++})} {(R_{++} + R_{--})^4}$