def get_om10_cc(xi1, xi2, om10_id):
    db = om10.DB(catalog="./qso_mock.fits")

    lens = db.get_lens(om10_id)
    zl = lens.ZLENS[0]
    zs = lens.ZSRC[0]
    qe = 1.0 / (1.0 - lens.ELLIP[0])
    phi = lens.PHIE[0]
    vd0 = lens.VELDISP[0]  # needed from OM10

    re = aa.re_sv(vd0, zl, zs)

    lpars = np.zeros((6))

    lpars[
        0] = 0.0  # x coordinate of the center of lens (in units of Einstein radius).
    lpars[
        1] = 0.0  # y coordinate of the center of lens (in units of Einstein radius).
    lpars[2] = 1.0 / qe  # Axis ratio of lens.
    lpars[3] = 0.0  # Core size of lens (in units of Einstein radius).
    lpars[4] = re  # Einstein radius of lens (in units of arcsec).
    lpars[5] = phi  # Orientation of lens (in units of degree).

    alpha1, alpha2, kappa, shears1, shear2, mu = lensing_model_SIE(
        xi1, xi2, lpars)
    return alpha1, alpha2, mu, kappa
Ejemplo n.º 2
0
 def __init__(self, catsim_cat):
     self.catalog = catsim_cat
     # ****** THIS ASSUMES THAT THE ENVIRONMENT VARIABLE OM10_DIR IS SET *******
     lensdb = om10.DB(catalog=os.environ['OM10_DIR'] +
                      "/data/qso_mock.fits")
     self.lenscat = lensdb.lenses.copy()
     return
Ejemplo n.º 3
0
    def __init__(self,
                 catsim_cat,
                 om10_cat='twinkles_tdc_rung4.fits',
                 density_param=1.):
        """
        Input:
        catsim_cat:
            The results array from an instance catalog.

        density_param:
            A float between 0. and 1.0 that determines the fraction of eligible agn objects that become lensed.

        Output:
        updated_catalog:
            A new results array with lens systems added.
        """

        self.catalog = catsim_cat
        # ****** THIS ASSUMES THAT THE ENVIRONMENT VARIABLE OM10_DIR IS SET *******
        lensdb = om10.DB(catalog=om10_cat)
        self.lenscat = lensdb.lenses.copy()
        self.density_param = density_param
        self.bandpassDict = BandpassDict.loadTotalBandpassesFromFiles(
            bandpassNames=['i'])

        specFileStart = 'Burst'
        for key, val in sorted(iteritems(SpecMap.subdir_map)):
            if re.match(key, specFileStart):
                galSpecDir = str(val)
        galDir = str(
            getPackageDir('sims_sed_library') + '/' + galSpecDir + '/')
        self.LRG_name = 'Burst.25E09.1Z.spec'
        self.LRG = Sed()
        self.LRG.readSED_flambda(str(galDir + self.LRG_name))
