Metadata-Version: 2.4
Name: WaLSAlib
Version: 1.1.1
Summary: WaLSA auxiliary routines for spectroscopy and solar feature tracking.
Author-email: WaLSA Team - Shahin Jafarzadeh <Shahin.Jafarzadeh@WaLSA.team>
License-Expression: Apache-2.0 AND GPL-3.0-only
Project-URL: Homepage, https://walsa.team
Project-URL: Repository, https://github.com/WaLSAteam/WaLSAlib
Project-URL: Issues, https://github.com/WaLSAteam/WaLSAlib/issues
Project-URL: Documentation, https://github.com/WaLSAteam/WaLSAlib#readme
Keywords: solar physics,spectroscopy,feature tracking,granulation
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Astronomy
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
License-File: vendor/SoFT/LICENSE
License-File: vendor/SoFTg/LICENSE
Requires-Dist: numpy>=1.23
Requires-Dist: scipy>=1.10
Requires-Dist: astropy>=5
Requires-Dist: matplotlib>=3.6
Requires-Dist: pandas>=1.5
Requires-Dist: scikit-image<0.28,>=0.21
Requires-Dist: pathos>=0.3
Requires-Dist: fastprogress>=1.0
Requires-Dist: tqdm>=4.64
Provides-Extra: soft-extras
Requires-Dist: sunpy[map,net]>=5; extra == "soft-extras"
Requires-Dist: EMD-signal>=1.6; extra == "soft-extras"
Requires-Dist: ipython>=8; extra == "soft-extras"
Provides-Extra: softg
Requires-Dist: torch>=2.6; extra == "softg"
Requires-Dist: torchvision>=0.21; extra == "softg"
Requires-Dist: lightning>=2.5; extra == "softg"
Requires-Dist: opencv-python-headless>=4.8; extra == "softg"
Requires-Dist: pillow>=9; extra == "softg"
Requires-Dist: tensorboard>=2.12; extra == "softg"
Provides-Extra: softg-gui
Requires-Dist: PyQt5>=5.15; extra == "softg-gui"
Requires-Dist: opencv-python-headless>=4.8; extra == "softg-gui"
Requires-Dist: torch>=2.6; extra == "softg-gui"
Provides-Extra: walsatools
Requires-Dist: WaLSAtools; extra == "walsatools"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Provides-Extra: build
Requires-Dist: build>=1.2; extra == "build"
Requires-Dist: twine>=6; extra == "build"
Requires-Dist: setuptools>=77; extra == "build"
Requires-Dist: wheel; extra == "build"
Requires-Dist: tomli>=2; python_version < "3.11" and extra == "build"
Dynamic: license-file

<div style="display: block; margin-bottom: 20px;">
    <img align="left" src="https://raw.githubusercontent.com/WaLSAteam/WaLSAlib/main/docs/images/WaLSAlib_logo.svg" alt="WaLSAlib" width="400" height="auto">
</div>

<br><br><br>

# WaLSAlib &ndash; WaLSA Library of Auxiliary Routines
<p align="left">
    <a href="#"><img src="https://img.shields.io/badge/WaLSAlib-v1.1.1-0066cc"></a>
    <a href="https://walsa.team" target="_blank"><img src="https://img.shields.io/badge/powered%20by-WaLSA%20Team-000d1a"></a>
    <a href="#"><img src="https://img.shields.io/badge/license-Apache%202.0%20%2B%20GPLv3-green"></a>
    <a href="https://doi.org/10.5281/zenodo.23043078"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23043078-blue.svg" alt="DOI"></a>
    <a href="https://pypi.org/project/WaLSAlib/"><img src="https://img.shields.io/pypi/v/WaLSAlib.svg?v=1" alt="PyPI Latest Release"></a>
</p>

