Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waikato-datamining/wai-spectralio
Python library for reading/writing various NIR, MIR, XRF spectroscopy data formats.
https://github.com/waikato-datamining/wai-spectralio
file-format python3 spectroscopy
Last synced: 5 days ago
JSON representation
Python library for reading/writing various NIR, MIR, XRF spectroscopy data formats.
- Host: GitHub
- URL: https://github.com/waikato-datamining/wai-spectralio
- Owner: waikato-datamining
- License: mit
- Created: 2020-01-08T21:56:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T04:54:46.000Z (7 months ago)
- Last Synced: 2024-04-22T05:53:05.453Z (7 months ago)
- Topics: file-format, python3, spectroscopy
- Language: Python
- Homepage:
- Size: 6.98 MB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
# wai-spectral-io
Python library for reading/writing various NIR, MIR, XRF spectral data formats.## Supported formats
* [ADAMS](https://adams.cms.waikato.ac.nz/) spectra (.spec, .spec.gz)
* ...## API
The following classes are defined by the API:
* `wai.spectralio.Spectrum` -- simple container for spectral data and associated sample data
* `wai.spectralio.OptionHandler` -- superclass for classes that require option-handling/parsing
* `wai.spectralio.SpectrumReader` -- superclass for spectral data readers (derived from `wai.spectralio.OptionHandler`)
* `wai.spectralio.SpectrumWriter` -- superclass for spectral data writers (derived from `wai.spectralio.OptionHandler`)Classes derived from `wai.spectralio.OptionHandler` can output help for the supported options
via the `options_help()` method.## Examples
The code below uses the convenience methods `read` and `write` provided by the `wai.spectralio.adams`
module for handling ADAMS spectra:```python
from wai.spectralio.adams import read, writesps = read("/some/where/data.spec.gz", options=["--keep_format"])
for sp in sps:
print(sp.id)
print(" ", sp.waves)
print(" ", sp.amplitudes)
print(" ", sp.sampledata)
write(sps, "/somewhere/else/blah.spec.gz", options=["--output_sampledata"])
```These two methods construct `Reader`/`Writer` objects on the fly and parse the supplied options.
Of course, you can use the `Reader` and `Writer` classes directly, e.g., when reusing the
same object multiple times:```python
from wai.spectralio.adams import Reader, Writerreader = Reader()
reader.options = ["--keep_format"]
sps = reader.read("/some/where/data.spec")
for sp in sps:
print(sp.id)
print(" ", sp.waves)
print(" ", sp.amplitudes)
print(" ", sp.sampledata)
writer = Writer()
writer.options = ["--output_sampledata"]
writer.write(sps, "/somewhere/else/blah.spec.gz")
```