Пример #1
0
def calculate_rf_quasar_magnitudes(quasar_redshift, apparent_magnitude_i, filters_dict):
    """Calculates the reference-frame quasar magnitudes in multiple filters

    Parameters
    ----------
    quasar_redshift : float
        Redshift of the source quasar
    apparent_magnitude_i : float
        Apparent magnitude of the source AGN in the I-band
    filters_dict : dict
        (See output of `get_sdss_filters` for details)
        Throughputs of various filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        representing the filter
        Each value is the reference-frame apparent magnitude of the quasar
        in the 'key' filter, of type float
    """
    from stellarpop import tools

    quasar_sed = tools.getSED('agn')
    q_offset = apparent_magnitude_i - tools.ABFilterMagnitude(filters_dict['i'], quasar_sed, quasar_redshift)
    rf_quasar_appmag = {}
    if quasar_redshift < 3.9:
        rf_quasar_appmag['u'] = tools.ABFilterMagnitude(filters_dict['u'], quasar_sed, quasar_redshift) + q_offset
    else:
        rf_quasar_appmag['u'] = 99.0
    for band in 'griz':
        rf_quasar_appmag[band] = tools.ABFilterMagnitude(filters_dict[band], quasar_sed, quasar_redshift) + q_offset
    return rf_quasar_appmag
Пример #2
0
def calculate_rf_lens_magnitudes(lens_redshift, velocity_dispersion,
                                 filters_dict):
    """Calculates the reference-frame lens magnitudes in multiple filters

    Parameters
    ----------
    lens_redshift : float
        Redshift of the lens
    velocity_dispersion : float
        Velocity dispersion of the lens
    filters_dict : dict
        (See output of `get_sdss_filters` for details)
        Throughputs of various filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        representing the filter
        Each value is the reference-frame apparent magnitude of the quasar
        in the 'key' filter, of type float
    """
    from stellarpop import tools
    from lenspop import population_functions, distances
    from astropy.cosmology import FlatLambdaCDM

    # Instantiate Distance
    distance = distances.Distance()  #TODO: necessary?
    # Instantiate LensPopulation
    lenspop = population_functions.LensPopulation_()
    # Instantiate FlatLambdaCDM cosmology with reasonable parameters
    cosmology = FlatLambdaCDM(H0=70.0, Om0=0.3)

    lens_sed = tools.getSED('BC_Z=1.0_age=9.000gyr')
    velocity_dispersion = np.atleast_1d(velocity_dispersion)

    # Absolute --> apparent magnitude conversion in the R-band
    lens_abmag_r = tools.ABFilterMagnitude(filters_dict['r'], lens_sed,
                                           lens_redshift)
    distance_modulus = cosmology.distmod(lens_redshift).value
    lens_appmag_r = lens_abmag_r + distance_modulus

    # [Reference frame] Absolute --> apparent magnitude conversion in the R-band
    rf_lens_abmag_r, _ = lenspop.EarlyTypeRelations(velocity_dispersion)
    rf_lens_appmag = {}
    rf_lens_appmag['r'] = rf_lens_abmag_r + distance_modulus

    # Quantity which is added to ~magnitude to convert it into reference-frame ~magnitude
    offset_rf = rf_lens_abmag_r - lens_abmag_r

    # Converting absolute magnitude to reference-frame apparent magnitude
    for band in 'ugiz':
        rf_lens_appmag[band] = tools.ABFilterMagnitude(
            filters_dict[band], lens_sed,
            lens_redshift) + offset_rf + distance_modulus
    return rf_lens_appmag
Пример #3
0
def calculate_rf_lens_magnitudes(lens_redshift, velocity_dispersion, filters_dict):
    """Calculates the reference-frame lens magnitudes in multiple filters

    Parameters
    ----------
    lens_redshift : float
        Redshift of the lens
    velocity_dispersion : float
        Velocity dispersion of the lens
    filters_dict : dict
        (See output of `get_sdss_filters` for details)
        Throughputs of various filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        representing the filter
        Each value is the reference-frame apparent magnitude of the quasar
        in the 'key' filter, of type float
    """
    from stellarpop import tools
    from lenspop import population_functions, distances
    from astropy.cosmology import FlatLambdaCDM

    # Instantiate Distance
    distance = distances.Distance() #TODO: necessary?
    # Instantiate LensPopulation
    lenspop = population_functions.LensPopulation_()
    # Instantiate FlatLambdaCDM cosmology with reasonable parameters
    cosmology = FlatLambdaCDM(H0=70.0, Om0=0.3)

    lens_sed = tools.getSED('BC_Z=1.0_age=9.000gyr')
    velocity_dispersion = np.atleast_1d(velocity_dispersion)

    # Absolute --> apparent magnitude conversion in the R-band
    lens_abmag_r = tools.ABFilterMagnitude(filters_dict['r'], lens_sed, lens_redshift)
    distance_modulus = cosmology.distmod(lens_redshift).value
    lens_appmag_r = lens_abmag_r + distance_modulus

    # [Reference frame] Absolute --> apparent magnitude conversion in the R-band
    rf_lens_abmag_r, _ = lenspop.EarlyTypeRelations(velocity_dispersion)
    rf_lens_appmag = {}
    rf_lens_appmag['r'] = rf_lens_abmag_r + distance_modulus

    # Quantity which is added to ~magnitude to convert it into reference-frame ~magnitude
    offset_rf = rf_lens_abmag_r - lens_abmag_r

    # Converting absolute magnitude to reference-frame apparent magnitude
    for band in 'ugiz':
        rf_lens_appmag[band] = tools.ABFilterMagnitude(filters_dict[band], lens_sed, lens_redshift) + offset_rf + distance_modulus
    return rf_lens_appmag
Пример #4
0
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
Пример #5
0
def MassB2(B,z):
    sed = tools.getSED('BC_Z=1.0_age=7.000gyr')
    bfilt = tools.filterfromfile('F555W_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.83
    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
Пример #6
0
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
Пример #7
0
def MassB1toB(B,z,age='4.000'):
    sed = tools.getSED('BC_Z=1.0_age='+age+'gyr')
    bfilt = tools.filterfromfile('F606W_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 # ref: EzGal
    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
Пример #8
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)
Пример #9
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)
Пример #10
0
def calculate_rf_quasar_magnitudes(quasar_redshift, apparent_magnitude_i,
                                   filters_dict):
    """Calculates the reference-frame quasar magnitudes in multiple filters

    Parameters
    ----------
    quasar_redshift : float
        Redshift of the source quasar
    apparent_magnitude_i : float
        Apparent magnitude of the source AGN in the I-band
    filters_dict : dict
        (See output of `get_sdss_filters` for details)
        Throughputs of various filters

    Returns
    -------
    dict
        Each key is one of string characters 'u', 'g', 'r', 'i', 'z'
        representing the filter
        Each value is the reference-frame apparent magnitude of the quasar
        in the 'key' filter, of type float
    """
    from stellarpop import tools

    quasar_sed = tools.getSED('agn')
    q_offset = apparent_magnitude_i - tools.ABFilterMagnitude(
        filters_dict['i'], quasar_sed, quasar_redshift)
    rf_quasar_appmag = {}
    if quasar_redshift < 3.9:
        rf_quasar_appmag['u'] = tools.ABFilterMagnitude(
            filters_dict['u'], quasar_sed, quasar_redshift) + q_offset
    else:
        rf_quasar_appmag['u'] = 99.0
    for band in 'griz':
        rf_quasar_appmag[band] = tools.ABFilterMagnitude(
            filters_dict[band], quasar_sed, quasar_redshift) + q_offset
    return rf_quasar_appmag
Пример #11
0
    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
Пример #12
0
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')'''

bmodz = splrep(age_array,bmags)
bmod0 = splrep(age_array-tl,bmags)
b0,bz = splev(age_array[:-1],bmod0), splev(age_array[:-1],bmodz) # where age_array now represents the age at z=0.55
Пример #13
0
lum_B, B_rest = MassB2(B,z)
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')
Пример #14
0
    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)
magoffset = m1 - filtermag
#print magoffset

if vega:
    m2 = tools.VegaFilterMagnitude(f2, SED, z2) + magoffset
else:
    m2 = tools.ABFilterMagnitude(f2, SED, z2) + magoffset
if z1 != z2:
Пример #15
0
    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)
magoffset = m1-filtermag
#print magoffset

if vega:
    m2 = tools.VegaFilterMagnitude(f2,SED,z2)+magoffset
else:
    m2 = tools.ABFilterMagnitude(f2,SED,z2)+magoffset
if z1!=z2: