Ejemplo n.º 1
0
 def beam_values(self, coords, time):
     """
         :param coords:
         :type coords: :class:`~astropy.coordinates.ICRS` or 
             :class:`~astropy.coordinates.SkyCoord`
         :param time:
         :type time: :class:`~astropy.time.Time`
     """
     if not isinstance(coords, (ICRS, SkyCoord)):
         raise TypeError('coords should be ICRS or SkyCoord object')
     if not isinstance(time, Time):
         raise TypeError('time should be Time object')
     # Real pointing
     if self.beamsquint:
         el = desquint_elevation(elevation=self.elana,
                                 opt_freq=self.squint_freq)
     else:
         el = self.elana.copy()
     az, el = analog_pointing(self.azana, el)
     log.info('Effective analog pointing=({}, {})'.format(az, el))
     # Array factor
     phase_center = ho_coord(az=az, alt=el, time=time)
     altazcoords = toAltaz(skycoord=coords, time=time)
     arrfac = self.array_factor(phase_center=phase_center,
                                coords=altazcoords,
                                antpos=ma_antpos(rot=self._rot))
     # Antenna Gain
     antgain = self.ant_gain(coords=coords, time=time)
     anagain = arrfac * antgain
     log.info('Anabeam (rot {}) computed for {} pixels.'.format(
         self._rot % 60, anagain.size))
     return anagain
Ejemplo n.º 2
0
def test_toaltaz():
    source = SkyCoord(180, 45, unit='deg')
    time = Time('2020-04-01 12:00:00')
    with pytest.raises(TypeError):
        altaz = toAltaz(skycoord=1, time=Time.now())
    with pytest.raises(TypeError):
        altaz = toAltaz(skycoord=source, time=1)
    with pytest.raises(TypeError):
        altaz = toAltaz(skycoord=source, time=time, kind=source)
    altaz = toAltaz(skycoord=source, time=time, kind='fast')
    assert isinstance(altaz, SkyCoord)
    assert altaz.az.deg == pytest.approx(8.651, 1e-3)
    assert altaz.alt.deg == pytest.approx(2.8895, 1e-4)
    altaz = toAltaz(skycoord=source, time=time, kind='normal')
    assert isinstance(altaz, SkyCoord)
    assert altaz.az.deg == pytest.approx(8.645, 1e-3)
    assert altaz.alt.deg == pytest.approx(2.8898, 1e-4)
Ejemplo n.º 3
0
    def beam_values(self, coords, time):
        """
            :param coords:
            :type coords: :class:`~astropy.coordinates.ICRS` or 
                :class:`~astropy.coordinates.SkyCoord`
            :param time:
            :type time: :class:`~astropy.time.Time`
        """
        if not isinstance(coords, (ICRS, SkyCoord)):
            raise TypeError('coords should be ICRS or SkyCoord object')
        if not isinstance(time, Time):
            raise TypeError('time should be Time object')

        # Build the Mini-Array 'summed' response
        abeams = {}
        for ma in self.ma:
            rot = ma_info['rot'][ma_info['ma'] == ma][0]
            if str(rot % 60) not in abeams.keys():
                ana = ABeam(freq=self.freq,
                            polar=self.polar,
                            azana=self.azana,
                            elana=self.elana,
                            ma=ma)
                ana.beamsquint = self.beamsquint
                anavals = ana.beam_values(coords=coords, time=time)
                abeams[str(rot % 60)] = anavals.copy()
            if not 'summa' in locals():
                summa = abeams[str(rot % 60)]
            else:
                summa += abeams[str(rot % 60)]
        # Array factor
        phase_center = ho_coord(az=self.azdig, alt=self.eldig, time=time)
        altazcoords = toAltaz(skycoord=coords, time=time)
        arrfac = self.array_factor(phase_center=phase_center,
                                   coords=altazcoords,
                                   antpos=ma_pos[np.isin(
                                       ma_info['ma'], self.ma)])
        # Arrayfactor * summed MA response
        digigain = arrfac * summa
        log.info('Digibeam computed for {} pixels.'.format(digigain.size))
        return digigain
