seddata = np.loadtxt('../sed_data/El_B2004a.sed') # turn into SED object sed = sedFilter.SED(seddata[:,0], seddata[:,1]) # instantiate photometry calculations # need cosmological model h=1. omegamat=0.3 omegaDE=0.7 wX=-1. wXa=0. cosmoModel = cosmo.cosmologyCalculator(h, omegamat, omegaDE, wX, wXa) # need error model # fractional flux error = 10% pars = {} pars["fracError"] = 0.1 errorModel = ephot.FractionalErrorModel(pars) # LSST errors, default parameters (=median observing conditions and 1yr of observations) LsstErrorModel = ephot.LSSTErrorModel() # Now can instantiate ObsMag class p = phot.ObsMag(sed, filterDict, cosmoModel, errorModel) pLSST = phot.ObsMag(sed, filterDict, cosmoModel, LsstErrorModel)
# filter set of choice is the LSST filters listOfFilters = 'LSST.filters' pathToFilters = '../filter_data' # create a dictionary: keyword is filter name, value is a Filter object filterDict = sedFilter.createFilterDict(listOfFilters, pathToFilters) # load in elliptical SED (1st col: wavelength in A, 2nd col: fluxes in wl units) seddata = np.loadtxt('../sed_data/El_B2004a.sed') testsed = sedFilter.SED(seddata[:,0], seddata[:,1]) # need cosmological model (with default parameter values) cosmomodel = cosmo.cosmologyCalculator() # Notice that the API for both the python and cython modules is the same: only difference is the import calcMagCython = cphot.CalcMag(testsed, filterDict, cosmomodel) calcMagPython = phot.CalcMag(testsed, filterDict, cosmomodel) # calculate magntidude in the LSST g band for a galaxy with M_r=-20 at different redshifts nz = 100 for i in range(nz): z = i*0.01 start_time = time.time() cython_result = calcMagCython.getMag("LSST_g", z, ("LSST_r", -20.)) end_time = time.time()
# List of filters for testing listOfFilters = 'LSST.filters' pathToFilters = '../filter_data' TEST_FILTERDICT = sedFilter.createFilterDict(listOfFilters, pathToFilters) FILTERLIST = sedFilter.orderFiltersByLamEff(TEST_FILTERDICT) # List of SEDs for testing SEDLIST = [] sedfiles = ['../sed_data/El_B2004a.sed','../sed_data/Sbc_B2004a.sed','../sed_data/Scd_B2004a.sed', '../sed_data/Im_B2004a.sed'] for name in sedfiles: seddata = np.loadtxt(name) SEDLIST.append(sedFilter.SED(seddata[:,0], seddata[:,1])) # Cosmological model COSMOMODEL = cosmo.cosmologyCalculator() class TestPhotCalcs(unittest.TestCase): def setUp(self): """Load in the test SED and filters""" self.testsed = TEST_SED self.testfilters = TEST_FILTERDICT self.filterlist = FILTERLIST def tearDown(self): """Delete test SED and filters""" del self.testsed
# load in elliptical SED (1st col: wavelength in A, 2nd col: fluxes in wl units) seddata = np.loadtxt('../sed_data/El_B2004a.sed') # turn into SED object sed = sedFilter.SED(seddata[:, 0], seddata[:, 1]) # instantiate photometry calculations # need cosmological model h = 1. omegamat = 0.3 omegaDE = 0.7 wX = -1. wXa = 0. cosmoModel = cosmo.cosmologyCalculator(h, omegamat, omegaDE, wX, wXa) # need error model # fractional flux error = 10% pars = {} pars["fracError"] = 0.1 errorModel = ephot.FractionalErrorModel(pars) # LSST errors, default parameters (=median observing conditions and 1yr of observations) LsstErrorModel = ephot.LSSTErrorModel() # Now can instantiate ObsMag class p = phot.ObsMag(sed, filterDict, cosmoModel, errorModel) pLSST = phot.ObsMag(sed, filterDict, cosmoModel, LsstErrorModel)
pathToFilters = '../filter_data' TEST_FILTERDICT = sedFilter.createFilterDict(listOfFilters, pathToFilters) FILTERLIST = sedFilter.orderFiltersByLamEff(TEST_FILTERDICT) # List of SEDs for testing SEDLIST = [] sedfiles = [ '../sed_data/El_B2004a.sed', '../sed_data/Sbc_B2004a.sed', '../sed_data/Scd_B2004a.sed', '../sed_data/Im_B2004a.sed' ] for name in sedfiles: seddata = np.loadtxt(name) SEDLIST.append(sedFilter.SED(seddata[:, 0], seddata[:, 1])) # Cosmological model COSMOMODEL = cosmo.cosmologyCalculator() class TestPhotCalcs(unittest.TestCase): def setUp(self): """Load in the test SED and filters""" self.testsed = TEST_SED self.testfilters = TEST_FILTERDICT self.filterlist = FILTERLIST def tearDown(self): """Delete test SED and filters""" del self.testsed del self.testfilters def test_throw_no_filter_error(self):
import time import cosmo # filter set of choice is the LSST filters listOfFilters = 'LSST.filters' pathToFilters = '../filter_data' # create a dictionary: keyword is filter name, value is a Filter object filterDict = sedFilter.createFilterDict(listOfFilters, pathToFilters) # load in elliptical SED (1st col: wavelength in A, 2nd col: fluxes in wl units) seddata = np.loadtxt('../sed_data/El_B2004a.sed') testsed = sedFilter.SED(seddata[:, 0], seddata[:, 1]) # need cosmological model (with default parameter values) cosmomodel = cosmo.cosmologyCalculator() # Notice that the API for both the python and cython modules is the same: only difference is the import calcMagCython = cphot.CalcMag(testsed, filterDict, cosmomodel) calcMagPython = phot.CalcMag(testsed, filterDict, cosmomodel) # calculate magntidude in the LSST g band for a galaxy with M_r=-20 at different redshifts nz = 100 for i in range(nz): z = i * 0.01 start_time = time.time() cython_result = calcMagCython.getMag("LSST_g", z, ("LSST_r", -20.)) end_time = time.time() cython_time = end_time - start_time