Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Hysteresis Processing

Install and import packages

import pmagpy.rockmag as rmag
import pmagpy.ipmag as ipmag
import pmagpy.contribution_builder as cb
import pandas as pd

from bokeh.plotting import figure, show
from bokeh.io import output_notebook
output_notebook()
Loading...
Loading...

Import local data in MagIC format

In this demonstration we will be using local data.

The data is from the following publication:

  • Swanson-Hysell, N. L., Avery, M. S., Zhang, Y., Hodgin, E. B., Sherwood, R. J., Apen, F. E., et al. (2021). The paleogeography of Laurentia in its early years: New constraints from the Paleoproterozoic East-Central Minnesota Batholith. Tectonics, 40, e2021TC006751. Swanson‐Hysell et al. (2021)

# set the dir_path to the directory where the measurements.txt file is located
dir_path = '../example_data/ECMB'

# set the name of the MagIC file
ipmag.unpack_magic('magic_contribution_20213.txt', 
                     dir_path = dir_path,
                     input_dir_path = dir_path,
                     print_progress=False)

# create a contribution object from the tables in the directory
contribution = cb.Contribution(dir_path)
measurements = contribution.tables['measurements'].df
specimens = contribution.tables['specimens'].df
1  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/contribution.txt
1  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/locations.txt
90  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/sites.txt
312  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/samples.txt
1574  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/specimens.txt
17428  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/measurements.txt
-I- Using online data model
-I- Getting method codes from earthref.org
-I- Importing controlled vocabularies from https://earthref.org

Get hysteresis data using the method code

The method codes relevant to hysteresis loops are:

  • LP-HYS for regular hysteresis loops

  • LP-HYS-O for hysteresis loops as a function of orientation

  • LP-HYS-T for hysteresis loops as a function of temperature

We can filter the data to only have data for LP-HYS.

hyst_measurements = measurements[measurements['method_codes'] == 'LP-HYS']

We can see what experimental hysteresis data are available in this dataset:

hyst_experiments = rmag.make_experiment_df(hyst_measurements)
hyst_experiments
Loading...

Process hysteresis data for one experiment

We can process the data from one of the experiments using the rmag.process_hyst_loop function. The processing steps behind the function are described in the hysteresis_processing_walk_through.ipynb notebook.

#specify the experiment name and specimen name
experiment_name = 'IRM-VSM3-LP-HYS-218845'
specimen_name = 'NED1-5c'

experiment_hyst = measurements[measurements['experiment'] == experiment_name].reset_index(drop=True)
experiment_results = rmag.process_hyst_loop(experiment_hyst['meas_field_dc'].values, experiment_hyst['magn_mass'].values, specimen_name)
Loading...
Loading...
Loading...
Loading...

Process hysteresis data for all experiments

The decision tree handles the full range of loop behavior within a batch: statistically linear loops terminate with only χHF reported, and loops that fail the closure test stop with the slope-independent parameters (Mr, Brh) and data quality statistics, with the remaining parameters as NaN in the results table. The fit_linear_loop=True and fit_open_loop=True arguments override these exits when full processing is desired.

results = rmag.process_hyst_loops(hyst_experiments,measurements)
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Export hysteresis loop statistics into a MagIC specimens data table

The add_hyst_stats_to_specimens_table function adds the summary hysteresis parameters (hyst_ms_mass, hyst_mr_mass, hyst_bc, hyst_xhf) to the MagIC columns of the specimens table, with the additional quality statistics (Q, Qf, FNL values, sigma, etc.) recorded in the description column.

specimens = rmag.add_hyst_stats_to_specimens_table(specimens, results)
specimens
Loading...

The updated table can then be written out as a MagIC-format specimens.txt file:

contribution.tables['specimens'].df = specimens
contribution.tables['specimens'].write_magic_file(dir_path=dir_path)
-I- overwriting /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/specimens.txt
-I- 1574 records written to specimens file
'/Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/ECMB/specimens.txt'

Processing hysteresis data that are not in MagIC format

While the workflow above is built around MagIC-formatted data — the recommended practice, since it keeps measurement-level data, metadata, and derived parameters together — the processing functions themselves operate on simple sequences of field and magnetization values. This makes these algorithms accessible to data coming from any stream: an instrument export, a spreadsheet, or a colleague’s text file.

A few conventions to be aware of:

  • Field values are expected in tesla. The high-field susceptibility unit conversions assume tesla, and a warning is printed if the field values appear to be in mT or Oe.

  • Magnetization can be in any consistent unit. Mass-normalized Am²/kg matches MagIC conventions and makes the resulting Ms and Mr directly comparable to database values.

  • Inputs are cleaned automatically by sanitize_hyst_inputs: plain Python lists, numeric strings, and dataframe columns are all accepted; measurement pairs with non-finite values are dropped with a report; and loops measured in either field sweep order (starting from positive or negative saturation) are handled.

Below we process a plain two-column CSV file (the NED18-2c loop exported with field_tesla and moment_Am2_per_kg columns):

plain_data = pd.read_csv('../example_data/plain_text/NED18_2c_hysteresis.csv')
plain_result = rmag.process_hyst_loop(plain_data['field_tesla'],
                                      plain_data['moment_Am2_per_kg'],
                                      'NED18-2c (from csv)')
Loading...
Loading...
Loading...
Loading...
References
  1. Swanson‐Hysell, N. L., Avery, M. S., Zhang, Y., Hodgin, E. B., Sherwood, R. J., Apen, F. E., Boerboom, T. J., Keller, C. B., & Cottle, J. M. (2021). The Paleogeography of Laurentia in Its Early Years: New Constraints From the Paleoproterozoic East‐Central Minnesota Batholith. Tectonics, 40(5). 10.1029/2021tc006751