コード例 #1
0
ファイル: horns_profiles.py プロジェクト: jchamilton75/MySoft
def make_a_map(x0, pointing, instrument, nside, coverage_threshold=0.01, todnoise=None, fits_string=None, noiseless=False):
    ############# Make TODs ###########################################################
    acquisition = QubicAcquisition(instrument, pointing,
                                 nside=nside,
                                 synthbeam_fraction=0.99)
    tod, x0_convolved = map2tod(acquisition, x0, convolution=True)
    if todnoise is None:
        todnoise = acquisition.get_noise()
    factnoise=1
    if noiseless:
        factnoise=0
    ##################################################################################

    
    ############# Make mapss ###########################################################
    print('Making map')
    maps, cov = tod2map_all(acquisition, tod + todnoise * factnoise, tol=1e-4, coverage_threshold=coverage_threshold)
    if MPI.COMM_WORLD.rank == 0:
        fitsmapname = 'maps_'+fits_string+'.fits'
        fitscovname = 'cov_'+fits_string+'.fits'
        print('Saving the map: '+fitsmapname)
        qubic.io.write_map(fitsmapname,maps)
        print('Saving the coverage: '+fitsmapname)
        qubic.io.write_map(fitscovname,cov)
    ##################################################################################

    return maps, cov, todnoise
コード例 #2
0
def test_add_subtract_grid_operator():
    acq = QubicAcquisition(150, sampling, detector_ngrids=2)
    tod = map2tod(acq, input_map, convolution=False)
    add = acq.get_add_grids_operator()
    sub = acq.get_subtract_grids_operator()
    assert_same(add(tod), tod[:992] + tod[992:])
    assert_same(sub(tod), tod[:992] - tod[992:])
コード例 #3
0
def test_add_subtract_grid_operator():
    acq = QubicAcquisition(150, sampling, detector_ngrids=2)
    tod = map2tod(acq, input_map, convolution=False)
    add = acq.get_add_grids_operator()
    sub = acq.get_subtract_grids_operator()
    assert_same(add(tod), tod[:992] + tod[992:])
    assert_same(sub(tod), tod[:992] - tod[992:])
コード例 #4
0
ファイル: script_two_fp.py プロジェクト: jchamilton75/MySoft
def get_maps(spectra, inst, sampling, nside, x0, coverage_threshold=0.01,savefile=None, savefile_noiseless=None, noI=False):
  #if x0 is None:
  #  print("Running Synfast")
  #  x0 = np.array(hp.synfast(spectra[1:],nside,fwhm=0,pixwin=True,new=True)).T
  #  if noI: x0[:,0]*=0
  acquisition = QubicAcquisition(inst, sampling,
                                nside=nside,
                                synthbeam_fraction=0.99)
                                #max_nbytes=6e9)
  # simulate the timeline
  print('Now doing MAP2TOD (simulate data)')
  tod, x0_convolved = map2tod(acquisition, x0, convolution=True)
  print('TOD Done, now adding noise')
  bla = acquisition.get_noise()
  tod_noisy = tod + bla 
  # reconstruct using all available bolometers
  print('Now doing TOD2MAP (make map)')
  map_all, cov_all = tod2map_all(acquisition, tod_noisy, tol=1e-4, coverage_threshold=coverage_threshold)
  print('Map done')
  print('Now doing TOD2MAP (make map) on noiseless data')
  map_all_noiseless, cov_all_noiseless = tod2map_all(acquisition, tod, tol=1e-4, coverage_threshold=coverage_threshold)
  print('Noiseless Map done')
  mask = map_all_noiseless != 0
  x0_convolved[~mask,:] = 0
  rank = MPI.COMM_WORLD.rank
  if rank == 0:
    if savefile is not None:
      print('I am rank='+str(rank)+' and I try to save the file '+savefile)
      FitsArray(np.array([map_all[:,0], map_all[:,1], map_all[:,2], cov_all, x0_convolved[:,0], x0_convolved[:,1], x0_convolved[:,2]]), copy=False).save(savefile)
      print('I am rank='+str(rank)+' and I just saved the file '+savefile)
      print('I am rank='+str(rank)+' and I try to save the file '+savefile_noiseless)
      FitsArray(np.array([map_all_noiseless[:,0], map_all_noiseless[:,1], map_all_noiseless[:,2], cov_all_noiseless, x0_convolved[:,0], x0_convolved[:,1], x0_convolved[:,2]]), copy=False).save(savefile_noiseless)
      print('I am rank='+str(rank)+' and I just saved the file '+savefile_noiseless)
  return map_all, x0_convolved, cov_all, x0
