Exemple #1
0
def readmaps(directory,
             tes,
             asic,
             az,
             el,
             p,
             proj_name,
             nside=None,
             azmin=None,
             azmax=None,
             remove=None,
             verbose=False):
    """
	directory: path to flat maps (get_flatmap method used to read maps)
	npix: array of number of pixels
	el, az: coordinates from data
	proj_name: projection you want. It could be 'flat' or 'healpix'
	nside: healpix parameter needed
	p: pointing"""
    if proj_name == 'flat':
        filemaps = np.zeros((len(tes), len(el), len(az)))
        for i in range(len(tes)):
            filename = directory + 'flat_ASIC{}TES{}.fits'.format(
                asic[i], tes[i])
            if verbose:
                print("[FlatMapsFile]: Reading {} file".format(filename))
            #filemaps[i], _, _ = sbfit.get_flatmap(npix[i], directory,
            #	azmin=azmin, azmax=azmax, remove=remove)
            filemaps[i] = FitsArray(filename)

    elif proj_name == 'healpix':
        warn(
            "HEALPix projections: At the moment, HEALPix projection comes from the readout of flat maps \
			In future this should be change and read directly from TOD")

        if nside == None:
            nside = hp.get_nside(
                FitsArray(directory +
                          'hp_ASIC{}TES{}.fits'.format(asic[0], tes[0])))

        filemaps = np.zeros((len(tes), 12 * nside**2))
        for i in range(len(tes)):
            filename = directory + 'hp_ASIC{}TES{}.fits'.format(
                asic[i], tes[i])
            if verbose:
                print("[FlatMapsFile]: Reading {} file".format(filename))
            #auxmap, _, _ = sbfit.get_flatmap(npix[i], directory,
            #		azmin=azmin, azmax=azmax, remove=remove)

            filemaps[i] = FitsArray(filename)
    else:
        raise ValueError(
            "You didn't specified the projection you want: flat or healpix.")

    return filemaps
Exemple #2
0
def get_flatmap(TESNum,
                directory,
                azmin=None,
                azmax=None,
                elmin=None,
                elmax=None,
                remove=None,
                fitted_directory=None):
    themap = np.array(
        FitsArray(directory + '/Flat/imgflat_TESNum_{}.fits'.format(TESNum)))
    az = np.array(FitsArray(directory + '/Flat/azimuth.fits'.format(TESNum)))
    el = np.array(FitsArray(directory + '/Flat/elevation.fits'.format(TESNum)))
    if azmin is None:
        azmin = np.min(az)
    if azmax is None:
        azmax = np.max(az)
    if elmin is None:
        elmin = np.min(el)
    if elmax is None:
        elmax = np.max(el)
    okaz = (az >= azmin) & (az <= azmax)
    az = az[okaz]
    okel = (el >= elmin) & (el <= elmax)
    el = el[okel]
    themap = themap[:, okaz][okel, :]
    if remove is not None:
        mm = np.mean(remove)
        ss = np.std(remove)
        xc, yval, dx, dy, others = ft.profile(remove,
                                              themap,
                                              rng=[mm - 2 * ss, mm + 2 * ss],
                                              mode=True,
                                              nbins=20,
                                              cutbad=True,
                                              plot=False,
                                              dispersion=False,
                                              clip=3)
        bla = np.polyfit(xc, yval, 1, w=1. / dy**2)
        pp = np.poly1d(bla)
        themap -= pp(remove)

    if fitted_directory is None:
        return themap, az, el
    else:
        ### Read fitted synthesized beam
        thefile = open(fitted_directory + '/fit-TES{}.pk'.format(TESNum), 'rb')
        fitpars = pickle.load(thefile, encoding='latin1')
        thefile.close()
        sbfitmodel = SbModelIndepPeaks(nrings=2,
                                       common_fwhm=True,
                                       no_xy_shift=False,
                                       distortion=False)
        x = np.meshgrid(az * np.cos(np.radians(50)), np.flip(el))
        fitmap, newxxyy = sbfitmodel(x, fitpars, return_peaks=True)
        return themap, az, el, fitmap, newxxyy
Exemple #3
0
def maps_from_files(files, silent=False):
    """allmost equivalent to get_all_maps, 
    used in the functions that compute spectra 
    """
    if not silent: print('Reading Files')
    nn = len(files)
    mm = FitsArray(files[0])
    sh = np.shape(mm)
    maps = np.zeros((nn, sh[0], sh[1], sh[2]))
    for i in xrange(nn):
        maps[i,:,:,:] = FitsArray(files[i])
        
    totmap = np.sum(np.sum(np.sum(maps, axis=0), axis=0),axis=1)
    seenmap = totmap > -1e20
    return maps, seenmap
Exemple #4
0
def read_all_maps(files, nsub, seenmap):
    """
    Read all realisations of I,Q,U maps for one number of subbands 
    Only seen pixels are stored in order to save memory.

    nsub : number of subbands
    seenmap : list of booleans for pixels observed or not

    mapsout : array of shape (nreals, nsub, npixok, 3)
        
    """
    print('\nReading all maps')

    nfiles = len(files)
    print(files, nfiles)
    npixok  = np.sum(seenmap)
    mapsout = np.zeros((nfiles, nsub, npixok, 3))
    for ifile in xrange(nfiles):
        print('Doing: ' + files[ifile], 'nsub=' + str(nsub))
        sys.stdout.flush()
        sys.stdout.write('\r Reading: ' + files[ifile] + ' ({:3.1f} %)'.format(100 * (ifile + 1) * 1. / nfiles))
        mm = FitsArray(files[ifile])
        mapsout[ifile, :, :, :] = mm[:, seenmap, :]
    sys.stdout.flush()    
    return mapsout
Exemple #5
0
def coverage(dictionaries, regions, bands, makeCov = False, filename = None):
	"""
	Read or make the coverage maps for the bands and regions 

	Assumes one config: FI or TD (info will be read it from dictionatries[0])
	Parameters: 
		dictionaries:
			array of Qubic dictionaries
		regions: 
			sky regions where coverage will be computed or read
		bands: 
			150 or 220GHz
		filename:
			Array of filenames of coverages maps. #filenames = #regions + #bands. Default: read this 4 files 
			["doc/FastSimulator/Data/DataFastSimulator_FI150Q_coverage.fits'",
			 "doc/FastSimulator/Data/DataFastSimulator_FI220Q_coverage.fits'",
			 "doc/FastSimulator/Data/DataFastSimulator_FI150G_coverage.fits'",
			 "doc/FastSimulator/Data/DataFastSimulator_FI220G_coverage.fits'" ]
	Return: 
		coveragesmaps:  
			maps with format priority: region (in regions) and then band (in bands ascendent order). 
			It take the first letter in regions to use in name when reading maps from files.
			Shape: (len(regions) +len(bands), npix)
	"""


	#regions = ['Qubic_field', 'GalCen_field']
	#bands = ['150', '220']

	global_dir = Qubic_DataDir(datafile='instrument.py', datadir=os.environ['QUBIC_DATADIR'])
	if filename == None:
		import itertools
		config = dictionaries[0]['config']
		filename = [global_dir + '/doc/FastSimulator/Data/DataFastSimulator_{}{}{}_coverage.fits'.format(config, jband, ireg[0]) \
		for ireg, jband in itertools.product(regions, bands)]
	else:
		filename = filename

	coveragesmaps = np.zeros((len(regions) * len(bands), 12 * dictionaries[0]['nside'] ** 2, ))
	if makeCov:
		#Save coverage maps with format priority: region (in regions) and then band (in bands ascendent order) 
		cov = np.shape((len(regions)+len(bands), 
						dictionaries[0]['nf_recon'], 
						12 * dictionaries[0]['nside'] ** 2))
		for jr, region in enumerate(regions):
			for jb, band in enumerate(bands):
				index = len(bands) * jr + jb
				cov[index] = make_cov[dictionaries[index]]
				coveragesmaps[index] = np.sum(cov[index], axis = 0)  # Average the bands
				coveragesmaps[index] /= np.max(coveragesmaps[index]) # Normalize by the max
	else:
		for jr, region in enumerate(regions):
			for jb, band in enumerate(bands):
				index = len(bands) * jr + jb
				#print(index, len(coveragesmaps), len(regions), len(bands))
				coveragesmaps[index] = FitsArray(filename[index])

	return coveragesmaps
Exemple #6
0
 def func(lmax, n):
     class XpolDummy(Xpol):
         def __init__(self):
             self.lmax = lmax
             self.wl = np.ones(max(n+1, 1))
     xpol = XpolDummy()
     mll = xpol._get_Mll(binning=False)
     expected = FitsArray('test/data/xpol_mll_{}_{}.fits'.format(lmax, n))
     assert_same(mll, expected, atol=200)
Exemple #7
0
    def save_azel_mymap(self, mymap, TESNum):

        repository = os.getcwd() + '/Fits/Flat'
        try:
            os.makedirs(repository)
        except OSError:
            if not os.path.isdir(repository):
                raise

        FitsArray(mymap).save(repository +
                              '/imgflat_TESNum_{}.fits'.format(TESNum))
Exemple #8
0
def get_seenmap(files):
    """ 
    Return a list of len the number of pixels, 
    True or False if the pixel is observed or not in files.
    files : list of .fits files

    seenmap : list of len npix
    """
    print('\nGetting Observed pixels map')
    m = FitsArray(files[0])
    npix = np.shape(m)[1]
    seenmap = np.zeros(npix) == 0
    for i in xrange(len(files)):
        sys.stdout.flush()
        sys.stdout.write('\r Reading: '+files[i]+' ({:3.1f} %)'.format(100*(i+1)*1./len(files)))
        m = FitsArray(files[i])
        bla = np.mean(m, axis=(0,2)) != hp.UNSEEN
        seenmap *= bla
    sys.stdout.flush()
    return seenmap
Exemple #9
0
def run_asic(idnum,
             Vtes,
             fff,
             dc,
             theasicfile,
             asic,
             reselect_ok=False,
             lowcut=0.5,
             highcut=15.,
             nbins=50,
             nointeractive=False,
             doplot=True,
             notch=None,
             lastpassallfree=False,
             name='fib',
             okfile=None,
             initpars=None,
             timerange=None,
             removesat=False,
             stop_each=False,
             rangepars=None):
    """

    Parameters
    ----------
    idnum
    Vtes
    fff : float
        Modulation frequency of the external source
    dc : float
        Duty cycle of the modulation
    theasicfile
    asic
    reselect_ok : bool
        If true, you will select the good TES one by one, if False, you will use the file created before.
    lowcut
    highcut
    nbins
    nointeractive
    doplot
    notch
    lastpassallfree
    name
    okfile
    initpars
    timerange
    removesat
    stop_each
    rangepars

    Returns
    -------

    """
    fib = idnum
    ### Read data
    # GOING TO TEST PASSING IN THESE VARS
    FREQ_SAMPLING = (2e6 / 128 / 100)
    time, dd, a = qs2array(theasicfile, FREQ_SAMPLING, timerange=timerange)
    ndet, nsamples = np.shape(dd)

    ### Fold the data at the modulation period of the fibers
    ### Signal is also badpass filtered before folding
    folded, tt, folded_nonorm = fold_data(time,
                                          dd,
                                          1. / fff,
                                          lowcut,
                                          highcut,
                                          nbins,
                                          notch=notch)

    if nointeractive:
        reselect_ok = False
        answer = 'n'
    else:
        if reselect_ok:
            print('\n\n')
            answer = raw_input(
                'This will overwrite the file for OK TES. Are you sure you want to proceed [y/n]'
            )
        else:
            answer = 'n'

    if answer == 'y':
        print(
            'Now going to reselect the OK TES and overwrite the corresponding file'
        )
        #### Pass 1 - allows to obtain good values for t0 basically
        #### Now perform the fit on the median folded data
        print('')
        print('FIRST PASS')
        print('First Pass is only to have a good guess of the t0, '
              'your selection should be very conservative - only high S/N')
        # if initpars == Noy
        # ne:
        # 	initpars = [dc, 0.06, 0., 0.6]
        av, params, err = fit_average(tt,
                                      folded,
                                      fff,
                                      dc,
                                      fib,
                                      Vtes,
                                      initpars=initpars,
                                      fixpars=[0, 0, 0, 0],
                                      doplot=True,
                                      name=name)

        #### And the fit on all data with this as a first guess forcing some parameters
        #### it returns the list of OK detectorsy
        allparams, allerr, allchi2, ndf, ok = fit_all(
            tt,
            folded,
            av,
            initpars=[dc, params[1], params[2], params[3]],
            fixpars=[1, 0, 1, 0],
            rangepars=rangepars,
            stop_each=True)

        #### Pass 2
        #### Refit with only the above selected ones in order to have good t0
        #### Refit the median of the OK detectors
        print('')
        print('SECOND PASS')
        print(
            'Second pass is the final one, please select the pixels that seem OK'
        )
        av, params, err = fit_average(tt,
                                      folded[ok, :],
                                      fff,
                                      dc,
                                      fib,
                                      Vtes,
                                      initpars=initpars,
                                      fixpars=[0, 0, 0, 0],
                                      doplot=True,
                                      name=name)

        #### And the fit on all data with this as a first guess forcing some parameters
        #### it returns the list of OK detectors
        allparams, allerr, allchi2, ndf, ok = fit_all(
            tt,
            folded,
            av,
            initpars=[dc, params[1], params[2], params[3]],
            rangepars=rangepars,
            fixpars=[1, 0, 1, 0],
            stop_each=True)

        #### Final Pass
        #### The refit them all with only tau and amp as free parameters
        #### also do not normalize amplitudes of folded
        allparams, allerr, allchi2, ndf, ok_useless = fit_all(
            tt,
            folded_nonorm * 1e9,
            av,
            initpars=[dc, params[1], params[2], params[3]],
            rangepars=rangepars,
            fixpars=[1, 0, 1, 0],
            functname=simsig_nonorm)

        okfinal = ok * (allparams[:, 1] < 1.)
        ### Make sure no thermometer is included
        okfinal[[3, 35, 67, 99]] = False
        # Save the list of OK bolometers
        if okfile is None:
            FitsArray(okfinal.astype(int)).save(
                'TES-OK-{}{}-asic{}.fits'.format(name, fib, asic))
        else:
            FitsArray(okfinal.astype(int)).save(okfile)
    else:
        # if initpars is None:
        # 	initpars = [dc, 0.06, 0., 0.6]
        if okfile is None:
            okfinal = np.array(
                FitsArray('TES-OK-{}{}-asic{}.fits'.format(name, fib,
                                                           asic))).astype(bool)
        else:
            okfinal = np.array(FitsArray(okfile)).astype(bool)
        if removesat:
            #### remove pixels looking saturated
            saturated = (np.min(folded_nonorm, axis=1) < removesat)
            okfinal = (okfinal * ~saturated).astype(bool)

    if doplot is False:
        ### Now redo the fits one last time
        av, params, err = fit_average(tt,
                                      folded[okfinal, :],
                                      fff,
                                      dc,
                                      fib,
                                      Vtes,
                                      initpars=initpars,
                                      fixpars=[0, 0, 0, 0],
                                      doplot=False,
                                      clear=False,
                                      name=name)

        allparams, allerr, allchi2, ndf, ok_useless = fit_all(
            tt,
            folded_nonorm * 1e9,
            av,
            initpars=[dc, params[1], params[2], params[3]],
            fixpars=[1, 0, 1, 0],
            functname=simsig_nonorm,
            rangepars=rangepars)
    else:
        figure(figsize=(6, 8))
        subplot(3, 1, 1)
        ### Now redo the fits one last time
        av, params, err = fit_average(tt,
                                      folded[okfinal, :],
                                      fff,
                                      dc,
                                      fib,
                                      Vtes,
                                      initpars=initpars,
                                      fixpars=[0, 0, 0, 0],
                                      doplot=True,
                                      clear=False,
                                      name=name)
        print(params)
        print(err)

        if lastpassallfree:
            fixed = [0, 0, 0, 0]
        else:
            fixed = [1, 0, 1, 0]
        allparams, allerr, allchi2, ndf, ok_useless = fit_all(
            tt,
            folded_nonorm * 1e9,
            av,
            initpars=[dc, params[1], params[2], params[3]],
            fixpars=fixed,
            functname=simsig_nonorm,
            stop_each=stop_each,
            rangepars=rangepars)

        subplot(3, 2, 3)
        mmt, sst = meancut(allparams[okfinal, 1], 3)
        hist(allparams[okfinal, 1],
             range=[0, mmt + 4 * sst],
             bins=10,
             label=statstr(allparams[okfinal, 1], cut=3))
        xlabel('Tau [sec]')
        legend()
        title('Asic {} - {} {}'.format(name, asic, fib))
        subplot(3, 2, 4)
        mma, ssa = meancut(allparams[okfinal, 3], 3)
        hist(allparams[okfinal, 3],
             range=[0, mma + 4 * ssa],
             bins=10,
             label=statstr(allparams[okfinal, 3], cut=3))
        legend()
        xlabel('Amp [nA]')

        pars = allparams
        tau = pars[:, 1]
        tau[~okfinal] = np.nan
        amp = pars[:, 3]
        amp[~okfinal] = np.nan

        if asic == 1:
            tau1 = tau
            tau2 = None
            amp1 = amp
            amp2 = None
        else:
            tau1 = None
            tau2 = tau
            amp1 = None
            amp2 = amp

        subplot(3, 2, 5)
        imtau = image_asics(data1=tau1, data2=tau2)
        imshow(imtau,
               vmin=0,
               vmax=mmt + 4 * sst,
               cmap='viridis',
               interpolation='nearest')
        title('Tau - {} {} - asic {}'.format(name, fib, asic))
        colorbar()
        subplot(3, 2, 6)
        imamp = image_asics(data1=amp1, data2=amp2)
        imshow(imamp,
               vmin=0,
               vmax=mma + 6 * ssa,
               cmap='viridis',
               interpolation='nearest')
        colorbar()
        title('Amp - {} {} - asic {}'.format(name, fib, asic))
        tight_layout()

    return tt, folded, okfinal, allparams, allerr, allchi2, ndf
centers = [centerQ, centerQ, centerG, centerG]
dictionaries = [d150Q, d220Q, d150G, d220G]

regions = ['Qubic_field', 'GalCen_field']
bands = ['150', '220']

nf_recon = d150Q['nf_recon']

print(" =========== DONE ======== ")

print("# Read coverage maps")
coveragesmaps = fsed.coverage(dictionaries, regions, bands)

print("# Read FullMap (noise+foreground with nside = 256)")
maps = FitsArray("DataSED/SED_FullMaps_nside{}_nreals{}.fits".format(nside_new,nreals))

print("# Read sky (dust + synch) down graded to nside {}".format(nside_new))
fgr_map_ud = FitsArray("DataSED/SED_ForegMaps_nside{}_nreals{}.fits".format(nside_new,nreals))

print("# Read noise down graded to nside {}".format(nside_new))
noise_ud_i = FitsArray("DataSED/SED_NoiseMaps_nside{}_nreals{}.fits".format(nside_new,nreals))

print("# Read covariance matrix")
bandreg = ["FI150Q", "FI220Q", "FI150G", "FI220G"]
Cp_prime = []
for j, idict in enumerate(bandreg):
	Cp_prime.append(FitsArray("DataSED/SED_CovarMatrix_nside{}_nreals{}_{}.fits".format(nside_new,nreals, bandreg[j])))
#Cp_prime = FitsArray("SED_CovarMatrix_nside{}_nreals{}.fits".format(nside_new,nreals))

print("# Compute mask for coverage map and compute downgraded coverage map")
Exemple #11
0
allfiles_ang = np.sort(glob.glob(dirfiles + 'angles*_' + names + '_*.fits'))
allfiles_ang = np.sort(allfiles_ang)

allels = np.zeros(len(allfiles))
for i in range(len(allfiles)):
    allels[i] = str.split(allfiles[i], '_')[-1][:-5]

print 'Found {} Files'.format(len(allfiles))

#### Read files
alldata = []
allaz = []
allel = []
allang_az = []
for j in range(len(allfiles)):
    data = np.array(FitsArray(allfiles[j]))
    sh = np.shape(data)
    alldata.append((data.T - np.median(data, axis=1)).T)
    bla = np.array(FitsArray(allfiles_ang[j]))
    allaz.append(bla[0, :])
    allel.append(bla[1, :] + 124.35)
    allang_az.append(bla[2, :])

#### Make a fake TOD for healpix mapping
tod = dl.make_tod(alldata)
az = dl.make_tod(allaz, axis=0)
el = dl.make_tod(allel, axis=0)

#### Make directories
dir_files = '/Volumes/Data/Qubic/Calib-TD/Synthesized_Beams_Files/' + freq
dir_img = '/Volumes/Data/Qubic/Calib-TD/Synthesized_Beams_Images/' + freq
Exemple #12
0
def do_some_dets(detnums,
                 d,
                 p,
                 directory,
                 fittedpeakfile,
                 az,
                 el,
                 proj_name,
                 custom=False,
                 q=None,
                 nside=None,
                 tol=5e-3,
                 refit=False,
                 resample=False,
                 newsize=70,
                 doplot=True,
                 verbose=True,
                 sbfitmodel=None,
                 angs=None,
                 usepeaks=None,
                 azmin=None,
                 azmax=None,
                 remove=None,
                 fitted_directory=None,
                 weighted=False,
                 nf_sub_rec=1,
                 lowcut=1e-3,
                 highcut=0.3):

    if nside is not None:
        d['nside'] = nside
    s = qubic.QubicScene(d)

    if q == None:
        q = qubic.QubicMultibandInstrument(d)

    if len(q) == 1:
        xgrf, ygrf, FP_index, index_q = sc.get_TES_Instru_coords(q,
                                                                 frame='GRF',
                                                                 verbose=False)
    else:
        xgrf, ygrf, FP_index, index_q = sc.get_TES_Instru_coords(q[0],
                                                                 frame='GRF',
                                                                 verbose=False)

    # Create TES, index and ASIC numbers assuming detnums is continuos TES number (1-248).
    tes, asic = np.zeros((len(detnums), ), dtype=int), np.zeros(
        (len(detnums), ), dtype=int)
    qpix = np.zeros((len(detnums), ), dtype=int)

    for j, npix in enumerate(detnums):
        tes[j], asic[j] = (npix, 1) if (npix < 128) else (npix - 128, 2)
        qpix[j] = tes2pix(tes[j], asic[j]) - 1
        if verbose:
            print("DETNUM{} TES{} ASIC{} QPIX{}".format(
                npix, tes[j], asic[j], qpix[j]))

    #Center of FOV
    azcen_fov = np.mean(az)
    elcen_fov = np.mean(el)

    #Directory where the maps are:
    mapsdir = directory
    #File where the fitted peaks are:
    peaksdir = fittedpeakfile

    if not custom:
        if verbose:
            print('')
            print('Normal Reconstruction')
        qcut = select_det(qubic.QubicMultibandInstrument(d), detnums)
        #qcut = select_det(qubic.QubicMultibandInstrument(d),[145])
    else:
        if verbose:
            print('')
            print('Custom Reconstruction')
        ### Refit or not the locations of the peaks
        ### from the synthesized beam images
        ### First instantiate a jchinstrument (modified from instrument
        ### to be able to read peaks from a file)

        print("Generating jchinstrument")
        qcut = select_det(
            jcinst.QubicMultibandInstrument(d,
                                            peakfile=fittedpeakfile,
                                            tes=tes,
                                            asic=asic), qpix)
        print("LEN(qcut) and detector", len(qcut),
              np.shape(qcut[0].detector.center))
        print("Generating jchinstrument"[::-1])

        ### In the present case, we use the peak measurements at 150 GHz
        ### So we assume its index is len(qcut)//2
        id150 = len(qcut) // 2
        nu = qcut[id150].filter.nu
        synthbeam = qcut[id150].synthbeam
        horn = getattr(qcut[id150], 'horn', None)
        primary_beam = getattr(qcut[id150], 'primary_beam', None)
        # Cosine projection with elevation center of the FOV considering symetric scan in azimuth for each elevation step
        thecos = np.cos(np.radians(elcen_fov))

        #Read map (flat or healpy) for each detector
        print("TES ASIC", tes, asic)
        filemaps = readmaps(directory,
                            tes,
                            asic,
                            az,
                            el,
                            p,
                            proj_name=proj_name,
                            nside=d['nside'],
                            verbose=verbose)

        # Compute measured coordenates
        allphis_M, allthetas_M, allvals_M = get_data_Mrefsyst(
            detnums,
            filemaps,
            az,
            el,
            fitted_directory,
            fittedpeakfile,
            proj_name,
            resample=resample,
            newsize=newsize,
            azmin=azmin,
            azmax=azmax,
            remove=remove,
            sbfitmodel=sbfitmodel,
            refit=refit,
            verbose=verbose)
        if doplot:
            _plot_onemap(filemaps,
                         az,
                         el, [allphis_M, allthetas_M],
                         proj_name,
                         makerotation=False)

        ### Now we want to perform the rotation to go to boresight
        ### reference frame (used internally by QubicSoft)
        if verbose:
            print("Solid angles synthbeam = {:.3e}, QubicScene {:.3e}".format(
                synthbeam.peak150.solid_angle, s.solid_angle))

        allphis_Q, allthetas_Q, allvals_Q, numpeak = convert_M2Q(
            detnums,
            allphis_M,
            allthetas_M,
            allvals_M,
            elcen_fov,
            solid_angle=synthbeam.peak150.solid_angle,
            nu=nu,
            horn=horn,
            solid_angle_s=s.solid_angle,
            angs=angs,
            verbose=verbose)
        print("allphis_Q , allvals_Q shapes", np.shape(allphis_Q),
              np.shape(allvals_Q))

        if doplot:
            plt.title("xy coord. of peaks in M and Q ref system")
            plt.plot(np.cos(allphis_M[0]) * np.sin(allthetas_M[0]),
                     np.sin(allphis_M[0]) * np.sin(allthetas_M[0]),
                     'r+',
                     ms=10,
                     label="M ref syst")
            plt.plot(np.cos(allphis_Q[0]) * np.sin(allthetas_Q[0]),
                     np.sin(allphis_Q[0]) * np.sin(allthetas_Q[0]),
                     'b+',
                     ms=10,
                     label="Q ref syst")
            plt.legend()
            plt.show()

        if doplot:
            # Plot peaks in measured reference frame.
            _plot_grfRF(detnums, xgrf, ygrf, qcut, numpeak)

        for idet in range(len(detnums)):
            position = np.ravel(qcut[0].detector[idet].center)
            position = -position / np.sqrt(np.sum(position**2))
            theta_center = np.arcsin(np.sqrt(position[0]**2 + position[1]**2))
            phi_center = np.arctan2(position[1], position[0])
            rav_thQ = np.ravel(allthetas_Q[idet, :])
            rav_phQ = np.ravel(allphis_Q[idet, :])
            ## Now we identify the nearest peak to the theoretical Line Of Sight
            angdist = np.zeros(len(rav_phQ))
            for k in range(len(rav_phQ)):
                angdist[k] = sbfit.ang_dist([theta_center, phi_center],
                                            [rav_thQ[k], rav_phQ[k]])
                print(k, np.degrees(angdist[k]))
            idxmin = np.argmin(angdist)
            numpeak[idet] = idxmin

        ### We nowwrite the temporary file that contains the peaks locations to be used
        if usepeaks is None:
            peaknums = np.arange(9)
        else:
            peaknums = usepeaks
        data = [
            allthetas_Q[:, peaknums], allphis_Q[:, peaknums] - np.pi,
            allvals_Q[:, peaknums], numpeak
        ]
        file = open(os.environ['QUBIC_PEAKS'] + 'peaks.pk', 'wb')
        pickle.dump(data, file)
        file.close()

    ### Make the TODs from the measured synthesized beams
    realTOD = np.zeros((len(detnums), len(p)))
    sigmaTOD = np.zeros(len(detnums))
    if weighted:
        sumweight = 0.

    allimg = []

    for i in range(len(detnums)):
        if proj_name == "flat":
            filename = directory + 'flat_ASIC{}TES{}.fits'.format(
                asic[i], tes[i])
            img = FitsArray(filename)
        elif proj_name == "healpix":
            filename = directory + '../../Flat/synth_beam/flat_ASIC{}TES{}.fits'.format(
                asic[i], tes[i])
            img = FitsArray(filename)
        allimg.append(img)
        fact = 1  #5e-28
        realTOD[i, :] = np.ravel(img) * fact

        if weighted:  ## Not to be used - old test...
            realTOD[i, :] *= 1. / ss**2
            sumweight += 1. / ss**2
    print("All img", np.shape(allimg))
    ### new code multiband
    plt.figure()
    for i in range(len(detnums)):
        plt.plot(realTOD[i, :], label='TES#{0:}'.format(detnums[i]))
    plt.legend()
    plt.xlabel('Samples')
    plt.ylabel('TOD')
    plt.show()

    plt.figure()
    for i in range(len(detnums)):
        spectrum_f, freq_f = ft.power_spectrum(np.arange(len(realTOD[i, :])),
                                               realTOD[i, :])
        pl = plt.plot(freq_f,
                      spectrum_f,
                      label='TES#{0:}'.format(detnums[i]),
                      alpha=0.5)
        plt.xscale('log')
        plt.yscale('log')
    plt.legend()
    plt.xlabel('Fourier mode')
    plt.ylabel('Power Spectrum')
    plt.title('Before Filtering')
    plt.show()

    for i in range(len(detnums)):
        realTOD[i, :] = ft.filter_data(np.arange(len(realTOD[i, :])),
                                       realTOD[i, :], lowcut, highcut)
        mm, ss = ft.meancut(realTOD[i, :], 3)
        sigmaTOD[i] = ss
    if doplot:
        for i in range(len(detnums)):
            plt.figure()
            plt.subplot(1, 2, 1)
            plt.imshow(allimg[i] * fact,
                       vmin=mm - 3 * ss,
                       vmax=mm + 3 * ss,
                       extent=[
                           np.max(az) * thecos,
                           np.min(az) * thecos,
                           np.min(el),
                           np.max(el)
                       ],
                       aspect='equal')
            plt.colorbar()
            plt.title('Init - TOD {0:} RMS={1:5.2g}'.format(
                detnums[i], sigmaTOD[i]))
            plt.subplot(1, 2, 2)
            plt.imshow(np.reshape(realTOD[i, :], np.shape(img)),
                       vmin=mm - 3 * ss,
                       vmax=mm + 3 * ss,
                       extent=[
                           np.max(az) * thecos,
                           np.min(az) * thecos,
                           np.min(el),
                           np.max(el)
                       ],
                       aspect='equal')
            plt.colorbar()
            plt.title('Filtered - TOD {0:} RMS={1:5.2g}'.format(
                detnums[i], sigmaTOD[i]))

    plt.figure()
    for i in range(len(detnums)):
        spectrum_f, freq_f = ft.power_spectrum(np.arange(len(realTOD[i, :])),
                                               realTOD[i, :])
        pl = plt.plot(freq_f,
                      spectrum_f,
                      label='TES#{0:} Var*2pi={1:5.2g}'.format(
                          detnums[i], sigmaTOD[i]**2 * 2 * np.pi),
                      alpha=0.5)
        plt.plot(freq_f,
                 freq_f * 0 + sigmaTOD[i]**2 * 2 * np.pi,
                 color=pl[0].get_color())
        plt.xscale('log')
        plt.yscale('log')
    plt.ylim(np.min(sigmaTOD**2 * 2 * np.pi),
             np.max(sigmaTOD**2 * 2 * np.pi) * 1e9)
    plt.legend()
    plt.xlabel('Fourier mode')
    plt.ylabel('Power Spectrum')
    plt.title('After Filtering')
    if lowcut:
        plt.axvline(x=lowcut, color='k')
    if highcut:
        plt.axvline(x=highcut, color='k')
    plt.show()

    plt.figure()
    plt.clf()
    print('%%%%%%%%%%%%%%%%%%%%%%')
    ax = plt.subplot(111, projection='polar')
    print("len qcut", len(qcut[0].detector.center))
    print("=?===============================")
    print(np.shape(realTOD), np.shape(p), nf_sub_rec, np.shape(qcut))
    print("=?===============================")

    maps_recon, cov, nus, nus_edge = si.reconstruct_maps(
        realTOD,
        d,
        p,
        nf_sub_rec,
        x0=None,
        instrument=qcut,  #verbose=True,
        forced_tes_sigma=sigmaTOD)
    ax.set_rmax(0.5)
    #legend(fontsize=8)
    if weighted:
        maps_recon /= sumweight / len(detnums)
    return maps_recon, qcut, np.mean(cov, axis=0), nus, nus_edge
Exemple #13
0
 def __init__(self,
              band,
              scene,
              true_sky=None,
              factor=1,
              fwhm=0,
              mask=None,
              convolution_operator=None):
     """
     Parameters
     ----------
     band : int
         The band 150 or 220.
     scene : Scene
         The acquisition scene.
     true_sky : array of shape (npixel,) or (npixel, 3)
         The true CMB sky (temperature or polarized). The Planck observation
         will be this true sky plus a random independent gaussian noise
         realization.
     factor : 1 or 3 floats, optional
         The factor by which the Planck standard deviation is multiplied.
     fwhm : float, optional, !not used!
         The fwhm of the Gaussian used to smooth the map [radians].
     mask : array of shape (npixel, ) or None
         The boolean mask, which is equal True at pixels where we need Planck,
         that is outside the QUBIC field.
     """
     if band not in (150, 220):
         raise ValueError("Invalid band '{}'.".format(band))
     if true_sky is None:
         raise ValueError('The Planck Q & U maps are not released yet.')
     if scene.kind == 'IQU' and true_sky.shape[-1] != 3:
         raise TypeError('The Planck sky shape is not (npix, 3).')
     true_sky = np.array(hp.ud_grade(true_sky.T, nside_out=scene.nside),
                         copy=False).T
     if scene.kind == 'IQU' and true_sky.shape[-1] != 3:
         raise TypeError('The Planck sky shape is not (npix, 3).')
     self.scene = scene
     self.fwhm = fwhm
     self._true_sky = true_sky
     if mask is not None:
         self.mask = mask
     else:
         self.mask = np.ones(scene.npixel, dtype=np.bool)
     if band == 150:
         filename = 'Variance_Planck143GHz_Kcmb2_ns256.fits'
     else:
         filename = 'Variance_Planck217GHz_Kcmb2_ns256.fits'
     sigma = 1e6 * factor * np.sqrt(FitsArray(PATH + filename))
     if scene.kind == 'I':
         sigma = sigma[:, 0]
     elif scene.kind == 'QU':
         sigma = sigma[:, :2]
     if self.scene.nside != 256:
         sigma = np.array(hp.ud_grade(sigma.T, self.scene.nside, power=2),
                          copy=False).T
     self.sigma = sigma
     if convolution_operator is None:
         self.C = IdentityOperator()
     else:
         self.C = convolution_operator
Exemple #14
0
# Check that we do one simulation with only one reconstructed subband
if d['nf_recon'][0] != 1:
    raise ValueError(
        'You should do one simulation without spectroimaging as a reference.')

# Save the dictionary
shutil.copyfile(dictfilename, out_dir + name + '.dict')

# ==========================================

t0 = time.time()

# ===== Sky Creation or Reading =====

x0 = FitsArray(
    dictmaps +
    'nf_sub={}/nside{}_nfsub{}.fits'.format(nf_sub, d['nside'], nf_sub))
print('Input Map with shape:', np.shape(x0))

if x0.shape[1] % (12 * d['nside']**2) == 0:
    print('Good size')
else:
    y0 = np.ones((d['nf_sub'], 12 * d['nside']**2, 3))
    for i in range(d['nf_sub']):
        for j in range(3):
            y0[i, :, j] = hp.ud_grade(x0[i, :, j], d['nside'])

# Put I = 0
# x0[:, :, 0] = 0.

# Multiply Q, U maps
Exemple #15
0
####################### restore stuff ###################
import pickle
from pysimulators import FitsArray
## Pointing
infile=open('saved_ptg.dat', 'rb')
data=pickle.load(infile)
infile.close()
pointings=data['pointings']
mask=data['mask']

signoise=0.5
nbmc=10000
data=0
## Covariance matrix
covmc=FitsArray('covmc'+str(signoise)+'_'+str(nbmc)+'.dat')
cormc=FitsArray('cormc'+str(signoise)+'_'+str(nbmc)+'.dat')
###########################################################

##### build coverage
a=np.loadtxt('./cl_r=0.1bis2.txt')
ell=a[:,0]
ctt=np.concatenate([[0,0],a[:,1]*1e12*2*np.pi/(ell*(ell+1))])
cee=np.concatenate([[0,0],a[:,2]*1e12*2*np.pi/(ell*(ell+1))])
cte=np.concatenate([[0,0],a[:,4]*1e12*2*np.pi/(ell*(ell+1))])
cbb=np.concatenate([[0,0],a[:,7]*1e12*2*np.pi/(ell*(ell+1))])
ell=np.concatenate([[0,1],ell])
spectra=[ell,ctt,cte,cee,cbb]
nside=128
map_orig=hp.synfast(spectra[4],nside,fwhm=0,pixwin=True)
input_map=map_orig.copy()
kmax = 2
Exemple #16
0
                                                         lowcut,
                                                         highcut,
                                                         nbins=nbins,
                                                         median=True,
                                                         method=method,
                                                         doplot=False,
                                                         rebin=False,
                                                         verbose=False)
                all_az_el_azang.append(
                    np.array(
                        [unbinned['az'], unbinned['el'], unbinned['az_ang']]))
                allsb.append(unbinned['sb'])
            sh0 = allsb[0].shape
            sh1 = allsb[1].shape
            mini = np.min([sh0[1], sh1[1]])
            sb = np.append(allsb[0][:, :mini], allsb[1][:, :mini], axis=0)
            az_el_azang = np.array(all_az_el_azang[0][:, :mini])
            print az_el_azang.shape
            print sb.shape
            FitsArray(sb).save(
                savedir +
                'alltes_unbinned_{}_{}.fits'.format(n, elevations[ii]))
            FitsArray(az_el_azang).save(
                savedir +
                'angles_unbinned_{}_{}.fits'.format(n, elevations[ii]))
        else:
            if filesalreadydone:
                print 'files already exist on disk and I was asked not to replace them so doing nothing'
            else:
                print 'This should not happen... There is a bug'
Exemple #17
0
keywords_t.update({'mask': True})
keywords_types = (keywords_q, keywords_f, keywords_m, keywords_t)
dtypes = (bool, int, np.float32, np.float64, np.complex64, np.complex128)


def teardown():
    for file in glob.glob(filename + '*'):
        os.remove(file)


a = np.ones((4, 3))
a[1, 2] = 4
q = Quantity(a, unit='myunit', derived_units={'myunit': Quantity(2., 'Jy')})
header = create_fitsheader(fromdata=q, cdelt=0.5, crval=(4., 8.))
header['BUNIT'] = 'myunit'
f = FitsArray(q, header=header)
m = Map(f, origin='upper', error=a * 2, coverage=a * 3)
mask = np.zeros((4, 3), np.bool8)
mask[0, 2] = True
t = Tod(f, mask=mask)
del mask


def test_copy_false_subok_true():
    def func(obj1, t):
        obj2 = t(obj1, copy=False, subok=True)
        if isinstance(obj, t):
            assert obj1 is obj2
        else:
            assert obj1 is not obj2
            assert_equal(obj1, obj2)
Exemple #18
0
# Check that we do one simulation with only one reconstructed subband
if d['nf_recon'][0] != 1:
    raise ValueError('You should do one simulation without spectroimaging as a reference.')

# Save the dictionary
shutil.copyfile(dictfilename, out_dir + name + '.dict')

# ==========================================

t0 = time.time()

# ===== Sky Creation or Reading =====

# x0 = FitsArray(dictmaps + 'nf_sub={}/nside{}_nfsub{}.fits'.format(nf_sub, d['nside'], nf_sub))

x0 = FitsArray(dictmaps + 'Dust_d1_nside128_nfsub15.fits')
print('Input Map with shape:', np.shape(x0))

if x0.shape[1] % (12 * d['nside'] ** 2) == 0:
    print('Good size')
else:
    y0 = np.ones((d['nf_sub'], 12 * d['nside'] ** 2, 3))
    for i in range(d['nf_sub']):
        for j in range(3):
            y0[i, :, j] = hp.ud_grade(x0[i, :, j], d['nside'])

# Put I = 0
# x0[:, :, 0] = 0.

# Multiply Q, U maps
#x0[:, :, 1] *= multFactor
Exemple #19
0
from qubic import SpectroImLib as si
from qubicpack.utilities import Qubic_DataDir

from pysimulators import FitsArray

# Get a dictionary
dictfilename = os.environ['QUBIC_DICT']+'spectroimaging.dict'

d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)

nf_sub = [15,]#[2, 4, 5, 10, 12, 14, 15, 16, 18, 20, 22, 24]
dirc = './'

os.makedirs(dirc, exist_ok=True)

for nf in nf_sub:
    print(nf)
    d['nf_sub'] = nf
    sky_config = {'dust': models('d1', d['nside']), 'cmb': models('c1', d['nside'])}
    # sky_config = {'cmb': models('c1', d['nside'])}

    Qubic_sky = si.Qubic_sky(sky_config, d)
    x0 = Qubic_sky.get_simple_sky_map()
    dirc2 = dirc
    try:
        os.makedirs(dirc2)
    except:
        pass
    FitsArray(x0).save(dirc2 + 'CMB_nside{}_nfsub{}.fits'.format(d['nside'], nf))
Exemple #20
0
        pow_maynooth[i] = 1000 * power1[pixnums[i] -
                                        1] + 1000 * power2[pixnums[i] - 1]

img_maynooth = ft.image_asics(pow_maynooth, all1=True)
clf()
imshow(img_maynooth)
colorbar()

allfib = [2, 3, 4]
allcal = np.zeros(len(allfib))
allerrcal = np.zeros(len(allfib))
allnewok = []
for i in range(len(allfib)):
    fib = allfib[i]
    free = 'free13'
    allok = np.array(FitsArray('listok_fib{}_{}.fits'.format(
        fib, free))).astype(bool)
    allparams = np.array(FitsArray('params_fib{}_{}.fits'.format(fib, free)))
    allerr = np.array(FitsArray('err_fib{}_{}.fits'.format(fib, free)))
    allok = allok * np.isfinite(np.sum(allparams, axis=1)) * np.isfinite(
        np.sum(allerr, axis=1))

    cal, errcal, newok = ft.calibrate(fib,
                                      pow_maynooth,
                                      allparams,
                                      allerr,
                                      allok,
                                      cutparam=0.4,
                                      cuterr=0.03,
                                      bootstrap=10000)
    savefig('Calibration-Fib{}_new250119.png'.format(fib))
Exemple #21
0
delta_ell = int(sys.argv[8])
covcut = float(sys.argv[9])
is_spatial_corr = int(sys.argv[10])

### Initialize
global_dir = Qubic_DataDir(datafile='instrument.py',
                           datadir=os.environ['QUBIC_DATADIR'])
dictfilename = global_dir + '/dicts/BmodesNoDustNoSystPaper0_2020.dict'
# Read dictionary chosen
d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)
d['nside'] = 256
center = qubic.equ2gal(d['RA_center'], d['DEC_center'])

### Open Coverage File
cov = np.array(FitsArray(cov_file))

### Open Noise Profile
fit_n200k = pickle.load(open(file_noise_profile, "rb"))

### Open Cl for spatially  correlated noise
if is_spatial_corr == 0:
    print('No Spatial Correlations')
    clth = None
else:
    print('Spatial correlations from ' + clnoise_file)
    clth = pickle.load(open(clnoise_file, "rb"))
    alpha = 4.5  ### See notebook called "2pt-Correlation Function" for an empirical explanation of alpha
    clth = (clth - 1) * alpha + 1

print('Spatial correlations:')
Exemple #22
0
cutval = 2500

allimg = np.zeros((len(as1), 17, 17)) + np.nan
for i in range(len(as1)):
    allimg[i, :, :] = ft.image_asics(all1=amps[:, i])
    bad = allimg[i, :, :] > cutval
    allimg[i, :, :][bad] = np.nan
    clf()
    imshow(allimg[i, :, :], vmin=0, vmax=1000, cmap='viridis')
    colorbar()
    title('$\Delta$az={}'.format(az[i]))
    show()
    savefig('imgscan01022019_az_{}.png'.format(1100 + az[i]))
    #raw_input('Press a key')

FitsArray(allimg).save('allimg_scan_az.fits')
FitsArray(az).save('az_scan_az.fits')

thepix = 93
clf()
plot(az, amps[thepix, :])

#### Trying intercalibration from old fiber data
#### (probably worthless as at the time they were superconducting and now they are not)

calibration = FitsArray('/Users/hamilton/CMB/Qubic/Fibres/calibration.fits')
calibration_restrict = FitsArray(
    '/Users/hamilton/CMB/Qubic/Fibres/calibration_restrict.fits')

cutval = 200
Exemple #23
0
for nf_sub_rec in np.arange(noutmin, noutmax + 1):
    print('-------------------------- Map-Making on {} sub-map(s)'.format(
        nf_sub_rec))
    maps_recon, cov, nus, nus_edge, maps_convolved = si.reconstruct_maps(
        TOD, d, p, nf_sub_rec, x0=x0)
    if nf_sub_rec == 1:
        maps_recon = np.reshape(maps_recon, np.shape(maps_convolved))
    cov = np.sum(cov, axis=0)
    maxcov = np.max(cov)
    unseen = cov < maxcov * 0.1
    #diffmap = maps_convolved - maps_recon
    maps_convolved[:, unseen, :] = hp.UNSEEN
    maps_recon[:, unseen, :] = hp.UNSEEN
    #diffmap[:,unseen,:] = hp.UNSEEN
    #therms = np.std(diffmap[:,~unseen,:], axis = 1)

    print('************************** Map-Making on {} sub-map(s)Done'.format(
        nf_sub_rec))

    FitsArray(nus).save(name + '_nf{0}'.format(nf_sub_rec) + '_nus.fits')
    FitsArray(nus_edge).save(name + '_nf{0}'.format(nf_sub_rec) +
                             '_nus_edges.fits')
    FitsArray(maps_convolved).save(name + '_nf{0}'.format(nf_sub_rec) +
                                   '_maps_convolved.fits')
    FitsArray(maps_recon).save(name + '_nf{0}'.format(nf_sub_rec) +
                               '_maps_recon.fits')

    t1 = time.time()
    print('************************** All Done in {} minutes'.format(
        (t1 - t0) / 60))
Exemple #24
0
    cov = np.sum(cov, axis=0)
    maxcov = np.max(cov)
    unseen = cov < maxcov * 0.1
    #diffmap = maps_convolved - maps_recon
    maps_convolved[:, unseen, :] = hp.UNSEEN
    maps_recon[:, unseen, :] = hp.UNSEEN
    #diffmap[:,unseen,:] = hp.UNSEEN
    #therms = np.std(diffmap[:,~unseen,:], axis = 1)

    print('************************** Map-Making on {} sub-map(s)Done'.format(
        nf_sub_rec))

    #FitsArray(nus_edge).save(name + '_nf{0}_ptg{1}'.format(nf_sub_rec, ptg) + '_nus_edges.fits')
    #FitsArray(nus).save(name + '_nf{0}_ptg{1}'.format(nf_sub_rec, ptg)+ '_nus.fits')
    FitsArray(maps_convolved).save(rep_out + name +
                                   '_nf{}'.format(nf_sub_rec) +
                                   '_maps_convolved.fits')
    FitsArray(maps_recon).save(rep_out + name + '_nf{}'.format(nf_sub_rec) +
                               '_maps_recon.fits')

    t1 = time.time()
    print('************************** All Done in {} minutes'.format(
        (t1 - t0) / 60))

##### SIMU fix_hwp
# p = qubic.get_pointing(d)
# #I = np.array([0,2,4,6])
# pi_fraction = 6
# I = np.arange(pi_fraction/2)
# ptg_start = 500
# for simu in xrange(len(I)):
Exemple #25
0
def GenerateMaps(d, nus_in, reso = 1.5, size=200, p=None, writemap = False, readmap = False ):

	"""
	Compute input maps to use in: calibration (for both methods Fit and Sigma) & QUBIC pipeline. 
	Number of maps == len(nus_in)
	Input:
		d: QUBIC dictionary
		nus_in: frequencies where compute the point source map

	Return:
		input_maps: partition of the sky where the point source is.
		m0: point source (already integrated over pixels) [RING ordered]

	"""

	if p:
		if p.fix_az:
			center = (d['fix_azimuth']['az'],d['fix_azimuth']['el'])
		elif not p.fix_az:
			center = qubic.equ2gal(d['RA_center'], d['DEC_center'])
	else:
		center = qubic.equ2gal(d['RA_center'], d['DEC_center'])
	nsideLow, nsideHigh, _, _, sigma2fwhm = Parameters(d) 
	#center_gal = qubic.equ2gal(d['RA_center'], d['DEC_center'])
	pixel = hp.pixelfunc.ang2pix(nsideHigh, np.deg2rad(90-center[1]), np.deg2rad(center[0]), nest = True)
	vec_pix = hp.pix2vec(nsideHigh, pixel, nest = True)
	vec_pixeles = hp.pix2vec(nsideHigh, np.arange(12*nsideHigh**2), nest = True )
	ang_pixeles = np.arccos(np.dot(vec_pix,vec_pixeles))
	
	if d['config'] == 'FI':
		CteConfig = 61.347409
	elif d['config'] == 'TD':
		CteConfig = 153.36
	#mask
	print(nus_in)
	if not readmap:
		mask = np.rad2deg(ang_pixeles) < d['dtheta']
		# Generate Gaussian maps - model of point source with FWHM (or Sigma) given by nus_in
		c0 = np.zeros((len(nus_in),12*nsideHigh**2,3))
		noise = np.zeros((len(nus_in), 12*nsideHigh**2,1))
		
		T = d['temperature']
		amplitude = 1e22
		
		for i, n_i in enumerate(nus_in):
			print('Map {}'.format(i))
			fwhm_in = CteConfig/n_i # nus to fwhm
			for j,each in enumerate(ang_pixeles):
				if mask[j] == True:
					c0[i,j,0] = amplitude*f(each, fwhm_in, sigma2fwhm)
		c0[:,:,1] = c0[:,:,0]
		c0[:,:,2] = c0[:,:,0]
		m0 = np.empty((len(nus_in),12*nsideLow**2,3))
		m0[:,:,0] = hp.ud_grade(c0[:,:,0], nsideLow, order_in = 'NESTED', order_out = 'RING')
		
		input_maps = np.empty((len(nus_in),size,size))
		for i, mapa in enumerate(m0):
			input_maps[i] = hp.gnomview(mapa[:,0], rot = center,  
		                            reso = reso, xsize = size,
		                            return_projected_map=True)
		mp.close('all')

		if writemap: FitsArray(m0).save('point-source-map-TD-150GHz.fits')
		
		return input_maps, m0
	
	elif readmap:
		m0 = FitsArray('point-source-map-TD-150GHz.fits')
		input_maps = np.empty((len(nus_in),size,size))
		for i, mapa in enumerate(m0):
			input_maps[i] = hp.gnomview(mapa[:,0], rot = center,  
		                            reso = reso, xsize = size,
		                            return_projected_map=True)
		mp.close('all')

		return input_maps, m0
