Petrology tools
Project description
Lydwhitt_tools
A collection of functions and tools I have developed and find useful during my volcanology PhD.
Whilst I have a lot of tools and functions on my computer that I use regularly, I haven't yet put them all in a place to help others. There are a lot of very simple tasks that waste time, which I've created tools to complete, and I will be adding them to this repository over time.
I started collating this in August 2025 — so bear with me whilst I get it going!
Install
pip install lydwhitt-tools
Available tools
gechemical_filter(df, phase, total_perc=None, percentiles=None): This function is used to filter geochemical datasets using the Mahalanobis distance method in two passes. Please note the fuction filters out rows with totals <96 (default) prior to performing the mahalnobis test passes but re-adds them after processing so they can be plotted. dataframes will need filtering for this and both test results after function is used.
KDE(df, 'column') : This function creates a plottable KDE line for a column of values in a dataframe using the imporved sheather jones method to establish bandwidth. This methodology uses an integrated r script rather thna the usual python computing as this is more preferable in geochemical studies.
MD(x, y, z) : This function finds the value of the first peak found using the KDE function based on a minimum height threshold (may need adjusting per dataset).
iqr_one_peak(df, 'data', z) : This function finds the MD peak as with the previous function but also gives you the Q1 and Q3 range of each dataset.
recalc(df, phase, anhydrous=True, mol_values=True) : This function calculates the apfu or cation fraction of major elment data for Plg, Cpx, Ol and Liq (WR/Glass/MI) data. anhydrous needs to be specified for Liq data and if you dont want the mol fractions in the final dataframe just add the mol_values=true.
Detailed Usage
The geochemical_filter function filters geochemical datasets using the Mahalanobis distance method in two passes.
Function signature: lwt.geochemical_filter(df, phase, total_perc=None, percentiles=None)
Parameters:
phase(str) – e.g.,"Cpx","Plg","Liq". Must match the suffix used after oxide wt% values in your dataset.total_perc(float, optional) – Minimum total oxide percentage allowed. Defaults to96.percentiles(int, float, or tuple, optional) – Percentile cutoffs for Pass 1 and Pass 2.- Single value applies to both passes (e.g.,
percentiles=98). - Tuple gives different cutoffs for each pass (e.g.,
percentiles=(95, 99)).
- Single value applies to both passes (e.g.,
Example: Use different percentiles for each pass filtered_df = lwt.geochemical_filter(df, phase="Plg", total_perc=97, percentiles=(95, 99))
Output
The function returns the filtered DataFrame, including flags for each pass:
Mahalanobis– Mahalanobis distance for each row in the given pass.P1_Outlier– Boolean flag indicating if the row was an outlier in Pass 1.P2_Outlier– Boolean flag indicating if the row was an outlier in Pass 2.
Features Coming Soon
This repository will grow to include: -formula recalculations for different phases -simple plotting frameworks -data re-oragnisation tools for popular gothermobarometry packages
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lydwhitt_tools-1.1.3.tar.gz.
File metadata
- Download URL: lydwhitt_tools-1.1.3.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4479212f6d0b4d6acb73269075b6b83eb16b7a98c3bd35f40140320b7146d41
|
|
| MD5 |
807360ae1392886714ac7fe88add03cd
|
|
| BLAKE2b-256 |
0a953f303edef1f782c85ebf3f43a6806c30fc2f6d8cbe41cb759e7c111d71ff
|
Provenance
The following attestation bundles were made for lydwhitt_tools-1.1.3.tar.gz:
Publisher:
publish.yml on lydwhitt7/Lydwhitt_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lydwhitt_tools-1.1.3.tar.gz -
Subject digest:
b4479212f6d0b4d6acb73269075b6b83eb16b7a98c3bd35f40140320b7146d41 - Sigstore transparency entry: 676702921
- Sigstore integration time:
-
Permalink:
lydwhitt7/Lydwhitt_tools@a368472689cfdbd00dd1226b1e19cd0348a765ce -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/lydwhitt7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a368472689cfdbd00dd1226b1e19cd0348a765ce -
Trigger Event:
push
-
Statement type:
File details
Details for the file lydwhitt_tools-1.1.3-py3-none-any.whl.
File metadata
- Download URL: lydwhitt_tools-1.1.3-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee71d022caab0a539f41c7c004ad46d5e8855842da9dafcc56fbb1fe7e7bac2d
|
|
| MD5 |
62f5aeb738fe4649201e7b23e0695a3d
|
|
| BLAKE2b-256 |
649086ce459914c8e336ebb382a3f57a31ed3e56d3debd01deaa49c6a83c18db
|
Provenance
The following attestation bundles were made for lydwhitt_tools-1.1.3-py3-none-any.whl:
Publisher:
publish.yml on lydwhitt7/Lydwhitt_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lydwhitt_tools-1.1.3-py3-none-any.whl -
Subject digest:
ee71d022caab0a539f41c7c004ad46d5e8855842da9dafcc56fbb1fe7e7bac2d - Sigstore transparency entry: 676702924
- Sigstore integration time:
-
Permalink:
lydwhitt7/Lydwhitt_tools@a368472689cfdbd00dd1226b1e19cd0348a765ce -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/lydwhitt7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a368472689cfdbd00dd1226b1e19cd0348a765ce -
Trigger Event:
push
-
Statement type: