def _setup_gridbeam_interpolation(self):
        # grid beam coordinates
        self._x_grid = self._primary_beam.phi[:]
        self._y_grid = self._primary_beam.theta[:]

        # celestial coordinates
        angpos = hputil.ang_positions(self._nside)
        x_cel = coord.sph_to_cart(angpos).T

        # rotate to telescope coords
        # first align y with N, then polar axis with NCP
        self._x_tel = cylbeam.rotate_ypr(
            (1.5 * np.pi, np.radians(90.0 - self.latitude), 0), *x_cel)

        # mask any pixels outside grid
        x_t, y_t, z_t = self._x_tel
        self._pix_mask = ((z_t > 0)
                          & (np.abs(x_t) < np.abs(self._x_grid.max()))
                          & (np.abs(y_t) < np.abs(self._y_grid.max())))

        # pre-compute polarisation pattern
        # taken from driftscan
        zenith = np.array([np.pi / 2.0 - np.radians(self.latitude), 0.0])
        that, phat = coord.thetaphi_plane_cart(zenith)
        xhat, yhat, zhat = cylbeam.rotate_ypr([-self.rotation_angle, 0.0, 0.0],
                                              phat, -that,
                                              coord.sph_to_cart(zenith))

        self._pvec_x = cylbeam.polpattern(angpos, xhat)
        self._pvec_y = cylbeam.polpattern(angpos, yhat)
Example #2
0
    def _init_trans(self, nside):
        ## Internal function for generating some common Healpix maps (position,
        ## horizon). These should need to be generated only when nside changes.

        # Angular positions in healpix map of nside
        self._nside = nside
        self._angpos = hputil.ang_positions(nside)

        # The horizon function
        self._horizon = visibility.horizon(self._angpos, self.zenith)
Example #3
0
    def _init_trans(self, nside):
        ## Internal function for generating some common Healpix maps (position,
        ## horizon). These should need to be generated only when nside changes.

        # Angular positions in healpix map of nside
        self._nside = nside
        self._angpos = hputil.ang_positions(nside)

        # The horizon function
        self._horizon = visibility.horizon(self._angpos, self.zenith)
Example #4
0
    def Omega(self):
        r"""Return the beam solid angle :math:`\int |A(\boldsymbol{n})|^2 \ d^2\boldsymbol{n}`."""
        nside = 256
        angpos = hputil.ang_positions(nside)
        lat = np.radians(44.15268333) # exact value not important
        lon = np.radians(91.80686667) # exact value not important
        zenith = np.array([0.5*np.pi - lat, lon])
        horizon = visibility.horizon(angpos, zenith)

        pxarea = (4 * np.pi / (12 * nside**2))
        om = np.zeros_like(self.freqs)
        for fi in xrange(len(self.freqs)):
            width = self.width / (const.c / (1.0e9 * self.freqs[fi]))
            beam = cylbeam.beam_amp(angpos, zenith, width, self.fwhm_h, self.fwhm_h)
            om[fi] = np.sum(np.abs(beam)**2 * horizon) * pxarea

        return om
Example #5
0
    def _init_trans(self, nside):
        ## Internal function for generating some common Healpix maps (position,
        ## horizon). These should need to be generated only when nside changes.

        # Angular positions in healpix map of nside
        self._nside = nside
        self._angpos = hputil.ang_positions(nside)

        # The horizon function
        self._horizon = visibility.horizon(self._angpos, self.zenith)

        # size of the cartesian projection
        phi_size = 5 * self._nside + 1 # add 1 to make it odd for nside >= 2
        theta_range = self.beam_theta_range
        theta_size = ((theta_range[1] - theta_range[0]) / 180.0) * (phi_size / 2)
        theta_size = theta_size if (np.mod(theta_size, 2) == 1) else theta_size+1 # make it odd

        latra = [ 90.0-theta_range[1], 90.0-theta_range[0] ]
        self._cart_projector = hpproj.CartesianProj(xsize=phi_size, ysize=theta_size, latra=latra)
