Esempio n. 1
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
Esempio n. 2
0
    def get_dead_detectors_mask(self, quadrant=3):
        """
        Build masks for the FP where bad detectors are NAN and good detectors are 1., one of shape (34x34)
        and one of shape (17x17) for one quadrant.
        We use the ONAFP frame.

        Parameters
        ----------
        quadrant : int
            Quadrant of the focal plane in [1, 2, 3, 4]
            By default is 3 for the TD

        Returns
        -------
        full_mask : array of shape (34x34)
            mask for the full FP.
        quart_mask = array of shape (17x17)
            mask for one quadrant

        """
        FPidentity = make_id_focalplane()
        quad = np.rot90(np.reshape(FPidentity.quadrant, (34, 34)),
                        k=-1,
                        axes=(0, 1))

        calfile_path = Qubic_DataDir(datafile=self.d['detarray'])
        calfile = fits.open(calfile_path + '/' + self.d['detarray'])

        if self.d['detarray'] == 'CalQubic_DetArray_P87_TD.fits':
            full_mask = np.rot90(calfile['removed'].data, k=-1, axes=(0, 1))
            full_mask = np.where(full_mask == 1, np.nan, full_mask)
            full_mask = np.where(full_mask == 0, 1, full_mask)

            quart = full_mask[np.where(quad != quadrant, 6, full_mask) != 6]
            quart_mask = np.reshape(quart, (17, 17))

            return full_mask, quart_mask

        else:
            print('There is no dead detectors in this calfile')
Esempio n. 3
0
                 label='End-To-End Sub {}'.format(i + 1),
                 color=p[0].get_color())
        plt.axhline(y=1, color='k', ls=':')
        plt.xlabel(r'$\ell$')
        plt.ylabel(r'$C_\ell$')

    if dirsave is None:
        plt.show()
    else:
        plt.savefig(dirsave + f'Ctheta_{nfsub}bands_' + config + '.pdf',
                    format='pdf')
        plt.close()
    return allresults, allcth, allclth, lll, clth


global_dir = Qubic_DataDir(datafile='instrument.py',
                           datadir=os.environ['QUBIC_DATADIR'])
# Repository with full pipeline simulations
datadir = os.environ['DATA_SPECTROIM'] + 'Data_for_FastSimulator/'

# Repository where plots will be saved
dirsave = os.environ['DATA_SPECTROIM'] + 'Data_for_FastSimulator/plots/'

all_nf = [1, 2, 3, 4, 5, 8]
center = np.array([0, 0])
nptg = 10000
config = sys.argv[1]  # TD150 or FI150 or FI220
nbins = 50

for nfsub in all_nf:
    print(f'\n STARTING nfsub = {nfsub}')
    residuals, coverage, seenmap = get_maps_from_louise(datadir, nfsub, config)
Esempio n. 4
0
def rms_method(name, residuals_way, zones=1):
    """
    Get the std of the residuals from one simulation. 
    STD are computed over realisations and pixels for I, Q, U separately.

    Parameters
    ----------
    name : str
        Simulation file.
    residuals_way : str
        Way to compute residuals. 3 keywords : noiseless, conv or mean_recon
    zones : int
        Number of zones to divide the patch.

    Returns
    -------
    rms_I, rms_Q, rms_U : dictionarys containing RMS for IQU 
    setpar : a dict with some parameters of the simu.
    """
    # Get the repository where the simulation is
    rep_simu = Qubic_DataDir(datafile=name + '.dict') + '/'
    # print('rep_simu : ', rep_simu)

    # Dictionary saved during the simulation
    d = qubic.qubicdict.qubicDict()
    d.read_from_file(rep_simu + name + '.dict')
    setpar = {'tol': d['tol'], 'nep': d['detector_nep'], 'npoint': d['npointings']}

    nf_recon = d['nf_recon']

    rms_I, rms_Q, rms_U = dict(), dict(), dict()

    for irec in nf_recon:
        residuals = get_residuals(name, rep_simu, residuals_way, irec)
        files, maps_recon_patch, maps_conv_patch, maps_diff_patch = \
            rmc.get_patch_many_files(rep_simu + name, '*nfrecon{}*False*'.format(irec), verbose=False)

        npix_patch = maps_diff_patch.shape[2]
        setpar.update({'pixpatch': npix_patch})
        #         print(setpar)

        nreals = np.shape(residuals)[0]

        # This if is for the number of zones (1 or more)
        if zones == 1:
            rms_i, rms_q, rms_u = np.empty((irec,)), np.empty((irec,)), np.empty((irec,))

            for i in range(irec):
                # STD over pixels and realisations
                rms_i[i] = np.std(residuals[:, i, :, 0])
                rms_q[i] = np.std(residuals[:, i, :, 1])
                rms_u[i] = np.std(residuals[:, i, :, 2])
        else:
            angle = False
            if zones == 2:
                angle = True

            center = qubic.equ2gal(d['RA_center'], d['DEC_center'])
            seenmap = rmc.get_seenmap(files[0])
            nside = d['nside']

            residuals_zones = np.empty((nreals, zones, irec, npix_patch, 3))
            for real in range(nreals):
                pix_zones, residuals_zones[real] = rmc.make_zones(residuals[real], zones, nside, center, seenmap,
                                                                  angle=angle, dtheta=d['dtheta'], verbose=False,
                                                                  doplot=False)

            rms_i, rms_q, rms_u = np.empty((zones, irec,)), np.empty((zones, irec,)), np.empty((zones, irec,))
            for izone in range(zones):
                for i in range(irec):
                    rms_i[izone, i] = np.std(residuals_zones[:, izone, i, :, 0])
                    rms_q[izone, i] = np.std(residuals_zones[:, izone, i, :, 1])
                    rms_u[izone, i] = np.std(residuals_zones[:, izone, i, :, 2])

        rms_I.update({str(irec): rms_i})
        rms_Q.update({str(irec): rms_q})
        rms_U.update({str(irec): rms_u})

    return rms_I, rms_Q, rms_U, setpar
