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.

Backfield processing

This notebook processes rock magnetic backfield demagnetization data with the primary purpose of obtaining Bcr (coercivity of remanence) values.

import pmagpy.rockmag as rmag

import pmagpy.ipmag as ipmag
import pmagpy.pmag as pmag
import pmagpy.contribution_builder as cb
import pandas as pd
import matplotlib.pyplot as plt 

from bokeh.io import output_notebook
output_notebook(hide_banner=True)

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
Loading...

Import data

# define the path to the folder 
dir_path = '../example_data/SSRM2024C'
# download the data from the MagIC database using my private contribution key 
result, magic_file = ipmag.download_magic_from_id('20433', directory=dir_path, share_key='e0bc04fd-8725-4aff-8687-75d51e741bcc')
# unpack the MagIC file
ipmag.unpack_magic(magic_file, dir_path, print_progress=False)
# get the contribution object
contribution = cb.Contribution(dir_path)
# get the measurements table
measurements = contribution.tables['measurements'].df
measurements = measurements.dropna(axis=1, how='all')
specimens = contribution.tables['specimens'].df
Download successful. File saved to: ../example_data/SSRM2024C/magic_contribution_20433.txt
1  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/contribution.txt
1  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/locations.txt
16  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/sites.txt
28  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/samples.txt
50  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/specimens.txt
16966  records written to file  /Users/penokean/0000_GitHub/RockmagPy-notebooks/example_data/SSRM2024C/measurements.txt
-I- Using online data model
-I- Getting method codes from earthref.org
-I- Importing controlled vocabularies from https://earthref.org

Select specimen backfield experiment data

# filter for the backfield data
backfield_data = measurements[measurements['method_codes'] == 'LP-BCR-BF']
# investigate the specimens that have backfield data
backfield_data['specimen'].unique()
<StringArray> ['MA1-5-r gelcap', 'MA1-OX-r', 'SJ1-4-r gelcap', 'SJ5-5-r gelcap', 'WS3-1-r'] Length: 5, dtype: str
# select the specimen
specimen = 'SJ1-4-r gelcap'
specimen_data = backfield_data[backfield_data['specimen'] == specimen]

# investigate the available backfield experiments, sometimes multiple experiments are done on the same specimen
specimen_data['experiment'].unique()
<StringArray> ['IRM-VSM4-LP-BCR-BF-239364'] Length: 1, dtype: str
selected_experiment = specimen_data[specimen_data['experiment'] == 'IRM-VSM4-LP-BCR-BF-239364'].reset_index()

Process backfield data

selected_experiment, Bcr = rmag.process_backfield_data(selected_experiment)
print(f"Coercivity: {round(Bcr,7)} T")
print(f"Coercivity: {round(Bcr*1000,4)} mT")
Coercivity: 0.0196186 T
Coercivity: 19.6186 mT
rmag.plot_backfield_data(selected_experiment, plot_processed=False, Bcr=Bcr, interactive=True)
Loading...
Loading...

Applying smoothing

The rmag.process_backfield_data function can also be used to smooth the data. The code below implements such smoothing which is applied to the processed backfield which is then used to develop the coercivity spectra.

# spline smoothing with a light smoothing factor; increase smooth_frac for noisier data
selected_experiment, Bcr = rmag.process_backfield_data(selected_experiment,smooth_mode='spline',smooth_frac=0.005)
rmag.plot_backfield_data(selected_experiment, Bcr=Bcr, interactive=True)
Loading...
Loading...

Add the calculated Bcr values to the specimens data table

rmag.add_Bcr_to_specimens_table(specimens, 'IRM-VSM4-LP-BCR-BF-239364', Bcr)
specimens
Loading...

Overwrite the specimens data table

pmag.magic_write(dir_path + '/specimens.txt', specimens, 'specimens', dataframe=True)
50  records written to file  ../example_data/SSRM2024C/specimens.txt
(True, '../example_data/SSRM2024C/specimens.txt')

Export MagIC upload files

# ipmag.upload_magic(dir_path=dir_path,input_dir_path=dir_path, verbose=False)