def test_DustCharlotFallGetOpticalDepthClouds(self):
     z = 1.0
     effWave = 0.6563
     zStr = self.DUST.galaxies.GH5Obj.getRedshiftString(z)
     # Check returns error for incorrect component
     with self.assertRaises(ValueError):
         self.DUST.getOpticalDepthClouds(z, "total", effWave)
     # Check calculation
     metalsName = "diskGasMetallicity"
     DATA = self.DUST.galaxies.get(z, properties=[metalsName])
     factorClouds = rcParams.getfloat("dustCharlotFall",
                                      "opticalDepthCloudsFactor",
                                      fallback=1.0)
     wavelengthZeroPoint = rcParams.getfloat("dustCharlotFall",
                                             "wavelengthZeroPoint",
                                             fallback=5500.0)
     wavelengthExponent = rcParams.getfloat("dustCharlotFall",
                                            "wavelengthExponent",
                                            fallback=0.7)
     wavelengthRatio = (effWave / wavelengthZeroPoint)**wavelengthExponent
     localISMMetallicity = rcParams.getfloat("dustOpticalDepth",
                                             "localISMMetallicity",
                                             fallback=0.02)
     opticalDepthClouds = factorClouds * (
         DATA[metalsName].data * metallicitySolar) / localISMMetallicity
     opticalDepthClouds /= wavelengthRatio
     result = self.DUST.getOpticalDepthClouds(z, "disk", effWave)
     self.assertTrue(np.array_equal(result, opticalDepthClouds))
     return
