Ejemplo n.º 1
0
def simple_baseline_plotter(TDhornsFIconf, tdpair1, tdpair2, centers):
    """elaborate baseline comparison plot
    requires you have qubic inst loaded e.g.
    instFI = qubic.QubicInstrument(d)
    hornsFI = instFI.horn.open
    hornsTD = (col >= 8) & (col <= 15) & (row >= 8) & (row <= 15)
    ### Now create First Instrument and TD monochromatic
    instTD = qubic.QubicInstrument(d)
    instTD.horn.open[~hornsTD] = False"""
    import qubic
    d = qubic.qubicdict.qubicDict()
    d.read_from_file(
        '/home/james/libraries/qubic/qubic/dicts/pipeline_demo.dict')
    d['config'] = 'FI'
    q = qubic.QubicInstrument(d)
    centers = q.horn.center[:, 0:2]
    col = q.horn.column
    row = q.horn.row
    instFI = qubic.QubicInstrument(d)
    hornsFI = instFI.horn.open
    hornsTD = (col >= 8) & (col <= 15) & (row >= 8) & (row <= 15)
    instTD = qubic.QubicInstrument(d)
    instTD.horn.open[~hornsTD] = False

    plt.figure(figsize=(14, 14))

    instTD.horn.plot()
    plt.plot(centers[np.where(TDhornsFIconf == tdpair1[0]), 0],
             centers[np.where(TDhornsFIconf == tdpair1[0]), 1],
             'o',
             color='xkcd:burnt orange',
             markersize=7,
             mfc=None)
    plt.plot(centers[np.where(TDhornsFIconf == tdpair1[1]), 0],
             centers[np.where(TDhornsFIconf == tdpair1[1]), 1],
             'o',
             color='xkcd:burnt orange',
             markersize=7,
             alpha=1,
             mfc=None)
    plt.plot(centers[np.where(TDhornsFIconf == tdpair2[0]), 0],
             centers[np.where(TDhornsFIconf == tdpair2[0]), 1],
             'o',
             color='xkcd:sea green',
             markersize=7,
             alpha=1,
             mfc=None)
    plt.plot(centers[np.where(TDhornsFIconf == tdpair2[1]), 0],
             centers[np.where(TDhornsFIconf == tdpair2[1]), 1],
             'o',
             color='xkcd:sea green',
             markersize=7,
             alpha=1,
             mfc=None)
    plt.title('Horn Array')
    plt.xlabel('Horn Array X (m)')
    plt.ylabel('Horn Array Y (m)')
    plt.axis('equal')

    plt.tight_layout()
Ejemplo n.º 2
0
def create_acquisition_operator_REC(pointing,
                                    d,
                                    nf_sub_rec,
                                    verbose=False,
                                    instrument=None):
    # scene
    s = qubic.QubicScene(d)
    if d['nf_sub'] == 1:
        if verbose:
            print('Making a QubicInstrument.')
        q = qubic.QubicInstrument(d)
        # one subfreq for recons
        _, nus_edge, _, _, _, _ = qubic.compute_freq(
            d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth'])
        arec = qubic.QubicAcquisition(q, pointing, s, d)

        return arec
    else:
        if instrument is None:
            if verbose:
                print('Making a QubicMultibandInstrument.')
            q = qubic.QubicMultibandInstrument(d)
        else:
            q = instrument
        # number of sub frequencies for reconstruction
        _, nus_edge, _, _, _, _ = qubic.compute_freq(
            d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth'])
        # Operator for Maps Reconstruction
        arec = qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge)
        return arec
Ejemplo n.º 3
0
def create_acquisition_operator_TOD(pointing, d):
    # scene
    s = qubic.QubicScene(d)
    if d['nf_sub'] == 1:
        q = qubic.QubicInstrument(d)
        return qubic.QubicAcquisition(q, pointing, s, d)
    else:
        # Polychromatic instrument model
        q = qubic.QubicMultibandInstrument(d)
        # number of sub frequencies to build the TOD
        _, nus_edge_in, _, _, _, _ = qubic.compute_freq(
            d['filter_nu'] / 1e9, d['nf_sub'], d['filter_relative_bandwidth'])

        return qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge_in)
Ejemplo n.º 4
0
def create_acquisition_operator_TOD(pointing, d, verbose=False):
    # scene
    s = qubic.QubicScene(d)
    if d['nf_sub'] == 1:
        if verbose:
            print('Making a QubicInstrument.')
        q = qubic.QubicInstrument(d)
        return qubic.QubicAcquisition(q, pointing, s, d)
    else:
        # Polychromatic instrument model
        if verbose:
            print('Making a QubicMultibandInstrument.')
        q = qubic.QubicMultibandInstrument(d)
        # number of sub frequencies to build the TOD
        _, nus_edge_in, _, _, _, _ = qubic.compute_freq(
            d['filter_nu'] / 1e9,
            d['nf_sub'],  # Multiband instrument model
            d['filter_relative_bandwidth'])
        # Multi-band acquisition model for TOD fabrication
        return qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge_in)
