RSAbs 0.8__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rsabs-2.0.0/LICENSE.txt +17 -0
- rsabs-2.0.0/PKG-INFO +310 -0
- rsabs-2.0.0/README.md +283 -0
- rsabs-2.0.0/RSAbs/__init__.py +63 -0
- rsabs-2.0.0/RSAbs/compat.py +79 -0
- rsabs-2.0.0/RSAbs/core.py +464 -0
- rsabs-2.0.0/RSAbs/data/usgs_minerals_lut_cr.csv.gz +0 -0
- rsabs-2.0.0/RSAbs/data/usgs_minerals_lut_raw.csv.gz +0 -0
- rsabs-2.0.0/RSAbs/features.py +354 -0
- rsabs-2.0.0/RSAbs/library.py +793 -0
- rsabs-2.0.0/RSAbs/preprocessing.py +412 -0
- rsabs-2.0.0/RSAbs/viewer.py +270 -0
- rsabs-2.0.0/RSAbs/visualization.py +232 -0
- rsabs-2.0.0/RSAbs.egg-info/PKG-INFO +310 -0
- rsabs-2.0.0/RSAbs.egg-info/SOURCES.txt +26 -0
- rsabs-2.0.0/RSAbs.egg-info/dependency_links.txt +1 -0
- rsabs-2.0.0/RSAbs.egg-info/entry_points.txt +2 -0
- rsabs-2.0.0/RSAbs.egg-info/requires.txt +4 -0
- rsabs-2.0.0/RSAbs.egg-info/top_level.txt +1 -0
- rsabs-2.0.0/pyproject.toml +45 -0
- rsabs-2.0.0/setup.cfg +7 -0
- rsabs-2.0.0/setup.py +3 -0
- rsabs-2.0.0/tests/test_rsabs.py +298 -0
- RSAbs-0.8/PKG-INFO +0 -25
- RSAbs-0.8/RSAbs/__init__.py +0 -2
- RSAbs-0.8/setup.cfg +0 -3
- RSAbs-0.8/setup.py +0 -34
- {RSAbs-0.8 → rsabs-2.0.0}/RSAbs/absorptions.py +0 -0
- {RSAbs-0.8 → rsabs-2.0.0}/RSAbs/absorptions_depth.py +0 -0
- {RSAbs-0.8 → rsabs-2.0.0}/RSAbs/seek_absorptions.py +0 -0
- {RSAbs-0.8 → rsabs-2.0.0}/RSAbs/seek_absorptions_depth.py +0 -0
rsabs-2.0.0/LICENSE.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 MARK RADWIN
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
rsabs-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RSAbs
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Reflectance Spectroscopy Absorption Detection, Characterization, and Mineral Identification
|
|
5
|
+
Author-email: Mark Radwin <markradwin@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/radwinskis/RSAbs
|
|
8
|
+
Keywords: REFLECTANCE,SPECTROSCOPY,HYPERSPECTRAL,ABSORPTION,USGS,MINERALOGY
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE.txt
|
|
22
|
+
Requires-Dist: numpy>=1.24
|
|
23
|
+
Requires-Dist: scipy>=1.10
|
|
24
|
+
Requires-Dist: pandas>=2.0
|
|
25
|
+
Requires-Dist: matplotlib>=3.7
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# RSAbs v2.0
|
|
29
|
+
|
|
30
|
+
**Reflectance Spectroscopy Absorption Detection, Characterization, and Mineral Identification**
|
|
31
|
+
|
|
32
|
+
`RSAbs` is a Windows-friendly, open-source Python package for **VSWIR (350 to 2500 nm)** reflectance spectroscopy analysis (e.g., ASD FieldSpec 3, HyMap, and resampled multispectral sensors). It provides an object-oriented workflow (`SpectralAnalyzer`) for spectral preprocessing, sub-band absorption feature parameterization, feature filtering, interactive visualization, and multi-stage mineral identification against embedded **USGS Spectral Library Version 7 (`splib07a`)** lookup tables.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Architecture & Workflow Overview
|
|
37
|
+
|
|
38
|
+
```mermaid
|
|
39
|
+
flowchart LR
|
|
40
|
+
A["Raw or CR Spectra\n(CSV, DataFrame, ndarray)"] --> B["Preprocessing\nSplice Correct • Smooth\nMask • Continuum Remove\nResample"]
|
|
41
|
+
B --> C["Feature Extraction\nfind_peaks + Parabolic Fit\nDepth • FWHM • Asymmetry • Area"]
|
|
42
|
+
C --> D["Feature Filtering\nWavelength • Depth\nFWHM • Prominence • Area"]
|
|
43
|
+
C --> E["Mineral Identification\nStage 1: IDF + Region-Aware Kernel\nStage 2: Group Tie-Breaking\nStage 3: Iterative Residual Scoring"]
|
|
44
|
+
F["Embedded USGS splib07a LUTs\n(CR: 15,546 feats | RAW: 6,768 feats)\n+ Utah Environment Presets"] --> E
|
|
45
|
+
B --> G["Visualization\nsa.plot() & rsabs-viewer"]
|
|
46
|
+
C --> G
|
|
47
|
+
E --> G
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
`RSAbs` uses PEP 517 packaging via `pyproject.toml` and bundles the compressed USGS `splib07a` lookup tables directly inside `RSAbs/data/`.
|
|
55
|
+
|
|
56
|
+
**PyPI (pip):**
|
|
57
|
+
```bash
|
|
58
|
+
pip install RSAbs
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Conda (conda-forge):**
|
|
62
|
+
```bash
|
|
63
|
+
conda install -c conda-forge rsabs
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**From source (editable/development install):**
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/radwinskis/RSAbs.git
|
|
69
|
+
cd RSAbs
|
|
70
|
+
pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Dependencies:** `numpy>=1.24`, `scipy>=1.10`, `pandas>=2.0`, `matplotlib>=3.7` (Python `>=3.9`).
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 1. Spectral Preprocessing Methodology (`RSAbs.preprocessing`)
|
|
78
|
+
|
|
79
|
+
### 1.1 ASD FieldSpec 3 Splice Correction (`splice_correction`)
|
|
80
|
+
ASD FieldSpec 3 spectroradiometers use three detectors: VNIR Si (350 to 1000 nm), SWIR1 InGaAs (1001 to 1800 nm), and SWIR2 InGaAs (1801 to 2500 nm). These commonly exhibit step discontinuities at **1000 nm** and **1800 nm** due to fiber-optic bundle geometry and thermal drift (Hueni et al., 2017). Following standard ASD practice:
|
|
81
|
+
- **SWIR1 (1001 to 1800 nm)** is treated as the stable reference detector.
|
|
82
|
+
- A local linear fit (`fit_bands=5` adjacent SWIR1 bands) extrapolates expected reflectance across each boundary (1000 nm and 1800 nm).
|
|
83
|
+
- The offset $\Delta = R_{\text{extrap}} - R_{\text{edge}}$ is applied to the VNIR and SWIR2 segments either as a constant shift (`method="offset"`) or as a linearly tapered VNIR shift (`method="linear"`).
|
|
84
|
+
|
|
85
|
+
### 1.2 Smoothing & Bad-Band Masking (`smooth_spectra`, `mask_bands`)
|
|
86
|
+
- **Smoothing:** Savitzky-Golay polynomial smoothing (Savitzky & Golay, 1964; `window_length=11`, `polyorder=2`), moving average, or 1D Gaussian filtering.
|
|
87
|
+
- **Atmospheric Water-Vapor Masking:** Masks or linearly interpolates across standard noisy regions (`1350 to 1420 nm`, `1800 to 1960 nm`, `2420 to 2500 nm`, or custom intervals).
|
|
88
|
+
|
|
89
|
+
### 1.3 Upper Convex Hull Continuum Removal (`continuum_removal`)
|
|
90
|
+
Following Clark & Roush (1984), continuum removal isolates absorption features from background albedo and illumination slope:
|
|
91
|
+
- `RSAbs` computes the exact **upper convex hull** $C(\lambda)$ of $(\lambda, R(\lambda))$ in $O(N)$ time using Andrew's monotone chain algorithm (immune to collinearity errors on flat or noisy spectra).
|
|
92
|
+
- Continuum-removed reflectance is normalized as:
|
|
93
|
+
$$R_{CR}(\lambda) = \frac{R(\lambda)}{C(\lambda)}$$
|
|
94
|
+
- A local linear baseline (`method="linear"`) over a user-defined `window=(start_nm, end_nm)` is also supported.
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
### 1.4 Gaussian SRF Spectral Resampling (`resample_spectra`)
|
|
99
|
+
To bridge laboratory spectroscopy and satellite/airborne sensors, `RSAbs` resamples spectra using normalized **Gaussian Spectral Response Functions (SRFs)** parameterized by each target band's center wavelength $\lambda_j$ and Full Width at Half Maximum ($\text{FWHM}_j$, where $\sigma_j = \text{FWHM}_j / (2\sqrt{2\ln 2})$). Built-in presets include **`landsat8`**, **`landsat9`**, **`sentinel2`**, **`aster`**, and **`asd_1nm`**, plus arbitrary custom wavelength and FWHM arrays.
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 2. Absorption Detection & Geometric Parameterization (`RSAbs.features`)
|
|
106
|
+
|
|
107
|
+
### 2.1 Physical-Unit Peak Detection & Sub-Band Parabolic Refinement
|
|
108
|
+
1. **Local Minima Detection:** `scipy.signal.find_peaks(-R)` is parameterized in **physical wavelength units (nm)** (`min_distance_nm=10.0`, `min_width_nm=4.0`, `min_prominence=0.002`) converted dynamically via the spectrum's median sampling interval $\Delta\lambda$, making detection invariant to spectral resolution.
|
|
109
|
+
2. **Sub-Band Quadratic Interpolation (`_parabolic_minimum`):** To overcome discrete band-grid quantization, a 3-point parabola $y(\Delta\lambda) = a\,\Delta\lambda^2 + b\,\Delta\lambda + c$ is fit to each minimum and its immediate neighbors $(\lambda_{i-1}, \lambda_i, \lambda_{i+1})$ (Rodger et al., 2012):
|
|
110
|
+
$$\lambda_{\min} = \lambda_i - \frac{b}{2a}, \qquad R_{\min} = a(\lambda_{\min}-\lambda_i)^2 + b(\lambda_{\min}-\lambda_i) + c$$
|
|
111
|
+
|
|
112
|
+
### 2.2 Depth, Shoulders, FWHM, Area, and Asymmetry
|
|
113
|
+
For each detected feature between its flanking shoulders $(\lambda_L, \lambda_R)$ (`left_bases` and `right_bases` from `find_peaks`):
|
|
114
|
+
- **Band Depth ($D$):**
|
|
115
|
+
- *Continuum-removed spectra:* $D = 1 - R_{\min}$ (Clark & Roush, 1984).
|
|
116
|
+
- *Normal (non-CR) spectra:* A local linear continuum $C_{\text{loc}}(\lambda)$ is interpolated between $(\lambda_L, R_L)$ and $(\lambda_R, R_R)$, giving $D = 1 - R_{\min} / C_{\text{loc}}(\lambda_{\min})$.
|
|
117
|
+
- **Full Width at Half Maximum ($\text{FWHM}$):** Distance $\lambda_{\text{half}, R} - \lambda_{\text{half}, L}$ where the absorption depth profile $d(\lambda) = 1 - R_{\text{loc}}(\lambda)$ crosses $D/2$ on each flank.
|
|
118
|
+
- **Integrated Band Area (`area`):** Trapezoidal integral $\int_{\lambda_L}^{\lambda_R} d(\lambda)\,d\lambda$.
|
|
119
|
+
- **Normalized Area Asymmetry (`asymmetry`):** Bounded in $[-1, +1]$ following van der Meer (2004):
|
|
120
|
+
$$S = \frac{A_{\text{right}} - A_{\text{left}}}{A_{\text{right}} + A_{\text{left}}}$$
|
|
121
|
+
where $S < 0$ indicates skewness toward shorter wavelengths and $S > 0$ indicates skewness toward longer wavelengths.
|
|
122
|
+
|
|
123
|
+

|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 3. Embedded USGS `splib07a` Lookup Tables & Mineral Identification (`RSAbs.library`)
|
|
128
|
+
|
|
129
|
+
### 3.1 Dual Like-to-Like Lookup Tables
|
|
130
|
+
Because continuum removal shifts apparent absorption minima on sloped backgrounds (Clark & Roush, 1984), `RSAbs` embeds **two separate lookup tables** generated from the USGS Spectral Library Version 7 (`splib07a`, Chapter M: Minerals; Kokaly et al., 2017) using `RSAbs`'s own feature extraction pipeline (`scripts/build_usgs_library.py`):
|
|
131
|
+
- **`usgs_minerals_lut_cr.csv.gz`**: **15,546 features** across **1,263 spectra** (**224 unique minerals**), extracted after upper convex hull continuum removal.
|
|
132
|
+
- **`usgs_minerals_lut_raw.csv.gz`**: **6,768 features** across **1,181 spectra** (**222 unique minerals**), extracted directly from raw reflectance using local-continuum baselines.
|
|
133
|
+
|
|
134
|
+
`SpectralAnalyzer.identify_minerals()` automatically selects the matching table based on `self.continuum_removed` and emits a `UserWarning` if `continuum_removed=False` is passed on data whose column maxima are pinned near `1.0`.
|
|
135
|
+
|
|
136
|
+
### 3.2 Multi-Stage Mineral Scoring & Discrimination
|
|
137
|
+
|
|
138
|
+
#### Stage 1: IDF Specificity Weighting, Region-Aware Distance, & Matching Modes
|
|
139
|
+
1. **Why Inverse Mineral Frequency (IDF) Weighting Is Used:**
|
|
140
|
+
In VSWIR spectroscopy, ubiquitous hydroxyl and molecular water bands near ~1400 nm and ~1920 nm occur in more than half of all hydrous minerals as well as adsorbed surface moisture. Without specificity weighting, these deep water bands dominate depth-weighted comparisons and allow unrelated hydrated minerals to outrank diagnostic matches. Across all 224 minerals, each 20 nm wavelength bin receives an IDF weight:
|
|
141
|
+
$$\text{IDF}(\lambda) = \ln\!\left(\frac{N_{\text{minerals}} + 1}{n_{\text{minerals}}(\lambda) + 1}\right) + 0.5$$
|
|
142
|
+
Common bands (~1400 nm, ~1920 nm) receive lower weights, while mineral-diagnostic bands (e.g., 1765 nm alunite, 2165 nm kaolinite, 2265 nm jarosite, 2315 to 2340 nm carbonates) receive higher weights. Each reference feature is weighted by $\text{importance} = \text{depth} \times \text{IDF}(\lambda)$.
|
|
143
|
+
2. **Region-Aware Gaussian Wavelength Kernel:**
|
|
144
|
+
Crystal-field absorptions in the VNIR (< 1100 nm) are broad and commonly shift 15 to 40 nm with Fe/Al substitution, whereas vibrational bands in the SWIR (>= 1100 nm) are narrow and typically shift only 5 to 20 nm. `RSAbs` uses greedy 1-to-1 matching within $3\sigma$ with region-specific scales:
|
|
145
|
+
$$s_\lambda(\Delta\lambda) = \exp\!\left(-\frac{1}{2}\left(\frac{\Delta\lambda}{\sigma_{\text{region}}}\right)^2\right), \quad \sigma_{\text{VNIR}} = 20\text{ nm}, \quad \sigma_{\text{SWIR}} = 8\text{ nm}$$
|
|
146
|
+
3. **Suite-Completeness & Diagnostic-Presence Rules:**
|
|
147
|
+
- `min_ref_coverage=0.5`: Rejects candidates where fewer than 50% of the reference mineral's expected absorption suite is observed, preventing 10- to 18-band minerals from being identified from only 1 or 2 overlapping bands.
|
|
148
|
+
- `require_top_diagnostic=True`: Requires the mineral's #1 diagnostic band (and at least 2 of its top 3 for >= 3-band minerals) to be matched.
|
|
149
|
+
4. **Choosing Between `mode="mixture"` and `mode="pure"`:**
|
|
150
|
+
- **`mode="mixture"` (default):** Evaluates $0.65\,\text{recall}_{\text{ref}} + 0.35\,\text{coverage}_{\text{obs}}$ using wavelength position and IDF weighting only. Use this for natural rocks, soils, lakebed sediments, and dust samples where multiple minerals co-occur: extra bands from co-occurring minerals are not penalized, and overlapping shoulders or grain-size variations do not distort the score through FWHM or depth-ratio penalties.
|
|
151
|
+
- **`mode="pure"`:** Adds FWHM similarity, asymmetry similarity, and relative depth-ratio cosine similarity (`depth_ratio_sim`). Use this when characterizing clean, single-phase laboratory standards or mineral separates where both band positions and band shapes should match the reference spectrum.
|
|
152
|
+
|
|
153
|
+
#### Stage 2: Literature-Based Mineral-Group Tie-Breaking (`discriminate_groups=True`)
|
|
154
|
+
When candidates belong to overlapping mineral groups, targeted rules refine scores:
|
|
155
|
+
- **Al-OH Phyllosilicates (`Kaolinite`, `Dickite`, `Illite`, `Muscovite`, `Montmorillonite`):**
|
|
156
|
+
- `~2165 nm` doublet/shoulder separates kaolin-group minerals from illite, muscovite, and montmorillonite (Clark et al., 1990).
|
|
157
|
+
- Secondary `~2348 / 2435 nm` bands separate muscovite and illite from montmorillonite (Clark et al., 1990; Post & Noble, 1993).
|
|
158
|
+
- Hydration ratio $D_{1900}/D_{2200}$ and $\text{FWHM}_{2200}$ separate montmorillonite (> 1.1), illite (0.35 to 1.1, broader FWHM), and muscovite (< 0.35, sharp $\text{FWHM} < 45\text{ nm}$) when `2165 nm` is absent and no hydrated sulfate owns the `1940 nm` band (Post & Noble, 1993; Duke, 1994; Doublier et al., 2010).
|
|
159
|
+
- **Carbonates (`Aragonite`, `Dolomite`, `Calcite`):** Discriminated by sub-band $\text{CO}_3^{2-}$ position (< 2318 nm aragonite, 2318 to 2328 nm dolomite, >= 2332 nm calcite; Gaffey, 1986).
|
|
160
|
+
- **Fe3+ Oxides & Sulfates (`Hematite`, `Goethite`, `Jarosite`):** Discriminated using the 850 to 960 nm crystal-field band (< 890 nm hematite vs. 895 to 935 nm goethite; Sherman & Waite, 1985) and 2255 to 2275 nm Fe-OH + 905 to 955 nm for jarosite (Swayze et al., 2000), intentionally avoiding the noisy ~400 nm UV/blue edge.
|
|
161
|
+

|
|
162
|
+
#### Stage 3: Iterative Residual Scoring (`suppress_subsets=True`)
|
|
163
|
+
After selecting the highest-scoring mineral (#1), `RSAbs` marks its matched observed bands as **explained** and re-scores all remaining candidates **solely on unexplained bands** (`residual_score >= min_residual_score=0.12`). Secondary candidates whose matched bands are already accounted for by higher-scoring minerals are suppressed, while genuine secondary phases that explain remaining features (e.g., aragonite `2314 nm` or muscovite `2211 nm` alongside gypsum) are retained.
|
|
164
|
+
|
|
165
|
+
#### Stage 4: Geological Environment Presets (`environment=...`)
|
|
166
|
+
To prevent exotic, geologically implausible phases from appearing due to coincidental overlap on weak bands, `identify_minerals()` supports `include_minerals`, `exclude_minerals`, and five built-in depositional and geological environment presets (`ENVIRONMENT_PRESETS`) which will be expanded in the future (currently based on localities present in Utah):
|
|
167
|
+
|
|
168
|
+
| Environment Preset | Representative Utah Localities | Included Minerals (Matched to USGS `splib07a` LUT) |
|
|
169
|
+
| :--- | :--- | :--- |
|
|
170
|
+
| **`evaporite_playa`** | Great Salt Lake, Bonneville Salt Flats, Sevier Lake | `Gypsum`, `Anhydrite`, `Bassanite`, `Mirabilite`, `Thenardite`, `Bloedite`, `Epsomite`, `Kieserite`, `Polyhalite`, `Kainite`, `Halite`, `Carnallite`, `Syngenite`, `Aragonite`, `Calcite`, `Dolomite`, `Trona`, `Gaylussite`, `Sodium Bicarbonate`, `Colemanite`, `Ulexite`, `Tincalconite`, `Illite`, `Montmorillonite`, `Hectorite`, `Saponite`, `Nontronite`, `Kaolinite`, `Palygorskite`, `Sepiolite`, `Muscovite`, `Chlorite`, `Quartz`, `Opal`, `Albite`, `Microcline`, `Orthoclase`, `Hematite`, `Goethite`, `Ferrihydrite` |
|
|
171
|
+
| **`lacustrine_carbonate`** | Green River Fm, Lake Bonneville Marls, Uinta Basin | `Calcite`, `Dolomite`, `Aragonite`, `Siderite`, `Trona`, `Gaylussite`, `Analcime`, `Illite`, `Kaolinite`, `Montmorillonite`, `Saponite`, `Muscovite`, `Chlorite`, `Corrensite`, `Rectorite`, `Quartz`, `Opal`, `Chert`, `Albite`, `Orthoclase`, `Microcline`, `Gypsum`, `Anhydrite`, `Pyrite`, `Hematite`, `Goethite` |
|
|
172
|
+
| **`clastic_redbed`** | Colorado Plateau (Navajo, Wingate, Entrada, Chinle, Lisbon Valley) | `Hematite`, `Nanohematite`, `Goethite`, `Ferrihydrite`, `Lepidocrocite`, `Limonite`, `Maghemite`, `Kaolinite`, `Dickite`, `Illite`, `Montmorillonite`, `Muscovite`, `Chlorite`, `Rectorite`, `Glauconite`, `Quartz`, `Chert`, `Chalcedony`, `Opal`, `Calcite`, `Dolomite`, `Gypsum`, `Anhydrite`, `Barite`, `Albite`, `Microcline`, `Orthoclase`, `Sanidine` |
|
|
173
|
+
| **`hydrothermal_alteration`** | Marysvale Volcanic Field, Tintic, Bingham Canyon | `Alunite`, `Alunite K-Na`, `Alunite0.35K + .65Na`, `Alunite0.66K + .34Na`, `Alunite0.73K + .27Na`, `Jarosite`, `Ammonio-Jarosite`, `Copiapite`, `Coquimbite`, `Schwertmannite`, `Gypsum`, `Anhydrite`, `Barite`, `Sulfur`, `Kaolinite`, `Dickite`, `Nacrite`, `Halloysite`, `Pyrophyllite`, `Diaspore`, `Topaz`, `Zunyite`, `Illite`, `Ammonio-Illite/Smect`, `Muscovite`, `Paragonite`, `Montmorillonite`, `Beidellite`, `Buddingtonite`, `Chlorite`, `Clinochlore`, `Epidote`, `Calcite`, `Dolomite`, `Rhodochrosite`, `Quartz`, `Opal`, `Chalcedony`, `Hematite`, `Goethite`, `Lepidocrocite`, `Limonite`, `Pyrite`, `Malachite`, `Azurite`, `Chrysocolla` |
|
|
174
|
+
| **`marine_carbonate`** | Wasatch, Oquirrh, Confusion Range, Phosphoria Fm | `Calcite`, `Dolomite`, `Aragonite`, `Siderite`, `Quartz`, `Chert`, `Chalcedony`, `Fluorapatite`, `Hydroxyl-Apatite`, `Chlorapatite`, `Illite`, `Kaolinite`, `Glauconite`, `Muscovite`, `Chlorite`, `Goethite`, `Hematite`, `Pyrite` |
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 4. Step-by-Step Usage Guide
|
|
181
|
+
|
|
182
|
+
### Step 1: Load Spectral Data
|
|
183
|
+
Load a CSV/TXT file (with a `Wavelength` column and one column per sample), a `pd.DataFrame`, or a `np.ndarray`. Set `wavelength_unit="micrometer"` if wavelengths are in microns, and set `continuum_removed=True` if your input is already continuum-removed.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from RSAbs import SpectralAnalyzer
|
|
187
|
+
|
|
188
|
+
# Option A: Raw reflectance CSV (nm)
|
|
189
|
+
sa_raw = SpectralAnalyzer("raw_lab_spectra.csv", continuum_removed=False)
|
|
190
|
+
|
|
191
|
+
# Option B: Already continuum-removed CSV (like the included demo dataset)
|
|
192
|
+
sa = SpectralAnalyzer("demo/demo_spectra.csv", continuum_removed=True)
|
|
193
|
+
print(f"Loaded {sa.n_samples} samples across {sa.n_bands} bands.")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Step 2: Preprocess Raw Reflectance
|
|
197
|
+
Chain preprocessing steps cleanly. Each method returns a new `SpectralAnalyzer` instance without mutating your raw dataset.
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
sa_cr = (
|
|
201
|
+
sa_raw
|
|
202
|
+
.splice_correct(splice_wavelengths=(1000.0, 1800.0), method="offset")
|
|
203
|
+
.smooth(method="savgol", window_length=11, polyorder=2)
|
|
204
|
+
.mask_bands(interpolate=True) # bridges 1350-1420, 1800-1960, 2420-2500 nm
|
|
205
|
+
.continuum_remove(method="convex_hull") # sets continuum_removed=True automatically
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Step 3: Resample to Satellite or Airborne Sensors
|
|
210
|
+
Resample hyperspectral curves to multispectral bandpasses using built-in presets (`"landsat8"`, `"landsat9"`, `"sentinel2"`, `"aster"`, `"asd_1nm"`) or custom wavelengths and FWHMs.
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
landsat_sa = sa_raw.resample(target="landsat8")
|
|
214
|
+
aster_sa = sa_raw.resample(target="aster")
|
|
215
|
+
custom_sa = sa_raw.resample(target_wavelengths=[550, 660, 865, 1610, 2200], target_fwhm=20.0)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Step 4: Extract, Summarize, & Filter Absorption Features
|
|
219
|
+
Extract all absorption features (`wavelength`, `depth`, `prominence`, `fwhm`, `asymmetry`, `area`, `left_shoulder`, `right_shoulder`, `width_full`), inspect per-sample summaries, or filter by wavelength window and feature size.
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
# Per-sample summary table
|
|
223
|
+
print(sa.summary())
|
|
224
|
+
|
|
225
|
+
# Full feature table across all samples
|
|
226
|
+
features = sa.extract_features(min_depth=0.005, min_prominence=0.002)
|
|
227
|
+
|
|
228
|
+
# Filter to SWIR Al-OH / Mg-OH / carbonate features (2100 to 2380 nm) with depth >= 2%
|
|
229
|
+
swir_feats = sa.filter_features(
|
|
230
|
+
min_wavelength=2100,
|
|
231
|
+
max_wavelength=2380,
|
|
232
|
+
min_depth=0.02,
|
|
233
|
+
)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Step 5: Identify Minerals Against USGS `splib07a`
|
|
237
|
+
Run open exploration (`environment=None`) or constrain candidates to a Utah geological environment preset, custom whitelist, or blacklist.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from RSAbs import list_environments, list_usgs_minerals
|
|
241
|
+
|
|
242
|
+
# Inspect available environment presets and all 224 USGS minerals
|
|
243
|
+
print(list(list_environments().keys()))
|
|
244
|
+
|
|
245
|
+
# Recommended for natural samples / mixtures:
|
|
246
|
+
minerals = sa.identify_minerals(
|
|
247
|
+
environment="evaporite_playa",
|
|
248
|
+
mode="mixture",
|
|
249
|
+
top_n=3,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# Custom whitelist / blacklist example:
|
|
253
|
+
custom = sa.identify_minerals(
|
|
254
|
+
include_minerals=["Gypsum", "Aragonite", "Calcite", "Dolomite", "Muscovite"],
|
|
255
|
+
mode="mixture",
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Step 6: Visualize in Jupyter or Launch the Desktop Viewer
|
|
260
|
+
Plot spectra in a Jupyter Notebook with either individual feature minima (`annotation_mode="features"`) or deduplicated mineral diagnostic lines (`annotation_mode="minerals"`), or spin up the interactive desktop viewer.
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
# Publication-ready plot saved as both .jpg and .svg at 300 DPI
|
|
264
|
+
fig, ax = sa.plot(
|
|
265
|
+
annotation_mode="minerals",
|
|
266
|
+
xlim=(380, 2480),
|
|
267
|
+
ylim=(0.45, 1.05),
|
|
268
|
+
x_major_tick=200,
|
|
269
|
+
x_minor_tick=50,
|
|
270
|
+
save_path="outputs/sample_suite",
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# Spin up the interactive desktop viewer from Python
|
|
274
|
+
sa.launch_viewer()
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Or launch the desktop viewer directly from the command line:
|
|
278
|
+
```bash
|
|
279
|
+
rsabs-viewer demo/demo_spectra.csv --cr
|
|
280
|
+
# or for raw reflectance:
|
|
281
|
+
rsabs-viewer path/to/raw_spectra.csv
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Backward Compatibility (v0.8.1)
|
|
285
|
+
Legacy functional wrappers (`absorptions`, `absorptions_depth`, `seek_absorptions`, `seek_absorptions_depth`) remain available in `RSAbs.compat`.
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 5. References
|
|
290
|
+
|
|
291
|
+
- Clark, R. N., & Roush, T. L. (1984). Reflectance spectroscopy: Quantitative analysis techniques for remote sensing applications. *Journal of Geophysical Research: Solid Earth*, 89(B7), 6329–6340.
|
|
292
|
+
- Clark, R. N., King, T. V. V., Klejwa, M., Swayze, G. A., & Vergo, N. (1990). High spectral resolution reflectance spectroscopy of minerals. *Journal of Geophysical Research: Solid Earth*, 95(B8), 12653–12680.
|
|
293
|
+
- Clark, R. N., Swayze, G. A., Livo, K. E., Kokaly, R. F., Sutley, S. J., Dalton, J. B., McDougal, R. R., & Gent, C. A. (2003). Imaging spectroscopy: Earth and planetary remote sensing with the USGS Tetracorder and expert systems. *Journal of Geophysical Research: Planets*, 108(E12), 5131.
|
|
294
|
+
- Doublier, M. P., Roache, T., & Potel, S. (2010). Short-wavelength infrared spectroscopy: A new tool to determine illite crystallinity. *European Journal of Mineralogy*, 22(4), 605–618.
|
|
295
|
+
- Duke, E. F. (1994). Near infrared spectra of muscovite, Tschermak substitution, and metamorphic reaction progress. *Geology*, 22(7), 621–624.
|
|
296
|
+
- Gaffey, S. J. (1986). Spectral reflectance of carbonate minerals in the visible and near infrared (0.35–2.55 microns): Calcite, aragonite, and dolomite. *American Mineralogist*, 71(1–2), 151–162.
|
|
297
|
+
- Hueni, A., Damm, A., Kneubuehler, M., Schlaepfer, D., & Schaepman, M. E. (2017). Field and airborne spectroscopy cross validation: Some considerations. *IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing*, 10(3), 1117–1135.
|
|
298
|
+
- Kokaly, R. F., Clark, R. N., Swayze, G. A., Livo, K. E., Hoefen, T. M., Pearson, N. C., Wise, R. A., Benzel, W. M., Lowers, H. A., Driscoll, R. L., & Klein, A. J. (2017). *USGS Spectral Library Version 7* (Data Series 1035). U.S. Geological Survey.
|
|
299
|
+
- Post, J. L., & Noble, P. N. (1993). The near-infrared combination band frequencies of dioctahedral smectites, micas, and illites. *Clays and Clay Minerals*, 41(6), 639–644.
|
|
300
|
+
- Rodger, A., Laukamp, C., Haest, M., & Cudahy, T. (2012). A simple quadratic method of absorption feature wavelength estimation in continuum removed spectra. *Remote Sensing of Environment*, 118, 273–283.
|
|
301
|
+
- Savitzky, A., & Golay, M. J. E. (1964). Smoothing and differentiation of data by simplified least squares procedures. *Analytical Chemistry*, 36(8), 1627–1639.
|
|
302
|
+
- Sherman, D. M., & Waite, T. D. (1985). Electronic spectra of Fe3+ oxides and oxide hydroxides in the near IR to near UV. *American Mineralogist*, 70(11–12), 1262–1269.
|
|
303
|
+
- Swayze, G. A., Smith, K. S., Clark, R. N., Sutley, S. J., Pearson, R. M., Vance, J. S., Hageman, P. L., Briggs, P. H., Meier, A. L., Singleton, M. J., & Roth, S. (2000). Using imaging spectroscopy to map acidic mine waste. *Environmental Science & Technology*, 34(1), 47–54.
|
|
304
|
+
- van der Meer, F. (2004). Analysis of spectral absorption features in hyperspectral imagery. *International Journal of Applied Earth Observation and Geoinformation*, 5(1), 55–68.
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
MIT
|
rsabs-2.0.0/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# RSAbs v2.0
|
|
2
|
+
|
|
3
|
+
**Reflectance Spectroscopy Absorption Detection, Characterization, and Mineral Identification**
|
|
4
|
+
|
|
5
|
+
`RSAbs` is a Windows-friendly, open-source Python package for **VSWIR (350 to 2500 nm)** reflectance spectroscopy analysis (e.g., ASD FieldSpec 3, HyMap, and resampled multispectral sensors). It provides an object-oriented workflow (`SpectralAnalyzer`) for spectral preprocessing, sub-band absorption feature parameterization, feature filtering, interactive visualization, and multi-stage mineral identification against embedded **USGS Spectral Library Version 7 (`splib07a`)** lookup tables.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Architecture & Workflow Overview
|
|
10
|
+
|
|
11
|
+
```mermaid
|
|
12
|
+
flowchart LR
|
|
13
|
+
A["Raw or CR Spectra\n(CSV, DataFrame, ndarray)"] --> B["Preprocessing\nSplice Correct • Smooth\nMask • Continuum Remove\nResample"]
|
|
14
|
+
B --> C["Feature Extraction\nfind_peaks + Parabolic Fit\nDepth • FWHM • Asymmetry • Area"]
|
|
15
|
+
C --> D["Feature Filtering\nWavelength • Depth\nFWHM • Prominence • Area"]
|
|
16
|
+
C --> E["Mineral Identification\nStage 1: IDF + Region-Aware Kernel\nStage 2: Group Tie-Breaking\nStage 3: Iterative Residual Scoring"]
|
|
17
|
+
F["Embedded USGS splib07a LUTs\n(CR: 15,546 feats | RAW: 6,768 feats)\n+ Utah Environment Presets"] --> E
|
|
18
|
+
B --> G["Visualization\nsa.plot() & rsabs-viewer"]
|
|
19
|
+
C --> G
|
|
20
|
+
E --> G
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
`RSAbs` uses PEP 517 packaging via `pyproject.toml` and bundles the compressed USGS `splib07a` lookup tables directly inside `RSAbs/data/`.
|
|
28
|
+
|
|
29
|
+
**PyPI (pip):**
|
|
30
|
+
```bash
|
|
31
|
+
pip install RSAbs
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Conda (conda-forge):**
|
|
35
|
+
```bash
|
|
36
|
+
conda install -c conda-forge rsabs
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**From source (editable/development install):**
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/radwinskis/RSAbs.git
|
|
42
|
+
cd RSAbs
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Dependencies:** `numpy>=1.24`, `scipy>=1.10`, `pandas>=2.0`, `matplotlib>=3.7` (Python `>=3.9`).
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 1. Spectral Preprocessing Methodology (`RSAbs.preprocessing`)
|
|
51
|
+
|
|
52
|
+
### 1.1 ASD FieldSpec 3 Splice Correction (`splice_correction`)
|
|
53
|
+
ASD FieldSpec 3 spectroradiometers use three detectors: VNIR Si (350 to 1000 nm), SWIR1 InGaAs (1001 to 1800 nm), and SWIR2 InGaAs (1801 to 2500 nm). These commonly exhibit step discontinuities at **1000 nm** and **1800 nm** due to fiber-optic bundle geometry and thermal drift (Hueni et al., 2017). Following standard ASD practice:
|
|
54
|
+
- **SWIR1 (1001 to 1800 nm)** is treated as the stable reference detector.
|
|
55
|
+
- A local linear fit (`fit_bands=5` adjacent SWIR1 bands) extrapolates expected reflectance across each boundary (1000 nm and 1800 nm).
|
|
56
|
+
- The offset $\Delta = R_{\text{extrap}} - R_{\text{edge}}$ is applied to the VNIR and SWIR2 segments either as a constant shift (`method="offset"`) or as a linearly tapered VNIR shift (`method="linear"`).
|
|
57
|
+
|
|
58
|
+
### 1.2 Smoothing & Bad-Band Masking (`smooth_spectra`, `mask_bands`)
|
|
59
|
+
- **Smoothing:** Savitzky-Golay polynomial smoothing (Savitzky & Golay, 1964; `window_length=11`, `polyorder=2`), moving average, or 1D Gaussian filtering.
|
|
60
|
+
- **Atmospheric Water-Vapor Masking:** Masks or linearly interpolates across standard noisy regions (`1350 to 1420 nm`, `1800 to 1960 nm`, `2420 to 2500 nm`, or custom intervals).
|
|
61
|
+
|
|
62
|
+
### 1.3 Upper Convex Hull Continuum Removal (`continuum_removal`)
|
|
63
|
+
Following Clark & Roush (1984), continuum removal isolates absorption features from background albedo and illumination slope:
|
|
64
|
+
- `RSAbs` computes the exact **upper convex hull** $C(\lambda)$ of $(\lambda, R(\lambda))$ in $O(N)$ time using Andrew's monotone chain algorithm (immune to collinearity errors on flat or noisy spectra).
|
|
65
|
+
- Continuum-removed reflectance is normalized as:
|
|
66
|
+
$$R_{CR}(\lambda) = \frac{R(\lambda)}{C(\lambda)}$$
|
|
67
|
+
- A local linear baseline (`method="linear"`) over a user-defined `window=(start_nm, end_nm)` is also supported.
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
### 1.4 Gaussian SRF Spectral Resampling (`resample_spectra`)
|
|
72
|
+
To bridge laboratory spectroscopy and satellite/airborne sensors, `RSAbs` resamples spectra using normalized **Gaussian Spectral Response Functions (SRFs)** parameterized by each target band's center wavelength $\lambda_j$ and Full Width at Half Maximum ($\text{FWHM}_j$, where $\sigma_j = \text{FWHM}_j / (2\sqrt{2\ln 2})$). Built-in presets include **`landsat8`**, **`landsat9`**, **`sentinel2`**, **`aster`**, and **`asd_1nm`**, plus arbitrary custom wavelength and FWHM arrays.
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 2. Absorption Detection & Geometric Parameterization (`RSAbs.features`)
|
|
79
|
+
|
|
80
|
+
### 2.1 Physical-Unit Peak Detection & Sub-Band Parabolic Refinement
|
|
81
|
+
1. **Local Minima Detection:** `scipy.signal.find_peaks(-R)` is parameterized in **physical wavelength units (nm)** (`min_distance_nm=10.0`, `min_width_nm=4.0`, `min_prominence=0.002`) converted dynamically via the spectrum's median sampling interval $\Delta\lambda$, making detection invariant to spectral resolution.
|
|
82
|
+
2. **Sub-Band Quadratic Interpolation (`_parabolic_minimum`):** To overcome discrete band-grid quantization, a 3-point parabola $y(\Delta\lambda) = a\,\Delta\lambda^2 + b\,\Delta\lambda + c$ is fit to each minimum and its immediate neighbors $(\lambda_{i-1}, \lambda_i, \lambda_{i+1})$ (Rodger et al., 2012):
|
|
83
|
+
$$\lambda_{\min} = \lambda_i - \frac{b}{2a}, \qquad R_{\min} = a(\lambda_{\min}-\lambda_i)^2 + b(\lambda_{\min}-\lambda_i) + c$$
|
|
84
|
+
|
|
85
|
+
### 2.2 Depth, Shoulders, FWHM, Area, and Asymmetry
|
|
86
|
+
For each detected feature between its flanking shoulders $(\lambda_L, \lambda_R)$ (`left_bases` and `right_bases` from `find_peaks`):
|
|
87
|
+
- **Band Depth ($D$):**
|
|
88
|
+
- *Continuum-removed spectra:* $D = 1 - R_{\min}$ (Clark & Roush, 1984).
|
|
89
|
+
- *Normal (non-CR) spectra:* A local linear continuum $C_{\text{loc}}(\lambda)$ is interpolated between $(\lambda_L, R_L)$ and $(\lambda_R, R_R)$, giving $D = 1 - R_{\min} / C_{\text{loc}}(\lambda_{\min})$.
|
|
90
|
+
- **Full Width at Half Maximum ($\text{FWHM}$):** Distance $\lambda_{\text{half}, R} - \lambda_{\text{half}, L}$ where the absorption depth profile $d(\lambda) = 1 - R_{\text{loc}}(\lambda)$ crosses $D/2$ on each flank.
|
|
91
|
+
- **Integrated Band Area (`area`):** Trapezoidal integral $\int_{\lambda_L}^{\lambda_R} d(\lambda)\,d\lambda$.
|
|
92
|
+
- **Normalized Area Asymmetry (`asymmetry`):** Bounded in $[-1, +1]$ following van der Meer (2004):
|
|
93
|
+
$$S = \frac{A_{\text{right}} - A_{\text{left}}}{A_{\text{right}} + A_{\text{left}}}$$
|
|
94
|
+
where $S < 0$ indicates skewness toward shorter wavelengths and $S > 0$ indicates skewness toward longer wavelengths.
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 3. Embedded USGS `splib07a` Lookup Tables & Mineral Identification (`RSAbs.library`)
|
|
101
|
+
|
|
102
|
+
### 3.1 Dual Like-to-Like Lookup Tables
|
|
103
|
+
Because continuum removal shifts apparent absorption minima on sloped backgrounds (Clark & Roush, 1984), `RSAbs` embeds **two separate lookup tables** generated from the USGS Spectral Library Version 7 (`splib07a`, Chapter M: Minerals; Kokaly et al., 2017) using `RSAbs`'s own feature extraction pipeline (`scripts/build_usgs_library.py`):
|
|
104
|
+
- **`usgs_minerals_lut_cr.csv.gz`**: **15,546 features** across **1,263 spectra** (**224 unique minerals**), extracted after upper convex hull continuum removal.
|
|
105
|
+
- **`usgs_minerals_lut_raw.csv.gz`**: **6,768 features** across **1,181 spectra** (**222 unique minerals**), extracted directly from raw reflectance using local-continuum baselines.
|
|
106
|
+
|
|
107
|
+
`SpectralAnalyzer.identify_minerals()` automatically selects the matching table based on `self.continuum_removed` and emits a `UserWarning` if `continuum_removed=False` is passed on data whose column maxima are pinned near `1.0`.
|
|
108
|
+
|
|
109
|
+
### 3.2 Multi-Stage Mineral Scoring & Discrimination
|
|
110
|
+
|
|
111
|
+
#### Stage 1: IDF Specificity Weighting, Region-Aware Distance, & Matching Modes
|
|
112
|
+
1. **Why Inverse Mineral Frequency (IDF) Weighting Is Used:**
|
|
113
|
+
In VSWIR spectroscopy, ubiquitous hydroxyl and molecular water bands near ~1400 nm and ~1920 nm occur in more than half of all hydrous minerals as well as adsorbed surface moisture. Without specificity weighting, these deep water bands dominate depth-weighted comparisons and allow unrelated hydrated minerals to outrank diagnostic matches. Across all 224 minerals, each 20 nm wavelength bin receives an IDF weight:
|
|
114
|
+
$$\text{IDF}(\lambda) = \ln\!\left(\frac{N_{\text{minerals}} + 1}{n_{\text{minerals}}(\lambda) + 1}\right) + 0.5$$
|
|
115
|
+
Common bands (~1400 nm, ~1920 nm) receive lower weights, while mineral-diagnostic bands (e.g., 1765 nm alunite, 2165 nm kaolinite, 2265 nm jarosite, 2315 to 2340 nm carbonates) receive higher weights. Each reference feature is weighted by $\text{importance} = \text{depth} \times \text{IDF}(\lambda)$.
|
|
116
|
+
2. **Region-Aware Gaussian Wavelength Kernel:**
|
|
117
|
+
Crystal-field absorptions in the VNIR (< 1100 nm) are broad and commonly shift 15 to 40 nm with Fe/Al substitution, whereas vibrational bands in the SWIR (>= 1100 nm) are narrow and typically shift only 5 to 20 nm. `RSAbs` uses greedy 1-to-1 matching within $3\sigma$ with region-specific scales:
|
|
118
|
+
$$s_\lambda(\Delta\lambda) = \exp\!\left(-\frac{1}{2}\left(\frac{\Delta\lambda}{\sigma_{\text{region}}}\right)^2\right), \quad \sigma_{\text{VNIR}} = 20\text{ nm}, \quad \sigma_{\text{SWIR}} = 8\text{ nm}$$
|
|
119
|
+
3. **Suite-Completeness & Diagnostic-Presence Rules:**
|
|
120
|
+
- `min_ref_coverage=0.5`: Rejects candidates where fewer than 50% of the reference mineral's expected absorption suite is observed, preventing 10- to 18-band minerals from being identified from only 1 or 2 overlapping bands.
|
|
121
|
+
- `require_top_diagnostic=True`: Requires the mineral's #1 diagnostic band (and at least 2 of its top 3 for >= 3-band minerals) to be matched.
|
|
122
|
+
4. **Choosing Between `mode="mixture"` and `mode="pure"`:**
|
|
123
|
+
- **`mode="mixture"` (default):** Evaluates $0.65\,\text{recall}_{\text{ref}} + 0.35\,\text{coverage}_{\text{obs}}$ using wavelength position and IDF weighting only. Use this for natural rocks, soils, lakebed sediments, and dust samples where multiple minerals co-occur: extra bands from co-occurring minerals are not penalized, and overlapping shoulders or grain-size variations do not distort the score through FWHM or depth-ratio penalties.
|
|
124
|
+
- **`mode="pure"`:** Adds FWHM similarity, asymmetry similarity, and relative depth-ratio cosine similarity (`depth_ratio_sim`). Use this when characterizing clean, single-phase laboratory standards or mineral separates where both band positions and band shapes should match the reference spectrum.
|
|
125
|
+
|
|
126
|
+
#### Stage 2: Literature-Based Mineral-Group Tie-Breaking (`discriminate_groups=True`)
|
|
127
|
+
When candidates belong to overlapping mineral groups, targeted rules refine scores:
|
|
128
|
+
- **Al-OH Phyllosilicates (`Kaolinite`, `Dickite`, `Illite`, `Muscovite`, `Montmorillonite`):**
|
|
129
|
+
- `~2165 nm` doublet/shoulder separates kaolin-group minerals from illite, muscovite, and montmorillonite (Clark et al., 1990).
|
|
130
|
+
- Secondary `~2348 / 2435 nm` bands separate muscovite and illite from montmorillonite (Clark et al., 1990; Post & Noble, 1993).
|
|
131
|
+
- Hydration ratio $D_{1900}/D_{2200}$ and $\text{FWHM}_{2200}$ separate montmorillonite (> 1.1), illite (0.35 to 1.1, broader FWHM), and muscovite (< 0.35, sharp $\text{FWHM} < 45\text{ nm}$) when `2165 nm` is absent and no hydrated sulfate owns the `1940 nm` band (Post & Noble, 1993; Duke, 1994; Doublier et al., 2010).
|
|
132
|
+
- **Carbonates (`Aragonite`, `Dolomite`, `Calcite`):** Discriminated by sub-band $\text{CO}_3^{2-}$ position (< 2318 nm aragonite, 2318 to 2328 nm dolomite, >= 2332 nm calcite; Gaffey, 1986).
|
|
133
|
+
- **Fe3+ Oxides & Sulfates (`Hematite`, `Goethite`, `Jarosite`):** Discriminated using the 850 to 960 nm crystal-field band (< 890 nm hematite vs. 895 to 935 nm goethite; Sherman & Waite, 1985) and 2255 to 2275 nm Fe-OH + 905 to 955 nm for jarosite (Swayze et al., 2000), intentionally avoiding the noisy ~400 nm UV/blue edge.
|
|
134
|
+

|
|
135
|
+
#### Stage 3: Iterative Residual Scoring (`suppress_subsets=True`)
|
|
136
|
+
After selecting the highest-scoring mineral (#1), `RSAbs` marks its matched observed bands as **explained** and re-scores all remaining candidates **solely on unexplained bands** (`residual_score >= min_residual_score=0.12`). Secondary candidates whose matched bands are already accounted for by higher-scoring minerals are suppressed, while genuine secondary phases that explain remaining features (e.g., aragonite `2314 nm` or muscovite `2211 nm` alongside gypsum) are retained.
|
|
137
|
+
|
|
138
|
+
#### Stage 4: Geological Environment Presets (`environment=...`)
|
|
139
|
+
To prevent exotic, geologically implausible phases from appearing due to coincidental overlap on weak bands, `identify_minerals()` supports `include_minerals`, `exclude_minerals`, and five built-in depositional and geological environment presets (`ENVIRONMENT_PRESETS`) which will be expanded in the future (currently based on localities present in Utah):
|
|
140
|
+
|
|
141
|
+
| Environment Preset | Representative Utah Localities | Included Minerals (Matched to USGS `splib07a` LUT) |
|
|
142
|
+
| :--- | :--- | :--- |
|
|
143
|
+
| **`evaporite_playa`** | Great Salt Lake, Bonneville Salt Flats, Sevier Lake | `Gypsum`, `Anhydrite`, `Bassanite`, `Mirabilite`, `Thenardite`, `Bloedite`, `Epsomite`, `Kieserite`, `Polyhalite`, `Kainite`, `Halite`, `Carnallite`, `Syngenite`, `Aragonite`, `Calcite`, `Dolomite`, `Trona`, `Gaylussite`, `Sodium Bicarbonate`, `Colemanite`, `Ulexite`, `Tincalconite`, `Illite`, `Montmorillonite`, `Hectorite`, `Saponite`, `Nontronite`, `Kaolinite`, `Palygorskite`, `Sepiolite`, `Muscovite`, `Chlorite`, `Quartz`, `Opal`, `Albite`, `Microcline`, `Orthoclase`, `Hematite`, `Goethite`, `Ferrihydrite` |
|
|
144
|
+
| **`lacustrine_carbonate`** | Green River Fm, Lake Bonneville Marls, Uinta Basin | `Calcite`, `Dolomite`, `Aragonite`, `Siderite`, `Trona`, `Gaylussite`, `Analcime`, `Illite`, `Kaolinite`, `Montmorillonite`, `Saponite`, `Muscovite`, `Chlorite`, `Corrensite`, `Rectorite`, `Quartz`, `Opal`, `Chert`, `Albite`, `Orthoclase`, `Microcline`, `Gypsum`, `Anhydrite`, `Pyrite`, `Hematite`, `Goethite` |
|
|
145
|
+
| **`clastic_redbed`** | Colorado Plateau (Navajo, Wingate, Entrada, Chinle, Lisbon Valley) | `Hematite`, `Nanohematite`, `Goethite`, `Ferrihydrite`, `Lepidocrocite`, `Limonite`, `Maghemite`, `Kaolinite`, `Dickite`, `Illite`, `Montmorillonite`, `Muscovite`, `Chlorite`, `Rectorite`, `Glauconite`, `Quartz`, `Chert`, `Chalcedony`, `Opal`, `Calcite`, `Dolomite`, `Gypsum`, `Anhydrite`, `Barite`, `Albite`, `Microcline`, `Orthoclase`, `Sanidine` |
|
|
146
|
+
| **`hydrothermal_alteration`** | Marysvale Volcanic Field, Tintic, Bingham Canyon | `Alunite`, `Alunite K-Na`, `Alunite0.35K + .65Na`, `Alunite0.66K + .34Na`, `Alunite0.73K + .27Na`, `Jarosite`, `Ammonio-Jarosite`, `Copiapite`, `Coquimbite`, `Schwertmannite`, `Gypsum`, `Anhydrite`, `Barite`, `Sulfur`, `Kaolinite`, `Dickite`, `Nacrite`, `Halloysite`, `Pyrophyllite`, `Diaspore`, `Topaz`, `Zunyite`, `Illite`, `Ammonio-Illite/Smect`, `Muscovite`, `Paragonite`, `Montmorillonite`, `Beidellite`, `Buddingtonite`, `Chlorite`, `Clinochlore`, `Epidote`, `Calcite`, `Dolomite`, `Rhodochrosite`, `Quartz`, `Opal`, `Chalcedony`, `Hematite`, `Goethite`, `Lepidocrocite`, `Limonite`, `Pyrite`, `Malachite`, `Azurite`, `Chrysocolla` |
|
|
147
|
+
| **`marine_carbonate`** | Wasatch, Oquirrh, Confusion Range, Phosphoria Fm | `Calcite`, `Dolomite`, `Aragonite`, `Siderite`, `Quartz`, `Chert`, `Chalcedony`, `Fluorapatite`, `Hydroxyl-Apatite`, `Chlorapatite`, `Illite`, `Kaolinite`, `Glauconite`, `Muscovite`, `Chlorite`, `Goethite`, `Hematite`, `Pyrite` |
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 4. Step-by-Step Usage Guide
|
|
154
|
+
|
|
155
|
+
### Step 1: Load Spectral Data
|
|
156
|
+
Load a CSV/TXT file (with a `Wavelength` column and one column per sample), a `pd.DataFrame`, or a `np.ndarray`. Set `wavelength_unit="micrometer"` if wavelengths are in microns, and set `continuum_removed=True` if your input is already continuum-removed.
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from RSAbs import SpectralAnalyzer
|
|
160
|
+
|
|
161
|
+
# Option A: Raw reflectance CSV (nm)
|
|
162
|
+
sa_raw = SpectralAnalyzer("raw_lab_spectra.csv", continuum_removed=False)
|
|
163
|
+
|
|
164
|
+
# Option B: Already continuum-removed CSV (like the included demo dataset)
|
|
165
|
+
sa = SpectralAnalyzer("demo/demo_spectra.csv", continuum_removed=True)
|
|
166
|
+
print(f"Loaded {sa.n_samples} samples across {sa.n_bands} bands.")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Step 2: Preprocess Raw Reflectance
|
|
170
|
+
Chain preprocessing steps cleanly. Each method returns a new `SpectralAnalyzer` instance without mutating your raw dataset.
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
sa_cr = (
|
|
174
|
+
sa_raw
|
|
175
|
+
.splice_correct(splice_wavelengths=(1000.0, 1800.0), method="offset")
|
|
176
|
+
.smooth(method="savgol", window_length=11, polyorder=2)
|
|
177
|
+
.mask_bands(interpolate=True) # bridges 1350-1420, 1800-1960, 2420-2500 nm
|
|
178
|
+
.continuum_remove(method="convex_hull") # sets continuum_removed=True automatically
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Step 3: Resample to Satellite or Airborne Sensors
|
|
183
|
+
Resample hyperspectral curves to multispectral bandpasses using built-in presets (`"landsat8"`, `"landsat9"`, `"sentinel2"`, `"aster"`, `"asd_1nm"`) or custom wavelengths and FWHMs.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
landsat_sa = sa_raw.resample(target="landsat8")
|
|
187
|
+
aster_sa = sa_raw.resample(target="aster")
|
|
188
|
+
custom_sa = sa_raw.resample(target_wavelengths=[550, 660, 865, 1610, 2200], target_fwhm=20.0)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Step 4: Extract, Summarize, & Filter Absorption Features
|
|
192
|
+
Extract all absorption features (`wavelength`, `depth`, `prominence`, `fwhm`, `asymmetry`, `area`, `left_shoulder`, `right_shoulder`, `width_full`), inspect per-sample summaries, or filter by wavelength window and feature size.
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
# Per-sample summary table
|
|
196
|
+
print(sa.summary())
|
|
197
|
+
|
|
198
|
+
# Full feature table across all samples
|
|
199
|
+
features = sa.extract_features(min_depth=0.005, min_prominence=0.002)
|
|
200
|
+
|
|
201
|
+
# Filter to SWIR Al-OH / Mg-OH / carbonate features (2100 to 2380 nm) with depth >= 2%
|
|
202
|
+
swir_feats = sa.filter_features(
|
|
203
|
+
min_wavelength=2100,
|
|
204
|
+
max_wavelength=2380,
|
|
205
|
+
min_depth=0.02,
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Step 5: Identify Minerals Against USGS `splib07a`
|
|
210
|
+
Run open exploration (`environment=None`) or constrain candidates to a Utah geological environment preset, custom whitelist, or blacklist.
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from RSAbs import list_environments, list_usgs_minerals
|
|
214
|
+
|
|
215
|
+
# Inspect available environment presets and all 224 USGS minerals
|
|
216
|
+
print(list(list_environments().keys()))
|
|
217
|
+
|
|
218
|
+
# Recommended for natural samples / mixtures:
|
|
219
|
+
minerals = sa.identify_minerals(
|
|
220
|
+
environment="evaporite_playa",
|
|
221
|
+
mode="mixture",
|
|
222
|
+
top_n=3,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# Custom whitelist / blacklist example:
|
|
226
|
+
custom = sa.identify_minerals(
|
|
227
|
+
include_minerals=["Gypsum", "Aragonite", "Calcite", "Dolomite", "Muscovite"],
|
|
228
|
+
mode="mixture",
|
|
229
|
+
)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Step 6: Visualize in Jupyter or Launch the Desktop Viewer
|
|
233
|
+
Plot spectra in a Jupyter Notebook with either individual feature minima (`annotation_mode="features"`) or deduplicated mineral diagnostic lines (`annotation_mode="minerals"`), or spin up the interactive desktop viewer.
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
# Publication-ready plot saved as both .jpg and .svg at 300 DPI
|
|
237
|
+
fig, ax = sa.plot(
|
|
238
|
+
annotation_mode="minerals",
|
|
239
|
+
xlim=(380, 2480),
|
|
240
|
+
ylim=(0.45, 1.05),
|
|
241
|
+
x_major_tick=200,
|
|
242
|
+
x_minor_tick=50,
|
|
243
|
+
save_path="outputs/sample_suite",
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
# Spin up the interactive desktop viewer from Python
|
|
247
|
+
sa.launch_viewer()
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Or launch the desktop viewer directly from the command line:
|
|
251
|
+
```bash
|
|
252
|
+
rsabs-viewer demo/demo_spectra.csv --cr
|
|
253
|
+
# or for raw reflectance:
|
|
254
|
+
rsabs-viewer path/to/raw_spectra.csv
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Backward Compatibility (v0.8.1)
|
|
258
|
+
Legacy functional wrappers (`absorptions`, `absorptions_depth`, `seek_absorptions`, `seek_absorptions_depth`) remain available in `RSAbs.compat`.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 5. References
|
|
263
|
+
|
|
264
|
+
- Clark, R. N., & Roush, T. L. (1984). Reflectance spectroscopy: Quantitative analysis techniques for remote sensing applications. *Journal of Geophysical Research: Solid Earth*, 89(B7), 6329–6340.
|
|
265
|
+
- Clark, R. N., King, T. V. V., Klejwa, M., Swayze, G. A., & Vergo, N. (1990). High spectral resolution reflectance spectroscopy of minerals. *Journal of Geophysical Research: Solid Earth*, 95(B8), 12653–12680.
|
|
266
|
+
- Clark, R. N., Swayze, G. A., Livo, K. E., Kokaly, R. F., Sutley, S. J., Dalton, J. B., McDougal, R. R., & Gent, C. A. (2003). Imaging spectroscopy: Earth and planetary remote sensing with the USGS Tetracorder and expert systems. *Journal of Geophysical Research: Planets*, 108(E12), 5131.
|
|
267
|
+
- Doublier, M. P., Roache, T., & Potel, S. (2010). Short-wavelength infrared spectroscopy: A new tool to determine illite crystallinity. *European Journal of Mineralogy*, 22(4), 605–618.
|
|
268
|
+
- Duke, E. F. (1994). Near infrared spectra of muscovite, Tschermak substitution, and metamorphic reaction progress. *Geology*, 22(7), 621–624.
|
|
269
|
+
- Gaffey, S. J. (1986). Spectral reflectance of carbonate minerals in the visible and near infrared (0.35–2.55 microns): Calcite, aragonite, and dolomite. *American Mineralogist*, 71(1–2), 151–162.
|
|
270
|
+
- Hueni, A., Damm, A., Kneubuehler, M., Schlaepfer, D., & Schaepman, M. E. (2017). Field and airborne spectroscopy cross validation: Some considerations. *IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing*, 10(3), 1117–1135.
|
|
271
|
+
- Kokaly, R. F., Clark, R. N., Swayze, G. A., Livo, K. E., Hoefen, T. M., Pearson, N. C., Wise, R. A., Benzel, W. M., Lowers, H. A., Driscoll, R. L., & Klein, A. J. (2017). *USGS Spectral Library Version 7* (Data Series 1035). U.S. Geological Survey.
|
|
272
|
+
- Post, J. L., & Noble, P. N. (1993). The near-infrared combination band frequencies of dioctahedral smectites, micas, and illites. *Clays and Clay Minerals*, 41(6), 639–644.
|
|
273
|
+
- Rodger, A., Laukamp, C., Haest, M., & Cudahy, T. (2012). A simple quadratic method of absorption feature wavelength estimation in continuum removed spectra. *Remote Sensing of Environment*, 118, 273–283.
|
|
274
|
+
- Savitzky, A., & Golay, M. J. E. (1964). Smoothing and differentiation of data by simplified least squares procedures. *Analytical Chemistry*, 36(8), 1627–1639.
|
|
275
|
+
- Sherman, D. M., & Waite, T. D. (1985). Electronic spectra of Fe3+ oxides and oxide hydroxides in the near IR to near UV. *American Mineralogist*, 70(11–12), 1262–1269.
|
|
276
|
+
- Swayze, G. A., Smith, K. S., Clark, R. N., Sutley, S. J., Pearson, R. M., Vance, J. S., Hageman, P. L., Briggs, P. H., Meier, A. L., Singleton, M. J., & Roth, S. (2000). Using imaging spectroscopy to map acidic mine waste. *Environmental Science & Technology*, 34(1), 47–54.
|
|
277
|
+
- van der Meer, F. (2004). Analysis of spectral absorption features in hyperspectral imagery. *International Journal of Applied Earth Observation and Geoinformation*, 5(1), 55–68.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
MIT
|