コード例 #1
0
ファイル: bornProject.py プロジェクト: apetri/Dissertation
def convergenceVisualize(cmd_args,collection="c0",smooth=0.5*u.arcmin,fontsize=22):

	#Initialize plot
	fig,ax = plt.subplots(2,2,figsize=(16,16))

	#Load data
	cborn = ConvergenceMap.load(os.path.join(fiducial[collection].getMapSet("kappaBorn").home,"born_z2.00_0001r.fits"))
	cray = ConvergenceMap.load(os.path.join(fiducial[collection].getMapSet("kappa").home,"WLconv_z2.00_0001r.fits"))
	cll = ConvergenceMap.load(os.path.join(fiducial[collection].getMapSet("kappaLL").home,"postBorn2-ll_z2.00_0001r.fits"))
	cgp = ConvergenceMap.load(os.path.join(fiducial[collection].getMapSet("kappaGP").home,"postBorn2-gp_z2.00_0001r.fits"))

	#Smooth
	for c in (cborn,cray,cll,cgp):
		c.smooth(smooth,kind="gaussianFFT",inplace=True)

	#Plot
	cray.visualize(colorbar=True,fig=fig,ax=ax[0,0])
	(cray+cborn*-1).visualize(colorbar=True,fig=fig,ax=ax[0,1])
	cll.visualize(colorbar=True,fig=fig,ax=ax[1,0])
	cgp.visualize(colorbar=True,fig=fig,ax=ax[1,1])

	#Titles
	ax[0,0].set_title(r"$\kappa$",fontsize=fontsize)
	ax[0,1].set_title(r"$\kappa-\kappa^{(1)}$",fontsize=fontsize)
	ax[1,0].set_title(r"$\kappa^{(2-{\rm ll})}$",fontsize=fontsize)
	ax[1,1].set_title(r"$\kappa^{(2-{\rm gp})}$",fontsize=fontsize)

	#Switch off grids
	for i in (0,1):
		for j in (0,1):
			ax[i,j].grid(b=False) 

	#Save
	fig.tight_layout()
	fig.savefig("{0}/csample.{0}".format(cmd_args.type))
コード例 #2
0
ファイル: histograms.py プロジェクト: apetri/LensTools
def compute_histograms(map_id,simulation_set,smoothing_scales,index,generator,bin_edges):

	assert len(index.descriptor_list) == len(smoothing_scales)

	z = 1.0

	#Get map name to analyze
	map_name = simulation_set.getNames(z=z,realizations=[map_id])[0]

	#Load the convergence map
	convergence_map = ConvergenceMap.load(map_name)

	#Generate the shape noise map
	noise_map = generator.getShapeNoise(z=z,ngal=15.0*arcmin**-2,seed=map_id)

	#Add the noise
	convergence_map += noise_map

	#Measure the features
	hist_output = np.zeros(index.size)
	for n,descriptor in enumerate(index.descriptor_list):

		logging.debug("Processing {0} x {1}".format(map_name,smoothing_scales[n]))

		smoothed_map = convergence_map.smooth(smoothing_scales[n])
		v,hist_output[descriptor.first:descriptor.last] = smoothed_map.pdf(bin_edges)

	#Return the histograms in array format
	return hist_output
コード例 #3
0
def compute_histograms(map_id, simulation_set, smoothing_scales, index,
                       generator, bin_edges):

    assert len(index.descriptor_list) == len(smoothing_scales)

    z = 1.0

    #Get map name to analyze
    map_name = simulation_set.getNames(z=z, realizations=[map_id])[0]

    #Load the convergence map
    convergence_map = ConvergenceMap.load(map_name)

    #Generate the shape noise map
    noise_map = generator.getShapeNoise(z=z,
                                        ngal=15.0 * arcmin**-2,
                                        seed=map_id)

    #Add the noise
    convergence_map += noise_map

    #Measure the features
    hist_output = np.zeros(index.size)
    for n, descriptor in enumerate(index.descriptor_list):

        logging.debug("Processing {0} x {1}".format(map_name,
                                                    smoothing_scales[n]))

        smoothed_map = convergence_map.smooth(smoothing_scales[n])
        v, hist_output[descriptor.first:descriptor.last] = smoothed_map.pdf(
            bin_edges)

    #Return the histograms in array format
    return hist_output
コード例 #4
0
def test_power():

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	l_edges = np.arange(200.0,50000.0,200.0)
	
	fig,ax = plt.subplots()

	l,P_original = conv_map.powerSpectrum(l_edges)
	l,P_masked = (conv_map*mask_profile).powerSpectrum(l_edges)
	l,P_mask = mask_profile.powerSpectrum(l_edges)

	ax.plot(l,l*(l+1)*P_original/(2*np.pi),label="Unmasked")
	ax.plot(l,l*(l+1)*P_masked/(2*np.pi),label="Masked")
	ax.plot(l,l*(l+1)*P_masked/(2*np.pi*(1.0 - mask_profile.maskedFraction)**2),label="Re-scaled")
	ax.plot(l,l*(l+1)*P_mask/(2*np.pi),label="Mask")
	ax.set_xscale("log")
	ax.set_yscale("log")
	ax.set_xlabel(r"$l$")
	ax.set_ylabel(r"$l(l+1)P_l/2\pi$")

	ax.legend(loc="lower left")

	plt.savefig("power_mask.png")
	plt.clf()
コード例 #5
0
def convergence_stats(cmd_args):

    #Plot setup
    fig, ax = plt.subplots()

    #Load the convergence map and smooth on 1 arcmin
    conv = ConvergenceMap.load(os.path.join(dataExtern(), "conv1.fit"))
    conv.smooth(1.0 * u.arcmin, kind="gaussianFFT", inplace=True)

    #Find the peak locations and height
    sigma = np.linspace(-2., 11., 101)

    #Show the peak histogram and the PDF
    conv.peakHistogram(sigma, norm=True, fig=fig, ax=ax)

    ax_right = ax.twinx()
    conv.plotPDF(sigma, norm=True, fig=fig, ax=ax_right, color="red")

    #All PDF quantities are shown in red
    ax_right.spines["right"].set_color("red")
    ax_right.tick_params(axis="y", colors="red")
    ax_right.yaxis.label.set_color("red")

    #Save
    fig.savefig("convergence_stats." + cmd_args.type)
コード例 #6
0
def test_cross():

	#Load
	conv1 = ConvergenceMap.load("Data/conv1.fit")
	conv2 = ConvergenceMap.load("Data/conv2.fit")

	#Cross
	l,Pl = conv1.cross(conv2,l_edges=l_edges)

	#Visualize
	fig,ax = plt.subplots()
	ax.plot(l,np.abs(l*(l+1)*Pl/(2.0*np.pi)))
	ax.set_xscale("log")
	ax.set_yscale("log")
	ax.set_xlabel(r"$l$")
	ax.set_ylabel(r"$l(l+1)P_l/2\pi$")

	plt.savefig("cross_spectrum.png")
	plt.clf()
コード例 #7
0
def test_cross():

    #Load
    conv1 = ConvergenceMap.load("Data/conv1.fit")
    conv2 = ConvergenceMap.load("Data/conv2.fit")

    #Cross
    l, Pl = conv1.cross(conv2, l_edges=l_edges)

    #Visualize
    fig, ax = plt.subplots()
    ax.plot(l, np.abs(l * (l + 1) * Pl / (2.0 * np.pi)))
    ax.set_xscale("log")
    ax.set_yscale("log")
    ax.set_xlabel(r"$l$")
    ax.set_ylabel(r"$l(l+1)P_l/2\pi$")

    plt.savefig("cross_spectrum.png")
    plt.clf()
コード例 #8
0
def measure_from_IGS1(filename):

    #Read in the map
    logging.debug("Processing IGS1 map {0}".format(filename))
    conv_map = ConvergenceMap.load(filename)

    #Smooth 1 arcmin
    conv_map.smooth(1.0 * arcmin, inplace=True)

    #Measure the moments
    return conv_map.moments(connected=True, dimensionless=True)
コード例 #9
0
ファイル: gaussianity.py プロジェクト: apetri/LensTools
def measure_from_IGS1(filename):

	#Read in the map
	logging.debug("Processing IGS1 map {0}".format(filename))
	conv_map = ConvergenceMap.load(filename)

	#Smooth 1 arcmin
	conv_map.smooth(1.0*arcmin,inplace=True)

	#Measure the moments
	return conv_map.moments(connected=True,dimensionless=True)
