コード例 #1
0
ファイル: zspsmodel.py プロジェクト: bnord/LensPop
    def __init__(self,files,axes,filters,oldModels=None):
        """
        All arguments (files,axes,filters,redshifts) are required.

        `files' is a list of filenames. Each filename points to a pickle'd
            set of SPS spectra.
        `axes' is a dictionary; the keys are each of the parameters of the
            SPS model. Each key points to a dictionary with two keys: `points'
            and `eval.' The `points' value is an array describing the point
            the axis is defined on, and `eval' is a spline model for the axis.
        `filters' is a string (or list of strings) containing the name(s) of
            the filter(s) to be evaulated.
        `redshifts' is the redshift (or list of redshifts) at which the SEDs
            should be evaluated.
        """
        from stellarpop import tools
        self.filters = {}
        if type(filters)==type([]):
            for filter in filters:
                self.filters[filter] = tools.filterfromfile(filter)
        else:
            self.filters[filter] = tools.filterfromfile(filter)
        self.filter_names = self.filters.keys()

        self.axes_names = axes.keys()
        self.naxes = len(axes.keys())

        self.axes = axes
        self.files = files

        self.models = {}
        self.models = self.create_models(oldModels)
コード例 #2
0
    def __init__(self, spex, axes, filters, redshift=None):
        """
        All arguments (files,axes,filters,redshifts) are required.

        `files' is a list of filenames. Each filename points to a cPickle'd
            set of SPS spectra.
        `axes' is a dictionary; the keys are each of the parameters of the
            SPS model. Each key points to a dictionary with two keys: `points'
            and `eval.' The `points' value is an array describing the point
            the axis is defined on, and `eval' is a spline model for the axis.
        `filters' is a string (or list of strings) containing the name(s) of
            the filter(s) to be evaulated.
        `redshifts' is the redshift (or list of redshifts) at which the SEDs
            should be evaluated.
        """
        from stellarpop import tools
        self.filters = {}
        if type(filters) == type([]):
            for filter in filters:
                self.filters[filter] = tools.filterfromfile(filter)
        else:
            self.filters[filter] = tools.filterfromfile(filter)
        self.filter_names = self.filters.keys()

        self.axes = axes
        self.redshift = redshift
        self.spex = spex

        self.models = {}
        self.models = self.create_models()
        del self.spex
コード例 #3
0
ファイル: GetPhotometry.py プロジェクト: lindzlebean/EELs
def MassB2toB(B,z,age='4.000'):
    sed = tools.getSED('BC_Z=1.0_age='+age+'gyr')
    bfilt = tools.filterfromfile('F555W_ACS')
    restfilt = tools.filterfromfile('F435W_ACS')
    B_modrest = tools.ABFM(restfilt,sed,0.0) 
    B_modobs = tools.ABFM(bfilt,sed,z)
    B_rest = B + B_modrest - B_modobs
    mass_B = 0.4*(B_rest - B_modrest)
    B_sun = 5.372
    DL = dist.luminosity_distance(z)
    DM = 5.*np.log10(DL*1e6) - 5.
    B_restabs = B_rest - DM
    lum = -0.4*(B_restabs - B_sun)
    return lum, B_rest
コード例 #4
0
ファイル: PopulationFunctions.py プロジェクト: bnord/LensPop
    def Colourspline(self):
        from stellarpop import tools 
        sed = tools.getSED('BC_Z=1.0_age=10.00gyr')
        #different SEDs don't change things much

        rband=tools.filterfromfile('r_SDSS')
        z=self.zlbins
        self.colourspline={}
        for band in self.bands:
          if band!="VIS":  
            c=z*0
            Cband=tools.filterfromfile(band)
            for i in range(len(z)):
                c[i] = - (tools.ABFM(Cband,sed,z[i]) - tools.ABFM(rband,sed,0))
            self.colourspline[band]=interpolate.splrep(z,c)
コード例 #5
0
    def Colourspline(self):
        from stellarpop import tools
        sed = tools.getSED('BC_Z=1.0_age=10.00gyr')
        #different SEDs don't change things much

        rband = tools.filterfromfile('r_SDSS')
        z = self.zlbins
        self.colourspline = {}
        for band in self.bands:
            if band != "VIS":
                c = z * 0
                Cband = tools.filterfromfile(band)
                for i in range(len(z)):
                    c[i] = -(tools.ABFM(Cband, sed, z[i]) -
                             tools.ABFM(rband, sed, 0))
                self.colourspline[band] = interpolate.splrep(z, c)
