agepy.mag.hysteresis.optimized_faraday_correction
- optimized_faraday_correction(*hysteresis, verdet_guess, left_shift_guess, bracket=None, bounds=None, saturation_percentage=10, log_level=20)
Performs a correction of the Faraday-effect via analytic optimization method.
Performs optimization of a functional describing the difference between saturation region and analytic expression of the Faraday- effect. The correction might need to be combined with other correction methods (thermal drift, relative shifting, …) to obtain proper looking hysteresis curves. Note, that the optimized functional considers the linearly corrected data, but the function itself does not subtract the linear part. Hysteresis data can be supplied either as one tuple containing the magntic field and magnetization repectively or as multiple tuples containing the two hysteresis branches.
- Parameters:
- *hysteresis: ArrayLike
One or two 2-D arrays of shape (2, n) containing the magnetic field and magnetization of length n in the first axis.
- verdet_guess: float
Initial guess for verdet constant of the objective lens.
- left_shift_guess: float
Initial guess for the extremum position of the cos^2 function.
- bracket: Sequence[float, float(, float)], default None
Bracket parameter of
scipy.optimize.minimize_scalar. Defines the bracketing interval. Must be supplied ifboundsisNone.- bounds: Sequence[float, float]
Bounds parameter of
scipy.optimizle.minimize_scalar. Defines the upper and lower bounds of the guess values. Must be supplied ifbracketisNone.- saturation_percentage: float, default 10
Percentage value of points in at the end of the hysteresis branches belonging to the saturation region.
- log_level: int, default 10
log behavior of
python.loggingmodule for the optimization results.
- Returns:
NDArrayThe corrected magnetization values. If
hysteresisis supplied as whole sequence , then a 1-D array with the same length as the magnetization is returned. Ifhysteresisis two branches, a 2-D array is returned containing the two magnetization branches in the first axis.
- Return type:
ndarray[Any,dtype[TypeVar(_ScalarType_co, bound=generic, covariant=True)]]
Examples
The optimization parameters for this function try to describe the curvature in a hysteresis curve with a cos^2 function. The verdet constant is a material constant, that in this cas scales the width of the cos^2 function. For usual field ranges (10 - 100 mT) it is quite small and is in the proximity of 0.01 or lower. The left shift describes were the extremum of the of the cos^2 is and is in field units. This parameter can usually be estimated by plotting the hysteresis beforehand. The
boundsorbracketparameters describe the amplitude of the cos^2 and can take values from the range of the distance between saturation branches up until several times of that.The following example demonstrates a typical correction code.
>>> M, H = ... >>> M = drift_correction((H, M), slope=0.2) >>> M = shift_branch(M, shift_value=5) >>> M = optimized_faraday_correction((H, M), verdet_guess=0.01, left_shift_guess=5, bounds=(20, 500), saturation_percentage=30) >>> M = linear_correction((H, M), saturation_percentage=30)
The first two functions clean the raw data from potential thermal drift and tries to align the two hysteresis branches as good as possible. The better the alignment beforehand, the better the faraday correction works. It is suggested to plot the intermediate states and play with the parameters until it aligns best.
The faraday correction is then applied with the recommended guess parameters. Don’t expect these to work right out of the box though. Sometimes, one has to play around with the guess parameters to find a good solution. For some measurement data it might not work at all due to particular strong distortions or other effects. Generally, a longer saturation region in the input data yields better results.
Finally, a linear correction is applied to remove any remaining hysteresis tilt. The linear correction is considered in the optimized functional of the faraday correction. However, the correction itself only removes the faraday contribution itself. For a clean hysteresis this last step is therefore necessary.
Viable example inputs.
>>> faraday_correction((H, M), verdet_guess=0.01, left_shift_guess=5, saturation_percentage=10) array([<M-values>])
>>> faraday_correction((H1, M1), (H2, M2), verdet_guess=0.01, left_shift_guess=5, saturation_percentage=10) array([[<M1-values>], [<M2-values>]])
>>> hyst = array([H, M]) >>> faraday_correction(hyst, verdet_guess=0.01, left_shift_guess=5, saturation_percentage=10) array([<M-values>])
>>> hyst = array([[H1, M1], [H2, M2]]) >>> faraday_correction(*hyst, verdet_guess=0.01, left_shift_guess=5, saturation_percentage=10) array([[<M1-values>], [<M2-values>]])