コード例 #10
0
def convergence_measure_all(filename,index,mean_subtract,smoothing_scale=None):

	"""
	Measures all the statistical descriptors of a convergence map as indicated by the index instance
	
	"""

	logging.info("Processing {0}".format(filename))

	#Load the map
	conv_map = ConvergenceMap.load(filename)

	if mean_subtract:
		conv_map.data -= conv_map.mean()

	#Smooth the map maybe
	if smoothing_scale is not None:
		logging.info("Smoothing {0} on {1}".format(filename,smoothing_scale))
		conv_map.smooth(smoothing_scale,kind="gaussianFFT",inplace=True)

	#Allocate memory for observables
	descriptors = index
	observables = np.zeros(descriptors.size)

	#Measure descriptors as directed by input
	for n in range(descriptors.num_descriptors):
		
		if type(descriptors[n]) == PowerSpectrum:
			l,observables[descriptors[n].first:descriptors[n].last] = conv_map.powerSpectrum(descriptors[n].l_edges)
			
		elif type(descriptors[n]) == Moments:
			observables[descriptors[n].first:descriptors[n].last] = conv_map.moments(connected=descriptors[n].connected)
			
		elif type(descriptors[n]) == Peaks:
			v,observables[descriptors[n].first:descriptors[n].last] = conv_map.peakCount(descriptors[n].thresholds,norm=descriptors[n].norm)

		elif type(descriptors[n]) == PDF:
			v,observables[descriptors[n].first:descriptors[n].last] = conv_map.pdf(descriptors[n].thresholds,norm=descriptors[n].norm)
		
		elif type(descriptors[n]) == MinkowskiAll:
			v,V0,V1,V2 = conv_map.minkowskiFunctionals(descriptors[n].thresholds,norm=descriptors[n].norm)
			observables[descriptors[n].first:descriptors[n].last] = np.hstack((V0,V1,V2))
		
		elif type(descriptors[n]) == MinkowskiSingle:
			raise ValueError("Due to computational performance you have to measure all Minkowski functionals at once!")
		
		else:
			
			raise ValueError("Measurement of this descriptor not implemented!!!")

	#Return
	return observables
コード例 #11
0
def test_moments():

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_map = conv_map.mask(mask_profile)

	#Compute the moments in both masked and unmasked cases
	mom_original = conv_map.moments(connected=True)
	mom_masked = masked_map.moments(connected=True)
	rel_difference = np.abs(mom_masked/mom_original - 1.0)

	#Save the values and relative differences to file
	np.savetxt("masked_moments.txt",np.array([mom_original,mom_masked,rel_difference]),fmt="%.2e")
コード例 #12
0
def test_visualize():

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_fraction = conv_map.mask(mask_profile,inplace=True)

	fig,ax = plt.subplots(1,2,figsize=(16,8))
	mask_profile.visualize(fig,ax[0],cmap=plt.cm.binary)
	conv_map.visualize(fig,ax[1])

	ax[0].set_title("Mask")
	ax[1].set_title("Masked map: masking fraction {0:.2f}".format(masked_fraction))

	fig.tight_layout()
	fig.savefig("mask.png")
コード例 #13
0
def test_minkowski():

	th_minkowski = np.ogrid[-0.15:0.15:50j]

	#Set up plots
	fig,ax = plt.subplots(1,3,figsize=(24,8))

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	#Compute and plot the MFs for the unmasked map
	v,V0,V1,V2 = conv_map.minkowskiFunctionals(th_minkowski)
	ax[0].plot(v,V0,label="Unmasked")
	ax[1].plot(v,V1,label="Unmasked")
	ax[2].plot(v,V2,label="Unmasked")

	#Compute and plot the MFs for the masked, zero padded mask
	v,V0,V1,V2 = (conv_map*mask_profile).minkowskiFunctionals(th_minkowski)
	ax[0].plot(v,V0,linestyle="--",label="Zero padded")
	ax[1].plot(v,V1,linestyle="--",label="Zero padded")
	ax[2].plot(v,V2,linestyle="--",label="Zero padded")

	#Compute and plot the MFs for the masked map
	masked_fraction = conv_map.mask(mask_profile,inplace=True)
	v,V0,V1,V2 = conv_map.minkowskiFunctionals(th_minkowski)
	ax[0].plot(v,V0,label="Masked {0:.1f}%".format(masked_fraction*100))
	ax[1].plot(v,V1,label="Masked {0:.1f}%".format(masked_fraction*100))
	ax[2].plot(v,V2,label="Masked {0:.1f}%".format(masked_fraction*100))

	#Labels
	ax[0].set_xlabel(r"$\kappa$")
	ax[0].set_ylabel(r"$V_0(\kappa)$")

	ax[1].set_xlabel(r"$\kappa$")
	ax[1].set_ylabel(r"$V_1(\kappa)$")

	ax[2].set_xlabel(r"$\kappa$")
	ax[2].set_ylabel(r"$V_2(\kappa)$")

	ax[0].legend(loc="upper right")

	fig.tight_layout()

	plt.savefig("masked_minkowski.png")
	plt.clf()