コード例 #6
0
def getColor(f1, f2, z):
    import numpy
    from stellarpop import tools
    import spasmoid
    dir = spasmoid.__path__[0] + "/data"

    qso = numpy.loadtxt('%s/vandenBerk.dat' % dir)
    w = qso[:, 0].copy()
    m = qso[:, 1].copy()
    s = qso[:, 2].copy()

    f1 = tools.filterfromfile(f1)
    f2 = tools.filterfromfile(f2)

    sed = [w, m]
    color = tools.ABFilterMagnitude(f1, sed, z) - tools.ABFilterMagnitude(
        f2, sed, z)
    return color
コード例 #7
0
ファイル: PhotMass.py プロジェクト: lindzlebean/pylathon
def MassK(K,z):
    sed = tools.getSED('BC_Z=1.0_age=7.000gyr')
    kfilt = tools.filterfromfile('Kp_NIRC2')
    K_modrest = tools.ABFM(kfilt,sed,0.0) 
    K_modobs = tools.ABFM(kfilt,sed,z)
    K_rest = K + K_modrest - K_modobs
    mass_K = 0.4*(K_rest - K_modrest)
    K_sun = 5.19
    DL = dist.luminosity_distance(z)
    DM = 5.*np.log10(DL*1e6) - 5.
    K_restabs = K_rest - DM
    lum = -0.4*(K_restabs - K_sun)
    return lum, K_rest
コード例 #8
0
ファイル: PhotMass.py プロジェクト: lindzlebean/pylathon
def MassB1(B,z):
    sed = tools.getSED('BC_Z=1.0_age=7.000gyr')
    bfilt = tools.filterfromfile('F606W_ACS')
    B_modrest = tools.ABFM(bfilt,sed,0.0) 
    B_modobs = tools.ABFM(bfilt,sed,z)
    B_rest = B + B_modrest - B_modobs
    mass_B = 0.4*(B_rest - B_modrest)
    B_sun = 4.74
    DL = dist.luminosity_distance(z)
    DM = 5.*np.log10(DL*1e6) - 5.
    B_restabs = B_rest - DM
    lum = -0.4*(B_restabs - B_sun)
    return lum, B_rest
コード例 #9
0
ファイル: PhotMass.py プロジェクト: lindzlebean/pylathon
def MassR(R,z):
    sed = tools.getSED('BC_Z=1.0_age=7.000gyr')
    rfilt = tools.filterfromfile('F814W_ACS')  
    R_modrest = tools.ABFM(rfilt,sed,0.0)
    R_modobs = tools.ABFM(rfilt,sed,z)
    R_rest = R + R_modrest - R_modobs
    mass_R = 0.4*(R_rest - R_modrest)
    R_sun = 4.57
    DL = dist.luminosity_distance(z)
    DM = 5.*np.log10(DL*1e6) - 5.
    R_restabs = R_rest - DM
    lum = -0.4*(R_restabs - R_sun)
    return lum, R_rest
コード例 #10
0
def get_sdss_filters():
    """Retrieves the SDSS filter throughputs from files in stellarpop/filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        Each value is a tuple of (Numpy ndarray of wavelengths in Angstroms,
        Numpy ndarray of throughputs) 
    """
    from stellarpop import tools

    filters_dict = {}
    for band in 'ugriz':
        filters_dict[band] = tools.filterfromfile('%s_SDSS' %band)
    return filters_dict
コード例 #11
0
def get_sdss_filters():
    """Retrieves the SDSS filter throughputs from files in stellarpop/filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        Each value is a tuple of (Numpy ndarray of wavelengths in Angstroms,
        Numpy ndarray of throughputs) 
    """
    from stellarpop import tools

    filters_dict = {}
    for band in 'ugriz':
        filters_dict[band] = tools.filterfromfile('%s_SDSS' % band)
    return filters_dict
