Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look for resolution_shape='normal|uniform' in data file header #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions refl1d/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def load4(filename, keysep=":", sep=None, comment="#", name=None,
L=None, dL=None, T=None, dT=None, dR=None,
FWHM=False, radiation=None,
columns=None, data_range=(None, None),
resolution='normal',
resolution=None,
):
r"""
Load in four column data Q, R, dR, dQ.
Expand Down Expand Up @@ -1326,7 +1326,8 @@ def load4(filename, keysep=":", sep=None, comment="#", name=None,
data set.

*resolution* is 'normal' (default) or 'uniform'. Use uniform if you
are merging Q points from a finely stepped energy sensitive measurement.
are merging Q points from a finely stepped energy sensitive measurement
or if you are in scanning mode where each point sweeps over theta.
"""
entries = parse_multi(filename, keysep=keysep, sep=sep, comment=comment)
if columns:
Expand All @@ -1345,14 +1346,14 @@ def load4(filename, keysep=":", sep=None, comment="#", name=None,
back_reflectivity=back_reflectivity,
theta_offset=theta_offset,
sample_broadening=sample_broadening,
resolution=resolution,
)
data_args = dict(
radiation=radiation,
FWHM=FWHM,
T=T, L=L, dT=dT, dL=dL, dR=dR,
column_order=column_order,
index=index,
resolution=resolution,
)
if len(entries) == 1:
probe = _data_as_probe(entries[0], probe_args, **data_args)
Expand All @@ -1372,7 +1373,7 @@ def load4(filename, keysep=":", sep=None, comment="#", name=None,
return probe

def _data_as_probe(entry, probe_args, T, L, dT, dL, dR, FWHM, radiation,
column_order, index):
column_order, index, resolution):
name = probe_args['filename']
header, data = entry
if len(data) == 2:
Expand Down Expand Up @@ -1414,15 +1415,15 @@ def _data_as_probe(entry, probe_args, T, L, dT, dL, dR, FWHM, radiation,
make_probe = Probe

# Get T,dT,L,dL from header if it is not provided as an argument
def fetch_key(key, override):
def fetch_key(key, override, default=None):
# Note: pulls header and index pulled from context
if override is not None:
return override
elif key in header:
v = json.loads(header[key])
return np.array(v)[index] if isinstance(v, list) else v
else:
return None
return default

# Get T and L, either from user input or from datafile.
data_T = fetch_key('angle', T)
Expand Down Expand Up @@ -1462,6 +1463,9 @@ def fetch_key(key, override):
data_dLoL = dQdT2dLoL(data_Q, data_dQ, data_T, data_dT)
data_dL = data_dLoL * data_L

# Get resolution from file header if not given on command line.
resolution = fetch_key('resolution_shape', resolution, default='normal')

# Check reconstruction if user provided any of T, L, dT, or dL.
# Also, sample_offset or sample_broadening.
offset = probe_args['theta_offset']
Expand All @@ -1483,13 +1487,17 @@ def fetch_key(key, override):
L=data_L, dL=data_dL,
data=(data_R, data_dR),
dQ=data_dQ,
resolution=resolution,
**probe_args)
else:
# QProbe doesn't accept theta_offset or sample_broadening
qprobe_args = probe_args.copy()
qprobe_args.pop('theta_offset')
qprobe_args.pop('sample_broadening')
probe = QProbe(data_Q, data_dQ, data=(data_R, data_dR), **qprobe_args)
probe = QProbe(
data_Q, data_dQ, data=(data_R, data_dR),
resolution=resolution,
**qprobe_args)

return probe

Expand Down