usnistgov / PyHyperScattering

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

feat: Implement q-axes for xarray data #52

Open BijalBPatel opened 1 year ago

BijalBPatel commented 1 year ago

Building on discussion of 221012, loading RSoXS data in the Jupyterhub currently doesn't have a workflow for applying q labels.

Peter sketched out a solution that can be applied to xarray data sourced through either loader (files or bluesky)

def apply_q_labels(data):
    data_ds = data.to_dataset(name='images')
    data_ds['qpx'] = 2*np.pi*60e-6/(data.attrs['sdd']/1000)/((1.239842e-6/data_ds.energy)*1e10)
    data_ds['qx'] = (data_ds.pix_x-data.attrs['beamcenter_x'])*data_ds.qpx
    data_ds.qx.attrs['unit'] = 'Å'
    data_ds['qy'] = (data_ds.pix_y-data.attrs['beamcenter_y'])*data_ds.qpx
    data_ds.qy.attrs['unit'] = 'Å'
    data_ds_withq = data_ds.assign_coords({'qx':data_ds.qx,'qy':data_ds.qy})
    return data_ds_withq.images

Initial scope of this issue is to: