示例#1
0
def run_mpi():
    print "Rank :", rank, "started"
    npix = hp.nside2npix(config.nside_out)
    dim, ind_elements = cov_ut.get_dim(config.pol_type)
    bolo_list = [None, None, None]

    inv_cov_matrix_local = np.zeros((npix, ind_elements), dtype=np.float)
    b_matrix_local = np.zeros((npix, dim), dtype=np.float)
    hitmap_local = np.zeros(npix, dtype=np.float)

    bolo_segment_dict = get_local_bolo_segment_list(rank, size, config.bolo_list, config.segment_list)

    time.sleep(0.1*rank)
    print "Rank :", rank, ", Bolos and Segments :", bolo_segment_dict
    comm.Barrier()

    recon_dir = get_recon_dir()
    if rank == 0:
        make_data_dirs() 

    for bolo_name in bolo_segment_dict.keys():
        print "Rank :", rank, "Bolos class being generated"
        bolo_list = initialise_bolo(bolo_name, bolo_list)
        for segment in bolo_segment_dict[bolo_name]:
            prompter.prompt("Rank : %d doing Bolo : %s and segment : %d" % (rank, bolo_name, segment))
            if config.take_diff_signal:
                signal, v, pol_ang = acquire_difference_signal(bolo_a, bolo_b, segment)
            else:
                signal, v, pol_ang = acquire_signal(bolo, segment)
            if config.subtract_template:
                signal_TEMPLATE = bolo_TEMPLATE.read_timestream(segment, read_list=["signal"])["signal"]
                signal -= estimated_y*signal_TEMPLATE
            print "Rank :", rank, "Bolos signal read"
            hitpix = hp.vec2pix(config.nside_out, v[...,0], v[...,1], v[...,2])
            del v
            cov_ut.get_inv_cov_matrix(hitpix, pol_ang, signal, inv_cov_matrix_local, b_matrix_local, hitmap_local, npix, config.pol_type)
            print "Rank :", rank, "Inverse covariance matrix generated"

    if config.subtract_template:
        del signal_TEMPLATE
    del signal
    del pol_ang
    del hitpix

    inv_cov_matrix_local_segment = distribute_matrix(inv_cov_matrix_local, "cov_matrix")
    del inv_cov_matrix_local
    b_matrix_local_segment = distribute_matrix(b_matrix_local, "b_matrix")
    del b_matrix_local
    hitmap_local_segment = distribute_matrix(hitmap_local, "hitmap")
    del hitmap_local

    cov_matrix_local_segment = cov_ut.get_covariance_matrix(inv_cov_matrix_local_segment, hitmap_local_segment, config.pol_type)

    sky_map_local_segment = cov_ut.get_sky_map(cov_matrix_local_segment, b_matrix_local_segment, hitmap_local_segment, config.pol_type)

    write_segments(hitmap_local_segment, "hitmap", recon_dir) 
    write_segments(inv_cov_matrix_local_segment, "inverse_covariance_matrix", recon_dir) 
    write_segments(cov_matrix_local_segment, "covariance_matrix", recon_dir) 
    write_segments(sky_map_local_segment, "sky_map", recon_dir) 
示例#2
0
    def display_params(self):
        display_string = ""
        display_string += "Alpha : %f degrees\n" % (self.config.alpha)
        display_string += "Beta : %f degrees\n" % (self.config.beta)
        t_flight = self.config.t_segment*len(self.config.segment_list)
        display_string += "T flight : %f hours / %f days\n" % (t_flight/60.0/60.0, t_flight/60.0/60.0/24.0)
        display_string += "T segment : %f hours / %f days\n" % (self.config.t_segment/60.0/60.0, self.config.t_segment/60.0/60.0/24)
        display_string += "T precession : %f hours\n" % (self.config.t_prec/60.0/60.0)
        display_string += "T spin : %f seconds\n" % (self.config.t_spin)
        display_string += "Scan sampling rate : %f Hz\n" % (self.config.sampling_rate)
        display_string += "Theta co : %f arcmin\n" % (self.config.theta_co)
        display_string += "Theta cross : %f arcmin\n" % (self.config.theta_cross)
        display_string += "Oversampling rate : %d\n" % (self.config.oversampling_rate)
        display_string += "Scan resolution for beam integration : %f arcmin\n" % (self.config.scan_resolution)
        display_string += "Pixel size for NSIDE = %d : %f arcmin\n" % (self.config.nside_in, hp.nside2resol(self.config.nside_in, arcmin=True))
        n_steps = int(self.config.t_segment*self.config.sampling_rate)*self.config.oversampling_rate 
        display_string += "#Samples per segment : %d\n" %(n_steps)

        prompter.prompt(display_string, True)
示例#3
0
def run_mpi():
    if rank == 0:
        make_data_dirs()

    bolo_segment_dict = get_local_bolo_segment_list(rank, size, config.bolo_list, config.segment_list)
    comm.Barrier()
    time.sleep(0.1*rank)
    print "Rank :", rank, "Local bolo segment list :\n", bolo_segment_dict
    comm.Barrier()

    tot_seg = 0
    for keys in bolo_segment_dict.keys():
        tot_seg += len(bolo_segment_dict[keys])

    if "hitmap" in config.timestream_data_products:
        hitmap_local = np.zeros(hp.nside2npix(config.nside_in))

    for bolo_name in bolo_segment_dict.keys():
        bolo = Bolo(bolo_name, config)
        for segment in bolo_segment_dict[bolo_name]:
            start_seg = time.time()
            prompter.prompt("Doing Bolo : %s Segment : %d Rank : %d" % (bolo_name, segment+1, rank))
            if "hitmap" in config.timestream_data_products:
                hitmap_local += bolo.simulate_timestream(segment)
            else:
                bolo.simulate_timestream(segment)
            stop_seg = time.time()
            prompter.prompt("Rank : " + str(rank) + " Time taken : " + str(stop_seg - start_seg) + ". Projected time : " + str((stop_seg - start_seg)*tot_seg))

    prompter.prompt("Done simulating")

    
    if "hitmap" in config.timestream_data_products:
        hitmap = np.zeros(hitmap_local.size)

        comm.Reduce(hitmap_local, hitmap, MPI.SUM, 0)
        
        scan_dir = os.path.join(config.general_data_dir, config.sim_tag, config.scan_tag)
        if rank == 0:
            hp.write_map(os.path.join(scan_dir, "hitmap_in.fits"), hitmap)
示例#4
0
    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