Exemple #26
0
# Look at the coverage of the sky
coverage = np.sum(cov.copy(), axis=0)
maxcov = np.max(coverage)
unseen = coverage < maxcov * 0.1
print(maps_convolved.shape)
maps_convolved[:, unseen, :] = hp.UNSEEN
maps_recon[:, unseen, :] = hp.UNSEEN

# Wait for everyone to finish
MPI.COMM_WORLD.Barrier()

#### Save maps
if rank == 0:
    rnd_name = qss.random_string(10)
    directory = '/global/homes/h/hamilton/qubic/jc/EndToEndMaps/'
    FitsArray(maps_recon).save(directory + namesim + '_maps_recon_seed_' +
                               str(seed) + '_' + rnd_name + '.fits')
    FitsArray(maps_convolved).save(directory + namesim +
                                   '_maps_convolved_seed_' + str(seed) + '_' +
                                   rnd_name + '.fits')
    FitsArray(coverage).save(directory + namesim + '_maps_coverage_' +
                             rnd_name + '.fits')

    with open(directory + namesim + '_dictionary_' + rnd_name + '.pickle',
              'wb') as handle:
        pickle.dump(d, handle, protocol=2)

    with open(directory + namesim + '_input_cell_' + rnd_name + '.pickle',
              'wb') as handle:
        pickle.dump(Qubic_sky.input_cmb_spectra, handle, protocol=2)

        print(
def test_detector_indexing():
    expected = FitsArray('test/data/detector_indexing.fits')
    assert_same(q.detector.index, expected)
Exemple #28
0
def get_data_Mrefsyst(detnums,
                      filemaps,
                      az,
                      el,
                      fitted_directory,
                      fittedpeakfile,
                      proj_name,
                      resample=None,
                      newsize=None,
                      azmin=None,
                      azmax=None,
                      remove=None,
                      sbfitmodel=None,
                      refit=False,
                      verbose=False):
    """
	Compute theta, phi for all TES in the measured reference system
	"""

    thecos = np.cos(np.radians(np.mean(el)))
    if refit:
        if verbose: print('We refit the peak locations')
        ### We call the fitting function for the Synthesized beam
        xypeaks = []
        for i in range(len(detnums)):
            if fitted_directory is None:

                if sbfitmodel is None:
                    sbfitmodel = sbfit.SbModelIndepPeaks(nrings=2,
                                                         common_fwhm=True,
                                                         no_xy_shift=False,
                                                         distortion=False)
                if verbose:
                    print('Using Fit Model {} for TES #{}'.format(
                        sbfitmodel.name, detnums[i]))

                figure()
                fit, thexypeaks = sbfit.fit_sb(filemaps,
                                               az,
                                               el,
                                               sbfitmodel,
                                               resample=resample,
                                               newsize=newsize,
                                               verbose=verbose,
                                               doplot=True,
                                               extra_title='TES #{}'.format(
                                                   detnums[i]))
                print('FITING')
                show()
            else:
                filemaps, az, el, fitmap, thexypeaks = sbfit.get_flatmap(
                    detnums[i],
                    directory,
                    azmin=azmin,
                    azmax=azmax,
                    remove=remove,
                    fitted_directory=fitted_directory)
            xypeaks.append(thexypeaks)

        ### Convert to measurement coordinate system
        xypeaks = np.array(xypeaks)
        allthetas_M = np.radians(90 - (xypeaks[:, 1, :] - elcen_fov))
        allphis_M = np.radians(-xypeaks[:, 0, :])  #*thecos)
        allvals_M = xypeaks[:, 2, :]
    else:
        if verbose:
            print('No refitting of the peak locations')
            print("[FitFiles]: Reading {} file".format(fittedpeakfile))
        ### We just read them from the old peak file
        peaks = np.array(FitsArray(fittedpeakfile))
        #Thph indexes
        if proj_name == "flat":
            thphidx = [0, 1]
            peaks[:, 1, :] = peaks[:, 1, :] / thecos
        elif proj_name == "healpix":
            thphidx = [0, 1]
            peaks[:, 1, :] = peaks[:, 1, :]
        ### An put them in the expected format. Save TES of interest
        mypeaks = peaks[np.array(detnums) - 1, :, :]
        #Peaks in degrees
        allphis_M = mypeaks[:, 1, :]
        allthetas_M = mypeaks[:, 0, :]
        allvals_M = mypeaks[:, 2, :]
    return allphis_M, allthetas_M, allvals_M
Exemple #29
0
    grounding.append(bla[-2])
    motor.append(bla[-1])


a1 = qp()
a1.read_qubicstudio_dataset(dirs[0], asic=1)
a2 = qp()
a2.read_qubicstudio_dataset(dirs[0], asic=2)

nsamples = len(a1.timeline(TES=66))
FREQ_SAMPLING = 1./a1.sample_period()
spectrum, freq = mlab.psd(2
a1.timeline(TES=66), Fs=FREQ_SAMPLING, NFFT=nsamples, window=mlab.window_hanning)


ok1 = np.array(FitsArray('/Users/hamilton/Qubic/ExternalSource/ScanAz2019-01-30_OK_Asic1.fits'), dtype=bool)
ok2 = np.array(FitsArray('/Users/hamilton/Qubic/ExternalSource/ScanAz2019-01-30_OK_Asic2.fits'), dtype=bool)
ok = np.append(ok1,ok2)


clf()
plot(freq, spectrum)
xscale('log')
yscale('log')

allspecs = []
allfreqs = []
medspec = []
for i in range(len(dirs)):
    a1 = qp()
    a1.read_qubicstudio_dataset(dirs[i], asic=1)
Exemple #30
0
           interpolation='nearest')

    # imshow(img / img_ref, cmap='viridis', vmin=0, vmax=3, interpolation='nearest')
    # imshow(img / np.nanmean(img), cmap='viridis', vmin=0, vmax=3, interpolation='nearest')
    colorbar()
    # if pos == 0:
    #     title('Int Sphere Ref 2019-02-14')
    # else:
    title('Int Sphere 2019-02-15 pos{}'.format(pos + 1))

# savefig(basedir + 'int_sphere_pos1-4_divided_ref')

# Try intercalibration
intercal = img / img[16, 0]

allimg = np.array(FitsArray('allimg_scan_az.fits'))
az = np.array(FitsArray('az_scan_az.fits'))

for i in range(len(az)):
    clf()
    subplot(1, 2, 1)
    imshow(allimg[i, :, :], cmap='viridis', vmin=0, vmax=1000)
    title(az[i])
    subplot(1, 2, 2)
    imshow(allimg[i, :, :] / intercal, cmap='viridis', vmin=0, vmax=1000)
    title('Intercalibrated')
    show()
    savefig('scan_az_int_sphere_{}.png'.format(1100 + az[i]))
    # raw_input('press a key')

pixnums = [2, 96, 67, 58 + 128]