spec-rt 0.1.1__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.
Files changed (39) hide show
  1. spec_rt-0.1.1/LICENSE +21 -0
  2. spec_rt-0.1.1/MANIFEST.in +3 -0
  3. spec_rt-0.1.1/PKG-INFO +46 -0
  4. spec_rt-0.1.1/README.md +22 -0
  5. spec_rt-0.1.1/docs/Makefile +11 -0
  6. spec_rt-0.1.1/docs/api.rst +23 -0
  7. spec_rt-0.1.1/docs/conf.py +26 -0
  8. spec_rt-0.1.1/docs/configuration.rst +72 -0
  9. spec_rt-0.1.1/docs/examples.rst +34 -0
  10. spec_rt-0.1.1/docs/index.rst +17 -0
  11. spec_rt-0.1.1/docs/input_format.rst +52 -0
  12. spec_rt-0.1.1/docs/installation.rst +10 -0
  13. spec_rt-0.1.1/docs/outputs.rst +34 -0
  14. spec_rt-0.1.1/docs/performance.rst +46 -0
  15. spec_rt-0.1.1/docs/usage.rst +71 -0
  16. spec_rt-0.1.1/examples/example_spec.txt +162 -0
  17. spec_rt-0.1.1/examples/example_spec_csv_outputs/CNMonlydata.csv +3 -0
  18. spec_rt-0.1.1/examples/example_spec_csv_outputs/Fulldata.csv +2 -0
  19. spec_rt-0.1.1/examples/example_spec_csv_outputs/WNMonlydata.csv +2 -0
  20. spec_rt-0.1.1/examples/example_spec_fit.png +0 -0
  21. spec_rt-0.1.1/examples/run_example_spec.py +57 -0
  22. spec_rt-0.1.1/pyproject.toml +45 -0
  23. spec_rt-0.1.1/setup.cfg +4 -0
  24. spec_rt-0.1.1/src/spec_rt/__init__.py +22 -0
  25. spec_rt-0.1.1/src/spec_rt/spectra_decomposing.py +877 -0
  26. spec_rt-0.1.1/src/spec_rt/spectra_decomposing_io.py +280 -0
  27. spec_rt-0.1.1/src/spec_rt/spectra_decomposing_plotting.py +114 -0
  28. spec_rt-0.1.1/src/spec_rt/spectra_decomposing_utils.py +30 -0
  29. spec_rt-0.1.1/src/spec_rt.egg-info/PKG-INFO +46 -0
  30. spec_rt-0.1.1/src/spec_rt.egg-info/SOURCES.txt +37 -0
  31. spec_rt-0.1.1/src/spec_rt.egg-info/dependency_links.txt +1 -0
  32. spec_rt-0.1.1/src/spec_rt.egg-info/requires.txt +15 -0
  33. spec_rt-0.1.1/src/spec_rt.egg-info/top_level.txt +1 -0
  34. spec_rt-0.1.1/tests/test_example_spec.py +83 -0
  35. spec_rt-0.1.1/tests/test_example_spec_csv_outputs.py +105 -0
  36. spec_rt-0.1.1/tests/test_gaussfitspec_boundary.py +112 -0
  37. spec_rt-0.1.1/tests/test_imports.py +26 -0
  38. spec_rt-0.1.1/tests/test_io_validation.py +119 -0
  39. spec_rt-0.1.1/tests/test_utils_plotting_outputs.py +188 -0