コード例 #12
0
ファイル: db.py プロジェクト: stevet40/OM10
    def paint(self, Nmax=None, verbose=False,
              lrg_input_cat='$OM10_DIR/data/LRGo.txt',
              qso_input_cat='$OM10_DIR/data/QSOo.txt',
              synthetic=False):
        """
        Add new columns to the table, for the magnitudes in various filters.

        Parameters
        ----------
        synthetic : boolean
            Use `lenspop` to make synthetic magnitudes in various filters
        target : string
            Paint lenses ('lens') or sources ('source')
        lrg_input_cat : string
            Name of LRG catalog, if not using synthetic paint
        qso_input_cat : string
            Name of QSO catalog, if not using synthetic paint
        verbose : boolean
           print progress to stdout

        Notes
        -----
        * Synthetic painting is very slow, as we loop over each object.
        * The treatment of QSOs may be flawed: the offset calculation has not
          been tested.

        """

        if synthetic==False:
        # read data from SDSS
            f=open(os.path.expandvars(lrg_input_cat),'r')
            lrg=loadtxt(f)
            f.close()
            g=open(os.path.expandvars(qso_input_cat),'r')
            qso=loadtxt(g)
            g.close()

        ###MY OWN REDSHIFT ONLY MATCHING HERE:

            lens_props = ['MAGG_LENS','MAGR_LENS','MAGI_LENS','MAGZ_LENS', \
            'MAGW1_LENS','MAGW2_LENS','MAGW3_LENS','MAGW4_LENS', 'SDSS_FLAG_LENS']

            src_props = ['MAGG_SRC','MAGR_SRC','MAGI_SRC','MAGZ_SRC', \
            'MAGW1_SRC','MAGW2_SRC','MAGW3_SRC','MAGW4_SRC', 'SDSS_FLAG_SRC']

            tmp_lens = Table(np.zeros((len(self.sample),len(lens_props)),dtype='f8'),names=lens_props)
            tmp_src = Table(np.zeros((len(self.sample),len(src_props)),dtype='f8'),names=src_props)

            if verbose: print('setup done')

            lrg_sort = lrg[np.argsort(lrg[:,0]),:]
            qso_sort = qso[np.argsort(qso[:,0]),:]
            lens_count = 0

            for lens in self.sample:

                #paint lens
                ind = np.searchsorted(lrg_sort[:,0],lens['ZLENS'])
                if ind >= len(lrg_sort): ind = len(lrg_sort) - 1
                tmp_lens[lens_count] = lrg_sort[ind,6:] - lrg_sort[ind,8] + lens['APMAG_I'] #assign colors, not mags
                #paint source
                qso_ind = np.searchsorted(qso_sort[:,0],lens['ZSRC'])
                if qso_ind >= len(qso_sort): qso_ind = len(qso_sort) - 1
                tmp_src[lens_count] = qso_sort[qso_ind,1:] - qso_sort[qso_ind,3] + lens['MAGI']

                lens_count += 1

            self.sample = hstack([self.sample,tmp_lens,tmp_src])


        if synthetic==True:
            lens_count = 0
            total = len(self.sample)
            Rfilter = tools.filterfromfile('r_SDSS')
            Ufilter = tools.filterfromfile('u_SDSS')
            # sort the Ufilter array
            Ufilterarg=np.sort(Ufilter[1])
            Ufilter = (Ufilter[0], Ufilterarg, 1)
            Gfilter = tools.filterfromfile('g_SDSS')
            Ifilter = tools.filterfromfile('i_SDSS')
            Zfilter = tools.filterfromfile('z_SDSS')
            self.Nlenses=len(self.sample)
            bands = ('r_SDSS_lens', 'g_SDSS_lens', 'i_SDSS_lens', 'z_SDSS_lens', 'u_SDSS_lens','r_SDSS_quasar', 'g_SDSS_quasar', 'i_SDSS_quasar', 'z_SDSS_quasar', 'u_SDSS_quasar')
            if verbose: print('OM10: computing synthetic magnitudes in the following bands: ', bands)
            # call a distance class constructor
            d = distances.Distance()
            # number of data in the table of calculated magnitude
            totalEntrees = self.Nlenses*10.0
            t = Table(np.arange(totalEntrees).reshape(self.Nlenses, 10),
                      names=bands)
            Lsed = tools.getSED('BC_Z=1.0_age=9.000gyr')
            Qsed = tools.getSED('agn')
            from astropy.cosmology import FlatLambdaCDM
            cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
            lenspop_constructor = population_functions.LensPopulation_()
            for lens in self.sample:
                # calculate the quasar magnitude
                redshift = lens['ZSRC']
                RF_Imag_app_q = lens['MAGI_IN']
                Qoffset = RF_Imag_app_q - tools.ABFilterMagnitude(Ifilter, Qsed, redshift)
                RF_Rmag_app_q = tools.ABFilterMagnitude(Rfilter, Qsed, redshift) + Qoffset
                RF_Gmag_app_q = tools.ABFilterMagnitude(Gfilter, Qsed, redshift) + Qoffset
                RF_Zmag_app_q = tools.ABFilterMagnitude(Zfilter, Qsed, redshift) + Qoffset
                if(redshift<3.9):
                    RF_Umag_app_q = tools.ABFilterMagnitude(Ufilter, Qsed, redshift) + Qoffset
                elif(redshift>=3.9):
                    RF_Umag_app_q = 99
                # calculate the lens magnitude
                veldisp = np.atleast_1d(lens['VELDISP'])
                redshift = lens['ZLENS']
                # Reference Frame Absolute R magnitude
                RF_RMag_abs, _ = lenspop_constructor.EarlyTypeRelations(veldisp)
                RMag_abs = tools.ABFilterMagnitude(Rfilter, Lsed, redshift)
                distMod = cosmo.distmod(redshift).value
                Rmag_app = RMag_abs + distMod
                offset_abs_app = RMag_abs - Rmag_app
                offset_RF_abs = RF_RMag_abs - RMag_abs
                RF_Rmag_app = RF_RMag_abs - offset_abs_app
                # Get filters and calculate magnitudes for each filter:
                RF_Umag_app = tools.ABFilterMagnitude(Ufilter, Lsed, redshift) + offset_RF_abs + distMod
                RF_Gmag_app = tools.ABFilterMagnitude(Gfilter, Lsed, redshift) + offset_RF_abs + distMod
                RF_Imag_app = tools.ABFilterMagnitude(Ifilter, Lsed, redshift) + offset_RF_abs + distMod
                RF_Zmag_app = tools.ABFilterMagnitude(Zfilter, Lsed, redshift) + offset_RF_abs + distMod
                t['u_SDSS_lens'][lens_count] = RF_Umag_app
                t['r_SDSS_lens'][lens_count] = RF_Rmag_app
                t['g_SDSS_lens'][lens_count] = RF_Gmag_app
                t['i_SDSS_lens'][lens_count] = RF_Imag_app
                t['z_SDSS_lens'][lens_count] = RF_Zmag_app
                t['u_SDSS_quasar'][lens_count] = RF_Umag_app_q
                t['r_SDSS_quasar'][lens_count] = RF_Rmag_app_q
                t['g_SDSS_quasar'][lens_count] = RF_Gmag_app_q
                t['i_SDSS_quasar'][lens_count] = RF_Imag_app_q
                t['z_SDSS_quasar'][lens_count] = RF_Zmag_app_q
                lens_count = lens_count + 1
                dot = np.mod(lens_count, total/np.min([79,total])) == 0
                if verbose and dot:
                    print('.', end="")

            # Update the sample by adding the table of calculated magnitude
            self.sample.add_columns(t.columns.values())
            self.lenses = self.sample.copy()

        return
