Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test high temperature - outside of interpolation range of zeta factor #134

Merged
merged 2 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tardis/plasma_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,12 @@ def calculate_saha_nebular(self, delta=None):
try:
zeta = interpolate.interp1d(zeta_data.columns.values, zeta_data.ix[phis.index].values)(self.t_rads)
except ValueError:
raise ValueError('Outside of interpolation area %s' % self.t_rads)
finally:
raise ValueError('t_rads outside of zeta factor interpolation'
' zeta_min={0:.2f} zeta_max={1:.2f} '
'- requested {2}'.format(
zeta_data.columns.values.min(), zeta_data.columns.values.max(),
self.t_rads))
else:
# fixing missing nan data
# issue created - fix with warning some other day
zeta[np.isnan(zeta)] = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
for funcargs in funcarglist])

class TestNLTELTEApproximtion(object):
class TestNLTELTEApproximation(object):

params = {"test_He_ltelevelpops" : [dict(ion_number = 0),
dict(ion_number = 1)]}

def setup(self):
self.nlte_species=[(2,0),(2,1)]
self.nlte_config = TARDISConfigurationNameSpace({'species':
Expand Down Expand Up @@ -100,3 +100,5 @@ def test_He_dilutelevelpops(self, dummy):
def test_He_dilutelevelpops_isnotLTE(self, ion_number):
lte_pops = self.atom_data.levels["g"].ix[(2,ion_number)].values * np.exp(- self.atom_data.levels["energy"].ix[(2,ion_number)].values * u.erg / const.k_B / self.plasma.t_rads / u.K).value
assert not np.allclose(lte_pops, self.atom_data.levels["g"].ix[(2,ion_number)][0]*self.plasma.level_populations[0].ix[(2,ion_number)].values, atol=0)


24 changes: 24 additions & 0 deletions tardis/tests/test_plasma_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from astropy import constants as const, units as u
import os
import tardis
from tardis import plasma_array, atomic
import pytest
#from numpy.testing import assert_allclose
data_path = os.path.join(tardis.__path__[0], 'tests', 'data')
helium_test_db = os.path.join(data_path, 'chianti_he_db.h5')


class TestNebularPlasma(object):

def setup(self):
atom_data = atomic.AtomData.from_hdf5(helium_test_db)
self.plasma = plasma_array.BasePlasmaArray.from_abundance(
{'He':1.0}, 1e-15*u.Unit('g/cm3'), atom_data, 10 * u.day,
ionization_mode='nebular', excitation_mode='dilute-lte')

def test_high_temperature(self):
with pytest.raises(ValueError) as excinfo:
self.plasma.update_radiationfield([100000.], [1.])

assert excinfo.value.message.startswith('t_rads outside of zeta '
'factor interpolation')