def get_v_obv(self, v_init, rot_qt): v = quaternion.transform(rot_qt, v_init) if self.config.gal_coords: v = self.transform_to_gal_coords(v) return v
def get_pol_ang(self, rot_qt, v_dir): alpha = np.deg2rad(self.config.alpha) #radians beta = np.deg2rad(self.config.beta) #radians total_opening = alpha + beta pol_ini = np.deg2rad(self.config.pol_phase_ini) pol_vec_ini = np.array([0.0, 1.0, 0.0]) pol_vec = quaternion.transform(rot_qt, np.tile(pol_vec_ini, self.nsamples).reshape(-1,3)) if self.config.gal_coords: pol_vec = self.transform_to_gal_coords(pol_vec) theta, phi = hp.vec2ang(v_dir) x_local = np.array(zip(np.cos(theta)*np.cos(phi), np.cos(theta)*np.sin(phi), -np.sin(theta))) y_local = np.array(zip(-np.sin(phi), np.cos(phi), np.zeros(phi.size))) proj_x = np.sum(pol_vec*x_local, axis=-1) proj_y = np.sum(pol_vec*y_local, axis=-1) pol_ang = np.pi - (np.arctan2(proj_y, proj_x) + pol_ini) % np.pi return pol_ang
def get_initial_vec(self, del_beta): alpha = np.deg2rad(self.config.alpha) #radians beta = np.deg2rad(self.config.beta) #radians if self.config.do_pencil_beam: del_x = np.deg2rad(self.config.offset_x/60.0/60.0) #radians del_y = np.deg2rad(self.config.offset_y/60.0/60.0) #radians else: del_x = 0.0 del_y = 0.0 del_beta_rad = np.deg2rad(del_beta/60.0) #radians total_opening = alpha + beta + del_beta_rad u_view = np.array([np.cos(total_opening), 0.0, np.sin(total_opening)]) x_roll_axis = np.array([0.0, 1.0, 0.0]) y_roll_axis = np.array([-np.sin(total_opening), 0.0, np.cos(total_opening)]) q_x_roll = quaternion.make_quaternion(del_x, x_roll_axis) q_y_roll = quaternion.make_quaternion(del_y, y_roll_axis) q_offset = quaternion.multiply(q_x_roll, q_y_roll) u_view = quaternion.transform(q_offset, u_view) return u_view
def simulate_timestream(self, segment, return_field=["signal", "v", "pol_ang"]): if segment == 0: #self.display_params() #self.beam.display_beam_settings() if self.config.write_beam: self.beam.write_beam(self.bolo_dir) rot_qt = self.generate_quaternion(segment) t_stream = {"signal" : None, "v" : None, "pol_ang" : None, "noise" : None} prompter.prompt("0.0") #Simulating the scan along the centre of the FOV v_init = self.get_initial_vec(0.0) v_central = self.get_v_obv(v_init, rot_qt) t_stream['v'] = v_central pol_ang = self.get_pol_ang(rot_qt, v_central) t_stream['pol_ang'] = pol_ang if self.config.sim_pol_type == "T": cos2=None sin2=None else: cos2 = np.cos(2*pol_ang) sin2 = np.sin(2*pol_ang) if "timestream_data" in self.config.timestream_data_products: self.make_write_dir(segment) self.write_timestream_data(v_central, "pointing_vec", segment) self.write_timestream_data(pol_ang, "pol_ang", segment) if not self.config.pipe_with_map_maker: del pol_ang beam_kernel_row = self.beam.get_beam_row(0.0) #The input argument is the beam offset from the centre hit_pix = hp.vec2pix(self.config.nside_in, v_central[...,0], v_central[...,1], v_central[...,2]) signal = self.generate_signal(hit_pix, beam_kernel_row, cos2, sin2) for del_beta in self.beam.del_beta: if del_beta == 0.0: continue prompter.prompt(str(del_beta)) beam_kernel_row = self.beam.get_beam_row(del_beta) v_init = self.get_initial_vec(del_beta) v = quaternion.transform(rot_qt, v_init) hit_pix = hp.vec2pix(self.config.nside_in, v[...,0], v[...,1], v[...,2]) signal += self.generate_signal(hit_pix, beam_kernel_row, cos2, sin2) beam_sum = np.sum(self.beam.beam_kernel[0]) signal /= beam_sum if self.config.add_noise: noise = self.noise_class.simulate_timestream_noise_from_parameters() if "timestream_data" in self.config.timestream_data_products: self.write_timestream_data(noise, "noise", segment) signal[::self.config.oversampling_rate] += noise if "timestream_data" in self.config.timestream_data_products: self.write_timestream_data(signal, "signal", segment) if self.config.pipe_with_map_maker: if self.config.do_pencil_beam: t_stream["signal"] = signal t_stream["v"] = v_central t_stream["pol_ang"] = pol_ang return t_stream else: t_stream["signal"] = signal[::self.config.oversampling_rate] t_stream["v"] = v_central[self.pad:-self.pad][::self.config.oversampling_rate] t_stream["pol_ang"] = pol_ang[self.pad:-self.pad][::self.config.oversampling_rate] return t_stream if "hitmap" in self.config.timestream_data_products: del signal hit_pix = hp.vec2pix(self.config.nside_in, v_central[...,0], v_central[...,1], v_central[...,2]) hitmap = self.get_hitmap(hit_pix) return hitmap