Metadata-Version: 2.4
Name: pyPetrograph
Version: 0.0.5
Summary: Thin-section petrography: RGB pixel labeling, multimodal grain objects, and mineral-map counts.
Author: Larry Syu-Heng Lai
License: AGPL-3.0-or-later
Project-URL: Homepage, https://github.com/GeoLarryLai/pyPetrograph
Project-URL: Repository, https://github.com/GeoLarryLai/pyPetrograph
Keywords: petrography,thin-section,mineralogy,segmentation,porosity
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pillow>=10
Requires-Dist: matplotlib>=3.7
Requires-Dist: scikit-learn>=1.3
Requires-Dist: scipy>=1.10
Requires-Dist: geopandas>=0.14
Requires-Dist: shapely>=2
Requires-Dist: rasterio>=1.3
Requires-Dist: affine>=2.4
Requires-Dist: joblib>=1.3
Requires-Dist: pandas>=2
Requires-Dist: lightgbm>=4
Requires-Dist: scikit-image>=0.22
Requires-Dist: PyQt5>=5.15
Provides-Extra: seg
Requires-Dist: tensorflow<2.22,>=2.16; extra == "seg"
Requires-Dist: keras>=3; extra == "seg"
Requires-Dist: segmenteverygrain==0.5.0; extra == "seg"
Provides-Extra: sam2
Requires-Dist: torch>=2.2; extra == "sam2"
Requires-Dist: torchvision; extra == "sam2"
Requires-Dist: sam2>=1.0; extra == "sam2"
Provides-Extra: xgb
Requires-Dist: xgboost>=2; extra == "xgb"
Provides-Extra: all
Requires-Dist: pyPetrograph[sam2,seg,xgb]; extra == "all"
Dynamic: license-file

# pyPetrograph

v0.0.5

pyPetrograph is a machine-learning toolkit for thin-section petrography. You can draw pores and grains by hand in an interactive label window (wand or polygon), train a LightGBM pixel model, and get porosity with a confidence range. You can count grains on a painted mineral map by matching legend colors and splitting grains that touch. Or you can line up plane-polarized (PPL) and cross-polarized (XPL) photos, let a U-Net outline the grains, and build one table row per object for grouping and naming.

> [!WARNING]
> This tool is under development. Use with caution. Notebooks, APIs, and numbers can still change.

> [!NOTE]
> For more careful grain-boundary detection and mapping, there is optional support for using [SegmentEveryGrain](https://github.com/zsylvester/segmenteverygrain) developed by **Zoltan Sylvester**. [SAM 2.1](https://github.com/facebookresearch/sam2) weights (~860 MB) are a further opt-in on their page, not part of the default install.

The current version is primarily developed by **Larry Syu-Heng Lai**, based on early source code scripted by **Zoltan Sylvester**, at the Quantitative Clastic Laboratory, Bureau of Economic Geology, The University of Texas at Austin. This development is also part of a collaboration with **Priyanka Periwal**, **Lucy Tingwei Ko**, **Kelly Hattori**, and **Amanda Calle** across multiple research groups and the [e-MAGE lab](https://www.beg.utexas.edu/research/labs/sem) in the Bureau of Economic Geology.

## Install

From [PyPI](https://pypi.org/project/pypetrograph/):

```bash
pip install pypetrograph
```

Alternatively, from this repo:

```bash
conda env create -f environment.yml
conda activate pypetrograph
pip install -e .
```

```bash
# Optional: finer grain-boundary mapping (SegmentEveryGrain)
# https://github.com/zsylvester/segmenteverygrain
pip install segmenteverygrain
```

This is SegmentEveryGrain’s “existing environment” path (install into the activated `pypetrograph` env). SAM 2.1 weights (~860 MB) are a further opt-in on their page, not part of this pip install.

## Demo notebooks

- [`pyPetrograph_rgb_porosity.ipynb`](pyPetrograph_rgb_porosity.ipynb) — draw labels, train LightGBM, get porosity
- [`pyPetrograph_mineralmap_count.ipynb`](pyPetrograph_mineralmap_count.ipynb) — count grains on painted mineral maps
- [`pyPetrograph_multimodal_grains.ipynb`](pyPetrograph_multimodal_grains.ipynb) — line up PPL + XPL, outline grains, build an object table

Example thin-section images are in `Test images/`. Analyzed results go to `outputs/`.

## License

GNU Affero General Public License 3.0 or later (`LICENSE`).