Example #6
0
def visualize_beam(args):
    angpos = hputil.ang_positions(args.nside)
    zenith = latlon_to_sphpol([args.lat, args.lon])
    beamx_resp = beamx(args.feed, args.freq, angpos, zenith, args.dish_width)
    beamy_resp = beamy(args.feed, args.freq, angpos, zenith, args.dish_width)
    # Create output image file name
    if args.outfile:
        out_file = args.outfile
    else:
        freq = ('%s'%args.freq).replace('.', '_')
        diameter = ('%s'%args.dish_width).replace('.', '_')
        out_file = 'beam_resp_%s__%s.%s'%(freq, diameter, args.figfmt)
    # Plot and save image
    fig = plt.figure(1, figsize=(args.figlength, args.figwidth))
    title1 = 'X beam pattern, f= %sMHz, d = %sm'%(args.freq, args.dish_width)
    healpy.mollview(beamx_resp[:, 1], fig=1, sub=121, title=title1, min=args.min, max=args.max)
    title2 = 'Y beam pattern, f= %sMHz, d = %sM'%(args.freq, args.dish_width)
    healpy.mollview(beamy_resp[:, 0], fig=1, sub=122, title=title2, min=args.min, max=args.max)
    if args.grid:
        healpy.graticule()
    fig.savefig(out_file)
    fig.clf()
Example #7
0
    def _init_trans(self, nside):
        ## Internal function for generating some common Healpix maps (position,
        ## horizon). These should need to be generated only when nside changes.

        # Angular positions in healpix map of nside
        self._nside = nside
        self._angpos = hputil.ang_positions(nside)

        # The horizon function
        self._horizon = visibility.horizon(self._angpos, self.zenith)

        # size of the cartesian projection
        phi_size = 5 * self._nside + 1  # add 1 to make it odd for nside >= 2
        theta_range = self.beam_theta_range
        theta_size = (
            (theta_range[1] - theta_range[0]) / 180.0) * (phi_size / 2)
        theta_size = theta_size if (np.mod(theta_size, 2)
                                    == 1) else theta_size + 1  # make it odd

        latra = [90.0 - theta_range[1], 90.0 - theta_range[0]]
        self._cart_projector = hpproj.CartesianProj(xsize=phi_size,
                                                    ysize=theta_size,
                                                    latra=latra)
Example #8
0
def rotate_phi(map, dphi):
    angpos = hputil.ang_positions(healpy.npix2nside(map.size))
    theta, phi = angpos[:, 0], ((angpos[:, 1] - dphi) % (2*np.pi))
    return healpy.get_interp_val(map, theta, phi)