コード例 #13
0
ファイル: SedFitting2.py プロジェクト: lindzlebean/pylathon
import numpy as np
import pylab as pl
import pyfits as py
from stellarpop import tools
from astLib import astCalc
from scipy.interpolate import splrep, splev, splint

''' Predict the offset as a function of age - currently from luminosity evolution alone. Assuming a single redshift of the source population of z=0.55, which I reckon is about the average (but haven't calculated...! How lazy.) '''
ages = ['0.001','0.010','0.125','0.250','0.375','0.500','0.625','0.750','0.875','1.000','1.250','1.500','1.700','1.750','2.000','2.200','2.250','2.500','3.500','4.500','5.500','6.000','7.000','8.000','9.000','10.00','12.00','15.00','20.00']
age_array = np.array([0.001,0.010,0.125,0.250,0.375,0.500,0.625,0.750,0.875,1.000,1.250,1.500,1.700,1.750,2.000,2.200,2.250,2.500,3.500,4.500,5.500,6.000,7.000,8.000,9.000,10.00,12.00,15.00,20.00])
z=0.55
tl = astCalc.tl(z)
bfilt1 = tools.filterfromfile('F555W_ACS')
bfilt = tools.filterfromfile('F606W_ACS')
rfilt = tools.filterfromfile('F814W_ACS')
bmags = np.zeros(len(ages))
rmags = bmags*0.
for i in range(len(ages)):
    sed = tools.getSED('BC_Z=1.0_age='+str(ages[i])+'gyr')
    bmags[i] = tools.ABFM(bfilt,sed,0)
    rmags[i] = tools.ABFM(rfilt,sed,0)