Ejemplo n.º 5
0
a = qubic.QubicMultibandAcquisition(q, p, s, d, nus_edge_in)

TOD = a.get_observation(x0, noiseless=True, convolution=False)

plt.plot(TOD[0, :])
plt.xlabel('pointing index')
plt.ylabel('TOD')
plt.show()

# Map making
if alaImager:
    nf_sub_rec = 1
    d['synthbeam_kmax'] = 0
    if oneComponent:
        d['kind'] = 'I'
    q = qubic.QubicInstrument(d)
    if sel_det:
        make_detector_subset_instrument(q, dets_FPindex, multiband=False)
    arec = qubic.QubicAcquisition(q, p, s, d)
else:
    nf_sub_rec = 2
    Nbfreq, nus_edge, nus, deltas, Delta, Nbbands = qubic.compute_freq(d['filter_nu'] / 1e9,
                                                                       nf_sub_rec,
                                                                       d['filter_relative_bandwidth'])

    arec = qubic.QubicMultibandAcquisition(q, p, s, d, nus_edge)

maps_recon, nit, error = arec.tod2map(TOD, d, cov=None)
print(maps_recon.shape)

# In the imager case, we reshape maps in order to avoid dimension problems...
Ejemplo n.º 6
0
    def get_power_fp_aberration(self,
                                rep,
                                doplot=True,
                                theta_source=0.,
                                freq_source=150.,
                                indep_config=None):
        """
        Compute power on the focal plane for a given horn configuration taking
        into account optical aberrations given in Creidhe simulations.

        Parameters
        ----------
        rep : str
            Path of the repository for the simulated files, can be download at :
            https://drive.google.com/open?id=19dPHw_CeuFZ068b-VRT7N-LWzOL1fmfG
        doplot : bool
            If True, make a plot with the intensity in the focal plane.
        theta_source : float
            Angle in degree between the optical axis of Qubic and the source.
        freq_source : float
            Frequency of the source in GHz
        indep_config : list of int
            By default it is None and in this case, it will use the baseline
            defined in your object on which you call the method.
            If you want an other configuration (all open for example), you can
            put here a list with the horns you want to open.

        Returns
        -------
        power : array of shape (nn, nn)
            Power in the focal plane at high resolution (sampling used in simulations).

        """
        if self.d['config'] != 'TD':
            raise ValueError('The instrument in the dictionary must be the TD')

        q = qubic.QubicInstrument(self.d)

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

        nhorns = len(files)
        if nhorns != 64:
            raise ValueError('You should have 64 .dat files')

        # Get the sample number from the first file
        data0 = pd.read_csv(files[0], sep='\t', skiprows=0)
        nn = data0['X_Index'].iloc[-1] + 1
        print('Sampling number = {}'.format(nn))

        # Get all amplitudes and phases for each open horn
        if indep_config is None:
            open_horns = self.baseline
            nopen_horns = len(self.baseline)
        else:
            open_horns = indep_config
            nopen_horns = len(indep_config)

        q.horn.open = False
        q.horn.open[np.asarray(open_horns) - 1] = True

        allampX = np.empty((nopen_horns, nn, nn))
        allphiX = np.empty((nopen_horns, nn, nn))
        allampY = np.empty((nopen_horns, nn, nn))
        allphiY = np.empty((nopen_horns, nn, nn))
        for i, swi in enumerate(open_horns):
            if swi < 1 or swi > 64:
                raise ValueError(
                    'The switch indices must be between 1 and 64 ')

            # Phase calculation
            # Not sure it is a good idea to do that...
            horn_x = q.horn.center[swi - 1, 0]
            horn_y = q.horn.center[swi - 1, 1]
            d = np.sqrt(horn_x**2 +
                        horn_y**2)  # distance between the horn and the center
            phi = -2 * np.pi / 3e8 * freq_source * 1e9 * d * np.sin(
                np.deg2rad(theta_source))

            data = pd.read_csv(files[swi - 1], sep='\t', skiprows=0)
            allampX[i, :, :] = np.reshape(np.asarray(data['MagX']), (nn, nn))
            allampY[i, :, :] = np.reshape(np.asarray(data['MagY']), (nn, nn))

            allphiX[i, :, :] = np.reshape(np.asarray(data['PhaseX']),
                                          (nn, nn)) + phi
            allphiY[i, :, :] = np.reshape(np.asarray(data['PhaseY']),
                                          (nn, nn)) + phi

        # Electric field for each open horn
        Ax = allampX * (np.cos(allphiX) + 1j * np.sin(allphiX))
        Ay = allampY * (np.cos(allphiY) + 1j * np.sin(allphiY))

        # Sum of the electric fields
        sumampx = np.sum(Ax, axis=0)
        sumampy = np.sum(Ay, axis=0)

        # Intensity in the focal plane with high resolution
        # and with the focal plane resolution
        power = np.abs(sumampx)**2 + np.abs(sumampy)**2
        power = power.T  # this transpose was in the Creidhe code

        if doplot:
            plt.figure()
            plt.subplot(121)
            q.horn.plot()
            plt.axis('off')

            plt.subplot(122)
            plt.imshow(power, origin='lower')
            plt.title('Power at the sampling resolution')
            plt.colorbar()

        return power
