mammos_analysis.hysteresis#
Hysteresis analysis and postprocessing functions.
Functions
|
Compute the B–H curve from a hysteresis loop. |
|
Extract the coercive field from a hysteresis loop. |
Determine the maximum energy product from a hysteresis loop. |
|
Extract the remanent magnetization from a hysteresis loop. |
|
|
Compute extrinsic properties of a hysteresis loop. |
|
Identify the largest field value over which the hysteresis loop is linear. |
Classes
|
Extrinsic properties extracted from a hysteresis loop. |
|
Linear segment properties extracted from a hysteresis loop. |
|
Properties related to the maximum energy product in a hysteresis loop. |
- class mammos_analysis.hysteresis.ExtrinsicProperties(Hc, Mr, BHmax)#
Extrinsic properties extracted from a hysteresis loop.
- class mammos_analysis.hysteresis.LinearSegmentProperties(Mr, Hmax, gradient, _H=None, _M=None)#
Linear segment properties extracted from a hysteresis loop.
- plot(ax=None)#
Plot the spontaneous magnetization data-points.
- Parameters:
ax (matplotlib.axes.Axes | None)
- Return type:
matplotlib.axes.Axes
- class mammos_analysis.hysteresis.MaximumEnergyProductProperties(Hd, Bd, BHmax)#
Properties related to the maximum energy product in a hysteresis loop.
- mammos_analysis.hysteresis.extract_B_curve(H, M, demagnetization_coefficient)#
Compute the B–H curve from a hysteresis loop.
- Parameters:
H (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – External magnetic field.
M (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – Spontaneous magnetization.
demagnetization_coefficient (float) – Demagnetization coefficient (0 to 1).
- Returns:
Magnetic flux density as an Entity.
- Raises:
ValueError – If the coefficient is out of range.
- Return type:
me.Entity
Examples
>>> import mammos_analysis.hysteresis >>> import mammos_entity as me >>> H = me.H([0, 1e4, 2e4], unit="A/m") >>> M = me.Ms([1e5, 2e5, 3e5], unit="A/m") >>> mammos_analysis.hysteresis.extract_B_curve(H, M, 1/3) MagneticFluxDensity(...)
- mammos_analysis.hysteresis.extract_coercive_field(H, M)#
Extract the coercive field from a hysteresis loop.
- mammos_analysis.hysteresis.extract_maximum_energy_product(H, B)#
Determine the maximum energy product from a hysteresis loop.
- Parameters:
H (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – External magnetic field.
B (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – Magnetic flux density.
- Returns:
Properties of the maximum energy product.
- Raises:
ValueError – If inputs are not monotonic or B decreases with H.
- Return type:
- mammos_analysis.hysteresis.extract_remanent_magnetization(H, M)#
Extract the remanent magnetization from a hysteresis loop.
- mammos_analysis.hysteresis.extrinsic_properties(H, M, demagnetization_coefficient=None)#
Compute extrinsic properties of a hysteresis loop.
- Parameters:
H (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – External magnetic field.
M (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – Spontaneous magnetization.
demagnetization_coefficient (float | None) – Demagnetization coefficient for BHmax.
- Returns:
ExtrinsicProperties containing Hc, Mr, and BHmax.
- Raises:
ValueError – If Hc or Mr calculation fails.
- Return type:
- mammos_analysis.hysteresis.find_linear_segment(H, M, margin, method='maxdev', min_points=5)#
Identify the largest field value over which the hysteresis loop is linear.
There are two possible criteria, selected by the method argument:
Max‐Deviation Criterion (method=”maxdev”): Require that every data point in the segment satisfies
\[\max_{\,i_0 \le i \le i_{\max}}\;\bigl|\,M_i - (m\,H_i + b)\bigr| \;\le\; \delta,\]where:
\(\{(H_i, M_i)\}\) are the data points,
\(m\) is the fitted slope,
\(b\) is the fitted intercept (value of \(M\) at \(H=0\)),
\(\delta\) is the user‐supplied margin (in the same units as \(M\)).
This guarantees each point lies within \(\pm \delta\).
RMS Criterion (method=”rms”): Require that the root‐mean‐square error over the segment satisfies
\[\mathrm{RMSE} \;=\; \sqrt{\frac{1}{n}\sum_{\,i=i_0}^{\,i_{\max}} \bigl(M_i - (m\,H_i + b)\bigr)^2} \;\le\; \delta,\]where \(n = i_{\max} - i_0 + 1\). Occasional points may exceed \(\delta\) provided the overall RMS error remains within \(\delta\).
- Parameters:
H (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – Applied magnetic field values. Must be monotonic.
M (mammos_entity.Entity | mammos_units.Quantity | np.ndarray) – Magnetization values corresponding to H.
margin (mammos_entity.Entity | mammos_units.Quantity | numbers.Number) – Allowed deviation \(\delta\).
method (str) – Which deviation test to use: - “maxdev” (default): per‐point maximum deviation, - “rms”: root‐mean‐square deviation.
min_points (int) – Minimum number of points required to attempt any fit.
- Returns:
Mr: fitted intercept \(b\) (magnetization at \(H=0\)),
Hmax: largest field value up to which data remain “linear” under the chosen criterion,
gradient: fitted slope \(m\) (dimensionless).
- Return type:
LinearSegmentProperties containing
Notes
Growing‐Window Fit We attempt to extend the segment one index at a time:
\[\{\,i_0,\,i_0+1,\,\dots,\,i\,\}.\]For each candidate endpoint \(i\), we fit a line \(\hat{M}(H) = m\,H + b\) via np.polyfit(H[i_0:i+1], M[i_0:i+1], 1). Then we compute either:
Max‐Deviation: \(\max_{j=i_0}^i\,\bigl|M_j - (m\,H_j + b)\bigr| \le \delta,\) or
RMS:
\[\mathrm{RMSE} \;=\; \sqrt{\frac{1}{\,i - i_0 + 1\,} \sum_{j=i_0}^{i} \bigl(M_j - (m\,H_j + b)\bigr)^2} \;\le\; \delta.\]
As soon as adding \(i+1\) would violate the chosen inequality, we stop and take \(i_{\max} = i\). We then refit \((m,b)\) on \(\{i_0,\dots,i_{\max}\}\) to produce the final slope/intercept returned.