def _1d_correlation(pos, min_cut, max_cut, end_s=0.02, ns=15, n_randoms=1, n_cores=1): """ Does a 1d correlation in either redshift or comoving distance space. """ if pos.max() < 10.0: A, g, t = sf.fit_selection_simple_z(pos) else: A, g, t = sf.fit_selection_simple(pos) DD = _correlation_1d_DD_wrapper(pos1=pos, end_s=end_s, ns=ns, n_cores=n_cores) print "Done DD" RR = np.zeros((ns)) DR = np.zeros((ns)) print "made zeros" for i in range(n_randoms): rand_r = sf.create_radial_selection(A, g, t, min_cut, max_cut, len(pos)) if i == 0: plt.hist(rand_r, normed=True) plt.hist(pos, normed=True) plt.show() go_ahead = str(raw_input("do you like what you see?? [Y/n]")) if go_ahead == 'n': raise ValueError("Okay we'll stop then") print len(rand_r) RR += _correlation_1d_DD_wrapper(pos1=rand_r, end_s=end_s, ns=ns, n_cores=n_cores) print "Done RR" DR += _correlation_1d_DR_wrapper(pos1=pos, pos2=rand_r, end_s=end_s, ns=ns, n_cores=n_cores) print "done DR" RR /= n_randoms DR /= n_randoms #Use the Landy-Szalay Estimator Corr = 1 + DD / RR - 2 * DR * (len(pos) - 1.0) / len(pos) / RR #Calculate the centre of bins s_bins = np.linspace(end_s / (2 * ns), end_s * (1 - 0.5 / ns), ns) print "got to the end..." print Corr return s_bins.copy(), Corr.copy()
def radial_mock(self, method="EEP", N=None, bins=100, new_lumfunc=False, min_acceptable=1, eps=0.01, max_iter=10, selbins=100): """ Creates a random catalogue of particles based on a defined selection function. Only radial co-ords. Ouput: radii :: length N vector (default length of survey) of radii """ z_min = self.survey_data['redshift'].min() z_max = self.survey_data['redshift'].max() if N is None: N = self.N if method is None: radii = sf.create_radial_selection_simple(z_min, z_max, N) else: M, phi = self.lum_func(Np=bins, method=method, new=new_lumfunc, min_acceptable=min_acceptable, eps=eps, max_iter=max_iter) s_of_z = sf.selection_of_z(selbins, phi, M, self.survey_data["mag_r"], self.survey_data["absmag"], self.survey_data["redshift"]) radii = sf.create_mock(s_of_z, z_min, z_max, N) #Plot it plt.clf() plt.hist(radii, bins=100, normed=True, label="Mock") plt.hist(self.survey_data['redshift'], bins=100, normed=True, label="Data") plt.legend() plt.savefig(self._dirs['SelectionFunction'] + 'N(z)_' + method + '_L' + str(bins) + "_S" + str(selbins) + '.' + self.plottype) return radii
def selection_function(self, method="EEP", bins=None, new_lumfunc=False, min_acceptable=1, eps=0.01, max_iter=10, selbins=100): """ Calculate a selection function value for each galaxy. INPUT PARAMETERS method ["EEP"] -- A method with which to calculate the lumfunc. If None, will use a simple parametrisation for the N(z) distribution. bins [None] -- How many bins to use in the given method new_lumfunc [False] -- Whether to force a new lumfunc calculation even if previous results exist new_selection [False] -- Whether to force a new selection function calcualtion even if previous results exit. min_acceptable -- Lowest acceptable number of galaxies per bin eps -- Target uncertainty for convergence in EEP max_iter -- Maximum iterations for EEP """ if method is None: A, g, t = sf.fit_selection_simple(self.survey_data['c_dist'], bins=bins, verbose=self.verbose) self.survey_data['weight'] = 1.0 / sf.get_sel_from_nd(A, g, t)(self.survey_data['c_dist']) #WRITE OUT A SIMPLE PLOT FOR CHECKING! if not bins: bins = utils.FD_bins(self.survey_data['c_dist']) plt.clf() plt.title("N(d) with selection function for Sample " + self.sample_name + " from " + self.survey_name) hist, edges = np.histogram(self.survey_data['c_dist'], density=True, bins=bins) centres = edges[:-1] + (edges[1] - edges[0]) / 2.0 plt.plot(centres, hist) plt.plot(centres, sf.selection_simple(centres, A, g, t)) plt.xlabel("Comoving Distance") plt.ylabel("Normalised Count") plt.savefig(self._dirs['SelectionFunction'] + 'N(d)_' + str(bins) + "bins.eps") plt.show() self.selection_params = {'A':A, 'g':g, 't':t} else: M, phi = self.lum_func(Np=bins, method=method, new=new_lumfunc, min_acceptable=min_acceptable, eps=eps, max_iter=max_iter) if selbins is None: self.survey_data['weight'] = 1. / sf.selection_of_galaxies(phi, M, self.survey_data['mag_r'], self.survey_data["absmag"]) #Plot it up plt.clf() plt.plot(self.survey_data["redshift"], 1. / self.survey_data["weight"], linestyle="None", marker='.', markersize=1) plt.xlabel("Redshift") plt.ylabel("Selection Function") plt.yscale("log") plt.savefig(self._dirs['SelectionFunction'] + 'SelectionFunction_' + method + '_' + str(bins) + '.' + self.plottype) else: s_of_z = sf.selection_of_z(selbins, phi, M, self.survey_data["mag_r"], self.survey_data["absmag"], self.survey_data["redshift"]) self.survey_data['weight'] = 1. / np.exp(s_of_z(self.survey_data['redshift'])) #Make a plot z = np.linspace(self.survey_data['redshift'].min(), self.survey_data['redshift'].max(), 1000) plt.clf() plt.plot(z, np.exp(s_of_z(z))) plt.yscale('log') plt.xlabel("Redshift") plt.ylabel("Selection Function") plt.savefig(self._dirs['SelectionFunction'] + 'SelectionFunctionAve_' + method + '_L' + str(bins) + "_S" + str(selbins) + '.' + self.plottype)