Skip to content

Commit

Permalink
Allow None or scalar for dxl and dxw in simplified interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Jun 7, 2023
1 parent 0bc9754 commit 67770f9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sasmodels/direct_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ def _interpret_data(self, data: Data, model: KernelModel) -> None:
else:
res = resolution.Perfect1D(q)
elif (getattr(data, 'dxl', None) is not None
and getattr(data, 'dxw', None) is not None):
or getattr(data, 'dxw', None) is not None):
res = resolution.Slit1D(
data.x[index],
q_length=data.dxl[index],
q_width=data.dxw[index])
q_length=None if data.dxl is None else data.dxl[index],
q_width=None if data.dxw is None else data.dxw[index])
else:
res = resolution.Perfect1D(data.x[index])
elif self.data_type == 'Iq-oriented':
Expand All @@ -275,9 +275,10 @@ def _interpret_data(self, data: Data, model: KernelModel) -> None:
or getattr(data, 'dxw', None) is None):
raise ValueError("oriented sample with 1D data needs slit resolution")

res = resolution2d.Slit2D(data.x[index],
qx_width=data.dxw[index],
qy_width=data.dxl[index])
res = resolution2d.Slit2D(
data.x[index],
qx_width=data.dxw[index],
qy_width=data.dxl[index])
else:
raise ValueError("Unknown data type") # never gets here

Expand Down Expand Up @@ -492,7 +493,12 @@ def Iq(model, q, dq=None, ql=None, qw=None, **pars):
"""
from .data import Data1D, _as_numpy
data = Data1D(x=q, dx=dq)
data.dxl, data.dxw = _as_numpy(ql), _as_numpy(qw)
def broadcast(v):
return (
None if v is None
else np.full(len(q), v) if np.isscalar(v)
else _as_numpy(v))
data.dxl, data.dxw = broadcast(ql), broadcast(qw)
return _direct_calculate(model, data, pars)

def Iqxy(model, qx, qy, dqx=None, dqy=None, **pars):
Expand Down

0 comments on commit 67770f9

Please sign in to comment.