ncnrdata - NCNR Data

ANDR Instrument definition for NCNR AND/R diffractometer/reflectometer.
MAGIK Instrument definition for NCNR MAGIK diffractometer/reflectometer.
NCNRData
NG1 Instrument definition for NCNR NG-1 reflectometer.
NG7 Instrument definition for NCNR NG-7 reflectometer.
PBR Instrument definition for NCNR PBR reflectometer.
XRay Instrument definition for NCNR X-ray reflectometer.
find_xsec Find files containing the polarization cross-sections.
load Return a probe for NCNR data.
load_magnetic Return a probe for magnetic NCNR data.
parse_ncnr_file Parse NCNR reduced data file returning header and data.

NCNR data loaders

The following instruments are defined:

MAGIK, PBR, ANDR, NG1, NG7 and XRay

These are refl1d.instrument.Monochromatic classes tuned with default instrument parameters and loaders for reduced NCNR data.

The instruments can be used to load data or to compute resolution functions for the purposes.

Example loading data:

>>> from refl1d.names import *
>>> datafile = sample_data('chale207.refl')
>>> instrument = NCNR.ANDR(Tlo=0.5, slits_at_Tlo=0.2, slits_below=0.1)
>>> probe = instrument.load(datafile)
>>> probe.plot(view='log')

Magnetic data has multiple cross sections and often has fixed slits:

>>> datafile = sample_data('lha03_255G.refl')
>>> instrument = NCNR.NG1(slits_at_Tlo=1)
>>> probe = instrument.load_magnetic(datafile)
>>> probe.plot(view='SA', substrate=silicon) # Spin asymmetry view

For simulation, you need a probe and a sample:

>>> instrument = NCNR.ANDR(Tlo=0.5, slits_at_Tlo=0.2, slits_below=0.1)
>>> probe = instrument.probe(T=numpy.linspace(0,5,51))
>>> probe.plot_resolution()
>>> sample = silicon(0,10) | gold(100,10) | air
>>> M = Experiment(probe=probe, sample=sample)
>>> M.simulate_data() # Optional
>>> M.plot()

And for magnetic:

>>> instrument = NCNR.NG1(slits_at_Tlo=1)
>>> #sample = silicon(0,10) | Magnetic(permalloy(100,10),rho_M=3) | air
>>> #M = Experiment(probe=probe, sample=sample)
>>> #M.simulate_data()
>>> #M.plot()
>>> #probe = instrument.simulate_magnetic(sample, T=numpy.linspace(0,5,51))
>>> #h = pylab.plot(probe.Q, probe.dQ)
>>> #h = pylab.ylabel('resolution (1-sigma)')
>>> #h = pylab.xlabel('Q (inv A)')

See instrument for details.