Ejemplo n.º 4
0
def get_halo_IDs(om10_id):
    db = om10.DB(catalog="./qso_mock.fits")

    lens = db.get_lens(om10_id)
    #nim= lens.NIMG[0]
    #md = lens.APMAG_I[0]
    #ms = lens.MAGI_IN[0]
    ys1 = lens.XSRC[0]
    ys2 = lens.YSRC[0]
    #xl = 0.0
    #yl = 0.0
    zl = lens.ZLENS[0]
    zs = lens.ZSRC[0]
    qe = 1.0 / (1.0 - lens.ELLIP[0])
    phi = lens.PHIE[0]
    vd0 = lens.VELDISP[0]  # needed from OM10
    mtotal0 = aa.m200_sv(vd0, zl)  # needed from OM10
    print "Input: ", phi, qe, mtotal0, vd0
    #----------------------------------------------------------------------
    # index, snapid,haloid,subhid,ag_stellar,ag_total,eq_stellar,eq_total,ms_stellar,ms_total,vd_stellar
    #
    snapid, haloid, subhid, ag_total, eq_stellar, ms_total, vd_stellar = np.loadtxt(
        "../produce_e_catalogs/results.dat",
        usecols=(1, 2, 3, 5, 6, 9, 10),
        unpack=True)

    nhalos = len(subhid)

    ksi_om10 = (ag_total/phi-1.0)**2.0/nhalos*0.0+(eq_stellar/qe-1.0)**2.0/nhalos*0.4 \
             + (ms_total/mtotal0-1.0)**2.0/nhalos*0.01+(vd_stellar*(1.0+zl)/vd0-1.0)**2.0/nhalos*100.4

    idx = ksi_om10 == np.min(ksi_om10)

    print "Matched: ", ag_total[idx], eq_stellar[idx], ms_total[
        idx], vd_stellar[idx]

    snapid_n = int(snapid[idx])
    haloid_n = int(haloid[idx])
    subhid_n = int(subhid[idx])

    lpar = [snapid_n, haloid_n, subhid_n, zl]
    spar = [ys1, ys2, lens.MAGI_IN[0], zs]
    #----------------------------------------------------------------------
    mui = lens.MAG[0]
    nim = lens.NIMG[0]
    ms = lens.MAGI_IN[0]
    muis = ms - 2.5 * np.log10(np.abs(mui[:nim]))
    ximg1 = lens.XIMG[0][:nim]
    ximg2 = lens.YIMG[0][:nim]
    #print "om10.plot_lens: source magnitudes, magnification, image magnitudes:",ms,mui[:nim],mi
    ipar = [ximg1, ximg2, muis]
    return lpar, spar, ipar, lens
Ejemplo n.º 5
0
        # hdus.header.set('CRVAL1',0.0,'Right ascension (J2000 degrees)')

        # Write them out
        hdus.writeto(scifile,clobber=True)
        hduv.writeto(varfile,clobber=True)

        return


# ======================================================================

if __name__ == '__main__':

# Some examples!

    db = om10.DB(catalog=os.path.expandvars("$OM10_DIR/data/qso_mock.fits"))


# Get one lens:

    id = 7176527
    lens = db.get_lens(id)

# Set up imager:

    imager = om10.Imager(survey='PS1')

    # imager.set('fov',6.0) # Needs to change imsize too!

# Make a single image of the lens:
Ejemplo n.º 6
0
 def setUp(self):
     self.db = om10.DB()
     self.db.paint(synthetic=True)
Ejemplo n.º 7
0
    def __init__(self,
                 catsim_cat,
                 visit_mjd,
                 specFileMap,
                 sed_path,
                 om10_cat='twinkles_lenses_v2.fits',
                 sne_cat='dc2_sne_cat.csv',
                 density_param=1.,
                 cached_sprinkling=False,
                 agn_cache_file=None,
                 sne_cache_file=None,
                 defs_file=None):
        """
        Parameters
        ----------
        catsim_cat: catsim catalog
            The results array from an instance catalog.
        visit_mjd: float
            The mjd of the visit
        specFileMap: 
            This will tell the instance catalog where to write the files
        om10_cat: optional, defaults to 'twinkles_lenses_v2.fits
            fits file with OM10 catalog
        sne_cat: optional, defaults to 'dc2_sne_cat.csv'
        density_param: `np.float`, optioanl, defaults to 1.0
            the fraction of eligible agn objects that become lensed and should
            be between 0.0 and 1.0.
        cached_sprinkling: boolean
            If true then pick from a preselected list of galtileids
        agn_cache_file: str
        sne_cache_file: str
        defs_file: str

        Returns
        -------
        updated_catalog:
            A new results array with lens systems added.
        """

        twinklesDir = getPackageDir('Twinkles')
        om10_cat = os.path.join(twinklesDir, 'data', om10_cat)
        self.catalog = catsim_cat
        # ****** THIS ASSUMES THAT THE ENVIRONMENT VARIABLE OM10_DIR IS SET *******
        lensdb = om10.DB(catalog=om10_cat, vb=False)
        self.lenscat = lensdb.lenses.copy()
        self.density_param = density_param
        self.bandpassDict = BandpassDict.loadTotalBandpassesFromFiles(
            bandpassNames=['i'])

        self.sne_catalog = pd.read_csv(
            os.path.join(twinklesDir, 'data', sne_cat))
        #self.sne_catalog = self.sne_catalog.iloc[:101] ### Remove this after testing
        self.used_systems = []
        self.visit_mjd = visit_mjd
        self.sn_obj = SNObject(0., 0.)
        self.write_dir = specFileMap.subdir_map['(^specFileGLSN)']
        self.sed_path = sed_path

        self.cached_sprinkling = cached_sprinkling
        if self.cached_sprinkling is True:
            if ((agn_cache_file is None) | (sne_cache_file is None)):
                raise AttributeError(
                    'Must specify cache files if using cached_sprinkling.')
            #agn_cache_file = os.path.join(twinklesDir, 'data', 'test_agn_galtile_cache.csv')
            self.agn_cache = pd.read_csv(agn_cache_file)
            #sne_cache_file = os.path.join(twinklesDir, 'data', 'test_sne_galtile_cache.csv')
            self.sne_cache = pd.read_csv(sne_cache_file)
        else:
            self.agn_cache = None
            self.sne_cache = None

        if defs_file is None:
            self.defs_file = os.path.join(twinklesDir, 'data',
                                          'catsim_defs.csv')
        else:
            self.defs_file = defs_file

        specFileStart = 'Burst'
        for key, val in sorted(iteritems(SpecMap.subdir_map)):
            if re.match(key, specFileStart):
                galSpecDir = str(val)
        self.galDir = str(
            getPackageDir('sims_sed_library') + '/' + galSpecDir + '/')

        self.imSimBand = Bandpass()
        self.imSimBand.imsimBandpass()
        #self.LRG_name = 'Burst.25E09.1Z.spec'
        #self.LRG = Sed()
        #self.LRG.readSED_flambda(str(galDir + self.LRG_name))
        #return

        #Calculate imsimband magnitudes of source galaxies for matching

        agn_fname = str(
            getPackageDir('sims_sed_library') + '/agnSED/agn.spec.gz')
        src_iband = self.lenscat['MAGI_IN']
        src_z = self.lenscat['ZSRC']
        self.src_mag_norm = []
        for src, s_z in zip(src_iband, src_z):
            agn_sed = Sed()
            agn_sed.readSED_flambda(agn_fname)
            agn_sed.redshiftSED(s_z, dimming=True)
            self.src_mag_norm.append(matchBase().calcMagNorm(
                [src], agn_sed, self.bandpassDict))
        #self.src_mag_norm = matchBase().calcMagNorm(src_iband,
        #                                            [agn_sed]*len(src_iband),
        #
        #                                            self.bandpassDict)

        self.defs_dict = {}
        with open(self.defs_file, 'r') as f:
            for line in f:
                line_defs = line.split(',')
                if len(line_defs) > 1:
                    self.defs_dict[line_defs[0]] = line_defs[1].split('\n')[0]
Ejemplo n.º 8
0
    phs = source_cat[5]
    ndex = source_cat[6]
    zs = source_cat[7]

    #g_limage = sersic_SB_2D_tot(yi1,yi2,ysc1,ysc2,mag_tot,Reff_arc,qs,phs,zs)
    Da_s = p13.angular_diameter_distance(2.0).value
    Reff = Reff_arc * Da_s / apr * 1e6  # pc
    Ieff = sersic_mag_tot_to_Ieff(mag_tot, Reff, ndex, zs)
    g_limage = sersic_2d(yi1, yi2, ysc1, ysc2, Ieff, Reff_arc, qs, phs, ndex)

    return g_limage


if __name__ == '__main__':

    db = om10.DB(catalog="../qso_mock.fits")
    #lid = 7176527
    lid = 630751
    lens = db.get_lens(lid)

    lid = lens.LENSID[0]
    xl1 = 0.0
    xl2 = 0.0
    vd = lens.VELDISP[0]  # needed from OM10
    zd = lens.ZLENS[0]
    zs = lens.ZSRC[0]
    ql = 1.0 - lens.ELLIP[0]
    phi = lens.PHIE[0]
    print ql
    #how to calculate I_eff_mag, R_eff_arc, qs, phs
Ejemplo n.º 9
0
    pylab.axis([-xmax, xmax, -xmax, xmax])
    # Add a grid:
    pylab.grid(color='grey', linestyle='--', linewidth=0.5)

    # Plot graph to file:
    if saveImg:
        pngfile = "om10_qso_ID=" + str(id) + ".png"
        pylab.savefig(pngfile)
        print "om10.plot_lens: figure saved to file:", pngfile


# ======================================================================

if __name__ == '__main__':

    db = om10.DB(catalog="data/qso_mock.fits")

    # Pull out a specific lens and plot it:
    id = 7176527
    lens = db.get_lens(id)
    om10.plot_lens(lens)

    # Plot 3 random lenses and plot them:
    lenses = db.select_random(maglim=21.4, area=30000.0, IQ=1.0, Nlens=3)
    if lenses is not None:
        for id in lenses.LENSID:
            lens = db.get_lens(id)
            om10.plot_lens(lens)

# ======================================================================
Ejemplo n.º 10
0
 def setUp(self):
     print "\nStarting a DB instance from scratch:"
     self.db = om10.DB(catalog=None)
     return
Ejemplo n.º 11
0
"""
Script that runs to generate toy catalogs
"""

import lenspop
import om10
import desc.slrealizer
import format_sdss_to_om10
import time

# initialize om10
db = om10.DB(vb=False, catalog='../../../data/qso_mock.fits')
# we select LSST-like lenses by quering with these values
db.select_random(maglim=23.3, area=5000.0, IQ=0.75)
# calculate the synthetic magnitude for the OM10 catalog -- need this
db.paint(synthetic=True)
# calculate the sizes for the OM10 catalog -- if you want to assume the point-source-like-galaxies, get rid of this
#db.calculate_size()
# initialize realizer
realizer = desc.slrealizer.SLRealizer(
    catalog=db, observation='../../../data/twinkles_observation_history.csv')
t0 = time.time()
realizer.make_source_catalog(
    save_dir='../../../data/source_catalog_galsim_noise_perfect.csv')
t1 = time.time()
print("Making the source catalog took %f seconds." % (t1 - t0))
realizer.make_object_catalog(
    source_table_dir='../../../data/source_catalog_galsim_noise_perfect.csv',
    save_dir='../../../data/object_catalog_galsim_noise_perfect.csv')
t2 = time.time()
print("Making the object catalog took %f seconds." % (t2 - t1))
Ejemplo n.º 12
0
def gauss_2d(x, y, xc, yc, sig):
    res0 = ((x - xc)**2 + (y - yc)**2) / sig**2
    res = np.exp(-0.5 * res0)
    return res


if __name__ == '__main__':
    print lef.lambda_e_tot(0.09182339)
    bsz = 4.0
    nnn = 512
    dsx = bsz / nnn

    x1, x2 = make_r_coor(nnn, dsx)
    #---------------------------------------------
    db = om10.DB(catalog="/Users/uranus/GitHub/OM10/data/qso_mock.fits")
    # lid = 7176527
    # lid = 8519202
    # lid = 30184793
    # lid = 14864406
    # lid = 347938
    lid = 21393434
    lens = db.get_lens(lid)

    om10.plot_lens(lens)

    xl1 = 0.0
    xl2 = 0.0
    vd = lens.VELDISP[0]  # needed from OM10
    ql = 1.0 - lens.ELLIP[0]
    le = lef.lambda_e_tot(lens.ELLIP[0])