Esempio n. 5
0
from qubic import AnalysisMC as amc

import qubic
from qubic import equ2gal

from qubicpack.utilities import Qubic_DataDir

stokes = ['I', 'Q', 'U']

# ================= Get the simulation files ================

# Simulation date and name
date_name = '20190813_QU10'

# Get the repository where the simulation is
rep_simu = Qubic_DataDir(datafile=date_name + '.dict') + '/'

# Dictionary saved during the simulation
d = qubic.qubicdict.qubicDict()
d.read_from_file(rep_simu + date_name + '.dict')

# Coordinates of the zone observed in the sky
center = equ2gal(d['RA_center'], d['DEC_center'])

# Number of subbands used during the simulation
nf_recon = d['nf_recon'][0]
nf_sub = d['nf_sub']
print('nf_sub = {}, nf_recon = {}'.format(nf_sub, nf_recon))

# Get fits files names in a list
fits_noise = np.sort(glob.glob(rep_simu + date_name + '*nfrecon{}_noiselessFalse*.fits'.format(nf_recon)))
Esempio n. 6
0
def MainProg(filepath, pklrep, tesdatrep):

    start = timeit.default_timer()
    repfile = filepath
    #strip Modal qb filename from filepath
    qbfilename = os.path.splitext(os.path.basename(repfile))[0]

    # Use a tool from qubicpack to get a path
    basedir = Qubic_DataDir(datafile='instrument.py', )
    print('basedir : ', basedir)
    dictfilename = basedir + '/dicts/global_source_oneDet.dict'
    d = qubic.qubicdict.qubicDict()
    #d.read_from_file('../qubic/qubic/dicts/global_source_oneDet.dict')
    #change to moddded dictionary
    d.read_from_file(
        '/home/james/libraries/qubic/qubic/dicts/global_source_oneDetFI.dict')
    q = qubic.QubicMultibandInstrument(d)

    vtxs = q[0].detector.vertex
    vtxcounter = np.zeros(992)
    print("vertexes shape: ", vtxs.shape)

    MagXarr, PhaXarr, ReXarr, ImXarr, MagYarr, PhaYarr, ReYarr, ImYarr, vtxcntarr, PixCenX, PixCenY = getXYcoords(
        filepath, vtxs)
    print('getxycoordfunctest', max(MagXarr), MagXarr.shape)

    vtxcounter = np.vstack((vtxcounter, vtxcntarr))
    vtxcounter = vtxcounter.T
    vtxcounter = vtxcounter[:, 1:3]

    #caluclate and return instensity values for given mag & phase PIXELS
    IntX, IntY, IntT = IntensityCalc(MagXarr, PhaXarr, MagYarr, PhaYarr)
    print('intensity tests shape max', IntX.shape, max(IntX))

    dat = np.vstack(
        (MagXarr, PhaXarr, ReXarr, ImXarr, MagYarr, PhaYarr, ReYarr, ImYarr,
         vtxcntarr, PixCenX, PixCenY, IntX, IntY, IntT))
    dat = dat.T

    #save the mag&pha data with the calculated intensity values PIXELS
    #chose whether to bother even saving the un-normed data if it just gets overwitten
    #dataIO(dat, tesdatrep, qbfilename)
    datmodstring = 'datmod'
    #dataAnalysis function normalises the data PIXELS
    datmod = dataAnalysis(dat)
    dataIO(datmod, tesdatrep, qbfilename)

    #load MODAL style data point data
    dataCF1 = np.loadtxt(repfile, skiprows=1)
    xycoords = np.array(dataCF1[:, 2:4])
    freq = dataCF1[0, 10]
    print('frequency', freq)

    #return intensity values for data points in the MODAL style
    Ix, Iy, IT = IntensityCalcRAW(repfile)
    ITnans = [(np.nan if x == 0 else x) for x in IT]
    ITnans = np.asarray(ITnans)

    #save in a folder as pickle files with all data accesible.
    SaveVars(MagXarr, PhaXarr, ReXarr, ImXarr, MagYarr, PhaYarr, ReYarr,
             ImYarr, vtxcntarr, PixCenX, PixCenY, IntX, IntY, IntT, Ix, Iy, IT,
             xycoords, qbfilename, freq, pklrep)

    os.system('spd-say "Main program has finished"')
    stop = timeit.default_timer()
    time = stop - start
    seconds = (time - int(time)) * 60
    print(time / 60, 'm', seconds, 's')
