Skip to content

Commit

Permalink
Merge pull request #101 from kelle/fix-more-tests
Browse files Browse the repository at this point in the history
Fix one tests and warnings
  • Loading branch information
kelle authored Sep 18, 2024
2 parents 0115ca7 + 59ee5fe commit 590f23c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
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
from pkg_resources import resource_filename
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 = 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'])
17 changes: 9 additions & 8 deletions sedkit/modelgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)


Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sedkit/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions sedkit/tests/test_catalog.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 4 additions & 4 deletions sedkit/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""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


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))
temp_file = importlib_resources.files('sedkit')/ 'data/models/evolutionary/dmestar_test.txt'
os.remove(temp_file)
14 changes: 7 additions & 7 deletions sedkit/tests/test_modelgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 590f23c

Please sign in to comment.