コード例 #5
0
ファイル: analysis.py プロジェクト: MStolpovskiy/myqubic
 def __init__(self,
              acquisition_or_rec_map,
              input_map,
              coverage=None,
              mode='all',
              coverage_thr=0.0,
              tol=1e-4,
              maxiter=300,
              pickable=True,
              noise=True,
              weighted_noise=False,
              run_analysis=True,
              calculate_coverage=False):
     modes = 'all', 'each'
     if mode not in modes:
         raise ValueError("The only modes implemented are {0}.".format(
                 strenum(modes, 'and')))
     self.pickable = pickable
     if isinstance(acquisition_or_rec_map, QubicAcquisition):
         acquisition = acquisition_or_rec_map
         convolution = acquisition.get_convolution_peak_operator()
         self._scene_band = acquisition.scene.nu / 1e9
         self._scene_nside = acquisition.scene.nside
         self._scene_kind = acquisition.scene.kind
         if not pickable:
             self.acquisition = acquisition
         self._detectors_number = len(acquisition.instrument.detector)
         if run_analysis:
             time0 = time()
             self._tod, self.input_map_convolved = map2tod(
                 acquisition, input_map, convolution=True)
             time1 = time()
             print time1 - time0, 'for map2tod'
             if noise:
                 # 4.7 corresponds to a one year of data noise
                 self._tod += 4.7 * acquisition.get_noise()
             if mode == 'all':
                 tod2map_func = tod2map_all
             elif mode == 'each':
                 tod2map_func = tod2map_each
             time0 = time()
             self.reconstructed_map, self.coverage = tod2map_func(
                 acquisition, self._tod, tol=tol, maxiter=maxiter)
             time1 = time()
             print time1 - time0, 'for tod2map'
         if calculate_coverage:
             self.calc_coverage()
             self.coverage = convolution(self.coverage)
         self.coverage_thr = coverage_thr
     else:
         if coverage == None:
             raise TypeError("Must provide the coverage map!")
         self._coverage_thr = coverage_thr
         self._scene_band = None
         self._scene_nside = hp.npix2nside(len(coverage))
         self._scene_kind = 'IQU' if acquisition_or_rec_map.shape[1] == 3 else 'I'
         self._detectors_number = 1984 if self._scene_kind == 'IQU' else 992
         self.input_map_convolved = input_map # here the input map must be already convolved!
         self.reconstructed_map = acquisition_or_rec_map
         self.coverage = coverage
コード例 #6
0
    initpointing[i] = bla[0]
    bar.update()

fracvals = [0.3, 0.5, 0.9, 0.999]
mapmean_cmb = np.zeros((len(fracvals), npointings))
mapmean_dust = np.zeros((len(fracvals), npointings))
mapmean_all = np.zeros((len(fracvals), npointings))
maprms_cmb = np.zeros((len(fracvals), npointings))
maprms_dust = np.zeros((len(fracvals), npointings))
maprms_all = np.zeros((len(fracvals), npointings))
for j in np.arange(len(fracvals)):
    frac = fracvals[j]
    print(j, len(fracvals))
    theinst = QubicInstrument('monochromatic', nside=nside,
                              synthbeam_fraction=frac)
    tod_cmb, toto = map2tod(theinst, initpointing, mapscmb, convolution=True)
    tod_dust, toto = map2tod(theinst, initpointing, mapsdust, convolution=True)
    tod_all, toto = map2tod(theinst, initpointing, maps, convolution=True)
    mapmean_cmb[j] = np.mean(tod_cmb, axis=0)
    maprms_cmb[j] = np.std(tod_cmb, axis=0)
    mapmean_dust[j] = np.mean(tod_dust, axis=0)
    maprms_dust[j] = np.std(tod_dust, axis=0)
    mapmean_all[j] = np.mean(tod_all, axis=0)
    maprms_all[j] = np.std(tod_all, axis=0)


FitsArray(mapmean_cmb, copy=False).save('small2_mapmean_cmb.fits')
FitsArray(mapmean_dust, copy=False).save('small2_mapmean_dust.fits')
FitsArray(mapmean_all, copy=False).save('small2_mapmean_all.fits')
FitsArray(maprms_cmb, copy=False).save('small2_maprms_cmb.fits')
FitsArray(maprms_dust, copy=False).save('small2_maprms_dust.fits')
コード例 #7
0
  print('Initially Q map RMS is : '+str(np.std(x0[:,1])))
  print('Initially U map RMS is : '+str(np.std(x0[:,2])))
  print('new I map RMS is : '+str(np.std(x0_noI[:,0])))
  print('new Q map RMS is : '+str(np.std(x0_noI[:,1])))
  print('new U map RMS is : '+str(np.std(x0_noI[:,2])))
  ##################################################################################





  ############# Make TODs ###########################################################
  acquisition = QubicAcquisition(instFull, new_sampling,
                                 nside=nside,
                                 synthbeam_fraction=0.99)
  tod, x0_convolved = map2tod(acquisition, x0, convolution=True)
  tod_noI, x0_noI_convolved = map2tod(acquisition, x0_noI, convolution=True)
  todnoise = acquisition.get_noise()
  ##################################################################################




  ############# Make maps ###########################################################
  th_acquisition = QubicAcquisition(instFull, sampling,
                                 	nside=nside,
                                 	synthbeam_fraction=0.99)

  strrnd = random_string(10)

  fits_noI_input = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noI_input_'+strrnd+'.fits'
コード例 #8
0
sampling = create_sweeping_pointings(
    [racenter, deccenter], duration, ts, angspeed, delta_az, nsweeps_el,
    angspeed_psi, maxpsi)
sampling.angle_hwp = np.random.random_integers(0, 7, len(sampling)) * 11.25

# get the acquisition model
acquisition = QubicAcquisition(150, sampling,
                               nside=nside,
                               synthbeam_fraction=0.99,
                               detector_tau=0.01,
                               detector_sigma=1.,
                               detector_fknee=1.,
                               detector_fslope=1)

# simulate the timeline
tod, x0_convolved = map2tod(acquisition, x0, convolution=True)
tod_noisy = tod + acquisition.get_noise()

# reconstruct using two methods
map_all, cov_all = tod2map_all(acquisition, tod, tol=1e-2)
map_each, cov_each = tod2map_each(acquisition, tod, tol=1e-2)


# some display
def display(map, cov, msg, sub):
    for i, (kind, lim) in enumerate(zip('IQU', [200, 10, 10])):
        map_ = map[..., i].copy()
        mask = cov == 0
        map_[mask] = np.nan
        hp.gnomview(map_, rot=center, reso=5, xsize=400, min=-lim, max=lim,
                    title=msg + ' ' + kind, sub=(3, 3, 3 * (sub-1) + i+1))