コード例 #14
0
ファイル: bornProject.py プロジェクト: apetri/Dissertation
def excursion(cmd_args,smooth=0.5*u.arcmin,threshold=0.02,fontsize=22):

	#Set up plot
	fig,ax = plt.subplots(1,2,figsize=(16,8))

	#Load map
	conv = ConvergenceMap.load(os.path.join(fiducial["c0"].getMapSet("kappa").home,"WLconv_z2.00_0001r.fits"))
	conv.smooth(smooth,kind="gaussianFFT",inplace=True)

	#Build excursion set
	exc_data = np.zeros_like(conv.data)
	exc_data[conv.data>threshold] = 1.
	exc = ConvergenceMap(exc_data,angle=conv.side_angle)

	#Define binary colorbar
	cmap = plt.get_cmap("RdBu")
	cmaplist = [ cmap(i) for i in range(cmap.N) ]
	cmap = cmap.from_list("binary map",cmaplist,cmap.N)
	bounds = np.array([0.0,0.5,1.0])
	norm = matplotlib.colors.BoundaryNorm(bounds,cmap.N)

	#Plot the two alongside
	conv.visualize(colorbar=True,cbar_label=r"$\kappa$",fig=fig,ax=ax[0])
	exc.visualize(colorbar=True,cmap="binary",norm=norm,fig=fig,ax=ax[1])

	#Overlay boundary on the image
	mask = conv.mask(exc_data.astype(np.int8))
	i,j = np.where(mask.boundary>0)
	scale = conv.resolution.to(u.deg).value
	ax[0].scatter(j*scale,i*scale,color="red",marker=".",s=0.5)
	ax[0].set_xlim(0,conv.side_angle.to(u.deg).value)
	ax[0].set_ylim(0,conv.side_angle.to(u.deg).value)

	#Format right colorbar
	cbar = exc.ax.get_images()[0].colorbar
	cbar.outline.set_linewidth(1)
	cbar.outline.set_edgecolor("black")
	cbar_ticks = cbar.set_ticks([0,0.25,0.5,0.75,1])
	cbar.ax.set_yticklabels(["",r"$\kappa<\kappa_0$","",r"$\kappa>\kappa_0$",""],rotation=90)

	#Save
	fig.tight_layout()
	fig.savefig("{0}/excursion.{0}".format(cmd_args.type))
コード例 #15
0
def test_boundaries():

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_map = conv_map.mask(mask_profile)
	assert hasattr(masked_map,"_mask")
	assert masked_map._masked
	assert masked_map.side_angle == conv_map.side_angle
	assert masked_map.data.shape == conv_map.data.shape

	#Compute boundaries
	perimeter_area = masked_map.maskBoundaries()

	fig,ax = plt.subplots(1,3,figsize=(24,8))

	#Plot gradient boundary
	ax[0].imshow(masked_map._gradient_boundary,origin="lower",cmap=plt.cm.binary,interpolation="nearest",extent=[0,conv_map.side_angle.value,0,conv_map.side_angle.value])

	#Plot hessian (but not gradient) boundary
	ax[1].imshow(masked_map._gradient_boundary ^ masked_map._hessian_boundary,origin="lower",cmap=plt.cm.binary,interpolation="nearest",extent=[0,conv_map.side_angle.value,0,conv_map.side_angle.value])

	#Plot gradient and hessian boundary
	ax[2].imshow(masked_map.boundary,origin="lower",cmap=plt.cm.binary,interpolation="nearest",extent=[0,conv_map.side_angle.value,0,conv_map.side_angle.value])

	ax[0].set_xlabel(r"$x$(deg)")
	ax[0].set_ylabel(r"$y$(deg)")
	ax[0].set_title("Gradient boundary")

	ax[1].set_xlabel(r"$x$(deg)")
	ax[1].set_ylabel(r"$y$(deg)")
	ax[1].set_title("Hessian overhead")

	ax[2].set_xlabel(r"$x$(deg)")
	ax[2].set_ylabel(r"$y$(deg)")
	ax[2].set_title("Full boundary: perimeter/area={0:.3f}".format(perimeter_area))

	fig.tight_layout()

	plt.savefig("boundaries.png")
	plt.clf()
