def run_noise_sims(self, n_sims, seed=None): if not self.weights_are_normalized: self.normalize_weights() if seed is not None: if self.maps[0].feed is not None: feeds = np.array([self.maps[0].feed, self.maps[1].feed]) else: feeds = np.array([1, 1]) self.rms_xs = np.zeros((len(self.k_bin_edges) - 1, n_sims)) for i in range(n_sims): randmap = [ np.zeros(self.maps[0].rms.shape), np.zeros(self.maps[0].rms.shape) ] for j in range(len(self.maps)): if seed is not None: np.random.seed(seed * (i + 1) * (j + 1) * feeds[j]) randmap[j] = np.random.randn( *self.maps[j].rms.shape) * self.maps[j].rms w = np.sqrt(self.maps[0].w * self.maps[1].w) self.rms_xs[:, i] = tools.compute_cross_spec3d( (randmap[0] * w, randmap[1] * w), self.k_bin_edges, dx=self.maps[0].dx, dy=self.maps[0].dy, dz=self.maps[0].dz)[0] self.rms_xs_mean = np.mean(self.rms_xs, axis=1) self.rms_xs_std = np.std(self.rms_xs, axis=1) return self.rms_xs_mean, self.rms_xs_std
def calculate_xs( self, no_of_k_bins=15, print_show=False): #here take the number of k-bins as an argument n_k = no_of_k_bins self.k_bin_edges = np.logspace(-2.0, np.log10(1.5), n_k) calculated_xs = self.get_information() #store each cross-spectrum and corresponding k and nmodes by appending to these lists: self.xs = [] self.k = [] self.nmodes = [] index = 0 for i in range(len(self.maps)): for j in range( i, len(self.maps) ): #ensure that we don't compute the same pairs of maps twice <---------is this correct ? if i != j: #ensure that we compute xs, not auto spectrum index += 1 if print_show == True: map_name1 = calculated_xs[index - 1][1] map_name2 = calculated_xs[index - 1][2] if map_name1 == map_name2: print('Creating auto ps for ' + map_name1 + ', ' + '%01i' % (index) + ' out of ' + '%01i' % (len(calculated_xs)) + '.') else: print('Creating xs between ' + map_name1 + ' and ' + map_name2 + ', ' + '%01i' % (index) + ' out of ' + '%01i' % (len(calculated_xs)) + '.') self.normalize_weights( i, j) #normalize weights for given xs pair of maps my_xs, my_k, my_nmodes = tools.compute_cross_spec3d( (self.maps[i].map * np.sqrt(self.maps[i].w * self.maps[j].w), self.maps[j].map * np.sqrt(self.maps[i].w * self.maps[j].w)), self.k_bin_edges, dx=self.maps[i].dx, dy=self.maps[i].dy, dz=self.maps[i].dz) self.reverse_normalization( i, j ) #go back to the previous state to normalize again with a different map-pair self.xs.append(my_xs) self.k.append(my_k) self.nmodes.append(my_nmodes) self.xs = np.array(self.xs) self.k = np.array(self.k) self.nmodes = np.array(self.nmodes) return self.xs, self.k, self.nmodes
def run_noise_sims(self, n_sims, seed=None): self.rms_xs_mean = [] self.rms_xs_std = [] for i in range(len(self.maps)): for j in range( i, len(self.maps) ): #ensure that we don't take the same pairs of maps twice if i != j: #only for xs, not auto spectra self.normalize_weights(i, j) wi = self.maps[i].w wj = self.maps[j].w wh_i = np.where(np.log10(wi) < -0.5) wh_j = np.where(np.log10(wj) < -0.5) wi[wh_i] = 0.0 wj[wh_j] = 0.0 if seed is not None: if self.maps[i].feed is not None: feeds = np.array( [self.maps[i].feed, self.maps[j].feed]) else: feeds = np.array([1, 1]) rms_xs = np.zeros((len(self.k_bin_edges) - 1, n_sims)) for g in range(n_sims): randmap = [ np.zeros(self.maps[i].rms.shape), np.zeros(self.maps[i].rms.shape) ] for l in range(2): if seed is not None: np.random.seed(seed * (g + 1) * (l + 1) * feeds[l]) randmap[l] = np.random.randn( *self.maps[l].rms.shape) * self.maps[l].rms rms_xs[:, g] = tools.compute_cross_spec3d( (randmap[0] * np.sqrt(wi * wj), randmap[1] * np.sqrt(wi * wj)), self.k_bin_edges, dx=self.maps[i].dx, dy=self.maps[i].dy, dz=self.maps[i].dz)[0] self.reverse_normalization( i, j ) #go back to the previous state to normalize again with a different map-pair self.rms_xs_mean.append(np.mean(rms_xs, axis=1)) self.rms_xs_std.append(np.std(rms_xs, axis=1)) return self.rms_xs_mean, self.rms_xs_std
def calculate_xs(self): n_k = 15 self.k_bin_edges = np.logspace(-2.0, np.log10(1.5), n_k) if not self.weights_are_normalized: self.normalize_weights() w = np.sqrt(self.maps[0].w * self.maps[1].w) self.xs, self.k, self.nmodes = tools.compute_cross_spec3d( (self.maps[0].map * w, self.maps[1].map * w), self.k_bin_edges, dx=self.maps[0].dx, dy=self.maps[0].dy, dz=self.maps[0].dz) return self.xs, self.k, self.nmodes
def calculate_xs( self, no_of_k_bins=15): #here take the number of k-bins as an argument n_k = no_of_k_bins self.k_bin_edges = np.logspace(-2.0, np.log10(1.5), n_k) calculated_xs = self.get_information() #store each cross-spectrum and corresponding k and nmodes by appending to these lists: self.xs = [] self.k = [] self.nmodes = [] index = -1 for i in range(0, len(self.maps) - 1, 2): j = i + 1 index += 1 print('Computing xs between ' + calculated_xs[index][1] + ' and ' + calculated_xs[index][2] + '.') self.normalize_weights( i, j) #normalize weights for given xs pair of maps wi = self.maps[i].w wj = self.maps[j].w wh_i = np.where(np.log10(wi) < -0.5) wh_j = np.where(np.log10(wj) < -0.5) wi[wh_i] = 0.0 wj[wh_j] = 0.0 my_xs, my_k, my_nmodes = tools.compute_cross_spec3d( (self.maps[i].map * np.sqrt(wi * wj), self.maps[j].map * np.sqrt(wi * wj)), self.k_bin_edges, dx=self.maps[i].dx, dy=self.maps[i].dy, dz=self.maps[i].dz) self.reverse_normalization( i, j ) #go back to the previous state to normalize again with a different map-pair self.xs.append(my_xs) self.k.append(my_k) self.nmodes.append(my_nmodes) self.xs = np.array(self.xs) self.k = np.array(self.k) self.nmodes = np.array(self.nmodes) return self.xs, self.k, self.nmodes