Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150, sampling, scene)
y, x0_convolved = acq.get_observation(x0, convolution=True, noiseless=True)

# map-making
x, coverage = tod2map_all(acq, y, disp=True, tol=1e-4, coverage_threshold=0)
mask = coverage > 0


# some display
def display(x, title):
    x = x.copy()
    x[~mask] = np.nan
    hp.gnomview(x, rot=center_gal, reso=5, xsize=600, min=-200, max=200,
                title=title)

display(x0, 'Original map')
display(x0_convolved, 'Convolved original map')
display(x, 'Reconstructed map (gaussian approximation)')
display(x - x0_convolved, 'Residual map (gaussian approximation)')
mp.show()
Exemplo n.º 4
0
acquisition = QubicAcquisition(150,
                               sampling,
                               scene,
                               synthbeam_fraction=0.99,
                               detector_tau=0.01,
                               detector_nep=1.e-17,
                               detector_fknee=1.,
                               detector_fslope=1)

# simulate the timeline
tod, x0_convolved = acquisition.get_observation(x0,
                                                convolution=True,
                                                noiseless=True)

# 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,
Exemplo n.º 5
0
from __future__ import division
from qubic import (create_random_pointings, gal2equ, QubicAcquisition,
                   QubicScene, tod2map_all)
import numpy as np
import qubic

# read the input map
input_map = qubic.io.read_map(qubic.data.PATH + 'syn256_pol.fits',
                              field='I_STOKES')
nside = 256

# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150, sampling, scene)
hit = acq.get_hitmap()

# Produce the Time-Ordered data
tod = acq.get_observation(input_map)
output_map, coverage = tod2map_all(acq, tod)

print(acq.comm.rank, output_map[coverage > 0][:5])
print(acq.comm.rank, hit[hit > 0][:10])
Exemplo n.º 6
0
# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150, sampling, scene)
y, x0_convolved = acq.get_observation(x0, convolution=True, noiseless=True)

# map-making
x, coverage = tod2map_all(acq, y, disp=True, tol=1e-4, coverage_threshold=0)
mask = coverage > 0


# some display
def display(x, title):
    x = x.copy()
    x[~mask] = np.nan
    hp.gnomview(x,
                rot=center_gal,
                reso=5,
                xsize=600,
                min=-200,
                max=200,
                title=title)
Exemplo n.º 7
0
  fits_noiseless = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noiseless_'+strrnd+'.fits'
  fits_noise = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noisy_'+strrnd+'.fits'
  fits_spoiled_noiseless = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_spoiled_noiseless_'+strrnd+'.fits'
  fits_spoiled_noise = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_spoiled_noisy_'+strrnd+'.fits'
  fits_noI_noiseless = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noI_noiseless_'+strrnd+'.fits'
  fits_noI_noise = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noI_noisy_'+strrnd+'.fits'
  fits_noI_spoiled_noiseless = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noI_spoiled_noiseless_'+strrnd+'.fits'
  fits_noI_spoiled_noise = 'maps_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_noI_spoiled_noisy_'+strrnd+'.fits'

  fits_cov = 'cov_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_'+strrnd+'.fits'
  fits_spoiled_cov = 'cov_ns'+str(nside)+'_noise'+str(noise)+'_sigptg'+str(sigptg)+'_spoiled_'+strrnd+'.fits'


  coverage_threshold = 0.01
  print('Making noiseless map with true coverage')
  maps_noiseless, cov_noiseless = tod2map_all(acquisition, tod, tol=1e-4, coverage_threshold=coverage_threshold)
  if rank == 0:
    print('Saving the noiseless map with true coverage: '+fits_noiseless)
    qubic.io.write_map(fits_noiseless,maps_noiseless) 



  mask = cov_noiseless == 0
  x0_convolved[mask,:] = 0
  x0_noI_convolved[mask,:] = 0

  if rank == 0:
    print('Saving the input map: '+fits_input)
    qubic.io.write_map(fits_input,x0_convolved) 
    print('Saving the noI input map: '+fits_noI_input)
    qubic.io.write_map(fits_noI_input, x0_noI_convolved) 
Exemplo n.º 8
0
from qubic import (
    create_random_pointings, gal2equ, QubicAcquisition, QubicScene,
    tod2map_all)
import numpy as np
import qubic

# read the input map
input_map = qubic.io.read_map(qubic.data.PATH + 'syn256_pol.fits',
                              field='I_STOKES')
nside = 256

# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150, sampling, scene)
hit = acq.get_hitmap()

# Produce the Time-Ordered data
tod = acq.get_observation(input_map)
output_map, coverage = tod2map_all(acq, tod)

print acq.comm.rank, output_map[coverage > 0][:5]
print acq.comm.rank, hit[hit > 0][:10]
Exemplo n.º 9
0
# 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))

center = equ2gal(racenter, deccenter)

mp.figure(1)
Exemplo n.º 10
0
# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)

# acquisition model
acq = QubicAcquisition(150, sampling, kind='I')
acq_simple = SimpleAcquisition(150, sampling, kind='I')
hit = acq.get_hitmap()
C = acq.get_convolution_peak_operator()

tod = acq.get_observation(input_map)
output_map, coverage = tod2map_all(acq, tod)
output_map[coverage == 0] = np.nan
coverage[coverage == 0] = np.nan

tod_simple = acq_simple.get_observation(input_map)
output_map_simple, coverage_simple = tod2map_all(acq_simple, tod_simple)
output_map_simple[coverage_simple == 0] = np.nan
coverage_simple[coverage_simple == 0] = np.nan


# some display
def display(x, title, min=-200, max=200):
    hp.gnomview(x, rot=center_gal, reso=5, xsize=600, min=min, max=max,
                title=title)

display(input_map, 'Original map')