コード例 #16
0
ファイル: bornProject.py プロジェクト: apetri/Dissertation
def convergencePeaks(cmd_args,fontsize=22):

	#Plot setup
	fig,ax = plt.subplots(1,2,figsize=(16,8))

	#Load the convergence map and smooth on 0.5 arcmin
	conv = ConvergenceMap.load(os.path.join(fiducial["c0"].getMapSet("kappa").home,"WLconv_z2.00_0001r.fits"))
	conv.smooth(0.5*u.arcmin,kind="gaussianFFT",inplace=True)

	#Find the peak locations and height
	sigma = np.linspace(-2.,13.,101)
	height,positions = conv.locatePeaks(sigma,norm=True)

	#Show the convergence with the peak locations
	conv.visualize(fig=fig,ax=ax[0],colorbar=True,cbar_label=r"$\kappa$")
	ax[0].scatter(*positions[height>2.].to(u.deg).value.T,color="red",marker="o")
	ax[0].set_xlim(0,conv.side_angle.to(u.deg).value)
	ax[0].set_ylim(0,conv.side_angle.to(u.deg).value)

	#Build a gaussianized version of the map
	gen = GaussianNoiseGenerator.forMap(conv)
	ell = np.linspace(conv.lmin,conv.lmax,100)
	ell,Pell = conv.powerSpectrum(ell)
	convGauss = gen.fromConvPower(np.array([ell,Pell]),bounds_error=False,fill_value=0.)

	#Show the peak histogram (measured + gaussian)
	conv.peakHistogram(sigma,norm=True,fig=fig,ax=ax[1],label=r"${\rm Measured}$")
	convGauss.peakHistogram(sigma,norm=True,fig=fig,ax=ax[1],label=r"${\rm Gaussianized}$")
	conv.gaussianPeakHistogram(sigma,norm=True,fig=fig,ax=ax[1],label=r"${\rm Prediction}:(dN_{\rm pk}/d\nu)_G$")

	#Limits
	ax[1].set_ylim(1,1.0e3)

	#Labels
	ax[1].set_xlabel(r"$\kappa/\sigma_0$",fontsize=fontsize)
	ax[1].set_ylabel(r"$dN_{\rm pk}(\kappa)$")
	ax[1].legend()

	#Save
	fig.tight_layout()
	fig.savefig("{0}/convergencePeaks.{0}".format(cmd_args.type))
コード例 #17
0
    def from_file(
        cls,
        map_file: str,
        opening_angle: float,
        quantity: str,
        dir_in: str,
        npix: Optional[int] = None,
        convert_unit: bool = True,
    ) -> "SkyArray":
        """
        Initialize class by reading the skymap data from pandas hdf5 file
        or numpy array.
        The file can be pointed at via map_filename or file_dsc.

        Args:
            map_filename:
                File path with which skymap pd.DataFrame can be loaded.
            opening_angle: [deg]
        """
        assert map_file, "There is no file being pointed at"

        file_extension = map_file.split(".")[-1]
        if file_extension == "h5":
            map_df = pd.read_hdf(map_file, key="df")
            return cls.from_dataframe(
                map_df,
                opening_angle,
                quantity,
                dir_in,
                map_file,
                npix,
                convert_unit,
            )
        elif file_extension in ["npy", "fits"]:
            if file_extension == "npy":
                map_array = np.load(map_file)
            elif file_extension == "fits":
                map_array = ConvergenceMap.load(map_file, format="fits").data
            return cls.from_array(map_array, opening_angle, quantity, dir_in,
                                  map_file)
コード例 #18
0
def main(datapath, output_file):
    ell = np.logspace(np.log10(500), np.log10(5000), 38)  # multipole bin edges
    data = pd.DataFrame(columns=cosmology+ell_bins)
    data.to_csv(output_file) # save columns to file
    # make a single row to receive data
    data = data.append(pd.DataFrame(
        np.zeros(len(cosmology) + len(ell_bins)).reshape(1, -1),
        columns=cosmology+ell_bins))
    for _, dirs, _ in os.walk(datapath):
        for d in dirs:
            for root, _, files in os.walk(os.path.join(datapath, d)):  
                for conv_map_fit in files:
                    try:
                        conv_map = ConvergenceMap.load(os.path.join(root,conv_map_fit))
                        hdul = fits.open(os.path.join(root, conv_map_fit))[0].header
                        for c_param in cosmology:
                            data[c_param] = hdul[c_param]
                        l, power_spectrum = conv_map.powerSpectrum(ell)
                        data[ell_bins] = power_spectrum
                        data.to_csv(output_file, mode="a", header=False)
                    except:
                        continue
