usnistgov / PyHyperScattering

Tools for hyperspectral x-ray and neutron scattering data loading, reduction, slicing, and visualization.
Other
7 stars 9 forks source link

Integrator incorrect energy dependence #89

Closed pdudenas closed 1 year ago

pdudenas commented 1 year ago

This may be related to #84. Here is an SST1 scan processed with PyHyper 0.1.10, 0.2.0, 0.2.1. In 0.2+, the peak shifts to smaller q, suggesting an incorrect q calibration. Perhaps the integrator isn't being selected correctly.

image
pbeaucage commented 1 year ago

@pdudenas can you share the scan number for this example data?

pdudenas commented 1 year ago

48239

pbeaucage commented 1 year ago

@pdudenas and I spent some time troubleshooting this today. It came down to an interesting sequence dependence, which feels worth memorializing here.

Example code:

isvlo = load.loadRun(load.c[48239])#, dims=['energy'])
WAXSinteg = PyHyperScattering.integrate.PFEnergySeriesIntegrator(geomethod='template_xr', template_xr = isvlo)
isvlo_int = WAXSinteg.integrateImageStack(isvlo)
isvlo_azim = isvlo_int.unstack('system').mean('chi')

isvlo_int_uss = WAXSinteg.integrateImageStack(isvlo.unstack('system'))
isvlo_azim_uss = isvlo_int_uss.mean('chi')

isvlo_azim.plot(norm=LogNorm(1e1,1e5),x='q', xscale='log')
plt.xlim(5e-3)
plt.title(f'No unstack Version {PyHyperScattering.__version__}')

plt.figure()
isvlo_azim_uss.plot(norm=LogNorm(1e1,1e5),x='q', xscale='log')
plt.xlim(5e-3)
plt.title(f'Unstack Version {PyHyperScattering.__version__}')

image image

Basically, if the system multiindex was unstacked before integrating, the integrator could see the energy fine as an index and get appropriate values. If it wasn't unstacked, it would just get the whole array and integrate using the first energy value.

This is fixed in #93 by adding some flexible code that finds energy inside multiindexes if it isn't at the top level.