Skip to content

Commit

Permalink
Merge branch 'main' of github.com:BDNYC/sedkit into absolute_flux_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kelle committed Nov 15, 2024
2 parents d79d875 + f1b7430 commit 4eadbc6
Show file tree
Hide file tree
Showing 35 changed files with 182 additions and 1,816 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Run tests

on:
pull_request:
Expand All @@ -10,12 +10,11 @@ jobs:
SEDkit-CI:

name: Python - ${{ matrix.python-version }}
runs-on: macos-latest
strategy:
max-parallel: 5
matrix:
os: ['macos-latest']
python-version: [ '3.11' ]
runs-on: ${{ matrix.os }}
python-version: [ "3.13", "3.12", "3.11", ]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -26,10 +25,16 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
run: |
python -m pip install --upgrade pip
pip install .[test]
pip install ".[test]"
- name: Test with pytest
- name: List packages
run: |
pip list
- name: Test with pytest
# tb=no: no traceback
# disable-warnings: disable pytest warnings
run: |
pytest --tb=no --disable-warnings
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ target/
.idea/
.idea/*
.vscode/settings.json

sedkit/data/models/atmospheric/spexprismlibrary/index.p
17 changes: 17 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
authors:
- family-names: Filippazzo
given-names: Joseph
orcid: https://orcid.org/0000-0002-0201-8306
- family-names: Alejandro Merchan
given-names: Sherelyn
orcid: https://orcid.org/0000-0003-0548-0093
- family-names: Cruz
given-names: Kelle
orcid: https://orcid.org/0000-0002-1821-0650
cff-version: 1.2.0
doi: 10.5281/zenodo.14014658
repository-code: https://github.com/BDNYC/sedkit/
title: 'sedkit'
type: software
message: "If you use this software, please cite the Zenodo record"
license: BSD-3-Clause
24 changes: 7 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
The MIT License (MIT)
Copyright (c) 2024, Joe Filippazzo, Sherelyn Alejandro Merchan, Kelle Cruz

Copyright (c) 2019 Joe Filippazzo
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 changes: 24 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
[![Build Status](https://github.com/hover2pi/sedkit/actions/workflows/ci.yml/badge.svg)](https://github.com/hover2pi/sedkit/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/hover2pi/sedkit/badge.svg?branch=master&service=github)](https://coveralls.io/github/hover2pi/sedkit?branch=master)
[![Documentation Status](https://readthedocs.org/projects/sedkit/badge/?version=latest)](https://sedkit.readthedocs.io/en/latest/?badge=latest)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14014658.svg)](https://doi.org/10.5281/zenodo.14014658)


## Introduction

`sedkit` is a collection of pure Python modules for simple SED construction and analysis. Users can create individual SEDs or SED catalogs from spectra and/or photometry and calculate fundamental parameters (f<sub>bol</sub>, M<sub>bol</sub>, L<sub>bol</sub>, T<sub>eff</sub>, mass, log(g)) using the methods presented in [Filippazzo et al. (2015)](http://adsabs.harvard.edu/abs/2015ApJ...810..158F).
`sedkit` is a collection of pure Python modules for simple SED construction and analysis. Users can create individual SEDs or SED catalogs from spectra and/or photometry and calculate fundamental parameters (f<sub>bol</sub>, M<sub>bol</sub>, L<sub>bol</sub>, T<sub>eff</sub>, mass, log(g)) using the methods presented in [Filippazzo et al. (2015)](http://adsabs.harvard.edu/abs/2015ApJ...810..158F) and described in the documentation: https://sedkit.readthedocs.io/.


## Installation

Install via PyPI with
Install in an environment with Python 3.11, 3.12, 3.13.

```
pip install sedkit
```
### Developer Instructions

or via `conda` with
If you plan to modify and/or contribute to the code, clone the repository and then install an editable version of the package and the requirements for running the tests.

```
git clone https://github.com/hover2pi/sedkit.git
cd sedkit
conda env create -f env/environment-3.11.yml --force
conda activate sedkit
python setup.py install
pip install -e ".[test]"
```

## Demo
Expand Down Expand Up @@ -55,10 +55,10 @@ trap1.find_WISE()
Spectrum arrays or ASCII/FITS files can also be added to the SED data.

```python
from pkg_resources import resource_filename
spec_file = resource_filename('sedkit', 'data/Trappist-1_NIR.fits')
import importlib.resources
spec_file = str(importlib.resources.files('sedkit')/ 'data/Trappist-1_NIR.fits')
import astropy.units as u
trap1.add_spectrum_file(spec_file, wave_units=u.um, flux_units=u.erg/u.s/q.cm**2/u.AA)
trap1.add_spectrum_file(spec_file, wave_units=u.um, flux_units=u.erg/u.s/u.cm**2/u.AA)
```

Other data which may affect the calculated and inferred fundamantal parameters can be set at any time.
Expand Down Expand Up @@ -201,20 +201,19 @@ trap1.evo_model = 'DUSTY00'
trap1.infer_mass()
```

<img src="https://github.com/hover2pi/sedkit/blob/master/sedkit/data/figures/Lbol_v_mass.png" height="400">

A variety of atmospheric model grids can be fit to the data with or without MCMC analysis,
<img src="sedkit/data/figures/Lbol_v_mass.png" height="400">

<!-- A variety of atmospheric model grids can be fit to the data with or without MCMC analysis,
```python
from sedkit import BTSettl
trap1.fit_modelgrid(BTSettl(), mcmc=True)
```
``` -->

And any arbitrary atlas of models can be applied as well.
Any arbitrary atlas of models (stored in `data\models\atmospheric`) can be used to fit the data with or without MCMC analysis.

```python
from sedkit import SpexPrismLibrary
trap1.fit_modelgrid(SpexPrismLibrary())
trap1.fit_modelgrid(SpexPrismLibrary(), mcmc=True)
```

Inspect the SED at any time with the interactive plotting method.
Expand All @@ -223,28 +222,22 @@ Inspect the SED at any time with the interactive plotting method.
trap1.plot(integral=True, best_fit=True)
```

<img src="https://github.com/hover2pi/sedkit/blob/master/sedkit/data/figures/sed_plot.png" height="500">
<img src="sedkit/data/figures/sed_plot.png" height="500">

References for all data can be accessed via the `refs` attribute.

Entire catalogs of `SED` objects can also be created and their properties can be arbitrarily compared and analyzed with the `sedkit.catalog.Catalog()` object.

<img src="https://github.com/hover2pi/sedkit/blob/master/sedkit/data/figures/Lbol_v_SpT.png" height="500">
<img src="sedkit/data/figures/Lbol_v_SpT.png" height="500">

Please read the full documentation for details on this functionality and much more.
Please read the [full documentation](https://sedkit.readthedocs.io/en/latest/) for details on this functionality and much more.

## Documentation
## Documentation and Notebooks

Full documentation for the latest build can be found on [ReadTheDocs](https://sedkit.readthedocs.io/en/latest/).
Full documentation is available: https://sedkit.readthedocs.io/.

The package also contains detailed Jupyter notebooks highlighting the core functionality of its primary classes, including

- [sedkit.spectrum.Spectrum](https://github.com/hover2pi/sedkit/blob/master/sedkit/notebooks/working_with_spectra.ipynb)
- [sedkit.sed.SED](https://github.com/hover2pi/sedkit/blob/master/sedkit/notebooks/create_sed.ipynb)
- [sedkit.catalog.Catalog](https://github.com/hover2pi/sedkit/blob/master/sedkit/notebooks/create_catalog.ipynb)

If you use or reference this software, please cite [Filippazzo et al. (submitted to PASP)]()

## Licensed

This project is Copyright (c) Joe Filippazzo and licensed under the terms of the BSD 3-Clause license. See the licenses folder for more information.
- [sedkit.spectrum.Spectrum](sedkit/notebooks/working_with_spectra.ipynb)
- [sedkit.sed.SED](sedkit/notebooks/create_sed.ipynb)
- [sedkit.catalog.Catalog](sedkit/notebooks/create_catalog.ipynb)
22 changes: 12 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@ description="Spectral energy distribution construction and analysis tools"
keywords=['astronomy']
classifiers=[
'Intended Audience :: Science/Research',
"License :: OSI Approved :: MIT License",
'Operating System :: OS Independent',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Software Development :: Libraries :: Python Modules',
]
requires-python = ">=3.11"
requires-python = ">=3.11,<=3.13"
dependencies = [
"astropy>=5.3.1",
"astroquery>=0.4.6",
"astropy>=6.1.3",
"astroquery>=0.4.7",
"astropy>=6.1.3",
"astroquery>=0.4.7",
"bokeh>=3.2.1",
"dill>=0.3.4",
"dustmaps>=1.0.9",
"emcee>=3.1.1",
"numpy>=1.25.1",
"pandas>=1.3.5",
"scipy>=1.8.0",
"dustmaps>=1.0.13",
"emcee>=3.1.6",
"numpy>=2.1",
"pandas>=2.2.2",
"scipy>=1.14.1",
"svo-filters>=0.4.4",
"importlib-resources"
"setuptools>=64",
]
dynamic = ["version"]
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions sedkit/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dill
import pickle
from copy import copy
import importlib_resources
import importlib.resources
import shutil

from astropy.io import ascii
Expand Down Expand Up @@ -983,5 +983,5 @@ def __init__(self, **kwargs):
super().__init__(name='M Dwarf Catalog', **kwargs)

# Read the names from the file
file = importlib_resources.files('sedkit')/ 'data/sources.txt'
file = str(importlib.resources.files('sedkit')/ 'data/sources.txt')
self.from_file(file, run_methods=['find_SDSS', 'find_2MASS', 'find_WISE'])
Binary file modified sedkit/data/figures/Lbol_v_SpT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sedkit/data/figures/Lbol_v_mass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sedkit/data/figures/sed_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions sedkit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from glob import glob
import os
from pkg_resources import resource_filename
import importlib.resources

from astropy.io import ascii
import astropy.table as at
Expand All @@ -19,7 +19,7 @@ def process_dmestar(dir=None, filename='dmestar_solar.txt'):
"""Combine all DMESTAR isochrones into one text file"""
# Get the filenames
if dir is None:
dir = resource_filename('sedkit', 'data/models/evolutionary/DMESTAR/')
dir = str(importlib.resources.files('sedkit')/ 'data/models/evolutionary/DMESTAR/')

files = glob(os.path.join(dir, '*'))

Expand All @@ -40,7 +40,7 @@ def process_dmestar(dir=None, filename='dmestar_solar.txt'):
if len(tables) > 0:
table = at.vstack(tables)
table.meta = None
path = resource_filename('sedkit', 'data/models/evolutionary/')
path = str(importlib.resources.files('sedkit')/ 'data/models/evolutionary/')
table.write(os.path.join(path, filename), format='csv')

else:
Expand Down
6 changes: 3 additions & 3 deletions sedkit/isochrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os
import glob
from pkg_resources import resource_filename
import importlib.resources

import astropy.units as q
import astropy.constants as ac
Expand All @@ -33,7 +33,7 @@

# A list of all supported evolutionary models
try:
EVO_MODELS = [os.path.basename(m).replace('.txt', '') for m in glob.glob(resource_filename('sedkit', 'data/models/evolutionary/*'))]
EVO_MODELS = [os.path.basename(m).replace('.txt', '') for m in glob.glob(str(importlib.resources.files('sedkit')/ 'data/models/evolutionary/*'))]
# Fails RTD build for some reason
except:
EVO_MODELS = ['COND03', 'dmestar_solar', 'DUSTY00', 'f2_solar_age', 'hybrid_solar_age', 'nc+03_age','nc+0.0_age', 'nc-03_age', 'nc_solar_age','nc+0.5_age','nc-0.5_age', 'parsec12_solar','ATMO_NEQ_strong','ATMO_NEQ_strong_MIRI','chaubrier_2022.txt']
Expand All @@ -54,7 +54,7 @@ def __init__(self, name, units=None, verbose=True, **kwargs):

# Set the path
self.name = name
self.path = resource_filename('sedkit', 'data/models/evolutionary/{}.txt'.format(self.name))
self.path = str(importlib.resources.files('sedkit')/ 'data/models/evolutionary/{}.txt').format(self.name)
self._age_units = None
self._mass_units = None
self._radius_units = None
Expand Down
6 changes: 3 additions & 3 deletions sedkit/modelgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pickle
from functools import partial
from multiprocessing import Pool
import importlib_resources
import importlib.resources
from pathlib import Path

import astropy.units as q
Expand Down Expand Up @@ -761,7 +761,7 @@ def __init__(self, root=None, **kwargs):

# Load the model grid
modeldir = 'data/models/atmospheric/btsettl'
root = root or importlib_resources.files('sedkit')/ modeldir
root = root or str(importlib.resources.files('sedkit')/ modeldir)
self.load(root)


Expand All @@ -777,7 +777,7 @@ def __init__(self):

# Load the model grid
model_path = 'data/models/atmospheric/spexprismlibrary'
root = importlib_resources.files('sedkit')/ model_path
root = str(importlib.resources.files('sedkit')/ model_path)
self.load(root)

# Add numeric spectral type
Expand Down
Loading

0 comments on commit 4eadbc6

Please sign in to comment.