コード例 #19
0
def test_pdf():

	th_pdf = np.ogrid[-0.15:0.15:50j]

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_map = conv_map.mask(mask_profile)

	v,p_original = conv_map.pdf(th_pdf)
	v,p_masked = masked_map.pdf(th_pdf)

	#Plot the two histograms
	plt.plot(v,p_original,label="Unmasked")
	plt.plot(v,p_masked,label="Masked {0:.1f}%".format(mask_profile.maskedFraction * 100))

	#Labels
	plt.xlabel(r"$\kappa$")
	plt.ylabel(r"$P(\kappa)$")
	plt.legend(loc="upper right")

	plt.savefig("masked_pdf.png")
	plt.clf()
コード例 #20
0
def test_peaks():

	th_peaks = np.ogrid[-0.04:0.12:50j]

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_map = conv_map.mask(mask_profile)

	v,pk_orig = conv_map.peakCount(th_peaks)
	v,pk_masked = masked_map.peakCount(th_peaks)

	#Plot the difference
	plt.plot(v,pk_orig,label=r"Unmasked: $N_p=${0}".format(int(integrate.simps(pk_orig,x=v))))
	plt.plot(v,pk_masked,label=r"With {0:.1f}% area masking: $N_p=${1}".format(mask_profile.maskedFraction * 100,int(integrate.simps(pk_masked,x=v))))
	plt.plot(v,pk_masked/(1.0 - mask_profile.maskedFraction),label="Re-scaled")

	#Labels
	plt.xlabel(r"$\kappa$")
	plt.ylabel(r"$dN/d\kappa$")
	plt.legend(loc="upper left")

	plt.savefig("masked_peaks.png")
	plt.clf()
コード例 #21
0
def test_peak_locations():

	th_peaks = np.arange(0.24,0.5,0.01)

	conv_map = ConvergenceMap.load("Data/unmasked.fit")
	mask_profile = Mask.load("Data/mask.fit")

	masked_map = conv_map.mask(mask_profile)

	#Locate the peaks on the map
	values,location = masked_map.locatePeaks(th_peaks)

	#Visualize the map and the peak locations
	fig,ax = plt.subplots(1,2,figsize=(16,8))
	masked_map.visualize(fig=fig,ax=ax[0],colorbar=True)
	masked_map.visualize(fig=fig,ax=ax[1])

	ax[1].scatter(location[:,0].value,location[:,1].value,color="black")
	ax[1].set_xlim(0.0,masked_map.side_angle.value)
	ax[1].set_ylim(0.0,masked_map.side_angle.value)

	#Save the figure
	fig.tight_layout()
	fig.savefig("masked_peak_locations.png")
コード例 #22
0
def convergence_visualize(cmd_args):

    #Plot setup
    fig, ax = plt.subplots()

    #Load the convergence map and smooth on 1 arcmin
    conv = ConvergenceMap.load(os.path.join(dataExtern(), "conv1.fit"))
    conv.smooth(1.0 * u.arcmin, kind="gaussianFFT", inplace=True)

    #Find the peak locations and height
    sigma_peaks = np.linspace(-2., 11., 101)
    height, positions = conv.locatePeaks(sigma_peaks, norm=True)

    #Show the map and the peaks on it (left panel)
    conv.visualize(fig=fig, ax=ax, colorbar=True, cbar_label=r"$\kappa$")
    ax.scatter(*positions[height > 2.].to(u.deg).value.T,
               color="black",
               marker="x")
    ax.set_xlim(0, conv.side_angle.to(u.deg).value)
    ax.set_ylim(0, conv.side_angle.to(u.deg).value)

    #Save the figure
    fig.tight_layout()
    fig.savefig("convergence_visualize." + cmd_args.type)
コード例 #23
0
try:

    from lenstools import ConvergenceMap

except ImportError:

    import sys
    sys.path.append("..")
    from lenstools import ConvergenceMap