Пример #2
0
 def test_SpectralEnergyDistributionErgPerSecond(self):
     # Test function for converting SED units to erg/s.
     sed0 = np.random.rand(100).reshape(20,5)        
     zeroCorrection = rcParams.getfloat("spectralEnergyDistribution",
                                        "zeroCorrection",
                                        fallback=1.0e-50)        
     sedT = np.log10(np.copy(sed0)+zeroCorrection)
     sedT += np.log10(luminosityAB)
     sedT -= np.log10(erg)
     sedT = 10.0**sedT
     sedC = self.SED.ergPerSecond(sed0)
     diff = np.fabs(sedT-sedC).flatten()
     [self.assertLessEqual(d,1.0e-6) for d in diff]
     return
 def test_DustCharlotFallGetOpticalDepthISM(self):
     z = 1.0
     zStr = self.DUST.galaxies.GH5Obj.getRedshiftString(z)
     effWave = 0.6563
     # Check returns error for incorrect component
     with self.assertRaises(ValueError):
         self.DUST.getOpticalDepthISM(z, "total", effWave)
     # Check calculation
     opticalDepth = "diskDustOpticalDepthCentral:dustAtlas"
     DATA = self.DUST.galaxies.get(z, properties=[opticalDepth])
     factorISM = rcParams.getfloat("dustCharlotFall",
                                   "opticalDepthISMFactor",
                                   fallback=1.0)
     wavelengthZeroPoint = rcParams.getfloat("dustCharlotFall",
                                             "wavelengthZeroPoint",
                                             fallback=5500.0)
     wavelengthExponent = rcParams.getfloat("dustCharlotFall",
                                            "wavelengthExponent",
                                            fallback=0.7)
     wavelengthRatio = (effWave / wavelengthZeroPoint)**wavelengthExponent
     opticalDepthISM = factorISM * DATA[opticalDepth].data / wavelengthRatio
     result = self.DUST.getOpticalDepthISM(z, "disk", effWave)
     self.assertTrue(np.array_equal(result, opticalDepthISM))
     return
 def test_MagnitudeGet(self):
     z = 1.0
     zStr = self.MAGS.galaxies.GH5Obj.getRedshiftString(z)
     # Test absolute magnitudes
     name = "diskMagnitudeAbsolute:SDSS_r:rest:" + zStr
     lumName = "diskLuminositiesStellar:SDSS_r:rest:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data + zeroCorrection)
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     name = "totalMagnitudeAbsolute:SDSS_r:rest:" + zStr + ":AB"
     lumName = "totalLuminositiesStellar:SDSS_r:rest:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data + zeroCorrection)
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     name = "totalMagnitudeAbsolute:SDSS_r:observed:" + zStr + ":vega"
     lumName = "totalLuminositiesStellar:SDSS_r:observed:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data +
                             zeroCorrection) + -0.139302055718797
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     # Test apparent magnitudes
     name = "diskMagnitudeApparent:SDSS_r:rest:" + zStr
     lumName = "diskLuminositiesStellar:SDSS_r:rest:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName, "redshift"])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data + zeroCorrection)
     dm = self.MAGS.galaxies.GH5Obj.cosmology.band_corrected_distance_modulus(
         GALS["redshift"].data)
     truth += dm
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     name = "totalMagnitudeApparent:SDSS_r:rest:" + zStr + ":AB"
     lumName = "totalLuminositiesStellar:SDSS_r:rest:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName, "redshift"])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data + zeroCorrection)
     dm = self.MAGS.galaxies.GH5Obj.cosmology.band_corrected_distance_modulus(
         GALS["redshift"].data)
     truth += dm
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     name = "totalMagnitudeApparent:SDSS_r:observed:" + zStr + ":vega"
     lumName = "totalLuminositiesStellar:SDSS_r:observed:" + zStr
     GALS = self.MAGS.galaxies.get(z, properties=[lumName, "redshift"])
     zeroCorrection = rcParams.getfloat("magnitude",
                                        "zeroCorrection",
                                        fallback=1.0e-50)
     truth = -2.5 * np.log10(GALS[lumName].data +
                             zeroCorrection) + -0.139302055718797
     dm = self.MAGS.galaxies.GH5Obj.cosmology.band_corrected_distance_modulus(
         GALS["redshift"].data)
     truth += dm
     DATA = self.MAGS.get(name, z)
     self.assertEqual(DATA.name, name)
     self.assertTrue(np.allclose(truth, DATA.data))
     # Check returns None for missing luminosities
     name = "diskMagnitudeApparent:SDSS_X:rest:" + zStr
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore")
         self.assertIsNone(self.MAGS.get(name, z))
     # Test crashes for bad names
     names = [
         "basicMass", "diskMagnitude:SDSS_r:rest:z1.000",
         "diskApparentMagnitude:SDSS_r:rest:z1.000",
         "diskAbsoluteMagnitude:SDSS_r:rest:z1.000",
         "diskMagnitudeapparent:SDSS_r:rest:z1.000"
     ]
     for name in names:
         with self.assertRaises(RuntimeError):
             self.MAGS.get(name, z)
     return
 def test_LuminositiesGet(self):
     # Check bad names
     redshift = 1.0
     name = "totalLineLuminosity:balmerAlpha6563:rest:z1.000"
     with self.assertRaises(RuntimeError):
         DATA = self.LINES.get(name, redshift)
     # Check values
     zStr = self.LINES.galaxies.GH5Obj.getRedshiftString(redshift)
     component = "disk"
     for line in self.LINES.CLOUDY.listAvailableLines()[:1]:
         name = component + "LineLuminosity:" + line + ":rest:" + zStr
         LymanName, HeliumName, OxygenName = self.LINES.getContinuumLuminosityNames(
             name)
         FLUXES = self.LINES.getContinuumLuminosities(name, redshift)
         if any([FLUXES[name] is None for name in FLUXES.keys()]):
             warnings.warn(funcname+"(): Unable to compute emission line luminosity as one of the "+\
                               "continuum luminosities is missing. Returning None instance.")
             luminosity = None
         else:
             metals = component + "GasMetallicity"
             hydrogen = component + "HydrogenGasDensity"
             GALS = self.LINES.galaxies.get(redshift,
                                            properties=[metals, hydrogen])
             hydrogenGasDensity = np.log10(np.copy(GALS[hydrogen].data))
             metallicity = np.log10(np.copy(GALS[metals].data) + 1.0e-50)
             del GALS
             ionizingFluxHydrogen = self.LINES.getIonizingFluxHydrogen(
                 FLUXES[LymanName].data)
             numberHIIRegion = self.LINES.getNumberHIIRegions(
                 redshift, component)
             mask = numberHIIRegion == 0.0
             numberHIIRegion[mask] = 1.0
             ionizingFluxHydrogen -= np.log10(numberHIIRegion)
             ionizingFluxHeliumToHydrogen = self.LINES.getIonizingFluxRatio(
                 FLUXES[LymanName].data, FLUXES[HeliumName].data)
             ionizingFluxOxygenToHelium = self.LINES.getIonizingFluxRatio(
                 FLUXES[HeliumName].data, FLUXES[OxygenName].data)
             luminosity = np.copy(
                 self.LINES.CLOUDY.interpolate(
                     line, metallicity, hydrogenGasDensity,
                     ionizingFluxHydrogen, ionizingFluxHeliumToHydrogen,
                     ionizingFluxOxygenToHelium))
             luminosityMultiplier = self.LINES.getLuminosityMultiplier(
                 name, redshift)
             luminosity *= (luminosityMultiplier * numberHIIRegion * erg /
                            luminositySolar)
             zeroCorrection = rcParams.getfloat("emissionLine",
                                                "zeroCorrection",
                                                fallback=1.0e-50)
             luminosity += zeroCorrection
         DATA = self.LINES.get(name, redshift)
         if luminosity is None:
             self.assertIsNone(DATA.data)
         else:
             diff = np.fabs(DATA.data - luminosity)
             [
                 self.assertLessEqual(d, 1.0e-6) for d in diff
                 if np.invert(np.isnan(d))
             ]
             maskD = np.isnan(DATA.data)
             mask0 = np.isnan(luminosity)
             [self.assertEqual(m, n) for m, n in zip(maskD, mask0)]
     return