Ejemplo n.º 7
0
    def get_power_fp_aberration(self, rep, doplot=True, indep_config=None):
        """
        Compute power on the focal plane for a given horn configuration taking
        into account optical aberrations given by Maynooth simulations. The source
        is on the optical axis emitting at 150GHz.

        Parameters
        ----------
        rep : str
            Path of the repository for the simulated files, can be download at :
            https://drive.google.com/open?id=19dPHw_CeuFZ068b-VRT7N-LWzOL1fmfG
        doplot : bool
            If True, make a plot with the intensity in the focal plane.
        indep_config : list of int
            By default it is None and in this case, it will use the baseline
            defined in your object on which you call the method.
            If you want an other configuration (all open for example), you can
            put here a list with the horns you want to open.

        Returns
        -------
        power : array of shape (nn, nn)
            Power on the focal plane at high resolution (sampling used in simulations).

        """
        if self.d['config'] != 'TD':
            raise ValueError('The instrument in the dictionary must be the TD')

        q = qubic.QubicInstrument(self.d)

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

        nhorns = len(files)
        if nhorns != 64:
            raise ValueError('You should have 64 .dat files')

        # This is done to get the right file for each horn
        horn_transpose = np.arange(64)
        horn_transpose = np.reshape(horn_transpose, (8, 8))
        horn_transpose = np.ravel(horn_transpose.T)

        # Get the sample number from the first file
        data0 = pd.read_csv(files[0], sep='\t', skiprows=0)
        nn = data0['X_Index'].iloc[-1] + 1
        print('Sampling number = {}'.format(nn))

        # Get all amplitudes and phases for each open horn
        if indep_config is None:
            open_horns = self.baseline
            nopen_horns = len(self.baseline)
        else:
            open_horns = indep_config
            nopen_horns = len(indep_config)

        q.horn.open = False
        q.horn.open[np.asarray(open_horns) - 1] = True

        allampX = np.empty((nopen_horns, nn, nn))
        allphiX = np.empty((nopen_horns, nn, nn))
        allampY = np.empty((nopen_horns, nn, nn))
        allphiY = np.empty((nopen_horns, nn, nn))
        for i, swi in enumerate(open_horns):
            if swi < 1 or swi > 64:
                raise ValueError(
                    'The switch indices must be between 1 and 64 ')

            thefile = files[horn_transpose[swi - 1]]
            # print('Horn ', swi, ': ', thefile[98:104])
            data = pd.read_csv(thefile, sep='\t', skiprows=0)

            allampX[i, :, :] = np.reshape(np.asarray(data['MagX']), (nn, nn)).T
            allampY[i, :, :] = np.reshape(np.asarray(data['MagY']), (nn, nn)).T

            allphiX[i, :, :] = np.reshape(np.asarray(data['PhaseX']),
                                          (nn, nn)).T
            allphiY[i, :, :] = np.reshape(np.asarray(data['PhaseY']),
                                          (nn, nn)).T

        # Electric field for each open horn
        Ax = allampX * (np.cos(allphiX) + 1j * np.sin(allphiX))
        Ay = allampY * (np.cos(allphiY) + 1j * np.sin(allphiY))

        # Sum of the electric fields
        sumampx = np.sum(Ax, axis=0)
        sumampy = np.sum(Ay, axis=0)

        # Power on the focal plane
        power = np.abs(sumampx)**2 + np.abs(sumampy)**2

        if doplot:
            plt.figure()
            plt.subplot(121)
            q.horn.plot()
            plt.axis('off')

            plt.subplot(122)
            plt.imshow(power, origin='lower')
            plt.title('Power at the sampling resolution')
            plt.colorbar()

        return power