import numpy as np
from astropy.units import deg, rad

import matplotlib.pyplot as plt

test_map = ConvergenceMap.load("Data/conv.fit")

#Set bin edges
l_edges = np.arange(200.0, 50000.0, 200.0)
thresholds_mf = np.arange(-2.0, 2.0, 0.2)
thresholds_pk = np.arange(-1.0, 5.0, 0.2)


def test_visualize():

    assert test_map.data.dtype == np.float

    test_map.setAngularUnits(deg)
    test_map.visualize()
    test_map.savefig("map.png")
    test_map.setAngularUnits(deg)
コード例 #24
0
def cfht_convergence_measure_all(filename,index,mask_filename,mean_subtract=False):

	"""
	Measures all the statistical descriptors of a convergence map as indicated by the index instance
	
	"""

	logging.debug("Processing {0}".format(filename))

	#Load the map
	conv_map = ConvergenceMap.load(filename,format=cfht_fits_loader)

	if mask_filename is not None:
		
		#Load the mask
		mask_profile = ConvergenceMap.load(mask_filename,format=cfht_fits_loader)
		logging.debug("Loading mask from {0}".format(mask_filename))
		#Mask the map
		masked_conv_map = conv_map.mask(mask_profile)

	if mean_subtract:
		
		if mask_filename is not None:
			masked_conv_map.data -= masked_conv_map.mean()
		else:
			conv_map.data -= conv_map.mean()

	#Allocate memory for observables
	descriptors = index
	observables = np.zeros(descriptors.size)

	#Measure descriptors as directed by input
	for n in range(descriptors.num_descriptors):

		
		if type(descriptors[n]) == PowerSpectrum:
			
			if mask_filename is None:
				l,observables[descriptors[n].first:descriptors[n].last] = conv_map.powerSpectrum(descriptors[n].l_edges)
			else:
				l,observables[descriptors[n].first:descriptors[n].last] = (conv_map*mask_profile).powerSpectrum(descriptors[n].l_edges)

		elif type(descriptors[n]) == Moments:

			if mask_filename is None:
				observables[descriptors[n].first:descriptors[n].last] = conv_map.moments(connected=descriptors[n].connected)
			else:
				observables[descriptors[n].first:descriptors[n].last] = masked_conv_map.moments(connected=descriptors[n].connected)
		
		elif type(descriptors[n]) == Peaks:
			
			if mask_filename is None:
				v,observables[descriptors[n].first:descriptors[n].last] = conv_map.peakCount(descriptors[n].thresholds,norm=descriptors[n].norm)
			else:
				v,observables[descriptors[n].first:descriptors[n].last] = masked_conv_map.peakCount(descriptors[n].thresholds,norm=descriptors[n].norm)

		elif type(descriptors[n]) == PDF:

			if mask_filename is None:
				v,observables[descriptors[n].first:descriptors[n].last] = conv_map.pdf(descriptors[n].thresholds,norm=descriptors[n].norm)
			else:
				v,observables[descriptors[n].first:descriptors[n].last] = masked_conv_map.pdf(descriptors[n].thresholds,norm=descriptors[n].norm)
		
		elif type(descriptors[n]) == MinkowskiAll:
			
			if mask_filename is None:
				v,V0,V1,V2 = conv_map.minkowskiFunctionals(descriptors[n].thresholds,norm=descriptors[n].norm)
			else:
				v,V0,V1,V2 = masked_conv_map.minkowskiFunctionals(descriptors[n].thresholds,norm=descriptors[n].norm)
			
			observables[descriptors[n].first:descriptors[n].last] = np.hstack((V0,V1,V2))
		
		elif type(descriptors[n]) == MinkowskiSingle:
			
			raise ValueError("Due to computational performance you have to measure all Minkowski functionals at once!")
		
		else:
			
			raise ValueError("Measurement of this descriptor not implemented!!!")

	#Return
	return observables
