Esempio n. 1
0
 def func(d):
     x_ = np.array(x if d.kind == 'c' else x.real, dtype=d)
     actual = abs2(x_)
     expected = np.abs(x_**2)
     assert_same(actual, expected)
     abs2(x_, actual)
     assert_same(actual, expected)
Esempio n. 2
0
def psd2(array, sampling_frequency=1, fftw_flag='FFTW_MEASURE'):
    """
    Return two-dimensional PSD.

    Parameters
    ----------
    array : array-like
       Two-dimensional array.
    sampling_frequency : float
       The sampling frequency.
    fftw_flag : string
       The FFTW planner flag.

    Returns
    -------
    psd : ndarray
       The Power Spectrum Density, such as
           sum psd * bandwidth = mean(array**2)
       with bandwidth = sampling_frequency ** 2 / array.size is the PSD bin
       area.

    """
    array = np.asarray(array)
    if array.ndim != 2:
        raise ValueError('The input array is not two-dimensional.')
    s = abs2(FFTOperator(array.shape, fftw_flag=fftw_flag)(array))
    s /= array.size**2
    bandwidth = sampling_frequency**2 / array.size
    s /= bandwidth
    return Map(scipy.fftpack.fftshift(s))
Esempio n. 3
0
def psd2(array, sampling_frequency=1, fftw_flag='FFTW_MEASURE'):
    """
    Return two-dimensional PSD.

    Parameters
    ----------
    array : array-like
       Two-dimensional array.
    sampling_frequency : float
       The sampling frequency.
    fftw_flag : string
       The FFTW planner flag.

    Returns
    -------
    psd : ndarray
       The Power Spectrum Density, such as
           sum psd * bandwidth = mean(array**2)
       with bandwidth = sampling_frequency ** 2 / array.size is the PSD bin
       area.

    """
    array = np.asarray(array)
    if array.ndim != 2:
        raise ValueError('The input array is not two-dimensional.')
    s = abs2(FFTOperator(array.shape, fftw_flag=fftw_flag)(array))
    s /= array.size**2
    bandwidth = sampling_frequency**2 / array.size
    s /= bandwidth
    return Map(scipy.fftpack.fftshift(s))
Esempio n. 4
0
    def _get_synthbeam(scene,
                       position,
                       area,
                       nu,
                       bandwidth,
                       horn,
                       primary_beam,
                       secondary_beam,
                       synthbeam_dtype=np.float32,
                       theta_max=45):
        """
        Return the monochromatic synthetic beam for a specified location
        on the focal plane, multiplied by a given area and bandwidth.

        Parameters
        ----------
        scene : QubicScene
            The scene.
        position : array-like of shape (..., 3)
            The 3D coordinates where the response is computed, in meters.
        area : array-like
            The integration area, in m^2.
        nu : float
            The frequency for which the response is computed [Hz].
        bandwidth : float
            The filter bandwidth [Hz].
        horn : PackedArray
            The horn layout.
        primary_beam : Beam
            The primary beam.
        secondary_beam : Beam
            The secondary beam.
        synthbeam_dtype : dtype, optional
            The data type for the synthetic beams (default: float32).
            It is the dtype used to store the values of the pointing matrix.
        theta_max : float, optional
            The maximum zenithal angle above which the synthetic beam is
            assumed to be zero, in degrees.

        """
        MAX_MEMORY_B = 1e9
        theta, phi = hp.pix2ang(scene.nside, scene.index)
        index = np.where(theta <= np.radians(theta_max))[0]
        nhorn = int(np.sum(horn.open))
        npix = len(index)
        nbytes_B = npix * nhorn * 24
        ngroup = np.ceil(nbytes_B / MAX_MEMORY_B).astype(np.int)
        out = np.zeros(position.shape[:-1] + (len(scene), ),
                       dtype=synthbeam_dtype)
        for s in split(npix, ngroup):
            index_ = index[s]
            sb = QubicInstrument._get_response(theta[index_], phi[index_],
                                               bandwidth, position, area, nu,
                                               horn, primary_beam,
                                               secondary_beam)
            out[..., index_] = abs2(sb, dtype=synthbeam_dtype)
        return out
    def _get_synthbeam_(
            scene, position, area, nu, bandwidth, horn, primary_beam, 
            secondary_beam, spectral_irradiance=1, 
            synthbeam_dtype=np.float32, theta_max=30):
        """
        Return the monochromatic synthetic beam for a specified location
        on the focal plane, multiplied by a given area and bandwidth.

        Parameters
        ----------
        scene : QubicScene
            The scene.
        x : array-like
            The X-coordinate in the focal plane where the response is 
            computed, in meters. If not provided, the detector central 
            positions are assumed.
        y : array-like
            The Y-coordinate in the focal plane where the response is 
            computed, in meters. If not provided, the detector central 
            positions are assumed.
        area : array-like
            The integration area, in m^2.
        nu : float
            The frequency for which the response is computed [Hz].
        bandwidth : float
            The filter bandwidth [Hz].
        horn : PackedArray
            The horn layout.
        primary_beam : Beam
            The primary beam.
        secondary_beam : Beam
            The secondary beam.
        synthbeam_dtype : dtype, optional
            The data type for the synthetic beams (default: float32).
            It is the dtype used to store the values of the pointing matrix.
        theta_max : float, optional
            The maximum zenithal angle above which the synthetic beam is
            assumed to be zero, in degrees.

        """
        MAX_MEMORY_B = 1e9
        theta, phi = hp.pix2ang(scene.nside, scene.index)
        index = np.where(theta <= np.radians(theta_max))[0]
        nhorn = int(np.sum(horn.open))
        npix = len(index)
        nbytes_B = npix * nhorn * 24
        ngroup = np.ceil(nbytes_B / MAX_MEMORY_B)
        out = np.zeros(position.shape[:-1] + (len(scene),),
                       dtype=synthbeam_dtype)
        for s in split(npix, ngroup):
            index_ = index[s]
            sb = MultiQubicInstrument._get_response(
                theta[index_], phi[index_], spectral_irradiance, position, 
                area, nu, horn, primary_beam, secondary_beam)
            out[..., index_] = abs2(sb, dtype=synthbeam_dtype)
        return out * bandwidth * deriv_and_const(nu, scene.nside)
