|
def AR(self,calc2d=False,two_AR=False,chi_width=5,calc2d_norm_energy=None): |
|
''' |
|
Calculate the RSoXS Anisotropic Ratio (AR) of either a single RSoXS scan or a polarized pair of scans. |
|
|
|
AR is defined as (para-perp)/(para+perp) where para is the chi slice parallel to the polarization direction, and perp is the chi slice 90 deg offset from the polarization direction. |
|
|
|
Args: |
|
img (xarray): image to plot |
|
calc2d (bool): calculate the AR using both polarizations |
|
two_AR (bool): return both polarizations if calc2d = True. If two_AR = False, return the average AR between the two polarizations. |
|
calc2d_norm_energy (numeric): if set, normalizes each polarization's AR at a given energy. THIS EFFECTIVELY FORCES THE AR TO 0 AT THIS ENERGY. |
|
chi_width (int, default 5): the width of chi slices used in calculating AR. |
|
''' |
|
if(not calc2d): |
|
para = self.slice_chi(0,chi_width=chi_width) |
|
perp = self.slice_chi(-90,chi_width=chi_width) |
|
return ((para - perp) / (para+perp)) |
|
elif(calc2d): |
|
para_pol = self.select_pol(0) |
|
perp_pol = self.select_pol(90) |
|
|
|
para_para = para_pol.rsoxs.slice_chi(0,chi_width=chi_width) |
|
para_perp = para_pol.rsoxs.slice_chi(-90,chi_width=chi_width) |
|
|
|
perp_perp = perp_pol.rsoxs.slice_chi(-90,chi_width=chi_width) |
|
perp_para = perp_pol.rsoxs.slice_chi(0,chi_width=chi_width) |
|
|
|
AR_para = ((para_para - para_perp)/(para_para+para_perp)) |
|
AR_perp = ((perp_perp - perp_para)/(perp_perp+perp_para)) |
|
|
|
if calc2d_norm_energy is not None: |
|
AR_para = AR_para / AR_para.sel(energy=calc2d_norm_energy) |
|
AR_perp = AR_perp / AR_perp.sel(energy=calc2d_norm_energy) |
|
|
|
if (AR_para < AR_perp).all() or (AR_perp < AR_para).all(): |
|
warnings.warn('One polarization has a systematically higher/lower AR than the other. Typically this indicates bad intensity values.',stacklevel=2) |
|
|
|
if two_AR: |
|
return (AR_para,AR_perp) |
|
else: |
|
return (AR_para+AR_perp)/2 |
|
else: |
|
raise NotImplementedError('Need either a single DataArray or a list of 2 dataarrays') |
Proposed changes:
Possible QOL additions:
Possible Connections with existing issues:
Existing Code for reference:
PyHyperScattering/src/PyHyperScattering/RSoXS.py
Lines 109 to 151 in 6603dd4