reflectometry / refl1d

1-D reflectometry fitting
https://refl1d.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
18 stars 24 forks source link

AttributeError: 'QProbe' object has no attribute 'calc_T' #163

Closed decaluwe closed 1 year ago

decaluwe commented 1 year ago

Hi, I am trying to run a fit on some data taken on Platypus, at ANSTO. When I try to run, I get the following error:

ERROR:root:Traceback (most recent call last): File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/bumps/fitproblem.py", line 504, in _nllf_components pmodel = (self.model_nllf() ^^^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/bumps/fitproblem.py", line 296, in model_nllf return self.fitness.nllf() ^^^^^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/refl1d/experiment.py", line 157, in nllf return 0.5*np.sum(self.residuals()**2) # + self._cache['nllf_scale'] ^^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/refl1d/experiment.py", line 116, in residuals QR = self.reflectivity() ^^^^^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/refl1d/experiment.py", line 490, in reflectivity calc_q, calc_r = self._reflamp() ^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/refl1d/experiment.py", line 438, in _reflamp calc_q = self.probe.calc_Q ^^^^^^^^^^^^^^^^^ File "/Users/decaluwe/opt/anaconda3/envs/refl1d/lib/python3.11/site-packages/refl1d/probe.py", line 422, in calc_Q Q = TL2Q(T=self.calc_T+self.theta_offset.value, L=self.calc_L) ^^^^^^^^^^^ AttributeError: 'QProbe' object has no attribute 'calc_T'

Input file and sample data attached. I run from the command line using:

python3.11 -m refl1d.main mwe.py --fit=dream --store=init_fit

refl1d just re-installed today via pip

pip install refl1d

Thanks in advance for any advice/help/feedback.

Steven

decaluwe commented 1 year ago

After some playing around, the error is with theta offset, which makes sense. Closing this, now.

andyfaff commented 1 year ago

The default file for Platypus is Q/R/dR/dQ, but if needed we could output an omega/domega/lambda/dlambda/R/dR file.

decaluwe commented 1 year ago

Thanks, @andyfaff -- the output format is good. The instrument just doesn't like having a theta_offset parameter (to adjust for potential errors in alignment).

This is not a significant issue, for me, at this point, so I'm fine to move ahead.

bmaranville commented 1 year ago

An earlier refactor to improve handling of theta_offset in Probe and PolarizedNeutronProbe introduced a bug in PolarizedQProbe, which was fixed in 0.8.16, but it looks like it also introduced the calc_Q bug in the QProbe class as well. We can fix that soon.

If you want to fit theta_offset though, I suggest using the Probe (NeutronProbe?) class instead of QProbe, as those classes calculate Q based on theta and lambda specifically to support theta_offset. The QProbe class does not keep track of theta or theta_offset.

decaluwe commented 1 year ago

Thanks, Brian. So I am loading the instrument using


from refl1d import anstodata as ansto
instrument = ansto.Platypus()
probe_ocp = instrument.load(data_1M_OCP)

I'm not sure what in this chain specifies a QProbe vs. a Probe/NeutronProbe...

bmaranville commented 1 year ago

Yes, that loader creates a QProbe. We can modify it to use NeutronProbe if the inputs can include the wavelength and theta, as Andrew suggested above.