Skip to content

Commit

Permalink
Change to importlib.resources (#134)
Browse files Browse the repository at this point in the history
Co-authored-by: pmocz <[email protected]>
  • Loading branch information
kelle and pmocz authored Nov 14, 2024
1 parent e737212 commit ed9d421
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 1,488 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ 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/u.cm**2/u.AA)
```
Expand Down
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ description="Spectral energy distribution construction and analysis tools"
keywords=['astronomy']
classifiers=[
'Intended Audience :: Science/Research',
"License :: OSI Approved :: MIT License",
'License :: OSI Approved :: BSD 3-Clause License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Software Development :: Libraries :: Python Modules',
]
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>=2.1.0",
"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"
"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'])
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 ed9d421

Please sign in to comment.