MagmaFrame basics

import MagmaPandas as mp
import pandas as pd

You read in .csv files with the read functions. Each phase has it’s own read function, e.g. read_melt(), and MagmaPandas currently supports melt, olivine, clinopyroxene and plagioclase.

All read functions eventually call pandas.read_csv(), where all keyword arguments get passed. The read functions expect all data to be in oxide wt. %, but anions can be kept as elements.

melt_file = "./data/melts.csv"
olivine_file = "./data/olivines.csv"

melt = mp.read_melt(melt_file, index_col=["name"])
olivine = mp.read_olivine(olivine_file, index_col=["name"])

Data can also be read directly to a MagmaFrame, using the same syntax as pandas DataFrames, with the exception that datatype (’cation’, ‘oxide’) and units (’mol fraction’, ‘wt. %’, ‘ppm’)) need to be specified.

Currently available MagmaFrames are MagmaFrame, Melt, Olivine, Clinopyroxene, Plagioclase, Magnetite and Ilmenite.

mp.Olivine({"SiO2": [38.5, 37.9], "FeO": [16.0, 15.9], "MgO": [44.4, 44.3]}, datatype="oxide", units="wt.%", index=["ol_1", "ol_2"])
SiO2 FeO MgO
ol_1 38.5 16.0 44.4
ol_2 37.9 15.9 44.3

MagmaFrames and MagmaSeries have the underlying structure of pandas DataFrames and Series and can use all of their methods:

isinstance(melt, pd.DataFrame), isinstance(melt.iloc[0], pd.Series)
(True, True)
melt.describe()
SiO2 Al2O3 MgO CaO FeO Na2O K2O MnO TiO2 P2O5 CO2 H2O F S Cl total
count 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000 10.0
mean 47.372314 16.205420 5.741570 9.981250 10.436615 3.779319 1.225155 0.144397 2.945412 0.557252 0.567206 0.786400 0.079962 0.122889 0.050053 100.0
std 1.665998 1.183514 1.279253 0.740269 1.042155 0.592292 0.278210 0.038657 0.600600 0.155661 0.174596 0.416988 0.014664 0.034545 0.013133 0.0
min 45.313339 14.539062 3.775658 8.926491 8.398151 3.177835 0.697769 0.088899 1.776185 0.289823 0.290155 0.293341 0.047654 0.068020 0.021157 100.0
25% 45.888515 15.511612 4.770648 9.454504 9.799938 3.364238 1.094556 0.133134 2.574574 0.526417 0.466633 0.491966 0.076888 0.095440 0.046920 100.0
50% 47.041178 15.831492 6.508831 9.941332 10.508595 3.650875 1.229554 0.136828 2.978823 0.562128 0.568718 0.637588 0.080606 0.127715 0.054831 100.0
75% 49.051739 16.970617 6.720004 10.372511 11.378910 3.949751 1.405008 0.151190 3.481313 0.619686 0.664343 1.106909 0.083603 0.144384 0.057558 100.0
max 49.402603 18.546715 6.909844 11.175276 11.619787 4.960919 1.603096 0.235836 3.635525 0.823385 0.821116 1.440208 0.107461 0.165884 0.063402 100.0
olivine[["FeO", "MgO"]].sum(axis=1)
name
PI032-01-04    60.431599
PI032-02-01    60.230499
PI032-02-03    60.134102
PI032-03-01    60.052002
PI032-04-01    60.175400
PI032-04-02    59.365799
PI032-04-03    59.394402
PI032-05-01    58.552601
PI041-02-01    61.860100
PI041-02-02    61.831001
dtype: float32

MagmaFrames have extra functionality for easy processing of geochemical data.

The elements and weights attributes store the names and atomic weights of all elements in the dataset as lists and Series:

melt.elements
['SiO2',
 'Al2O3',
 'MgO',
 'CaO',
 'FeO',
 'Na2O',
 'K2O',
 'MnO',
 'TiO2',
 'P2O5',
 'CO2',
 'H2O',
 'F',
 'S',
 'Cl']
melt.weights
SiO2      60.084
Al2O3    101.961
MgO       40.304
CaO       56.077
FeO       71.844
Na2O      61.979
K2O       94.195
MnO       70.937
TiO2      79.865
P2O5     141.943
CO2       44.008
H2O       18.015
F         18.998
S         32.065
Cl        35.453
dtype: float64
olivine.weights
SiO2      60.084
FeO       71.844
MgO       40.304
NiO       74.692
MnO       70.937
Al2O3    101.961
CaO       56.077
dtype: float64

Conversion to moles or cations is done via their respective methods:

cations = melt.cations()
cations
Si Al Mg Ca Fe Na K Mn Ti P C H F S Cl total
name
PI032-04-01 0.423566 0.146914 0.083195 0.092404 0.069965 0.062127 0.007632 0.000962 0.016439 0.002104 0.007357 0.082367 0.002138 0.002337 0.000493 0
PI032-04-02 0.421017 0.153607 0.083655 0.089501 0.071579 0.059583 0.010342 0.000992 0.017205 0.002455 0.007914 0.076539 0.002287 0.002672 0.000651 1
PI041-02-02 0.440556 0.179154 0.064994 0.088247 0.076789 0.065876 0.012331 0.001164 0.018921 0.004260 0.005680 0.039212 0.001352 0.001143 0.000322 1
PI041-03-01 0.417493 0.168724 0.093611 0.107072 0.081920 0.058963 0.013273 0.000863 0.021558 0.004247 0.009897 0.017782 0.002285 0.001479 0.000834 1
PI041-03-03 0.411283 0.170187 0.092439 0.108679 0.083246 0.060141 0.013519 0.000683 0.022277 0.003979 0.010175 0.018837 0.002346 0.001352 0.000854 1
PI041-05-04 0.428213 0.196165 0.051783 0.090160 0.072193 0.079850 0.018354 0.001047 0.016752 0.006256 0.006236 0.027574 0.002485 0.002038 0.000896 1
PI041-05-06 0.417089 0.179991 0.063569 0.086035 0.087416 0.069824 0.016266 0.001278 0.024603 0.004720 0.007864 0.035161 0.003057 0.002160 0.000967 1
PI041-07-01 0.403627 0.160385 0.088377 0.092641 0.084973 0.054227 0.014502 0.001081 0.023742 0.004197 0.005705 0.060833 0.002122 0.002736 0.000853 0
PI041-07-02 0.412226 0.165864 0.089394 0.097529 0.086552 0.055886 0.015681 0.001028 0.024030 0.004713 0.004592 0.037147 0.002103 0.002377 0.000879 1
PI052-01-02 0.426492 0.174757 0.048698 0.096906 0.060765 0.083217 0.017035 0.001728 0.011561 0.005051 0.003427 0.065241 0.002265 0.002063 0.000793 1
moles = melt.moles()
moles
SiO2 Al2O3 MgO CaO FeO Na2O K2O MnO TiO2 P2O5 CO2 H2O F S Cl total
name
PI032-04-01 0.498648 0.086478 0.097943 0.108783 0.082367 0.036570 0.004492 0.001133 0.019353 0.001238 0.008661 0.048484 0.002517 0.002751 0.000581 1.0
PI032-04-02 0.496051 0.090491 0.098564 0.105452 0.084336 0.035101 0.006093 0.001169 0.020272 0.001446 0.009325 0.045090 0.002695 0.003148 0.000767 1.0
PI041-02-02 0.518555 0.105437 0.076501 0.103871 0.090384 0.038769 0.007257 0.001370 0.022270 0.002507 0.006686 0.023077 0.001591 0.001345 0.000378 1.0
PI041-03-01 0.480702 0.097135 0.107784 0.123283 0.094322 0.033945 0.007641 0.000994 0.024822 0.002445 0.011396 0.010237 0.002631 0.001703 0.000960 1.0
PI041-03-03 0.474557 0.098185 0.106660 0.125399 0.096053 0.034697 0.007800 0.000789 0.025705 0.002296 0.011741 0.010868 0.002706 0.001560 0.000986 1.0
PI041-05-04 0.512278 0.117337 0.061949 0.107859 0.086365 0.047763 0.010978 0.001253 0.020040 0.003742 0.007460 0.016494 0.002973 0.002438 0.001071 1.0
PI041-05-06 0.492420 0.106249 0.075050 0.101574 0.103204 0.041217 0.009602 0.001508 0.029047 0.002786 0.009285 0.020756 0.003609 0.002551 0.001141 1.0
PI041-07-01 0.473225 0.094020 0.103617 0.108615 0.099625 0.031789 0.008501 0.001267 0.027836 0.002460 0.006689 0.035661 0.002488 0.003207 0.001000 1.0
PI041-07-02 0.479135 0.096393 0.103903 0.113359 0.100600 0.032479 0.009113 0.001195 0.027930 0.002739 0.005337 0.021588 0.002444 0.002763 0.001021 1.0
PI052-01-02 0.515492 0.105613 0.058860 0.117128 0.073446 0.050291 0.010295 0.002089 0.013974 0.003052 0.004143 0.039428 0.002737 0.002494 0.000958 1.0

the units attribute shows the data type and units:

melt.units, cations.units, moles.units
('oxide wt.%', 'cation mol fraction', 'oxide mol fraction')