Esempio n. 7
0
                    xy[:, 1],
                    marker='s',
                    s=150,
                    c=fl_mean[peak],
                    vmin=0.2,
                    vmax=0.40)
        plt.xlim((-0.06, 0.))
        plt.ylim((-0.06, 0.))
        plt.colorbar()

    return final_mean, final_std


# =========== Radial TES distances on the FP ================
# Get a dictionary
basedir = Qubic_DataDir(datafile='instrument.py', )
print('basedir : ', basedir)
dictfilename = basedir + '/dicts/global_source_oneDet.dict'

d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)
print(d['detarray'])

d['config'] = 'FI'
q = qubic.QubicInstrument(d)

tes_xy, rdist = get_tes_xycoords_radial_dist(q)

# Remove thermometers
r = rdist[rdist != 0.]
x = tes_xy[:, 0]
Esempio n. 8
0
                                    param_guess,
                                    args=(t,
                                          stable_time,
                                          folded[tes - 1, :]),
                                    bounds=([0., -2, -2, -2, -2, -2, -2, -2],
                                            [1., 2, 2, 2, 2, 2, 2, 2]),
                                    verbose=1
                                    )
            param_est[TESindex, :] = fit.x
            res_fit[TESindex] = make_combination(param_est[TESindex, :])

    return t, folded_bothasics, param_est, res_w, res_fit


# =============== Fringe simulations =================
rep = Qubic_DataDir(datafile='detcentres.txt')
print('rep:', rep)

# Get simulation files
files = sorted(glob.glob(rep + '/*.dat'))

# Get a dictionary
basedir = Qubic_DataDir(datafile='instrument.py', )
print('basedir : ', basedir)
dictfilename = basedir + '/dicts/global_source_oneDet.dict'
d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)

# Make an instrument
q = qubic.QubicInstrument(d)
Esempio n. 9
0
from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt

from qubicpack.utilities import Qubic_DataDir

import qubic
# import qubic.fibtools as ft
# import qubic.sb_fitting as sbfit
import qubic.selfcal_lib as sc


# Use a tool from qubicpack to get a path
basedir = Qubic_DataDir(datafile='instrument.py', )
print('basedir : ', basedir)
dictfilename = basedir + '/dicts/global_source_oneDet.dict'

# Get a dictionary
d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)
print(d['detarray'])

# Create an object
baseline = [25, 57]
q = qubic.QubicInstrument(d)
ca = sc.SelfCalibration(baseline, d)

S, Cminus_i, Cminus_j, Sminus_ij, Ci, Cj, Sij = ca.get_power_combinations(q)

plt.figure()
Esempio n. 10
0
        tanalpha_cut = tanalpha[(focal_length > mini) & (focal_length < maxi)]
        print(tes_dist_cut.shape, tanalpha_cut.shape)

        allfl_clip.append(fl_clip)
        alltes_dist_cut.append(tes_dist_cut)
        alltanalpha_cut.append(tanalpha_cut)

    fl_mean = [np.mean(fl) for fl in allfl_clip]
    fl_std = [np.std(fl) / np.sqrt(len(fl)) for fl in allfl_clip]

    return allfl_clip, fl_mean, fl_std


# ================== Test with simulated beams from Qubic soft ==================
# Get a dictionary
basedir = Qubic_DataDir(datafile='instrument.py', )
print('basedir : ', basedir)
dictfilename = basedir + '/dicts/global_source_oneDet.dict'

d = qubic.qubicdict.qubicDict()
d.read_from_file(dictfilename)
print(d['detarray'])

d['config'] = 'TD'
d['nside'] = 512
d['synthbeam_kmax'] = 1
q = qubic.QubicInstrument(d)
s = qubic.QubicScene(d)

tes_xy = q.detector.center[:, :2]
rdist = np.sqrt(tes_xy[:, 0]**2 + tes_xy[:, 1]**2)