Ejemplo n.º 4
0
def plotPointing(altaza=None, altazb=None, sourceName=None):
    """
    """
    fig, axs = plt.subplots(2 if sourceName is None else 3,
                            1,
                            sharex=True,
                            figsize=(15, 10))
    fig.subplots_adjust(hspace=0)

    if altaza is not None:
        if not altaza.endswith('.altazA'):
            raise TypeError('Wrong file format for altaza.')
        title = basename(altaza).replace('.altazA', '')
        aza = readPointing(altaza)
        azaTime = Time(aza['time'])
        tmin = azaTime[0]
        tmax = azaTime[-1]
        for abeam in np.unique(aza['anabeam']):
            mask = aza['anabeam'] == abeam
            axs[0].plot(
                azaTime[mask]
                [:-1].datetime,  # Do not show last pointing / back to zenith
                aza['az'][mask][:-1],
                linewidth='5.5',
                label=f'Analog requested (#{abeam})')
            axs[0].plot(azaTime[mask][:-1].datetime,
                        aza['az_cor'][mask][:-1],
                        linewidth='3',
                        label=f'Analog corrected (#{abeam})')
            axs[1].plot(azaTime[mask][:-1].datetime,
                        aza['el'][mask][:-1],
                        linewidth='5.5',
                        label=f'Analog requested (#{abeam})')
            axs[1].plot(azaTime[mask][:-1].datetime,
                        aza['el_cor'][mask][:-1],
                        linewidth='3',
                        label=f'Analog corrected (#{abeam})')
            axs[1].plot(azaTime[mask][:-1].datetime,
                        aza['el_eff'][mask][:-1],
                        linewidth='2',
                        label=f'Analog beamsquint corrected (#{abeam})')

    if altazb is not None:
        if not altazb.endswith('.altazB'):
            raise TypeError('Wrong file format for altazb.')
        title = basename(altazb).replace('.altazB', '')
        azb = readPointing(altazb)
        azbTime = Time(azb['time'])
        tmin = azbTime[0]
        tmax = azbTime[-1]
        for dbeam in np.unique(azb['digibeam']):
            mask = azb['digibeam'] == dbeam
            axs[0].plot(azbTime[mask].datetime,
                        azb['az'][mask],
                        linewidth='1',
                        label=f'Numeric (#{dbeam})')
            axs[1].plot(azbTime[mask].datetime,
                        azb['el'][mask],
                        linewidth='1',
                        label=f'Numeric (#{dbeam})')

    if (altaza is None) and (altazb is None):
        raise ValueError('At least one pointing file should be given.')

    if sourceName is not None:
        srcTime, srcAz, srcEl = altazProfile(sourceName=sourceName,
                                             tMin=tmin,
                                             tMax=tmax,
                                             dt=(tmax - tmin) / 20. -
                                             TimeDelta(0.5, format='sec'))
        axs[0].plot(srcTime.datetime,
                    srcAz,
                    color='black',
                    linestyle='--',
                    alpha=0.8,
                    label=f'{sourceName}')
        axs[1].plot(srcTime.datetime,
                    srcEl,
                    color='black',
                    linestyle='--',
                    alpha=0.8,
                    label=f'{sourceName}')

        if altaza is not None:
            for abeam in np.unique(aza['anabeam']):
                mask = aza['anabeam'] == abeam
                analog = ho_coord(alt=aza['el'][mask][:-1],
                                  az=aza['az'][mask][:-1],
                                  time=azaTime[mask][:-1])
                analog_cor = ho_coord(alt=aza['el_cor'][mask][:-1],
                                      az=aza['az_cor'][mask][:-1],
                                      time=azaTime[mask][:-1])
                analog_bscor = ho_coord(alt=aza['el_eff'][mask][:-1],
                                        az=aza['az_cor'][mask][:-1],
                                        time=azaTime[mask][:-1])
                source = toAltaz(skycoord=getSource(name=sourceName,
                                                    time=azaTime[mask][:-1]),
                                 time=azaTime[mask][:-1])
            axs[2].plot(azaTime[mask][:-1].datetime,
                        source.separation(analog).deg,
                        label=f'Analog (#{abeam})')
            axs[2].plot(azaTime[mask][:-1].datetime,
                        source.separation(analog_cor).deg,
                        label=f'Analog corrected (#{abeam})')
            axs[2].plot(azaTime[mask][:-1].datetime,
                        source.separation(analog_bscor).deg,
                        label=f'Analog beamsquint corrected (#{abeam})')

        if altazb is not None:
            for dbeam in np.unique(azb['digibeam']):
                mask = azb['digibeam'] == dbeam
                numeric = ho_coord(alt=azb['el'][mask],
                                   az=azb['az'][mask],
                                   time=azbTime[mask])
                source = toAltaz(skycoord=getSource(name=sourceName,
                                                    time=azbTime[mask]),
                                 time=azbTime[mask])
            axs[2].plot(azbTime[mask].datetime,
                        source.separation(numeric).deg,
                        label=f'Numeric (#{dbeam})')

        axs[2].set_ylabel(f'Separation from {sourceName} (deg)')
        axs[2].legend()
        axs[2].set_xlabel(f'UTC Time (since {tmin.iso})')
    else:
        axs[1].set_xlabel(f'UTC Time (since {tmin.iso})')

    axs[0].set_title('Pointing - ' + title)
    axs[0].set_ylabel('Azimuth (deg)')
    axs[0].legend()
    axs[1].set_ylabel('Elevation (deg)')
    axs[1].legend()
    plt.show()