mammos_analysis.hysteresis#

Hysteresis analysis and postprocessing functions.

Functions

extract_B_curve(H, M, ...)

Compute the B–H curve from a hysteresis loop.

extract_coercive_field(H, M)

Extract the coercive field from a hysteresis loop.

extract_maximum_energy_product(H, B)

Determine the maximum energy product from a hysteresis loop.

extract_remanent_magnetization(H, M)

Extract the remanent magnetization from a hysteresis loop.

extrinsic_properties(H, M[, ...])

Compute extrinsic properties of a hysteresis loop.

find_linear_segment(H, M, margin[, method, ...])

Identify the largest field value over which the hysteresis loop is linear.

Classes

ExtrinsicProperties(Hc, Mr, BHmax)

Extrinsic properties extracted from a hysteresis loop.

LinearSegmentProperties(Mr, Hmax, gradient)

Linear segment properties extracted from a hysteresis loop.

MaximumEnergyProductProperties(Hd, Bd, BHmax)

Properties related to the maximum energy product in a hysteresis loop.

class mammos_analysis.hysteresis.ExtrinsicProperties(Hc, Mr, BHmax)[source]#

Extrinsic properties extracted from a hysteresis loop.

Parameters:
BHmax: Entity#

Maximum energy product.

Hc: Entity#

Coercive field.

Mr: Entity#

Remanent magnetization.

class mammos_analysis.hysteresis.LinearSegmentProperties(Mr, Hmax, gradient, _H=None, _M=None)[source]#

Linear segment properties extracted from a hysteresis loop.

Parameters:
Hmax: Entity#

Maximum field strength in the linear segment.

Mr: Entity#

M(H=0) from linear segment fit.

gradient: Quantity#

Gradient of the linear segment.

plot(ax=None)[source]#

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)[source]#

Properties related to the maximum energy product in a hysteresis loop.

Parameters:
BHmax: Entity#

Maximum energy product value.

Bd: Entity#

Flux density at which BHmax occurs.

Hd: Entity#

Field strength at which BHmax occurs.

mammos_analysis.hysteresis.extract_B_curve(H, M, demagnetization_coefficient)[source]#

Compute the B–H curve from a hysteresis loop.

Parameters:
Returns:

Magnetic flux density as an Entity.

Raises:

ValueError – If the coefficient is out of range.

Return type:

mammos_entity.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)
Entity(ontology_label='MagneticFluxDensity', ...)
mammos_analysis.hysteresis.extract_coercive_field(H, M)[source]#

Extract the coercive field from a hysteresis loop.

Parameters:
Returns:

Coercive field in the same format as H.

Raises:

ValueError – If the coercive field cannot be calculated.

Return type:

mammos_entity.Entity

mammos_analysis.hysteresis.extract_maximum_energy_product(H, B)[source]#

Determine the maximum energy product from a hysteresis loop.

Parameters:
Returns:

Properties of the maximum energy product.

Raises:

ValueError – If inputs are not monotonic or B decreases with H.

Return type:

MaximumEnergyProductProperties

mammos_analysis.hysteresis.extract_remanent_magnetization(H, M)[source]#

Extract the remanent magnetization from a hysteresis loop.

Parameters:
Returns:

Remanent magnetization in the same format as M.

Raises:

ValueError – If the field does not cross zero or calculation fails.

Return type:

mammos_entity.Entity

mammos_analysis.hysteresis.extrinsic_properties(H, M, demagnetization_coefficient=None)[source]#

Compute extrinsic properties of a hysteresis loop.

Parameters:
Returns:

ExtrinsicProperties containing Hc, Mr, and BHmax.

Raises:

ValueError – If Hc or Mr calculation fails.

Return type:

ExtrinsicProperties

mammos_analysis.hysteresis.find_linear_segment(H, M, margin, method='maxdev', min_points=5)[source]#

Identify the largest field value over which the hysteresis loop is linear.

There are two possible criteria, selected by the method argument:

  1. 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\).

  2. 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:
Returns:

An object containing

  • 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

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.