def visualize_cyl_beam(args):
    """Visualize cylinder beam.
    """
    import numpy as np
    import healpy
    import hpvisual
    from drift.telescope import cylinder as cyl
    # from drift.core import telescope as tel
    from cora.util import hputil
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib import pyplot as plt
    from matplotlib.ticker import MultipleLocator

    if args.pol:
        pol_cyl = cyl.PolarisedCylinderTelescope(args.lat, args.lon)
        # pol_cyl.zenith = tel.latlon_to_sphpol([args.lat, args.lon]) # NOTE: this is wrong, use the constructor above or the following assignment, because the assignment will automatically trigger drift/util/config.py __set__() method, which will call tel.latlon_to_sphpol.
        # pol_cyl.zenith = [args.lat, args.lon]
        pol_cyl.cylinder_width = args.cyl_width
        pol_cyl._frequencies = np.array([args.freq])
        pol_cyl._angpos = hputil.ang_positions(args.nside)
        beamx_resp = pol_cyl.beamx(args.feed, 0)
        beamy_resp = pol_cyl.beamy(args.feed, 0)
        # Create output image file name
        if args.outfile:
            out_file = args.outfile
        else:
            freq = ('%s'%args.freq).replace('.', '_')
            cyl_width = ('%s'%args.cyl_width).replace('.', '_')
            out_file = 'pol_cyl_beam_resp_%s__%s.%s'%(freq, cyl_width, args.figfmt)
        # Plot and save image
        fig1 = plt.figure(1, figsize=(args.figlength, 2*args.figwidth))
        title11 = 'X feed theta direction, f = %s MHz, w = %s m'%(args.freq, args.cyl_width)
        title12 = 'X feed phi direction, f = %s MHz, w = %s m'%(args.freq, args.cyl_width)
        hpvisual.mollview(beamx_resp[:, 0], fig=1, sub=221, title=title11, min=args.min, max=args.max)
        hpvisual.mollview(beamx_resp[:, 1], fig=1, sub=222, title=title12, min=args.min, max=args.max)
        title21 = 'Y feed theta direction, f = %s MHz, w = %s m'%(args.freq, args.cyl_width)
        title22 = 'Y feed phi direction, f = %s MHz, w = %s m'%(args.freq, args.cyl_width)
        hpvisual.mollview(beamy_resp[:, 0], fig=1, sub=223, title=title21, min=args.min, max=args.max)
        hpvisual.mollview(beamy_resp[:, 1], fig=1, sub=224, title=title22, min=args.min, max=args.max)
        if args.grid:
            healpy.graticule()
        fig1.savefig(out_file)
        fig1.clf()

        # R_{I to I}
        II_resp = (beamx_resp[:, 0]**2 + beamx_resp[:, 1]**2 + beamy_resp[:, 0]**2 + beamy_resp[:, 1]**2) / 2.0
        # R_{P to I}
        PI_resp = (beamx_resp[:, 0]**2 - beamx_resp[:, 1]**2 + beamx_resp[:, 0]*beamx_resp[:, 1] + beamy_resp[:, 0]**2 - beamy_resp[:, 1]**2 + beamy_resp[:, 0]*beamy_resp[:, 1]) / 2.0

        # Plot the R_{I to I}response
        fig2 = plt.figure(2, figsize=(args.figlength, args.figwidth))
        hpvisual.mollview(II_resp, fig=2, min=args.min, max=args.max)
        if args.grid:
            healpy.graticule()
        fig2.savefig('II_mollview' + out_file)
        fig2.clf()

        # Plot the R_{P to I}response
        fig3 = plt.figure(3, figsize=(args.figlength, args.figwidth))
        hpvisual.mollview(PI_resp, fig=3, min=args.min, max=args.max)
        if args.grid:
            healpy.graticule()
        fig3.savefig('PI_mollview' + out_file)
        fig3.clf()


        # cart_array = healpy.cartview(II_resp, fig=3, lonra=[-10, 10], min=args.min, max=args.max, aspect=0.25, notext=True, hold=True, title='', return_projected_map=True)
        lon_range = [-10, 10]
        ext = (-10, 10, -90, 90)
        # R_{I to I } cartesian
        II_cart = hpvisual.cartview(II_resp, lonra=lon_range, return_projected_map=True)
        ticks = np.linspace(np.min(II_cart), np.max(II_cart), 6)
        ticks = np.around(ticks, decimals=1)
        plt.figure(figsize=(4, 5))
        plt.imshow(II_cart, extent=ext, aspect=0.2, origin='lower', vmin=ticks[0], vmax=ticks[-1])
        ax = plt.gca()
        ax.yaxis.set_major_locator(MultipleLocator(30))
        plt.xlabel('EW / deg')
        plt.ylabel('NS / deg')
        cbar = plt.colorbar(shrink=0.6 ,orientation='horizontal', ticks=ticks)
        cbar.solids.set_rasterized(True)
        plt.savefig('II_cartview_' + out_file)
        # R_{P to I } cartesian
        PI_cart = hpvisual.cartview(PI_resp, lonra=lon_range, return_projected_map=True)
        ticks = np.linspace(np.min(PI_cart), np.max(PI_cart), 4)
        ticks = np.around(ticks, decimals=2)
        plt.figure(figsize=(4, 5))
        plt.imshow(PI_cart, extent=ext, aspect=0.2, origin='lower', vmin=ticks[0], vmax=ticks[-1])
        ax = plt.gca()
        ax.yaxis.set_major_locator(MultipleLocator(30))
        plt.xlabel('EW / deg')
        plt.ylabel('NS / deg')
        cbar = plt.colorbar(shrink=0.6 ,orientation='horizontal', ticks=ticks)
        cbar.solids.set_rasterized(True)
        plt.savefig('PI_cartview_' + out_file)

    else:
        unpol_cyl = cyl.UnpolarisedCylinderTelescope(args.lat, args.lon)
        unpol_cyl.cylinder_width = args.cyl_width
        unpol_cyl._frequencies = np.array([args.freq])
        unpol_cyl._angpos = hputil.ang_positions(args.nside)
        beam_amp = unpol_cyl.beam(args.feed, 0)
        # Create output image file name
        if args.outfile:
            out_file = args.outfile
        else:
            freq = ('%s'%args.freq).replace('.', '_')
            cyl_width = ('%s'%args.cyl_width).replace('.', '_')
            out_file = 'unpol_cyl_beam_resp_%s__%s.%s'%(freq, cyl_width, args.figfmt)
        # Plot and save image
        fig = plt.figure(1, figsize=(args.figlength, args.figwidth))
        title = 'Beam pattern, f = %s MHz, w = %s m'%(args.freq, args.cyl_width)
        hpvisual.mollview(beam_amp, fig=1, sub=111, coord='G', title=title, min=args.min, max=args.max)
        if args.grid:
            healpy.graticule()
        fig.savefig(out_file)
        fig.clf()