Esempio n. 6
0
# out : complex array of shape (#positions, #horns)
#     The phase and transmission from the horns to the focal plane.
#A = inst._get_response_A(position, area, nu, horn, secondary_beam)
uvec = position / np.sqrt(np.sum(position**2, axis=-1))[..., None]
thetaphi = Cartesian2SphericalOperator('zenith,azimuth')(uvec)
sr = -area / position[..., 2]**2 * np.cos(thetaphi[..., 0])**3
tr = np.sqrt(secondary_beam(thetaphi[..., 0], thetaphi[..., 1]) *
             sr / secondary_beam.solid_angle)[..., None]
const = 2j * np.pi * nu / c
product = np.dot(uvec, horn[horn.open].center.T)
A = ne.evaluate('tr * exp(const * product)')

ih=122
clf()
subplot(1,3,1)
amp = np.reshape(abs2(A[:,ih])/np.max(abs2(A)),(100,100))
imshow(amp, extent= [np.min(xx), np.max(xx), np.min(xx), np.max(xx)])
colorbar()
subplot(1,3,2)
phase = np.reshape(angle(A[:,ih]),(100,100))
imshow(phase, extent= [np.min(xx), np.max(xx), np.min(xx), np.max(xx)])
colorbar()
draw()
subplot(1,3,3)
inst.horn.plot(facecolor_open='grey')
plot(inst.horn.center[ih,0],inst.horn.center[ih,1],'ro')
draw()



Esempio n. 7
0
    def _get_synthbeam(
        scene,
        position,
        area,
        nu,
        bandwidth,
        horn,
        primary_beam,
        secondary_beam,
        synthbeam_dtype=np.float32,
        theta_max=45,
        external_A=None,
    ):
        """
        Return the monochromatic synthetic beam for a specified location
        on the focal plane, multiplied by a given area and bandwidth.

        Parameters
        ----------
        scene : QubicScene
            The scene.
        position : array-like of shape (..., 3)
            The 3D coordinates where the response is computed, in meters.
        area : array-like
            The integration area, in m^2.
        nu : float
            The frequency for which the response is computed [Hz].
        bandwidth : float
            The filter bandwidth [Hz].
        horn : PackedArray
            The horn layout.
        primary_beam : Beam
            The primary beam.
        secondary_beam : Beam
            The secondary beam.
        synthbeam_dtype : dtype, optional
            The data type for the synthetic beams (default: float32).
            It is the dtype used to store the values of the pointing matrix.
        theta_max : float, optional
            The maximum zenithal angle above which the synthetic beam is
            assumed to be zero, in degrees.
        external_A : list of tables describing the phase and amplitude at each point of the focal
            plane for each of the horns:
            [0] : array of nn with x values in meters
            [1] : array of nn with y values in meters
            [2] : array of [nhorns, nn, nn] with amplitude
            [3] : array of [nhorns, nn, nn] with phase in degrees

        """
        MAX_MEMORY_B = 1e9
        theta, phi = hp.pix2ang(scene.nside, scene.index)
        index = np.where(theta <= np.radians(theta_max))[0]
        nhorn = int(np.sum(horn.open))
        npix = len(index)
        nbytes_B = npix * nhorn * 24
        ngroup = np.ceil(nbytes_B / MAX_MEMORY_B)
        out = np.zeros(position.shape[:-1] + (len(scene),), dtype=synthbeam_dtype)
        for s in split(npix, ngroup):
            index_ = index[s]
            sb = QubicInstrument._get_response(
                theta[index_],
                phi[index_],
                bandwidth,
                position,
                area,
                nu,
                horn,
                primary_beam,
                secondary_beam,
                external_A=external_A,
            )
            out[..., index_] = abs2(sb, dtype=synthbeam_dtype)
        return out