diff --git a/sedkit/catalog.py b/sedkit/catalog.py index 0bfbdf7e..37fa4628 100644 --- a/sedkit/catalog.py +++ b/sedkit/catalog.py @@ -10,7 +10,7 @@ import dill import pickle from copy import copy -from pkg_resources import resource_filename +import importlib_resources import shutil from astropy.io import ascii @@ -983,5 +983,5 @@ def __init__(self, **kwargs): super().__init__(name='M Dwarf Catalog', **kwargs) # Read the names from the file - file = resource_filename('sedkit', 'data/sources.txt') + file = importlib_resources.files('sedkit')/ 'data/sources.txt' self.from_file(file, run_methods=['find_SDSS', 'find_2MASS', 'find_WISE']) \ No newline at end of file diff --git a/sedkit/modelgrid.py b/sedkit/modelgrid.py index 2a21bb06..c8b2fb40 100644 --- a/sedkit/modelgrid.py +++ b/sedkit/modelgrid.py @@ -12,10 +12,10 @@ import glob import itertools import pickle -from copy import copy from functools import partial from multiprocessing import Pool -from pkg_resources import resource_filename +import importlib_resources +from pathlib import Path import astropy.units as q import astropy.io.votable as vo @@ -24,8 +24,8 @@ from scipy.interpolate import RegularGridInterpolator from svo_filters import svo -from . import utilities as u -from .spectrum import Spectrum +from sedkit import utilities as u +from sedkit.spectrum import Spectrum def interp_flux(flux, params, values): @@ -478,7 +478,7 @@ def load(self, dirname, **kwargs): self.index_path = os.path.join(dirname, 'index.p') if not os.path.isfile(self.index_path): - os.system("touch {}".format(self.index_path)) + Path(self.index_path).touch() # Index the models self.index_models(parameters=self.parameters, **kwargs) @@ -732,7 +732,8 @@ def save(self, file): # Make the file if necessary if not os.path.isfile(file): - os.system('touch {}'.format(file)) + Path(file).touch() + # Write the file f = open(file, 'wb') @@ -762,7 +763,7 @@ def __init__(self, root=None, **kwargs): # Load the model grid modeldir = 'data/models/atmospheric/btsettl' - root = root or resource_filename('sedkit', modeldir) + root = root or importlib_resources.files('sedkit')/ modeldir self.load(root) @@ -778,7 +779,7 @@ def __init__(self): # Load the model grid model_path = 'data/models/atmospheric/spexprismlibrary' - root = resource_filename('sedkit', model_path) + root = importlib_resources.files('sedkit')/ model_path self.load(root) # Add numeric spectral type diff --git a/sedkit/spectrum.py b/sedkit/spectrum.py index 8834d4c7..db1d5b24 100644 --- a/sedkit/spectrum.py +++ b/sedkit/spectrum.py @@ -602,7 +602,7 @@ def integrate(self, units=None, n_samples=10): spec = u.scrub(self.data) # Integrate the spectrum - val = (np.trapz(spec[1], x=spec[0]) * m).to(units) + val = (np.trapezoid(spec[1], x=spec[0]) * m).to(units) if self.unc is None: vunc = None @@ -615,7 +615,7 @@ def integrate(self, units=None, n_samples=10): uvals = [] for n in range(n_samples): usamp = np.random.normal(spec[1], spec[2]) - err = (np.trapz(usamp, x=spec[0]) * m).to(units) + err = (np.trapezoid(usamp, x=spec[0]) * m).to(units) uvals.append(abs(err.value - val.value)) # Get 1-sigma of distribution @@ -1153,7 +1153,7 @@ def synthetic_flux(self, bandpass, force=False, plot=False): idx = np.where([not np.isnan(i) for i in f])[0] # Calculate the flux - flx = (np.trapz(f[idx] * rsr[0][idx], x=wav[idx]) / np.trapz(rsr[0][idx], x=wav[idx])).to(self.flux_units) + flx = (np.trapezoid(f[idx] * rsr[0][idx], x=wav[idx]) / np.trapezoid(rsr[0][idx], x=wav[idx])).to(self.flux_units) # Calculate uncertainty if self.unc is not None: diff --git a/sedkit/tests/test_catalog.py b/sedkit/tests/test_catalog.py index 449e9506..27287034 100644 --- a/sedkit/tests/test_catalog.py +++ b/sedkit/tests/test_catalog.py @@ -1,11 +1,9 @@ """A suite of tests for the catalog.py module""" import unittest import copy -import os -from pkg_resources import resource_filename -from .. import sed -from .. import catalog +from sedkit import sed +from sedkit import catalog class TestCatalog(unittest.TestCase): diff --git a/sedkit/tests/test_helpers.py b/sedkit/tests/test_helpers.py index 1677e2cd..0796d344 100644 --- a/sedkit/tests/test_helpers.py +++ b/sedkit/tests/test_helpers.py @@ -1,6 +1,6 @@ """A suite of tests for the helpers.py module""" import os -from pkg_resources import resource_filename +import importlib_resources from sedkit import helpers as help @@ -8,9 +8,9 @@ def test_process_dmestar(): """Test the process_dmestar function""" # Process DMEStar files - dir = resource_filename('sedkit', 'data/models/evolutionary/DMESTAR/') + dir = importlib_resources.files('sedkit')/ 'data/models/evolutionary/DMESTAR/' help.process_dmestar(dir=dir, filename='dmestar_test.txt') # Delete temporary file - path = resource_filename('sedkit', 'data/models/evolutionary/dmestar_test.txt') - os.system('rm {}'.format(path)) \ No newline at end of file + temp_file = importlib_resources.files('sedkit')/ 'data/models/evolutionary/dmestar_test.txt' + os.remove(temp_file) \ No newline at end of file diff --git a/sedkit/tests/test_modelgrid.py b/sedkit/tests/test_modelgrid.py index c0f7d442..a32e63ee 100644 --- a/sedkit/tests/test_modelgrid.py +++ b/sedkit/tests/test_modelgrid.py @@ -4,8 +4,8 @@ import astropy.units as q -from .. import modelgrid as mg -from .. import utilities as u +from sedkit import modelgrid as mg +from sedkit import utilities as u class TestModelGrid(unittest.TestCase): @@ -18,7 +18,7 @@ def setUp(self): path = resource_filename('sedkit', 'data/models/atmospheric/spexprismlibrary') # Delete the pickle so the models need to be indexed - os.system('rm {}'.format(os.path.join(path, 'index.p'))) + os.remove(os.path.join(path, 'index.p')) # Load the model grid grid.load(path) @@ -82,11 +82,11 @@ def test_load_model(): def test_load_ModelGrid(): """Test the load_ModelGrid function""" grid = mg.BTSettl() - path = './test.p' - grid.save(path) - lmg = mg.load_ModelGrid(path) + test_p = './test.p' + grid.save(test_p) + lmg = mg.load_ModelGrid(test_p) assert isinstance(lmg, mg.ModelGrid) - os.system('rm test.p') + os.remove(test_p) def test_BTSettl():