Skip to main content

Tools for geochemical data analysis.

Project description

pyrolite

PyPI Docs Code Style: Black License: CSIRO Modified BSD/MIT License Say Thanks

Install

pip install pyrolite

Build Status

master develop
Build Status Build Status
Coverage Status Coverage Status

Maintainer: Morgan Williams (morgan.williams at csiro.au)

Usage Examples

Note: Examples for compositional data yet to come.

Elements and Oxides

Index Generators

All Elements up to U

>>> import pyrolite.geochem.common_elements as ce
>>> ce()  # string return
['H', 'He', 'Li', 'Be', ...,  'Th', 'Pa', 'U']
>>> ce(output='formula')  # periodictable.core.Element return
[H, He, Li, Be, ...,  Th, Pa, U]

Oxides for Elements with Positive Charges (up to U)

>>> import pyrolite.geochem.common_oxides as co
>>> co()  # string return
['H2O', 'He2O', 'HeO', 'Li2O', 'Be2O', 'BeO', 'B2O', 'BO', 'B2O3', ...,
'U2O', 'UO', 'U2O3', 'UO2', 'U2O5', 'UO3']
>>> co()  # periodictable.formulas.Formula return
[H, He, Li, Be, ...,  Th, Pa, U]

REE Elements

>>> from pyrolite.geochem import REE
>>> REE()
['La', 'Ce', 'Pr', 'Nd', 'Pm', ..., 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu']

Data Cleaning

Some simple utilities for cleaning up data tables are included. Assuming you're importing data into pd.DataFrame:

import pandas as pd
df = pd.DataFrame({'label':'basalt', 'ID': 19076,
                   'mgo':20.0, 'SIO2':30.0, 'cs':5.0, 'TiO2':2.0},
                  index=[0])
>>> df.columns
Index(['label', 'ID', 'mgo', 'SIO2', 'cs', 'TiO2'], dtype='object')
from pyrolite.util.text import titlecase
from pyrolite.geochem import tochem

>>> df.columns = [titlecase(h, abbrv=['ID']) for h in df.columns]
Index(['Label', 'ID', 'Mgo', 'Sio2', 'Cs', 'Tio2'], dtype='object')
>>> df.columns = tochem(df.columns)
Index(['Label', 'ID', 'MgO', 'SiO2', 'Cs', 'TiO2'], dtype='object')

Normalisation

A selection of reference compositions are included:

>>> from pyrolite.normalisation import ReferenceCompositions
>>> refcomp = ReferenceCompositions()
{
'Chondrite_PON': Model of Chondrite (Palme2014),
'D-DMM_WH': Model of DepletedDepletedMORBMantle (Workman2005),
'DMM_WH': Model of DepletedMORBMantle (Workman2005),
'DM_SS': Model of DepletedMantle (Salters2004),
'E-DMM_WH': Model of EnrichedDepletedMORBMantle (Workman2005),
'PM_PON': Model of PrimitiveMantle (Palme2014)
}
>>> CH = refcomp['Chondrite_PON']
>>> PM = refcomp['PM_PON']
>>> CH[REE()]
      value  unc_2sigma units
var                           
La    0.2414    0.014484   ppm
Ce    0.6194    0.037164   ppm
...
Tm   0.02609    0.001565   ppm
Yb    0.1687    0.010122   ppm
Lu   0.02503    0.001502   ppm

The normalize method can be used to normalise dataframes to a given reference (e.g. for spiderplots):

>>> from pyrolite.plot import spiderplot
>>> refcomp = ReferenceCompositions()
>>> CH = refcomp['Chondrite_PON']
>>> DMM = refcomp['DMM_WH']
>>>
>>> df = DMM.data.loc[REE(), ['value']]
>>> spiderplot(CH.normalize(df), label=f'{DMM.Reference}')
SpiderPlotExample

More reference compositions will soon be included (e.g. Sun and McDonough, 1989).

Data Density Plots

Log-spaced data density plots can be useful to visualise geochemical data density:

>>> from pyrolite.plot import densityplot
>>> # with a dataframe <df> containing columns Nb/Yb and Th/Yb
>>> densityplot(df, components=['Nb/Yb', 'Th/Yb'], bins=100, logspace=True)

Below is an example of ocean island basalt data (GEOROC compilation), plotted in a 'Pearce' discrimination diagram:

Ocean Island Basalt Nb/Yb vs Th/Yb

More on these discrimination diagrams: Pearce, J.A., 2008. Geochemical fingerprinting of oceanic basalts with applications to ophiolite classification and the search for Archean oceanic crust. Lithos 100, 14–48.

Dimensional Reduction using Orthagonal Polynomials ('Lambdas')

Derivation of weight values for deconstructing a smooth function into orthagonal polynomial components (e.g. for the REE):

>>> from pyrolite.geochem import lambda_lnREE
>>> refc = 'Chondrite_PON'
>>> # with a dataframe <df> containing REE data in columns La, ..., Lu
>>> lambdas = lambda_lnREE(df, exclude=['Pm'], norm_to=refc)

![Orthagonal Polynomial Example](https://raw.githubusercontent.com/morganjwilliams/pyrolite/develop /docs/resources/LambdaExample.png)

For more on using orthagonal polynomials to describe geochemical pattern data, see: O’Neill, H.S.C., 2016. The Smoothness and Shapes of Chondrite-normalized Rare Earth Element Patterns in Basalts. J Petrology 57, 1463–1508.

Classification

Some simple discrimination methods are implemented, including the Total Alkali-Silica (TAS) classification:

>>> from pyrolite.classification import Geochemistry
>>>
>>> cm = Geochemistry.TAS()
>>> df.TotalAlkali = df.Na2O + df.K2O
>>> df['TAS'] = cm.classify(df)

This classifier can be quickly added to a bivariate plot, assuming you have data in a pandas DataFrame:

>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>>
>>> df['TotalAlkali'] = df['Na2O'] + df['K2O']
>>>
>>> fig, ax = plt.subplots(1, figsize=(6, 4))
>>> cm.add_to_axes(ax, facecolor='0.9', edgecolor='k',
>>>                linewidth=0.5, zorder=-1)
>>> classnames = cm.clsf.fclasses + ['none']
>>> df['TAScolors'] = df['TAS'].map(lambda x: classnames.index(x))
>>> ax.scatter(df.SiO2, df.TotalAlkali, c=df.TAScolors,
>>>            alpha=0.5, marker='D', s=8, cmap='tab20c')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrolite-0.0.13.tar.gz (126.4 kB view details)

Uploaded Source

Built Distribution

pyrolite-0.0.13-py3-none-any.whl (131.7 kB view details)

Uploaded Python 3

File details

Details for the file pyrolite-0.0.13.tar.gz.

File metadata

  • Download URL: pyrolite-0.0.13.tar.gz
  • Upload date:
  • Size: 126.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for pyrolite-0.0.13.tar.gz
Algorithm Hash digest
SHA256 9e8f3f221b0bf4397ff33568ebfe124f4367f06c9292d78d806d07c1216f1923
MD5 87c7db3eea037460829b0ed5864fa313
BLAKE2b-256 6b0cc8806de1c05d2a4d5072c6c2e94259ab64e5f76454e3323051a861d5c463

See more details on using hashes here.

File details

Details for the file pyrolite-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: pyrolite-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 131.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for pyrolite-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9119dee741c522bf91b122c1324c8d47cad6747e772d396b03c69fe3305f81
MD5 c445feb653764e49f00261398a2bd0ba
BLAKE2b-256 e9aeac9babc08fde4a3ebbec28f15a58f07411c65b8b8d50bd2d03ecfc74e40a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page