reflectometry/refl1d

contract magnetic for both in-plane magnetic projections: avoid divide-by-zero error

Closed this issue · 0 comments

In the code for contract_mag, a projection of rho_M along one of the in-plane directions is used to create weighted_dz, which is later used as the denominator when calculating the average rho_M over the area. This can case divide-by-zero errors when the projection is exactly zero.

To reproduce, create a layer with theta_M = 90.0 or 270.0 (units of degrees for input), with dA > 0 and step = False (if microstepping, the smoothing function is not likely to land on exactly zero)

The logic in refl1d.lib_numba.contract_profile.contract_mag could be adjusted so that instead of checking a single in-plane projection of rho_M, we generate both in-plane rho_M projections and contract them together if they both meet the contraction criteria. After they are contracted, a new theta_M is calculated from the average values of rho_M_para and rho_M_perp as np.arctan2(mean_rho_M_para, mean_rho_M_perp) and mean_rho_M = np.sqrt(mean_rho_M_para**2 + mean_rho_M_perp**2)