Skip to main content

A simple spectral line finder

Project description

sslf is designed to be a dead-simple, effective and useful spectral line finder for 1D data. It utilises the continuous wavelet transform from scipy, which is a productive way to find even weak spectral lines.

Because there are many definitions for a spectral line, this package can not conceivably work in all cases. Here, I have designed sslf for Gaussian-profiled spectral lines. A big part of my work focuses on recovering weak signals in the noise, so sslf aims to identify lines, flag them, and subtract the non-zero bandpass around them.

Usage

With a 1D spectrum (spectral_data) and a range of scales to test (e.g. 1 through 20), statistically significant spectral peaks can be found with:

import numpy as np
from sslf.sslf import Spectrum

s = Spectrum(spectral_data)
s.find_cwt_peaks(scales=np.arange(1, 20), snr=6.5)
s.subtract_bandpass()

The flattened spectrum is then contained in s.modified, and peak locations at s.channel_peaks. Other parameters related to the peaks are s.peak_snrs, s.vel_peaks and s.channel_edges.

Note that the snr parameter specified to find_cwt_peaks actually refers to the signal-to-noise ratio in the wavelet domain, not the input-signal domain; for this reason, if you wanted all signals above 5-sigma, you would have to put in a little more work to determine what your spectrum’s noise RMS is and how it maps to the wavelet RMS.

Also note that channel_edges can be quite inaccurate; by default, this variable is populated by the wavelet scale that found the spectral line. The wavelet need not match very well; it only needs to be significant enough to be picked up by sslf. The Spectrum object has an optional refine_line_widths method which (hopefully) does a better job of finding the channel extent of all detected spectral lines. Read the documentation of sslf functions for more information.

find_cwt_peaks can optionally take the wavelet to be used in the wavelet transformation (Ricker wavelet by default). subtract_bandpass is a little harder to explain; more complicated examples of usage can be found in the notebooks directory. A reasonably complex example of sslf usage is here.

Contributions and Suggestions

I created this software because I could not find anything in the community that functioned similarly. So, I would welcome contributions to make this software more generally flexible, to be suitable for a wide audience. It’s really simple, just look at the code!

Issues? Bugs? Inconsistencies?

Absolutely! Please raise a GitLab issue if you find something odd, with your inputs and expected outputs, and I’ll attempt to fix it ASAP.

Installation

pip install sslf

or

  • clone this repo (git clone https://gitlab.com/cjordan/sslf.git)

  • within the directory, run: python setup.py install --optimize=1

Dependencies

  • python 2.7.x or 3.x

  • numpy 1.8+

  • scipy

  • future

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sslf-0.2.0-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sslf-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sslf-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for sslf-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b1cdd79085b95cd5ea675cc311b7aeabcf90b20c97ebea036305f7c21155225a
MD5 b1444b021a0190d61d3f72eb454c66ef
BLAKE2b-256 6989c8ff0c17c0e1af6b0b0f728adedcfd424d9c483c7ac3b92daae69d260ac6

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