def test_LuminositiesGetMassHIIRegions(self): # Test for computation for mass of HII regions mass = np.random.rand(1)[0] * 1.0e3 rcParams.update("emissionLine", "massHIIRegion", mass) diff = np.fabs(mass - self.LINES.getMassHIIRegions()) self.assertLessEqual(diff, 1.0e-6) return
def test_LuminositiesGetLifetimeHIIRegions(self): # Test calculation of HII lifetimes lifetime = np.random.rand(1)[0] * 1.0e-3 rcParams.update("emissionLine", "lifetimeHIIRegion", lifetime) diff = np.fabs(lifetime - self.LINES.getLifetimeHIIRegions()) self.assertLessEqual(diff, 1.0e-6) return
def test_Calzetti(self): rcParams.update("dustCalzetti", "Rv", 4.06) DUST = Calzetti() self.assertEqual(DUST.attrs["Rv"], 4.06) self.assertIsNotNone(DUST.curve) wavelengths = np.array([0.01, 0.12, 1.0, 2.2, 5.0]) self.assertTrue(type(DUST.curve(wavelengths)), np.ndarray) [self.assertTrue(type(DUST.curve(w)), float) for w in wavelengths] return
def test_Fitzpatrick(self): rcParams.update("dustFitzpatrick","Rv",2.71) DUST = Fitzpatrick() self.assertEqual(DUST.attrs["Rv"],2.71) self.assertIsNotNone(DUST.curve) wavelengths = np.array([0.01,0.12,1.0,10.0,20.0]) self.assertTrue(type(DUST.curve(wavelengths)),np.ndarray) [self.assertTrue(type(DUST.curve(w)),float) for w in wavelengths] return
def test_Allen(self): rcParams.update("dustAllen", "Rv", 3.09) DUST = Allen() self.assertEqual(DUST.attrs["Rv"], 3.09) self.assertIsNotNone(DUST.curve) wavelengths = np.array([0.01, 0.1, 3.0, 10.0, 20.0]) self.assertTrue(type(DUST.curve(wavelengths)), np.ndarray) [self.assertTrue(type(DUST.curve(w)), float) for w in wavelengths] return
def test_Prevot(self): rcParams.update("dustPrevot", "Rv", 3.09) DUST = Prevot() self.assertEqual(DUST.attrs["Rv"], 3.09) self.assertIsNotNone(DUST.curve) wavelengths = np.array([0.01, 0.1275, 1.0, 2.2, 5.0]) self.assertTrue(type(DUST.curve(wavelengths)), np.ndarray) [self.assertTrue(type(DUST.curve(w)), float) for w in wavelengths] return
def test_CloudyTableInterpolate(self): # Test incorrect calling of function badName = "notAnEmissionLine999" N = 1000 metallicity = np.random.rand(N) densityHydrogen = np.random.rand(N) ionizingFluxHydrogen = np.random.rand(N) ionizingFluxHeliumToHydrogen = np.random.rand(N) ionizingFluxOxygenToHelium = np.random.rand(N) with warnings.catch_warnings(): warnings.filterwarnings("ignore") with self.assertRaises(KeyError): self.CLOUDY.interpolate(badName, metallicity, densityHydrogen, ionizingFluxHydrogen, ionizingFluxHeliumToHydrogen, ionizingFluxOxygenToHelium) with self.assertRaises(TypeError): name = "balmerAlpha6563" self.CLOUDY.interpolate(name, metallicity) # Generate random data to test correct calling i = self.CLOUDY.getInterpolant("metallicity") diff = i.max() - i.min() metallicity = np.random.rand(N) * diff + i.min() i = self.CLOUDY.getInterpolant("densityHydrogen") diff = i.max() - i.min() densityHydrogen = np.random.rand(N) * diff + i.min() i = self.CLOUDY.getInterpolant("ionizingFluxHydrogen") diff = i.max() - i.min() ionizingFluxHydrogen = np.random.rand(N) * diff + i.min() i = self.CLOUDY.getInterpolant("ionizingFluxHeliumToHydrogen") diff = i.max() - i.min() ionizingFluxHeliumToHydrogen = np.random.rand(N) * diff + i.min() i = self.CLOUDY.getInterpolant("ionizingFluxOxygenToHelium") diff = i.max() - i.min() ionizingFluxOxygenToHelium = np.random.rand(N) * diff + i.min() # Test interpolation luminosity = self.CLOUDY.interpolate(name, metallicity, densityHydrogen, ionizingFluxHydrogen, ionizingFluxHeliumToHydrogen, ionizingFluxOxygenToHelium) self.assertIsInstance(luminosity, np.ndarray) metallicity[0] *= 1000.0 rcParams.update("cloudy", "fill_value", "nan") luminosity = self.CLOUDY.interpolate(name, metallicity, densityHydrogen, ionizingFluxHydrogen, ionizingFluxHeliumToHydrogen, ionizingFluxOxygenToHelium) self.assertTrue(np.any(np.isnan(luminosity))) rcParams.update("cloudy", "bounds_error", True) self.assertRaises(ValueError, self.CLOUDY.interpolate, name, metallicity, densityHydrogen, ionizingFluxHydrogen, ionizingFluxHeliumToHydrogen, ionizingFluxOxygenToHelium) return