**WaLSAlib** is a companion repository to [**WaLSAtools**](https://github.com/WaLSAteam/WaLSAtools), collecting practical workflow routines developed within the WaLSA Team to prepare *analysis-ready* products and time series for wave/oscillation studies (and related diagnostics). The focus here is on upstream and auxiliary steps that often sit between calibrated observations and the actual wave analysis.

WaLSAlib and its LineFit module are introduced in [Jafarzadeh et al. (2026)](https://doi.org/10.3389/fspas.2026.1843842), *Frontiers in Astronomy and Space Sciences*.

---

⭐ **If you find WaLSAlib useful**, please consider giving it a star (click the ⭐ at the top right of this page).  
It helps others discover the project and supports the growth of an open, cross-disciplinary wave analysis community.

🔔 To stay updated on new releases and features, click **“Watch → Custom → Releases”** at the top of the page.

---

## Scope and philosophy
Many routines in WaLSAlib are motivated by (and initially developed for) **Solar Physics** use cases — e.g., spectroscopy/spectro-polarimetry and time-series imaging — although they may be useful more broadly.

## Included modules

- **LineFit**: adaptive multi-line spectral fitting, line-core intensities, and LOS velocities.
- **SoFT**: solar feature detection, association, and tabulation, maintained independently at [mib-unitn/SoFT](https://github.com/mib-unitn/SoFT).
- **SoFTg**: classical granule segmentation and optional UNet++ training/inference, maintained independently at [mib-unitn/SoFTg](https://github.com/mib-unitn/SoFTg).

SoFT and SoFTg are bundled with WaLSAlib. See [upstream components](https://github.com/WaLSAteam/WaLSAlib/blob/main/docs/upstream.md) for source versions and maintenance instructions.

## Relationship to WaLSAtools
- **WaLSAlib**: spectral fitting, magnetic feature tracking, and granule segmentation
- **WaLSAtools**: wave and oscillation analysis methods (FFT/Welch, wavelets, cross-spectra, significance, etc.)

## Installation

Python 3.10 or newer is required. Install the package with:

```bash
pip install WaLSAlib
```

To install from a source checkout:

```bash
pip install .
# For development:
pip install -e '.[test,build]'
```

The base installation includes LineFit, SoFT tracking, and classical SoFTg segmentation.

## Quick start

```python
from WaLSAlib import LineFit, SoFT, SoFTg
```

The three public names accept any capitalization, for example:

```python
from WaLSAlib import Linefit, soft, softg
```

These aliases refer to the same fitting function and tracking namespaces. The package name is `WaLSAlib`; dotted submodule imports and function argument names follow their documented spelling.

### Spectral line fitting

`LineFit` accepts a spectrum or a sequence of spectra, a wavelength axis, rest wavelengths, and line labels:

```python
velocity, intensity = LineFit(
    spectra,
    wavelengths=wavelengths,
    refwavelength=rest_wavelengths,
    element=line_labels,
)
```

Wavelengths are expressed in nm and velocities in km/s. `linefit` is also available as an alias for `LineFit`. See the [LineFit examples](https://github.com/WaLSAteam/WaLSAlib/tree/main/examples/LineFit_Frontiers) for data preparation, fitting, and analysis workflows.

### Solar feature tracking

For a two-dimensional magnetogram, specify a detection threshold in the image's intensity units:

```python
labels = SoFT.detection(magnetogram, l_thr=20, sign="pos")
labels = SoFT.identification(labels, min_size=4)
```

`SoFT.track_all(...)` runs detection, association, and tabulation on a FITS sequence. Supply a dedicated working directory containing `00-data/`, with a trailing path separator. Each run replaces the contents of `01-mask/`, `02-id/`, and `03-assoc/`. Optional SunPy and EMD analysis functions are available through `SoFT.extras`.

### Granule segmentation

For a two-dimensional continuum image, specify the plate scale in km per pixel:

```python
granules, seeds, skeleton = SoFTg.segment_solar_granules(
    continuum_image, plate_scale=50
)
```

The UNet++ workflows use user-supplied training data and model checkpoints. Install the `softg` extra to access `SoFTg.model`, `SoFTg.predict`, and `SoFTg.train`:

```bash
python -m WaLSAlib._vendor.softg.train --help
python -m WaLSAlib._vendor.softg.predict --help
```

## Contributing

See [CONTRIBUTING.md](https://github.com/WaLSAteam/WaLSAlib/blob/main/CONTRIBUTING.md) for development and validation requirements, and the [release guide](https://github.com/WaLSAteam/WaLSAlib/blob/main/docs/release.md) for publishing instructions.

## Citation

The primary reference for WaLSAlib and LineFit is:

Jafarzadeh, S., Jess, D. B., Stangalini, M., et al. (2026). *Frontiers in Astronomy and Space Sciences*, **13**, 1843842. [doi:10.3389/fspas.2026.1843842](https://doi.org/10.3389/fspas.2026.1843842).

Please cite this paper when using WaLSAlib or LineFit in research. The software archive is available on [Zenodo](https://doi.org/10.5281/zenodo.23043078).

For analyses using SoFT, also cite [Berretti et al. (2025)](https://doi.org/10.1051/0004-6361/202452665). For SoFTg, cite Berretti et al. (2026); see the [upstream project](https://github.com/mib-unitn/SoFTg) for bibliographic details.

## License

WaLSAlib code is licensed under Apache-2.0 (see LICENSE). SoFT and SoFTg are licensed under GPLv3. **The combined distribution must be redistributed in compliance with GPLv3**, while retaining the Apache notices for the native code. The SPDX expression `Apache-2.0 AND GPL-3.0-only` records both sets of obligations; it is not a choice of licenses. See [THIRD_PARTY_NOTICES.md](https://github.com/WaLSAteam/WaLSAlib/blob/main/THIRD_PARTY_NOTICES.md) for provenance and adaptation details.