spec_rt-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hongxing Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include README.md
2
+ recursive-include docs *.rst *.py Makefile
3
+ recursive-include examples *.py *.txt *.png *.csv
spec_rt-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.2
2
+ Name: spec_rt
3
+ Version: 0.1.1
4
+ Summary: Gaussian-based absorption and emission spectral fitting tools.
5
+ License: MIT
6
+ Project-URL: Documentation, https://specrt.readthedocs.io/en/latest/
7
+ Project-URL: Homepage, https://pypi.org/project/spec-rt/
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: astropy>=5.0
12
+ Requires-Dist: gaussFitSpec>=1.0.1
13
+ Requires-Dist: matplotlib>=3.7
14
+ Requires-Dist: numpy>=1.24
15
+ Requires-Dist: pandas>=2.0
16
+ Requires-Dist: scipy>=1.10
17
+ Provides-Extra: dev
18
+ Requires-Dist: build>=1.2; extra == "dev"
19
+ Requires-Dist: pytest>=7.4; extra == "dev"
20
+ Requires-Dist: twine>=5.0; extra == "dev"
21
+ Provides-Extra: docs
22
+ Requires-Dist: sphinx>=8.0; extra == "docs"
23
+ Requires-Dist: sphinx-rtd-theme>=3.0; extra == "docs"
24
+
25
+ # spec_rt
26
+
27
+ [![PyPI version](https://img.shields.io/pypi/v/spec-rt.svg)](https://pypi.org/project/spec-rt/)
28
+ [![Documentation Status](https://readthedocs.org/projects/specrt/badge/?version=latest)](https://specrt.readthedocs.io/en/latest/)
29
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21052795.svg)](https://doi.org/10.5281/zenodo.21052795)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
31
+
32
+ Gaussian-based radiative-transfer fitting for absorption and emission spectra.
33
+
34
+ `spec_rt` fits absorption and emission spectra with Gaussian components and
35
+ exports radiative-transfer decomposition results. The PyPI project name is
36
+ `spec_rt`; the Python import package is also `spec_rt`.
37
+
38
+ ## Links
39
+
40
+ - PyPI: https://pypi.org/project/spec-rt/
41
+ - Documentation: https://specrt.readthedocs.io/en/latest/installation.html
42
+ - Source code: https://github.com/retarchen/specRT
43
+ - Citation DOI: https://doi.org/10.5281/zenodo.21052795
44
+
45
+ This release is archived on Zenodo and can be cited with DOI
46
+ `10.5281/zenodo.21052795`.
@@ -0,0 +1,22 @@
1
+ # spec_rt
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/spec-rt.svg)](https://pypi.org/project/spec-rt/)
4
+ [![Documentation Status](https://readthedocs.org/projects/specrt/badge/?version=latest)](https://specrt.readthedocs.io/en/latest/)
5
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21052795.svg)](https://doi.org/10.5281/zenodo.21052795)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+
8
+ Gaussian-based radiative-transfer fitting for absorption and emission spectra.
9
+
10
+ `spec_rt` fits absorption and emission spectra with Gaussian components and
11
+ exports radiative-transfer decomposition results. The PyPI project name is
12
+ `spec_rt`; the Python import package is also `spec_rt`.
13
+
14
+ ## Links
15
+
16
+ - PyPI: https://pypi.org/project/spec-rt/
17
+ - Documentation: https://specrt.readthedocs.io/en/latest/installation.html
18
+ - Source code: https://github.com/retarchen/specRT
19
+ - Citation DOI: https://doi.org/10.5281/zenodo.21052795
20
+
21
+ This release is archived on Zenodo and can be cited with DOI
22
+ `10.5281/zenodo.21052795`.
@@ -0,0 +1,11 @@
1
+ SPHINXBUILD ?= sphinx-build
2
+ SOURCEDIR = .
3
+ BUILDDIR = _build
4
+
5
+ .PHONY: html clean
6
+
7
+ html:
8
+ $(SPHINXBUILD) -b html $(SOURCEDIR) $(BUILDDIR)/html
9
+
10
+ clean:
11
+ rm -rf $(BUILDDIR)
@@ -0,0 +1,23 @@
1
+ API Reference
2
+ =============
3
+
4
+ .. automodule:: spec_rt
5
+ :members:
6
+ :exclude-members: SpectrumFitResult
7
+ :undoc-members:
8
+ :show-inheritance:
9
+
10
+ .. automodule:: spec_rt.spectra_decomposing
11
+ :members:
12
+ :undoc-members:
13
+ :show-inheritance:
14
+
15
+ .. automodule:: spec_rt.spectra_decomposing_io
16
+ :members:
17
+ :undoc-members:
18
+ :show-inheritance:
19
+
20
+ .. automodule:: spec_rt.spectra_decomposing_plotting
21
+ :members:
22
+ :undoc-members:
23
+ :show-inheritance:
@@ -0,0 +1,26 @@
1
+ """Sphinx configuration for specRT."""
2
+
3
+ from pathlib import Path
4
+ import sys
5
+
6
+ PROJECT_ROOT = Path(__file__).resolve().parents[1]
7
+ sys.path.insert(0, str(PROJECT_ROOT / "src"))
8
+
9
+ project = "spec_rt"
10
+ author = "Project contributors"
11
+ release = "0.1.1"
12
+
13
+ extensions = [
14
+ "sphinx.ext.autodoc",
15
+ "sphinx.ext.napoleon",
16
+ "sphinx.ext.viewcode",
17
+ ]
18
+
19
+ templates_path = ["_templates"]
20
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
21
+
22
+ html_theme = "sphinx_rtd_theme"
23
+ html_static_path = ["_static"]
24
+ autodoc_typehints = "description"
25
+ napoleon_google_docstring = True
26
+ napoleon_numpy_docstring = True
@@ -0,0 +1,72 @@
1
+ Configuration
2
+ =============
3
+
4
+ ``SpectraDecomposing`` keeps the original script-style configuration as
5
+ attributes. Set these before calling ``fit_and_plot()``.
6
+
7
+ Core options
8
+ ------------
9
+
10
+ ``name``
11
+ Source name written into plots and CSV files.
12
+
13
+ ``align_data``
14
+ If ``True``, interpolate absorption and emission spectra onto a shared
15
+ velocity grid before fitting.
16
+
17
+ ``peak_abs``
18
+ Optional absorption component centers. Leave as ``[]`` for automatic
19
+ Gaussian selection.
20
+
21
+ ``peak_emi``
22
+ Optional emission component centers. Setting this manually can make the
23
+ emission fit much faster.
24
+
25
+ ``Tsmin``
26
+ Lower bound for CNM spin temperature.
27
+
28
+ ``Tsky``
29
+ Background sky temperature. Use ``2.73`` for CMB-only, or add synchrotron
30
+ emission if available.
31
+
32
+ ``F``
33
+ Foreground fraction values tested for WNM components. The default is
34
+ ``[0, 0.5, 1]``.
35
+
36
+ ``max_auto_warm_components``
37
+ Optional cap for automatically selected WNM components. Leave as ``None``
38
+ for the full search, or set a small integer for faster examples.
39
+
40
+ Output options
41
+ --------------
42
+
43
+ ``savecsv``
44
+ If ``True``, write ``Fulldata.csv``, ``CNMonlydata.csv``, and
45
+ ``WNMonlydata.csv``.
46
+
47
+ ``datapath``
48
+ Directory where CSV files are written.
49
+
50
+ ``renew``
51
+ If ``True``, remove old rows with the same ``name`` before writing new
52
+ results. This is useful when redoing a fit.
53
+
54
+ Example
55
+ -------
56
+
57
+ .. code-block:: python
58
+
59
+ spec_fit = SpectraDecomposing(x, y, yerr, xemi, yemi, yemi_err)
60
+ spec_fit.name = "example_spec"
61
+ spec_fit.v_shift = 4
62
+ spec_fit.peak_abs = []
63
+ spec_fit.peak_emi = []
64
+ spec_fit.max_auto_warm_components = 1
65
+ spec_fit.Tsmin = 10
66
+ spec_fit.Tsky = 2.73
67
+ spec_fit.F = [0, 0.5, 1]
68
+ spec_fit.align_data = True
69
+ spec_fit.savecsv = True
70
+ spec_fit.renew = True
71
+ spec_fit.datapath = "examples/example_spec_csv_outputs"
72
+ spec_fit.fit_and_plot()
@@ -0,0 +1,34 @@
1
+ Examples
2
+ ========
3
+
4
+ The repository currently includes:
5
+
6
+ - ``examples/example_spec.txt`` as a real six-column absorption plus emission spectrum
7
+ - ``examples/run_example_spec.py`` to reproduce the legacy four-panel plot
8
+ - ``examples/example_spec_fit.png`` as the saved output from the packaged workflow
9
+ - ``examples/example_spec_csv_outputs/`` with example CSV products
10
+
11
+ Run the bundled example
12
+ -----------------------
13
+
14
+ .. code-block:: bash
15
+
16
+ python examples/run_example_spec.py
17
+
18
+ This creates:
19
+
20
+ - ``examples/example_spec_fit.png``
21
+ - ``examples/example_spec_csv_outputs/Fulldata.csv``
22
+ - ``examples/example_spec_csv_outputs/CNMonlydata.csv``
23
+ - ``examples/example_spec_csv_outputs/WNMonlydata.csv``
24
+
25
+ Example plot
26
+ ------------
27
+
28
+ .. image:: ../examples/example_spec_fit.png
29
+ :alt: Four-panel example_spec absorption and emission fit
30
+ :width: 100%
31
+
32
+ The upper two panels show the emission spectrum, best-fit model, and emission
33
+ residual. The lower two panels show the absorption spectrum in
34
+ ``1 - exp(-tau)`` form, the absorption fit, and its residual.
@@ -0,0 +1,17 @@
1
+ spec_rt documentation
2
+ =====================
3
+
4
+ This site documents the installable ``spec_rt`` Python package.
5
+
6
+ .. toctree::
7
+ :maxdepth: 2
8
+ :caption: Contents
9
+
10
+ installation
11
+ usage
12
+ input_format
13
+ configuration
14
+ outputs
15
+ examples
16
+ performance
17
+ api
@@ -0,0 +1,52 @@
1
+ Input Format
2
+ ============
3
+
4
+ The bundled ``examples/example_spec.txt`` file uses six columns:
5
+
6
+ 1. absorption velocity
7
+ 2. absorption spectrum
8
+ 3. absorption spectrum error
9
+ 4. emission velocity
10
+ 5. emission spectrum
11
+ 6. emission spectrum error
12
+
13
+ The bundled example stores the second column directly as ``1 - exp(-tau)``,
14
+ so it is kept unchanged before fitting:
15
+
16
+ .. code-block:: python
17
+
18
+ from spec_rt import load_six_column_spectrum
19
+
20
+ x, y, yerr, xemi, yemi, yemi_err = load_six_column_spectrum(
21
+ "examples/example_spec.txt",
22
+ absorption_format="one_minus_exp_tau",
23
+ )
24
+
25
+ After loading, ``y`` is guaranteed to be in the expected ``1 - exp(-tau)``
26
+ form, and the helper also drops non-finite emission rows.
27
+
28
+ Use :func:`spec_rt.validate_absorption_input` to confirm that the
29
+ absorption baseline remains close to zero before fitting.
30
+
31
+ Common checks
32
+ -------------
33
+
34
+ - The absorption array passed to ``SpectraDecomposing`` must already be
35
+ ``1 - exp(-tau)``.
36
+ - The absorption baseline should be close to zero outside the line.
37
+ - Error columns must be positive; rows with non-positive errors are dropped
38
+ before fitting.
39
+ - Emission rows with non-finite velocity, intensity, or error values are
40
+ dropped by ``load_six_column_spectrum``.
41
+
42
+ If your raw absorption file stores transmission as ``exp(-tau)``, use:
43
+
44
+ .. code-block:: python
45
+
46
+ load_six_column_spectrum("my_transmission_file.txt", absorption_format="transmission")
47
+
48
+ If your file already stores ``1 - exp(-tau)``, use:
49
+
50
+ .. code-block:: python
51
+
52
+ load_six_column_spectrum("examples/example_spec.txt", absorption_format="one_minus_exp_tau")
@@ -0,0 +1,10 @@
1
+ Installation
2
+ ============
3
+
4
+ Clone the repository and install the package in editable mode:
5
+
6
+ .. code-block:: bash
7
+
8
+ pip install spec_rt
9
+
10
+ Please install `gaussFitSpec <https://pypi.org/project/gaussFitSpec/>`_ first as this package depends on it for direct Gaussian fitting. It also depends on ``numpy``, ``scipy``, ``astropy``, ``pandas``, and ``matplotlib``.
@@ -0,0 +1,34 @@
1
+ Outputs
2
+ =======
3
+
4
+ When ``savecsv=True``, the fitter writes three CSV files.
5
+
6
+ ``Fulldata.csv``
7
+ One row per source with total CNM/WNM column density estimates, cold gas
8
+ fraction, sky temperature, and fitted uncorrected HI column density.
9
+
10
+ ``CNMonlydata.csv``
11
+ One row per cold component with optical depth, velocity, FWHM, spin
12
+ temperature, velocity shift, ordering, and CNM column density.
13
+
14
+ ``WNMonlydata.csv``
15
+ One row per warm component with brightness temperature, velocity, FWHM,
16
+ WNM column density, and foreground fraction value.
17
+
18
+ Redoing a fit
19
+ -------------
20
+
21
+ Use ``renew=True`` when repeating a fit for the same source:
22
+
23
+ .. code-block:: python
24
+
25
+ spec_fit.savecsv = True
26
+ spec_fit.renew = True
27
+ spec_fit.datapath = "examples/example_spec_csv_outputs"
28
+ spec_fit.fit_and_plot()
29
+
30
+ This removes previous rows with the same ``Name`` from the three CSV files
31
+ before appending the new results. It prevents duplicated rows when tuning
32
+ ``peak_abs``, ``peak_emi``, ``Tsmin``, or ``Tsky``.
33
+
34
+ The package no longer writes ``output.txt``.
@@ -0,0 +1,46 @@
1
+ Performance
2
+ ===========
3
+
4
+ The emission fit can become slow when the absorption fit contains many CNM
5
+ components. The expensive part is testing possible CNM foreground/background
6
+ orders and WNM foreground fractions.
7
+
8
+ For ``ncold`` cold components and ``nwarm`` warm components, the number of
9
+ candidate nonlinear emission fits can scale roughly as:
10
+
11
+ .. code-block:: text
12
+
13
+ ncold! * len(F) ** nwarm
14
+
15
+ Practical speed tips
16
+ --------------------
17
+
18
+ - Set ``peak_emi`` manually when you know the likely emission component
19
+ centers. This avoids a larger automatic search.
20
+ - Reduce ``F`` during exploration. For example, use ``spec_fit.F = [0.5]`` for
21
+ a fast first pass, then restore ``[0, 0.5, 1]`` for a final run.
22
+ - Limit absorption components by setting ``peak_abs`` manually or using
23
+ ``num_cold`` when the automatic fit over-splits noisy absorption spectra.
24
+ - Set ``max_auto_warm_components`` to cap the automatic emission search when
25
+ you want automatic centers but do not want to test many WNM components.
26
+ - Keep ``align_data=True`` when absorption and emission velocity grids differ.
27
+
28
+ Example fast first pass
29
+ -----------------------
30
+
31
+ .. code-block:: python
32
+
33
+ spec_fit.peak_emi = []
34
+ spec_fit.max_auto_warm_components = 1
35
+ spec_fit.F = [0.5]
36
+ spec_fit.num_cold = 5
37
+ spec_fit.fit_and_plot()
38
+
39
+ After the fit is stable, rerun with the fuller configuration if needed:
40
+
41
+ .. code-block:: python
42
+
43
+ spec_fit.F = [0, 0.5, 1]
44
+ spec_fit.num_cold = 0
45
+ spec_fit.renew = True
46
+ spec_fit.fit_and_plot()
@@ -0,0 +1,71 @@
1
+ Usage
2
+ =====
3
+
4
+ The package exposes the radiative-transfer class and re-exports the
5
+ ``gaussFitSpec`` Gaussian fitting API:
6
+
7
+ - ``SpectraDecomposing`` for combined absorption and emission decomposition
8
+ - ``fit_spectrum`` from ``gaussFitSpec`` for direct Gaussian component fitting
9
+
10
+ Basic imports:
11
+
12
+ .. code-block:: python
13
+
14
+ from spec_rt import (
15
+ SpectraDecomposing,
16
+ create_legacy_axes,
17
+ fit_spectrum,
18
+ load_six_column_spectrum,
19
+ )
20
+
21
+ Direct Gaussian fitting
22
+ -----------------------
23
+
24
+ Use ``fit_spectrum`` when you only need a Gaussian decomposition of one
25
+ one-dimensional spectrum:
26
+
27
+ .. code-block:: python
28
+
29
+ result = fit_spectrum(velocity, spectrum, spectrum_err, method="bic")
30
+ print(result.components)
31
+
32
+ Radiative-transfer fitting
33
+ --------------------------
34
+
35
+ Use ``SpectraDecomposing`` when you have matched absorption and emission
36
+ spectra:
37
+
38
+ .. code-block:: python
39
+
40
+ x, y, yerr, xemi, yemi, yemi_err = load_six_column_spectrum(
41
+ "examples/example_spec.txt",
42
+ absorption_format="one_minus_exp_tau",
43
+ )
44
+
45
+ fig, axes = create_legacy_axes()
46
+ spec_fit = SpectraDecomposing(x, y, yerr, xemi, yemi, yemi_err)
47
+ spec_fit.name = "example_spec"
48
+ spec_fit.ax = axes
49
+ spec_fit.align_data = True
50
+ spec_fit.peak_abs = []
51
+ spec_fit.peak_emi = []
52
+ spec_fit.max_auto_warm_components = 1
53
+ spec_fit.Tsmin = 10
54
+ spec_fit.Tsky = 2.73
55
+ spec_fit.fit_mode = "BIC"
56
+ spec_fit.fit_and_plot()
57
+
58
+ Saving CSV outputs
59
+ ------------------
60
+
61
+ Set ``savecsv=True`` and choose an output directory:
62
+
63
+ .. code-block:: python
64
+
65
+ spec_fit.savecsv = True
66
+ spec_fit.renew = True
67
+ spec_fit.datapath = "examples/example_spec_csv_outputs"
68
+ spec_fit.fit_and_plot()
69
+
70
+ ``renew=True`` removes old rows for the same source name before appending new
71
+ results, which is useful when you redo a fit.