1D reflectometry data usually come as ASCII columns: one row per q or
angle point, columns separated by whitespace or a delimiter,
comments marked by #. For instance, a GenX export — a
table of 1998 rows by 4 columns (double incident angle, simulated
intensity, measured intensity, its error):
# Dataset "Data 0" exported from GenX
# Column lables:
# x I_simulated I error(I)
1.000000000000000021e-02 1.000000000000000444e+00 0.0e+00 0.0e+00
1.028114993513341180e-02 9.928200261406419367e-01 0.0e+00 0.0e+00
...
9.994999999999997442e+00 4.016681554805528834e-09 0.0e+00 0.0e+00
The same data may come with an explicit delimiter; here a CSV table of 120 rows by 3 columns:
# q (1/nm), R, error of R
0.10,0.95,0.02
0.12,0.61,0.01
...
0.68,0.0021,0.0004
bornagain.ba_io.read_columns reads such tables, plain or gz/bz2
compressed. It selects the requested columns, returns one NumPy array per
column, and prepares the first column for use as a scan axis: BornAgain
requires strictly ascending values there, so the rows are sorted, and
rows with a negative or duplicate axis value are dropped.
from bornagain import ba_io
q, intensity, sigma = ba_io.read_columns(fname, usecols=(0, 1, 2))
For a delimited table, pass the delimiter explicitly:
q, intensity, sigma = ba_io.read_columns(fname, usecols=(0, 1, 2), delimiter=",")
The values are returned as stored in the file; converting them to BornAgain units is the script’s job. Two frequent cases — q stored in 1/angstrom:
import bornagain as ba
q_angstrom, intensity, sigma = ba_io.read_columns(fname, usecols=(0, 1, 2))
q = q_angstrom/ba.angstrom # 1/angstrom -> 1/nm
and the angle stored as double incident angle in degrees:
two_alpha, intensity = ba_io.read_columns(fname, usecols=(0, 1))
alpha = 0.5*two_alpha*ba.deg
After loading, crop, normalize, or filter the arrays directly in Python; the fit examples show these operations explicitly.
Motofit exports reflectivity in a fixed layout: an MFT marker line, a
key: value header, a blank line, and four 20-character columns:
MFT
Instrument: FIGA
...
Number of data points: 120
q refl refl_err q_res (FWHM)
0.00881962 0.809248 0.0293730 0.000680989
0.00909429 0.927860 0.0256534 0.000701933
bornagain.ba_io.read_motofit reads this format and returns the four
columns as NumPy arrays — q, reflectivity, its error, and the q
resolution (FWHM):
q, refl, refl_err, q_res = ba_io.read_motofit(fname)
The rows are sorted by q, and rows with a negative or duplicate q are
dropped, as in read_columns.