class refl1d.ncnrdata.ANDR(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR AND/R diffractometer/reflectometer.

Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.009
d_s1 = 2086.0
d_s2 = 230.0
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'AND/R'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'neutron'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 5.0042
class refl1d.ncnrdata.MAGIK(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR MAGIK diffractometer/reflectometer.

Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.009
d_s1 = 1759.0
d_s2 = 330.0
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'MAGIK'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'neutron'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 5.0042
class refl1d.ncnrdata.NCNRData[source]

Bases: object

load(filename, **kw)[source]
load_magnetic(filename, **kw)[source]
readfile(filename)[source]
class refl1d.ncnrdata.NG1(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR NG-1 reflectometer.

Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.015
d_s1 = 1905.0
d_s2 = 355.59999999999997
d_s3 = 228.6
d_s4 = 1066.8
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'NG-1'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'neutron'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 4.75
class refl1d.ncnrdata.NG7(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR NG-7 reflectometer.

Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.025
d_detector = 2000.0
d_s1 = 1625.0
d_s2 = 275.0
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'NG-7'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'neutron'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 4.768
class refl1d.ncnrdata.PBR(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR PBR reflectometer.

Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.015
d_s1 = 1835
d_s2 = 343
d_s3 = 380
d_s4 = 1015
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'PBR'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'neutron'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 4.75
class refl1d.ncnrdata.XRay(**kw)[source]

Bases: refl1d.ncnrdata.NCNRData, refl1d.instrument.Monochromatic

Instrument definition for NCNR X-ray reflectometer.

Normal dT is in the range 2e-5 to 3e-4.

Slits are fixed throughout the experiment in one of a few preconfigured openings. Please update this file with the standard configurations when you find them.

You can choose to ignore the geometric calculation entirely by setting the slit opening to 0 and using sample_broadening to define the entire divergence:

>>> from refl1d.names import *
>>> file = sample_data("spin_valve01.refl")
>>> xray = NCNR.XRay(slits_at_Tlo=0)
>>> data = xray.load(file, sample_broadening=1e-4)
>>> print(data.dT[5])
0.0001
Thi = 90
Tlo = 90
calc_dT(**kw)

Compute the angular divergence for given slits and angles

Parameters:
T OR Q : [float] | ° OR Å-1

measurement angles

slits : float OR (float,float) | mm

total slit opening from edge to edge, not beam center to edge

d_s1, d_s2 : float | mm

distance from sample to slit 1 and slit 2

sample_width : float | mm

size of sample

sample_broadening : float | ° FWHM

resolution changes from sample warp

Returns:
dT : [float] | ° FWHM

angular divergence

sample_broadening can be estimated from W, the full width at half maximum of a rocking curve measured in degrees:

sample_broadening = W - degrees( 0.5*(s1+s2) / (d1-d2))
calc_slits(**kw)

Determines slit openings from measurement pattern.

If slits are fixed simply return the same slits for every angle, otherwise use an opening range [Tlo,Thi] and the value of the slits at the start of the opening to define the slits. Slits below Tlo and above Thi can be specified separately.

T OR Q incident angle or Q Tlo, Thi angle range over which slits are opening slits_at_Tlo openings at the start of the range, or fixed opening slits_below, slits_above openings below and above the range

Use fixed_slits is available, otherwise use opening slits.

dLoL = 0.0006486766995329528
d_detector = None
d_s1 = 275.5
d_s2 = 192.5
d_s3 = 175.0
defaults()

Return default instrument properties as a printable string.

fixed_slits = None
instrument = 'X-ray'
load(filename, **kw)
load_magnetic(filename, **kw)
magnetic_probe(Aguide=270, shared_beam=True, H=0, **kw)

Simulate a polarized measurement probe.

Returns a probe with Q, angle, wavelength and the associated uncertainties, but not any data.

Guide field angle Aguide can be specified, as well as keyword arguments for the geometry of the probe cross sections such as slits_at_Tlo, Tlo, Thi, slits_below, and slits_above to define the angular divergence.

probe(**kw)

Return a probe for use in simulation.

Parameters:
Q : [float] | Å

Q values to be measured.

T : [float] | °

Angles to be measured.

Additional keyword parameters

Returns:
probe : Probe

Measurement probe with complete resolution information. The probe will not have any data.

If both Q and T are specified then Q takes precedents.

You can override instrument parameters using key=value. In particular, settings for slits_at_Tlo, Tlo, Thi, slits_below, and slits_above are used to define the angular divergence.

radiation = 'xray'
readfile(filename)
resolution(**kw)

Calculate resolution at each angle.

Return:
T, dT : [float] | °

Angles and angular divergence.

L, dL : [float] | Å

Wavelengths and wavelength dispersion.

sample_broadening = 0
sample_width = 10000000000.0
slits_above = None
slits_at_Tlo = None
slits_below = None
wavelength = 1.5416
refl1d.ncnrdata.find_xsec(filename)[source]

Find files containing the polarization cross-sections.

Returns tuple with file names for ++ +- -+ – cross sections, or None if the spin cross section does not exist.

refl1d.ncnrdata.load(filename, instrument=None, **kw)[source]

Return a probe for NCNR data.

Keyword arguments are as specified Monochromatic instruments.

refl1d.ncnrdata.load_magnetic(filename, Aguide=270, H=0, shared_beam=True, **kw)[source]

Return a probe for magnetic NCNR data.

filename (string, or 4x string)
If it is a string, then filenameA, filenameB, filenameC, filenameD, are the –, -+, +-, ++ cross sections, otherwise the individual cross sections should the be the file name for the cross section or None if the cross section does not exist.
Aguide (degrees)
Angle of the guide field relative to the beam. 270 is the default.
shared_beam (True)
Use false if beam parameters should be fit separately for the individual cross sections.

Other keyword arguments are for the individual cross section loaders as specified in instrument.Monochromatic.

The data sets should are the base filename with an additional character corresponding to the spin state:

'a' corresponds to spin --
'b' corresponds to spin -+
'c' corresponds to spin +-
'd' corresponds to spin ++

Unfortunately the interpretation is a little more complicated than this as the data acquisition system assigns letter on the basis of flipper state rather than neutron spin state. Whether flipper on or off corresponds to spin up or down depends on whether the polarizer/analyzer is a supermirror in transmission or reflection mode, or in the case of ^3He polarizers, whether the polarization is up or down.

For full control, specify filename as a list of files, with None for the missing cross sections.

refl1d.ncnrdata.parse_ncnr_file(filename)[source]

Parse NCNR reduced data file returning header and data.

header dictionary of fields such as ‘data’, ‘title’, ‘instrument’ data 2D array of data

If ‘columns’ is present in header, it will be a list of the names of the columns. If ‘instrument’ is present in the header, the default instrument geometry will be specified.

Slit geometry is set to the default from the instrument if it is not available in the reduced file.