def get_halo_cc(om10_id):
    db = om10.DB(catalog="./qso_mock.fits")

    lens = db.get_lens(om10_id)
    zl = lens.ZLENS[0]
    zs = lens.ZSRC[0]
    qe = 1.0 / (1.0 - lens.ELLIP[0])
    phi = lens.PHIE[0]
    vd0 = lens.VELDISP[0]  # needed from OM10
    mtotal0 = aa.m200_sv(vd0, zl)  # needed from OM10
    #----------------------------------------------------------------------
    # index, snapid,haloid,subhid,ag_stellar,ag_total,eq_stellar,eq_total,ms_stellar,ms_total,vd_stellar
    #
    snapid, haloid, subhid, ag_total, eq_stellar, ms_total, vd_stellar = np.loadtxt(
        "../produce_e_catalogs/results.dat",
        usecols=(1, 2, 3, 5, 6, 9, 10),
        unpack=True)

    print "Input: ", qe, phi, vd0, mtotal0

    nhalos = len(subhid)

    ksi_om10 = (ag_total/phi-1.0)**2.0/nhalos*0.0+(eq_stellar/qe-1.0)**2.0/nhalos*0.4 \
             + (ms_total/mtotal0-1.0)**2.0/nhalos*0.01+(vd_stellar*(1.0+zl)/vd0-1.0)**2.0/nhalos*100.4

    idx = ksi_om10 == np.min(ksi_om10)
    print "Matched: ", eq_stellar[idx], ag_total[idx], vd_stellar[
        idx], ms_total[idx]

    snapid_n = int(snapid[idx])
    #haloid_n = int(haloid[idx])
    subhid_n = int(subhid[idx])

    bsz = 30.0  # ckpc
    nnn = 512

    stars = il.snapshot.loadSubhalo(basePath, snapid_n, subhid_n, 'stars')
    x1 = stars['Coordinates'][:, 0]  #/1e3/(1.0+zl) # Mpc/h, comoving
    x2 = stars['Coordinates'][:, 1]  #/1e3/(1.0+zl) # Mpc/h, comoving
    x3 = stars['Coordinates'][:, 2]  #/1e3/(1.0+zl) # Mpc/h, comoving

    ptnl_p = stars['Potential']
    idx_ptnl_p_min = ptnl_p == ptnl_p.min()

    xcp1 = x1[idx_ptnl_p_min]
    xcp2 = x2[idx_ptnl_p_min]
    xcp3 = x3[idx_ptnl_p_min]

    (x1new, x2new) = trf.xy_rotate(x1, x2, xcp1, xcp2, -14.0)
    sdens = read_sdens_from_illustris(stars, x1new, x2new, x3 - xcp3,
                                      bsz / 512 * 10.0, nnn) * (1.0 + zl)**2.0

    kappa = sdens / mm.sigma_crit(zl, zs)

    bsz = bsz / 1e3 / mm.Dc(zl) * mm.apr  #arcsec
    dsx = bsz / nnn  #arcsec

    xi1, xi2 = make_r_coor(nnn, dsx)
    ai1, ai2 = pcs.call_cal_alphas0(sdens, nnn, bsz, zl, zs)

    mua = pcs.call_alphas_to_mu(ai1, ai2, nnn, dsx)
    return xi1, xi2, ai1, ai2, mua, kappa
Ejemplo n.º 14
0
Archivo: test.py Proyecto: mbaumer/OM10
 def setUp(self):
     # self.db = om10.DB(catalog=os.path.expandvars("$OM10_DIR/data/qso_mock.fits"))
     self.db = om10.DB(catalog=os.path.expandvars("data/qso_mock.fits"))
     return