コード例 #25
0
    root_path = cmd_args.path
    num_realizations = cmd_args.num_realizations

    #Smoothing scales in arcmin
    smoothing_scales = [theta * arcmin for theta in [0.1, 0.5, 1.0, 2.0]]
    bin_edges = np.ogrid[-0.15:0.15:128j]
    bin_midpoints = 0.5 * (bin_edges[1:] + bin_edges[:-1])

    #Create smoothing scale index for the histogram
    idx = Indexer.stack([PDF(bin_edges) for scale in smoothing_scales])

    #Create IGS1 simulation set object to look for the right simulations
    simulation_set = IGS1(root_path=root_path)

    #Look at a sample map
    sample_map = ConvergenceMap.load(
        simulation_set.getNames(z=1.0, realizations=[1])[0])

    #Initialize Gaussian shape noise generator
    generator = GaussianNoiseGenerator.forMap(sample_map)

    #Build Ensemble instance with the maps to analyze
    map_ensemble = Ensemble.fromfilelist(range(1, num_realizations + 1))

    #Measure the histograms and load the data in the ensemble
    map_ensemble.load(callback_loader=compute_histograms,
                      pool=pool,
                      simulation_set=simulation_set,
                      smoothing_scales=smoothing_scales,
                      index=idx,
                      generator=generator,
                      bin_edges=bin_edges)
コード例 #26
0
	
	from lenstools import ConvergenceMap

except ImportError:
	
	import sys
	sys.path.append("..")
	from lenstools import ConvergenceMap

import numpy as np
from astropy.units import deg,rad

import matplotlib.pyplot as plt


test_map = ConvergenceMap.load("Data/conv.fit")

#Set bin edges
l_edges = np.arange(200.0,50000.0,200.0)
thresholds_mf = np.arange(-2.0,2.0,0.2)
thresholds_pk = np.arange(-1.0,5.0,0.2)

def test_visualize():

	assert test_map.data.dtype == np.float

	test_map.setAngularUnits(deg)
	test_map.visualize()
	test_map.savefig("map.png")
	test_map.setAngularUnits(deg)
コード例 #27
0
def measure_power_spectrum(filename,l_edges):

	conv_map = ConvergenceMap.load(filename)
	l,Pl = conv_map.powerSpectrum(l_edges)
	return Pl
コード例 #28
0
ファイル: conv_peaks.py プロジェクト: liuxx479/halopeaks
#!python
# Jia Liu 2015/05/24
# This code reads in AHF maps and Gadget maps
# and return the peaks/ps for each set

#import WLanalysis
import numpy as np
from scipy import *
import sys, glob, os
#sys.modules["mpi4py"] = None
from emcee.utils import MPIPool
#from lenstools import Ensemble
from lenstools import ConvergenceMap 
from lenstools.defaults import load_fits_default_convergence

kmin = -0.08
kmax = 0.12
thresholds = linspace(kmin, kmax, 26)

peaksGen = lambda fn: ConvergenceMap.load(fn).peakCount(thresholds)

home = '/work/02977/jialiu/lenstools_home/'

storage = '/scratch/02977/jialiu/lenstools_storage/'

glob.glob()

peaks_fn_amiga = os.path.join(home,'Om0.300_Ol0.700/512b240/peaks_amiga.npy')

peaks_fn_gadget = os.path.join(home,'Om0.300_Ol0.700/512b240/peaks_gadget.npy')
コード例 #29
0
ファイル: histograms.py プロジェクト: apetri/LensTools
	root_path = cmd_args.path
	num_realizations = cmd_args.num_realizations
	
	#Smoothing scales in arcmin
	smoothing_scales = [ theta*arcmin for theta in [0.1,0.5,1.0,2.0] ]
	bin_edges = np.ogrid[-0.15:0.15:128j]
	bin_midpoints = 0.5*(bin_edges[1:] + bin_edges[:-1])
	
	#Create smoothing scale index for the histogram
	idx = Indexer.stack([PDF(bin_edges) for scale in smoothing_scales])
	
	#Create IGS1 simulation set object to look for the right simulations
	simulation_set = IGS1(root_path=root_path)
	
	#Look at a sample map
	sample_map = ConvergenceMap.load(simulation_set.getNames(z=1.0,realizations=[1])[0])
	
	#Initialize Gaussian shape noise generator
	generator = GaussianNoiseGenerator.forMap(sample_map)
	
	#Build Ensemble instance with the maps to analyze
	map_ensemble = Ensemble.fromfilelist(range(1,num_realizations+1))
	
	#Measure the histograms and load the data in the ensemble
	map_ensemble.load(callback_loader=compute_histograms,pool=pool,simulation_set=simulation_set,smoothing_scales=smoothing_scales,index=idx,generator=generator,bin_edges=bin_edges)
	
	if pool is not None:
		pool.close()

	##########################################################################################################################################
	###############################Ensemble data available at this point for covariance, PCA, etc...##########################################