Exemplo n.º 1
0
 def test_numexpr_num_threads(self):
     with _environment('OMP_NUM_THREADS', '5'):
         # NUMEXPR_NUM_THREADS has priority
         with _environment('NUMEXPR_NUM_THREADS', '3'):
             if 'sparc' in platform.machine():
                 self.assertEqual(1, numexpr._init_num_threads())
             else:
                 self.assertEqual(3, numexpr._init_num_threads())
Exemplo n.º 2
0
 def test_omp_num_threads(self):
     with _environment('OMP_NUM_THREADS', '5'):
         self.assertEquals(5, numexpr._init_num_threads())
Exemplo n.º 3
0
 def test_numexpr_num_threads(self):
     with _environment('OMP_NUM_THREADS', '5'):
         # NUMEXPR_NUM_THREADS has priority
         with _environment('NUMEXPR_NUM_THREADS', '3'):
             self.assertEquals(3, numexpr._init_num_threads())
Exemplo n.º 4
0
 def test_omp_num_threads(self):
     with _environment('OMP_NUM_THREADS', '5'):
         if 'sparc' in platform.machine():
             self.assertEqual(1, numexpr._init_num_threads())
         else:
             self.assertEqual(5, numexpr._init_num_threads())
Exemplo n.º 5
0
    def array_factor(self, az, el, antpos, freq):
        r""" Computes the array factor :math:`\mathcal{A}` (i.e.
            the far-field radiation pattern obtained for an array
            of :math:`n_{\rm ant}` radiators).

            .. math::
                \mathcal{A} = \left| \sum_{n_{\scriptscriptstyle \rm ant}} e^{2 \pi i \frac{\nu}{c} (\varphi_0 - \varphi)} \right|^2

            .. math::
                \varphi = \underset{\scriptstyle n_{\scriptscriptstyle \rm ant}\, \times\, 3}{\mathbf{P}_{\rm ant}} \cdot \pmatrix{
                    \cos(\phi)\cos(\theta)\\
                    \sin(\phi)\cos(\theta)\\
                    \sin(\theta)
                }

            .. math::
                \varphi_0 = \underset{\scriptstyle n_{\scriptscriptstyle \rm ant}\, \times\, 3}{\mathbf{P}_{\rm ant}} \cdot \pmatrix{
                    \cos(\phi_0)\cos(\theta_0)\\
                    \sin(\phi_0)\cos(\theta_0)\\
                    \sin(\theta_0)
                }

            :math:`\mathbf{P}_{\rm ant}` is the antenna position
            matrix, :math:`\phi` and :math:`\theta` are the sky
            local coordinates (azimuth and elevation respectively)
            gridded on a HEALPix representation, whereas 
            :math:`\phi_0` and :math:`\theta_0` are the pointing
            direction in local coordinates.

            :param az:
                Pointing azimuth (in degrees if `float`)
            :type az: `float` or :class:`~astropy.units.Quantity`
            :param el:
                Pointing elevation (in degrees if `float`)
            :type el: `float` or :class:`~astropy.units.Quantity`
            :param antpos:
                Antenna positions shaped as (n_ant, 3)
            :type antpos: :class:`~numpy.ndarray`
            :param freq:
                Frequency (in MHz if `float`)
            :type freq: `float` or :class:`~astropy.units.Quantity`

            :returns: Array factor
            :rtype: :class:`~numpy.ndarray`

        """
        def get_phi(az, el, antpos):
            """ az, el in radians
            """
            xyz_proj = np.array(
                [np.cos(az) * np.cos(el),
                 np.sin(az) * np.cos(el),
                 np.sin(el)])
            antennas = np.array(antpos)
            phi = np.dot(antennas, xyz_proj)
            return phi

        if not isinstance(az, u.Quantity):
            az *= u.deg
        if not isinstance(el, u.Quantity):
            el *= u.deg

        self.phase_center = to_radec(ho_coord(az=az, alt=el, time=self.time))

        phi0 = get_phi(az=[az.to(u.rad).value],
                       el=[el.to(u.rad).value],
                       antpos=antpos)
        phi_grid = get_phi(az=self.ho_coords.az.rad,
                           el=self.ho_coords.alt.rad,
                           antpos=antpos)
        nt = ne.set_num_threads(ne._init_num_threads())
        delay = ne.evaluate('phi_grid-phi0')
        coeff = 2j * np.pi / wavelength(freq).value

        if self.ncpus == 1:
            # Normal
            af = ne.evaluate('sum(exp(coeff*delay),axis=0)')
        # elif self.ncpus == 'numba':
        #     af = perfcompute(coeff * delay)
        else:
            # Multiproc
            af = np.sum(mp_expo(self.ncpus, coeff, delay), axis=0)

        #return np.abs(af * af.conjugate())
        return np.real(af * af.conjugate())