'''pl.figure()
pl.plot(age_array-tl,bmags,'Navy',label='b, z=0')
pl.plot(age_array,bmags,'CornflowerBlue',label='b,z=0.55')
pl.plot(age_array-tl,rmags,'Crimson',label='r, z=0')
pl.plot(age_array,rmags,'LightCoral',label='r,z=0.55')
pl.legend(loc='lower right')
pl.xlabel('age / Gyr')
pl.ylabel('AB magnitude')'''
コード例 #14
0
ファイル: PhotMass.py プロジェクト: lindzlebean/pylathon
lum_R, R_rest = MassR(R,z)
print 'J0913, source galaxy: ',  '%.2f'%B_rest, '%.2f'%R_rest, '%.2f'%lum_B, '%.2f'%lum_R

# J0837 - want to know its mass to compare with dust lane!
z = 0.528
B=20.75
lum_B, B_rest = MassB1(B,z)
print 'J0837: ', '%.2f'%B_rest,'%.2f'%lum_B



plot=False
if plot == True:
    ## visualise filters
    sed = tools.getSED('BC_Z=1.0_age=7.000gyr')
    bfilt = tools.filterfromfile('F606W_ACS')
    rfilt = tools.filterfromfile('F814W_ACS')
    kfilt = tools.filterfromfile('Kp_NIRC2')
    pl.figure()
    pl.plot(sed[0],sed[1],'k')
    pl.plot(bfilt[0],bfilt[1]*1e-5,'CornflowerBlue',label='F606W')
    pl.plot(rfilt[0],rfilt[1]*1e-5,'Crimson',label='F814W')
    pl.plot(kfilt[0],kfilt[1]*5e-8,'Orange',label='K')
    pl.xscale('log')
    pl.legend(loc='upper right')
    ## plot redshifted filters - say for the source
    z=0.69
    pl.plot(bfilt[0]/(1.+z),bfilt[1]*1e-5,'Blue',label='F606W')
    pl.plot(rfilt[0]/(1.+z),rfilt[1]*1e-5,'DarkRed',label='F814W')
    pl.plot(kfilt[0]/(1.+z),kfilt[1]*5e-8,'DarkOrange',label='K')
コード例 #15
0
ファイル: mag2mag.py プロジェクト: peterrwi/LensPop
    import os
    os.system(cmd)
    sys.exit()

if vega is None:
    vega = False  # No vega flag = use AB mags

if convert is None:
    convert = False

if m1 is None or f1 is None or z1 is None or SEDtype is None:
    print "Error: Incomplete input information. Use -u for usage."
    sys.exit()

from stellarpop import tools
f1 = tools.filterfromfile(f1)
if f2 is None:
    f2 = f1
else:
    f2 = tools.filterfromfile(f2)
if z2 is None:
    z2 = z1

SED = tools.getSED(SEDtype)

if vega:
    filtermag = tools.VegaFilterMagnitude(f1, SED, z1)
#    vegatmp = tools.getSED('Vega')
#    vegaAB = tools.ABFilterMagnitude(f1,vegatmp,0.)
else:
    filtermag = tools.ABFilterMagnitude(f1, SED, z1)
コード例 #16
0
ファイル: mag2mag.py プロジェクト: bnord/LensPop
    import os
    os.system(cmd)
    sys.exit()

if vega is None:
    vega = False # No vega flag = use AB mags

if convert is None:
    convert = False

if m1 is None or f1 is None or z1 is None or SEDtype is None:
    print "Error: Incomplete input information. Use -u for usage."
    sys.exit()

from stellarpop import tools
f1 = tools.filterfromfile(f1)
if f2 is None:
    f2 = f1
else:
    f2 = tools.filterfromfile(f2)
if z2 is None:
    z2 = z1

SED = tools.getSED(SEDtype)

if vega:
    filtermag = tools.VegaFilterMagnitude(f1,SED,z1)
#    vegatmp = tools.getSED('Vega')
#    vegaAB = tools.ABFilterMagnitude(f1,vegatmp,0.)
else:
    filtermag = tools.ABFilterMagnitude(f1,SED,z1)