MagnetoPy Independent
For data which does not conform to MagnetoPy
classes, you can still use the functions (fit_cauchy_cdf()
and fit_cauchy_pdf()
). Ultimately, all that is required to use these functions is passing your data as x
and y
variables, along with any starting guesses for the fit parameters.
An example notebook demonstrates how to work with the classes and functions described herein: Quantification of Hysteresis Data using Cauchy Distribution Functions
fit_cauchy_cdf(x, y, fitting_args)
Fits given x and y data (e.g., magnetic field and magnetization) to a sum of Cauchy cumulative distribution functions (CDFs).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
npt.ArrayLike
|
The x data, e.g., magnetic field. |
required |
y |
npt.ArrayLike
|
The y data, e.g., the magnetization. |
required |
fitting_args |
CauchyFittingArgs | int
|
The arguments needed to perform the fit. If an |
required |
Returns:
Type | Description |
---|---|
CauchyAnalysisResults
|
The results of the fit. |
Source code in magnetopy\analyses\cauchy\standalone.py
cauchy_cdf(h, params)
Generates data representing a sum of Cauchy cumulative distribution functions (CDFs).
Equation:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h |
FitVal
|
A FitVal (either a float or a numpy array) representing the x data (e.g., magnetic field). |
required |
params |
Parameters
|
Params must contain the following parameters as a valid |
required |
Returns:
Type | Description |
---|---|
FitVal
|
The float or numpy array representing the y data (e.g., the magnetization with respect to field). |
Source code in magnetopy\analyses\cauchy\standalone.py
fit_cauchy_pdf(x, y, fitting_args)
Fits given x and y data (e.g., magnetic field and the derivative of magnetization with respect to field) to a sum of Cauchy probability density functions (PDFs).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
npt.ArrayLike
|
The x data, e.g., magnetic field. |
required |
y |
npt.ArrayLike
|
The y data, e.g., the derivative of magnetization with respect to field. |
required |
fitting_args |
CauchyFittingArgs | int
|
The arguments needed to perform the fit. If an |
required |
Returns:
Type | Description |
---|---|
CauchyAnalysisResults
|
The results of the fit. |
Source code in magnetopy\analyses\cauchy\standalone.py
cauchy_pdf(h, params)
Generates data representing a sum of Cauchy probability density functions (PDFs).
Equation:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h |
FitVal
|
A FitVal (either a float or a numpy array) representing the x data (e.g., magnetic field). |
required |
params |
Parameters
|
Params must contain the following parameters as a valid |
required |
Returns:
Type | Description |
---|---|
FitVal
|
The float or numpy array representing the y data (e.g., the derivative of magnetization with respect to field). |
Source code in magnetopy\analyses\cauchy\standalone.py
CauchyParams
dataclass
Parameters for a single Cauchy term. All three terms can be floats, two-tuples, or three-tuples. If they are floats, they are used as the initial value for the fit. If they are two-tuples, the values represent the lower and upper bounds for the fit. If they are three-tuples, the values represent the initial value, lower bound, and upper bound for the fit.
All terms are optional. If a term is not provided, it is assumed to be zero.
Any float
values passed are cast to tuples.
Attributes:
Name | Type | Description |
---|---|---|
m_s |
float | tuple[float, float] | tuple[float, float, float]
|
The saturation magnetization of the term. If a float, the value is used as the initial value for the fit. If a two-tuple, the values represent the lower and upper bounds for the fit. If a three-tuple, the values represent the initial value, lower bound, and upper bound for the fit. |
h_c |
float | tuple[float, float] | tuple[float, float, float]
|
The coercive field of the term. If a float, the value is used as the initial value for the fit. If a two-tuple, the values represent the lower and upper bounds for the fit. If a three-tuple, the values represent the initial value, lower bound, and upper bound for the fit. |
gamma |
float | tuple[float, float] | tuple[float, float, float]
|
The term describing the broadness of the term. If a float, the value is used as the initial value for the fit. If a two-tuple, the values represent the lower and upper bounds for the fit. If a three-tuple, the values represent the initial value, lower bound, and upper bound for the fit. |
Source code in magnetopy\analyses\cauchy\standalone.py
as_dict()
Returns a dictionary representation of the object.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Keys are: "class", "m_s", "h_c", "gamma". |
Source code in magnetopy\analyses\cauchy\standalone.py
CauchyFittingArgs
dataclass
summary
Attributes:
Name | Type | Description |
---|---|---|
terms |
list[CauchyParams] | CauchyParams
|
The parameters for each individual Cauchy term to be used in the fit. A single term will be converted to a list of length one. |
Source code in magnetopy\analyses\cauchy\standalone.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
build_params(x_range, y_sat)
Uses the CauchyParams
given during object creation to build a Parameters
object compatible with lmfit
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_range |
tuple[float, float]
|
The minimum and maximum values of the x-axis. |
required |
y_sat |
float
|
In terms of magnetization, this is the saturation magnetization of the original M vs. H data. If the data under consideration is the derivative of magnetization with respect to field or is otherwise data in a form similar to that of the Cauchy PDF, y_sat will be half of the integral of the data over the x_range. |
required |
Returns:
Type | Description |
---|---|
Parameters
|
A |
Source code in magnetopy\analyses\cauchy\standalone.py
generate_data(x, form)
Generates simulated data representing a sum of Cauchy PDFs using the individual terms given during object creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
npt.ArrayLike
|
The x data, e.g., magnetic field. |
required |
form |
Literal['pdf', 'cdf']
|
The form of the Cauchy distribution to generate. |
"pdf"
|
Returns:
Type | Description |
---|---|
npt.ArrayLike
|
The y data, e.g., the derivative of magnetization with respect to field. |
Source code in magnetopy\analyses\cauchy\standalone.py
as_dict()
Returns a dictionary representation of the object.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Keys are: "class", "terms". |
Source code in magnetopy\analyses\cauchy\standalone.py
build_from_num_terms(num_terms, x_range, y_sat)
classmethod
Generates input parameters for a Cauchy fit based on the number of terms desired.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_terms |
int
|
The number of Cauchy terms to be used in the fit. |
required |
x_range |
tuple[float, float]
|
The minimum and maximum values of the x-axis. |
required |
y_sat |
float
|
In terms of magnetization, this is the saturation magnetization of the original M vs. H data. If the data under consideration is the derivative of magnetization with respect to field or is otherwise data in a form similar to that of the Cauchy PDF, y_sat will be half of the integral of the data over the x_range. |
required |
Returns:
Type | Description |
---|---|
CauchyFittingArgs
|
The input parameters for a Cauchy fit. |
Source code in magnetopy\analyses\cauchy\standalone.py
CauchyAnalysisResults
dataclass
The results of a fit to a Cauchy analysis (either CDF or PDF).
Attributes:
Name | Type | Description |
---|---|---|
terms |
list[CauchyTermResults]
|
The fit results for each individual Cauchy term; each term includes values for
|
chi_pd |
float
|
The fit value for the term describing a phenomena whose contribution to the magnetization is linear with respect to field (i.e., paramagnetism and diamagnetism). |
chi_pd_err |
float
|
The error of |
chi_squared |
float
|
The chi-squared value of the fit. |
reduced_chi_squared |
float
|
The reduced chi-squared value of the fit. |
m_s_unit |
str
|
The units of the |
h_c_unit |
str
|
The units of the |
gamma_unit |
str
|
The units of |
chi_pd_unit |
str
|
The units of |
Source code in magnetopy\analyses\cauchy\standalone.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
|
set_units(m_s, h_c, gamma, chi_pd)
Sets the units of the fit results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m_s |
str
|
The units of the |
required |
h_c |
str
|
The units of the |
required |
gamma |
str
|
The units of |
required |
chi_pd |
str
|
The units of |
required |
Source code in magnetopy\analyses\cauchy\standalone.py
as_dict()
Returns a dictionary representation of the object.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Keys are: "class", "terms", "chi_pd", "chi_pd_err", "chi_squared", "reduced_chi_squared", "m_s_unit", "h_c_unit", "gamma_unit", "chi_pd_unit". |
Source code in magnetopy\analyses\cauchy\standalone.py
generate_data(x, form)
Generates simulated data representing a sum of Cauchy PDFs or CDFs using the individual terms resulting from the fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
npt.ArrayLike
|
The x data, e.g., magnetic field. |
required |
form |
Literal['pdf', 'cdf']
|
The form of the Cauchy distribution to generate. |
"pdf"
|
Returns:
Type | Description |
---|---|
npt.ArrayLike
|
The y data, e.g., the derivative of magnetization with respect to field. |
Source code in magnetopy\analyses\cauchy\standalone.py
generate_data_by_term(x, form)
Generates simulated data representing each individual term resulting from the fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
npt.ArrayLike
|
The x data, e.g., magnetic field. |
required |
form |
Literal['pdf', 'cdf']
|
The form of the Cauchy distribution to generate. |
"pdf"
|
Returns:
Type | Description |
---|---|
list[npt.ArrayLike]
|
The y data, e.g., the derivative of magnetization with respect to field. |
Source code in magnetopy\analyses\cauchy\standalone.py
CauchyTermResults
dataclass
The fit results for a single Cauchy term. Note that these terms assume that the data was either M vs. H or dM/dH vs. H.
Attributes:
Name | Type | Description |
---|---|---|
m_s |
float
|
The saturation magnetization of the term. |
m_s_err |
float
|
The error in the saturation magnetization of the term. |
h_c |
float
|
The coercive field of the term. |
h_c_err |
float
|
The error in the coercive field of the term. |
gamma |
float
|
The parameter describing the broadness of the term. |
gamma_err |
float
|
The error in the parameter describing the broadness of the term. |