f = fields[i]
		voronoi_overdens = fits.open('%s/%s.mastermedVoronoi.overdens.100iterations.fits' % (voronoi_dir, f.name))
		mf_voronoi_slices_field = massFunction_voronoi_slices(f.name, f.zclust, f.sigmaz, f.area_arcmin2, f.voronoi.zlos, f.voronoi.zhis)

		detection_wcs = wcs.WCS(images[i])
		detection_image = fits.open(images[i])
		det_map = detection_image[0].data
		xx_det, yy_det = pylab.meshgrid(range(det_map.shape[1]), range(det_map.shape[0]))

		ra1, dec1 = detection_wcs.wcs_pix2world([0, 0], [0, 1], 1)
		px_scale_detection = mypy.radec_sep(ra1[0], dec1[0], ra1[1], dec1[1])

		for j in range(len(voronoi_overdens)):

			mypy.progress_bar(j, len(voronoi_overdens))

			vmap = voronoi_overdens[j].data
			vheader = voronoi_overdens[j].header
			zlo, zhi = vheader['Z1'], vheader['Z2']
			vwcs = wcs.WCS(vheader)
			xx_vor, yy_vor = pylab.meshgrid(range(vmap.shape[1]), range(vmap.shape[0]))
			ra_vor, dec_vor = vwcs.wcs_pix2world(xx_vor, yy_vor, 1)
			ra1, dec1 = vwcs.wcs_pix2world([0, 0], [0, 1], 1)
			px_scale_vor = mypy.radec_sep(ra1[0], dec1[0], ra1[1], dec1[1])


			'''
			interper = interpolate.interp2d(xx_vor, yy_vor, vmap)

			xnew = pylab.linspace(0, vmap.shape[1]-1, vmap.shape[1]*px_scale_vor/px_scale_detection)
x_all = pylab.zeros((len(inds0), len(snapshots)))
y_all = pylab.zeros((len(inds0), len(snapshots)))

x_min = pylab.zeros(len(inds0))
y_min = pylab.zeros(len(inds0))
x_max = pylab.zeros(len(inds0))
y_max = pylab.zeros(len(inds0))

lmass_all = pylab.zeros((len(inds0), len(snapshots)))
overdens_all = pylab.zeros((len(inds0), len(snapshots)))

t0 = time.time()

for i, ind0 in enumerate(inds0):

    mypy.progress_bar(i, len(inds0))

    ###  tracking galaxy through the first N-1 snapshots
    ind_tracker = ind0 * 1
    for j in range(len(cats) - 1):
        cat_b4 = cats[j]
        cat_afta = cats[j + 1]

        x_all[i][j] = cat_b4.x_cMpc[ind_tracker]
        y_all[i][j] = cat_b4.y_cMpc[ind_tracker]
        lmass_all[i][j] = pylab.log10(cat_b4.stellarMass[ind_tracker])

        vmap = vmaps[j]
        lx, ly = vmap.shape
        xtran = int(cat_b4.x_cMpc[ind_tracker] * lx / 100. -
                    0.5)  # pixel coordinate of galaxy in voronoi map
###  Briefly, these will be 2D histgrams in (V-J) vs. (U-V)
###  phase space, but instead of the colorbar scaling with
###  the NUMBER of objects in each cell it will correspond
###  to the MEDIAN (V-J) error and MEDIAN (U-V) error.
##############################################################
##############################################################


N_map_zphot = hist2d_zphot * 0.
uv_errMap_zphot = hist2d_zphot * 0.
vj_errMap_zphot = hist2d_zphot * 0.


for i_y in range(len(yedges_zphot)-1):

	mypy.progress_bar(i_y, len(yedges_zphot))

	for i_x in range(len(xedges_zphot)-1):

		ylo, yhi = yedges_zphot[i_y], yedges_zphot[i_y+1]
		xlo, xhi = xedges_zphot[i_x], xedges_zphot[i_x+1]

		inds_cell = pylab.find((uv_zphot > ylo) & (uv_zphot < yhi) & \
			                   (vj_zphot > xlo) & (vj_zphot < xhi))

		N_map_zphot[i_y][i_x] = len(inds_cell)
		uv_errMap_zphot[i_y][i_x] = pylab.median(uv_zphot_err[inds_cell])
		vj_errMap_zphot[i_y][i_x] = pylab.median(vj_zphot_err[inds_cell])


		###  setting cell in error maps
for g in simulation.galaxies:
	g.quenched[-1] = True
'''

#########################
###  Running simulation
#########################

print 'Running merger simulation...'
t0 = time.time()

for i_timestep in range(1, simulation.n_timesteps):

    t_step = simulation.t_array[i_timestep]

    mypy.progress_bar(i_timestep, simulation.n_timesteps)

    ###########################################
    ###  updating properties for all galaxies
    ###########################################

    for i_galaxy in range(len(simulation.galaxies)):

        g = simulation.galaxies[i_galaxy]

        ###  reset merger flag
        g.merged_in_this_timestep = False

        #############################################
        ###  grow galaxy via in situ star-formation
        #############################################
Exemple #5
0
                  [24, 0.73, 4.16, 0.37], [25, 0.79, 3.23, 0.27],
                  [26, 0.85, 2.29, 0.18], [27, 0.91, 1.34, 0.10],
                  [28, 1.00, 0.00, 0.001]]
snapshots = [snapshot(*info) for info in snapshots_info]

###  plotting galaxy positions (x vs. y) for each snapshot
pdf = PdfPages('../output/eagle_simulations/sky_positions.pdf')

fig = pylab.figure(figsize=(12., 11.))
sp = fig.add_subplot(111)

fig.subplots_adjust(left=0.09, bottom=0.09, top=0.95, right=0.95)

for si in range(len(snapshots)):

    mypy.progress_bar(si, len(snapshots))
    proper2comoving = (
        cosmo.kpc_proper_per_arcmin(snapshots[si].redshift) /
        cosmo.kpc_comoving_per_arcmin(snapshots[si].redshift)).value

    ###  grabbing galaxy data
    snap = snapshots[si]
    myQuery = "SELECT \
	            SH.GalaxyID as GalaxyID, \
	            SH.LastProgID as LastProgID, \
	            SH.TopLeafID as TopLeafID, \
	            SH.DescendantID as DescendantID, \
	            SH.CentreOfMass_x as x, \
	            SH.CentreOfMass_y as y, \
	            AP.Mass_Star as stellar_mass, \
	            AP.SFR as sfr \
    def __init__(self,
                 name,
                 version,
                 zclust,
                 sigmaz,
                 imname,
                 alpha=50,
                 chi2red_thresh=10):
        self.name = name  # e.g. "NEP 200"
        self.version = version  # e.g. "nep200_v0.0.4"
        self.zclust = zclust  # cluster redshift
        self.sigmaz = sigmaz  # 1sigma scatter in (zphot-zspec)/(1+zspec)
        self.zspec_lo = 0  # lower redshift bound for specz
        self.zspec_hi = 0  # upper redshift bound for specz
        self.alpha = alpha
        self.imname = imname

        self.cat = gunzip_read_gzip('%s/%s/%s.cat.gz' %
                                    (data_dir, version, version),
                                    readcat=1)
        self.zout = gunzip_read_gzip('%s/%s/%s.zout.gz' %
                                     (data_dir, version, version),
                                     readzout=1)
        self.fout = gunzip_read_gzip('%s/%s/%s.fout.gz' %
                                     (data_dir, version, version),
                                     readcat=1)

        print '  reading: %s_voronoi.pickle' % name
        self.voronoi = pickle.load(
            open('../data/%s_voronoi.pickle' % name, 'rb'))

        ###  UPDATING USE FLAG WITH REDUCE CHI**2 THRESHOLD
        chi2red = self.zout.chi_p / (self.zout.nfilt - 1.)
        cinds = pylab.find((chi2red > chi2red_thresh) & (self.cat.z_spec < 0))
        self.cat.use[cinds] = 0.

        xyrd1 = self.cat.x[0], self.cat.y[0], self.cat.ra[0], self.cat.dec[0]
        xyrd2 = self.cat.x[1], self.cat.y[1], self.cat.ra[1], self.cat.dec[1]
        d_arcsec = mypy.radec_sep(xyrd1[2], xyrd1[3], xyrd2[2], xyrd2[3])
        d_pixel = ((xyrd1[0] - xyrd2[0])**2 + (xyrd1[1] - xyrd2[1])**2)**0.5
        self.px_scale = d_arcsec / d_pixel

        ### getting z band magnitude
        try:
            self.zmagnitude = 25 - 2.5 * pylab.log10(self.cat.fluxauto_z)
        except:
            pass
        if name != 'SC1324':
            try:
                self.zmagnitude = 25 - 2.5 * pylab.log10(
                    self.cat.fluxauto_Zplus)
            except:
                pass

        ###  setting spatial flag based on Convex Hull method
        #zspecinds = pylab.find(self.cat.z_spec > 0)
        #self.spatial_flag = checkPoint(self.cat.ra[zspecinds], self.cat.dec[zspecinds], self.cat.ra, self.cat.dec)
        #self.inds_spatial = pylab.find(self.spatial_flag == 1)

        ###  setting spatial flag based on Concave Hull method (creates a "tighter" spatial selection than Cnvex Hull)
        zspecinds = pylab.find(self.cat.z_spec > 0)
        points = pylab.array(zip(self.cat.x[zspecinds], self.cat.y[zspecinds]))
        self.concave_hull, self.edge_points = alpha_shape(points, alpha)
        self.inds_spatial = CheckPoints(self.concave_hull.buffer(10),
                                        self.cat.x, self.cat.y)
        self.area_pix2 = self.concave_hull.buffer(10).area
        self.area_arcmin2 = self.area_pix2 * (self.px_scale / 60.)**2

        ###  SEGMENTATION IMAGE
        image = fits.open(imname)
        segmap = image[0].data * 0.
        xpoints, ypoints = [], []
        for x in range(segmap.shape[1]):
            mypy.progress_bar(x, segmap.shape[1])
            for y in range(segmap.shape[0]):
                xpoints.append(x)
                ypoints.append(y)
        xpoints = pylab.array(xpoints)
        ypoints = pylab.array(ypoints)

        concave_hull_segmap, edge_points_segmap = alpha_shape(points, alpha)
        inds_segmap = CheckPoints(concave_hull_segmap.buffer(10), xpoints,
                                  ypoints)
        inds_segmap_spatial = (ypoints[inds_segmap] - 1,
                               xpoints[inds_segmap] - 1)
        segmap[inds_segmap_spatial] += 1
        fits.writeto('../data/zspec_segmentation_maps/%s_segmap.fits' %
                     version,
                     segmap,
                     header=image[0].header,
                     clobber=1)
        print ''
Exemple #7
0
###  reading in residual maps
resid_maps = []
wcs_maps = []
for f in fields:
    residname = '/Volumes/PHOENIX/atomczak/DATA/ORELSE/tphot/images/%s_resid_pass2.fits' % f.name
    fopen = fits.open(residname)
    resid_maps.append(fopen)
    wcs_maps.append(wcs.WCS(residname))

radecs = []
modelnames = []
#for i in range(len(table.ID_gal)):
for i in range(50):

    mypy.progress_bar(i, len(table.ID_gal))

    ###  grabbing various coordinates of galaxy
    f = fields[int(table.ID_field[i])]
    ra = f.cat.ra[int(table.ID_gal[i]) - 1]
    dec = f.cat.dec[int(table.ID_gal[i]) - 1]
    flux24 = f.fir.ftot_mips24[int(table.ID_gal[i]) - 1]
    weight = table.weight[i]
    radecs.append([ra, dec])

    ###  reading in residual map
    resid = resid_maps[int(table.ID_field[i])][0].data
    wcsdat = wcs_maps[int(table.ID_field[i])]

    x, y = wcsdat.wcs_world2pix([ra], [dec], 1)
    x = int(x[0] + 0.5)