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'

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/unimos/0000_Github/RockmagPy-notebooks/example_data/SSRM2024C/contribution.txt
1  records written to file  /Users/unimos/0000_Github/RockmagPy-notebooks/example_data/SSRM2024C/locations.txt
16  records written to file  /Users/unimos/0000_Github/RockmagPy-notebooks/example_data/SSRM2024C/sites.txt
28  records written to file  /Users/unimos/0000_Github/RockmagPy-notebooks/example_data/SSRM2024C/samples.txt
50  records written to file  /Users/unimos/0000_Github/RockmagPy-notebooks/example_data/SSRM2024C/specimens.txt
16966  records written to file  /Users/unimos/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()
array(['MA1-5-r gelcap', 'MA1-OX-r', 'SJ1-4-r gelcap', 'SJ5-5-r gelcap',
       'WS3-1-r'], dtype=object)
# 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()
array(['IRM-VSM4-LP-BCR-BF-239364'], dtype=object)
selected_experiment = specimen_data[specimen_data['experiment'] == 'IRM-VSM4-LP-BCR-BF-239364'].reset_index()

Process backfield data#

selected_experiment, Bcr = rmag.backfield_data_processing(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)

Applying smoothing#

The rmag.backfield_data_processing 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.

selected_experiment, Bcr = rmag.backfield_data_processing(selected_experiment,smooth_mode='spline',smooth_frac=0.005)
rmag.plot_backfield_data(selected_experiment, Bcr=Bcr, interactive=True)

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
azimuth description dip experiments hyst_bc hyst_bc_offset hyst_bcr hyst_mr_mass hyst_ms_mass hyst_xhf ... rem_hirm_mass rem_sratio rem_sratio_back rem_sratio_forward result_quality sample specimen volume weight rem_bcr
specimen name
HH8-1-r 181.3 Haliburton Highlands 8-1 VSM specimen 43.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g HH8-3 HH8-1-r 0.000001 0.000072 NaN
HH8-1x 181.3 Haliburton Highlands 8-1 X-T specimen 43.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g HH8-3 HH8-1x 0.000001 0.000181 NaN
HH8-3b 181.3 Haliburton Highlands 8-3 core 43.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g HH8-3 HH8-3b 0.000000 0.000000 NaN
MA1-1b 211.7 MA1-1 core 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-1 MA1-1b 0.000000 0.015202 NaN
MA1-2-r 222.7 MA1-2 VSM specimen 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-2 MA1-2-r 0.000001 0.000081 NaN
MA1-2b 222.7 MA1-2 core 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-2 MA1-2b 0.000000 0.015471 NaN
MA1-2x 222.7 MA1-2 X-T specimen 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-2 MA1-2x 0.000001 0.000146 NaN
MA1-3b 215.7 MA1-3 core 49.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-3 MA1-3b 0.000000 0.015741 NaN
MA1-5-r gelcap NaN gel cap for MPMS NaN None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-5-r MA1-5-r gelcap 0.000000 0.000090 NaN
MA1-5b 226.7 Marcy anorthosite 1-5 core 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-5 MA1-5b 0.000000 0.000000 NaN
MA1-8b 236.7 MA1-8 core 51.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-8 MA1-8b 0.000000 0.015539 NaN
MA1-OX-cube 211.7 MA1-OX X-T cube specimen 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-1 MA1-OX-cube 0.000001 0.011767 NaN
MA1-OX-r 211.7 MA1-OX VSM specimen 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-1 MA1-OX-r 0.000001 0.000113 NaN
MA1-OX-x 211.7 MA1-OX X-T specimen 56.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA1-1 MA1-OX-x 0.000001 0.000205 NaN
MA5-3-r 0.0 Marcy anorthosite 5-3 VSM specimen 0.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA5-4 MA5-3-r 0.000001 0.000090 NaN
MA5-4b 289.3 Marcy anorthosite 5-4 core 64.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g MA5-4 MA5-4b 0.000000 0.000000 NaN
SJ1-1b 181.5 St Jean 1-1 core 48.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-1 SJ1-1b 0.000000 0.000000 NaN
SJ1-1x 181.5 St Jean 1-1 core 48.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-1 SJ1-1x 0.000001 0.000000 NaN
SJ1-2b 189.5 SJ1-2 core 50.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-2 SJ1-2b 0.000000 0.016136 NaN
SJ1-3-r 179.5 SJ1-3 VSM specimen 55.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-3 SJ1-3-r 0.000001 0.000089 NaN
SJ1-3b 179.5 SJ1-3 core 55.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-3 SJ1-3b 0.000000 0.016219 NaN
SJ1-3x 179.5 SJ1-3 X-T specimen 55.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-3 SJ1-3x 0.000001 0.000086 NaN
SJ1-4-r gelcap NaN gel cap for MPMS NaN None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-4-r SJ1-4-r gelcap 0.000000 0.000069 NaN
SJ1-5b 174.5 SJ1-5 core 36.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-5 SJ1-5b 0.000000 0.013974 NaN
SJ1-5x 174.5 SJ1-5 X-T specimen 36.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ1-5 SJ1-5x 0.000001 0.000062 NaN
SJ5-5-r gelcap NaN gel cap for MPMS NaN None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ5-5-r SJ5-5-r gelcap 0.000000 0.000143 NaN
SJ5-5b 38.9 St Jean 5-4 core 47.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g SJ5-5 SJ5-5b 0.000000 0.000000 NaN
TH1-1b 77.6 Thanet gabbro 1-1 core 17.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g TH1-1 TH1-1b 0.000000 0.000000 NaN
TH1-2-r 0.0 Thanet gabbro 1-2 VSM core 0.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g TH1-1 TH1-2-r 0.000001 0.000087 NaN
WS3-1-r 11.6 Whitestone anorthosite 3-1 VSM specimen 69.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g WS3-1 WS3-1-r 0.000001 0.000093 NaN
WS3-1b 11.6 Whitestone anorthosite 3-1 core 69.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g WS3-1 WS3-1b 0.000000 0.000000 NaN
WS3-1x 11.6 Whitestone anorthosite 3-1 X-T specimen 69.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g WS3-1 WS3-1x 0.000001 0.000083 NaN
WS9-1-r 308.7 Whitestone anorthosite 9-1 VSM core 48.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g WS9-1 WS9-1-r 0.000001 0.000176 NaN
WS9-1b 308.7 Whitestone anorthosite 9-1 core 48.0 None NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN g WS9-1 WS9-1b 0.000000 0.000000 NaN
HH8-1-r NaN None NaN IRM-VSM3-LP-HYS-239366 0.385700 -1.135000e-02 NaN 0.000031 -0.000434 1.546000e-07 ... NaN NaN NaN NaN None HH8-3 HH8-1-r NaN 0.000072 NaN
MA1-5-r gelcap NaN None NaN IRM-VSM3-LP-HYS-239371 0.003126 2.087000e-04 NaN 0.002624 0.118800 2.125000e-08 ... NaN NaN NaN NaN None MA1-5-r MA1-5-r gelcap NaN 0.000090 NaN
MA1-OX-r NaN None NaN IRM-VSM3-LP-HYS-239373 0.009699 1.141000e-04 NaN 0.117200 0.829900 1.039000e-06 ... NaN NaN NaN NaN None MA1-1 MA1-OX-r NaN 0.000113 NaN
MA1-OX-r NaN None NaN IRM-VSM4-LP-HYS-239361 0.009273 -1.335000e-04 NaN 0.113600 0.907100 1.014000e-06 ... NaN NaN NaN NaN None MA1-1 MA1-OX-r NaN 0.000113 NaN
MA1-OX-r NaN None NaN IRM-VSM4-LP-HYS-239360 0.009273 -1.335000e-04 NaN 0.113600 0.907100 1.014000e-06 ... NaN NaN NaN NaN None MA1-1 MA1-OX-r NaN 0.000113 NaN
MA1-OX-r NaN None NaN IRM-VSM4-LP-HYS-239377 0.008366 -1.466000e-04 NaN 0.135500 0.906200 1.013000e-06 ... NaN NaN NaN NaN None MA1-1 MA1-OX-r NaN 0.000113 NaN
SJ1-4-r gelcap NaN None NaN IRM-VSM4-LP-HYS-239362 0.005387 -5.115000e-05 NaN 0.002785 0.068540 6.427000e-09 ... NaN NaN NaN NaN None SJ1-4-r SJ1-4-r gelcap NaN 0.000069 NaN
SJ5-5-r gelcap NaN None NaN IRM-VSM3-LP-HYS-239368 0.003830 1.238000e-04 NaN 0.079200 2.135000 1.985000e-07 ... NaN NaN NaN NaN None SJ5-5-r SJ5-5-r gelcap NaN 0.000143 NaN
TH1-2-r NaN None NaN IRM-VSM4-LP-HYS-239383 0.009204 1.397000e-10 NaN 0.010700 0.086650 1.232000e-07 ... NaN NaN NaN NaN None TH1-1 TH1-2-r NaN 0.000087 NaN
WS3-1-r NaN None NaN IRM-VSM3-LP-HYS-239367 0.001666 1.163000e-04 NaN 0.081580 5.388000 2.708000e-07 ... NaN NaN NaN NaN None WS3-1 WS3-1-r NaN 0.000093 NaN
MA1-5-r gelcap NaN None NaN IRM-VSM3-LP-BCR-BF-239370 NaN NaN 0.0311 0.002470 NaN NaN ... 0.000000 0.000 0.1 1.0 None MA1-5-r MA1-5-r gelcap NaN 0.000090 NaN
MA1-OX-r NaN None NaN IRM-VSM3-LP-BCR-BF-239372 NaN NaN 0.0537 0.120400 NaN NaN ... 0.000000 0.113 0.1 1.0 None MA1-1 MA1-OX-r NaN 0.000113 NaN
MA1-OX-r NaN None NaN IRM-VSM4-LP-BCR-BF-239379 NaN NaN 0.0600 0.135800 NaN NaN ... 0.012450 0.083 0.1 1.8 None MA1-1 MA1-OX-r NaN 0.000113 NaN
SJ1-4-r gelcap NaN None NaN IRM-VSM4-LP-BCR-BF-239364 NaN NaN 0.0196 0.002780 NaN NaN ... 0.000027 0.894 0.1 1.8 None SJ1-4-r SJ1-4-r gelcap NaN 0.000069 0.019619
SJ5-5-r gelcap NaN None NaN IRM-VSM3-LP-BCR-BF-239369 NaN NaN 0.0152 0.079250 NaN NaN ... 0.000000 0.000 0.1 1.0 None SJ5-5-r SJ5-5-r gelcap NaN 0.000143 NaN
WS3-1-r NaN None NaN IRM-VSM3-LP-BCR-BF-239374 NaN NaN 0.0110 0.080810 NaN NaN ... 0.000000 0.940 0.1 1.0 None WS3-1 WS3-1-r NaN 0.000093 NaN

50 rows × 25 columns

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)