Пример #1
0
def test_radec_yagzag_quat_init():
    att = [1.0, 2.0, 3.0]
    q_att = Quat(att)

    yag0, zag0 = radec_to_yagzag(1.1, 2.1, q_att)
    yag1, zag1 = radec_to_yagzag(1.1, 2.1, att)
    assert yag0 == yag1
    assert zag0 == zag1

    ra0, dec0 = yagzag_to_radec(100.1, 200.1, q_att)
    ra1, dec1 = yagzag_to_radec(100.1, 200.1, att)
    assert dec0 == dec1
    assert ra0 == ra1
Пример #2
0
def test_radec_yagzag_multidim(shape):
    """Test radec_to_yagzag and yagzag_to_radec for multidimensional inputs"""
    dec = 0.5
    ras = np.linspace(0., 1., 24)
    eqs = np.empty(shape=(24, 3))
    eqs[..., 0] = 0.1
    eqs[..., 1] = np.linspace(-0.1, 0.1, 24)
    eqs[..., 2] = np.linspace(-1, 1, 24)

    ras_nd = ras.reshape(shape)
    qs_nd = Quat(equatorial=eqs.reshape(shape + (3, )))

    # First do everything as scalars
    yagzags_list = [
        radec_to_yagzag(ra, dec, Quat(equatorial=eq))
        for ra, eq in zip(ras.tolist(), eqs.tolist())
    ]
    yagzags_nd_from_list = np.array(yagzags_list).reshape(shape + (2, ))

    # Test broadcasting by providing a scalar for `dec`
    yags, zags = radec_to_yagzag(ras_nd, dec, qs_nd)
    assert yags.shape == shape
    assert zags.shape == shape
    assert np.allclose(yags, yagzags_nd_from_list[..., 0])
    assert np.allclose(zags, yagzags_nd_from_list[..., 1])

    ras_rt, decs_rt = yagzag_to_radec(yags, zags, qs_nd)
    assert ras_rt.shape == shape
    assert decs_rt.shape == shape
    assert np.allclose(ras_rt, ras_nd)
    assert np.allclose(decs_rt, dec)
Пример #3
0
def search_agasc(yang, zang, field_agasc, q_aca):
    """
    Search the retrieved agasc region for a star at the specified
    yang, zang, and return the star if there is a match.

    :param yang:
    :param zang:
    :param field_agasc: the retrieved agasc star field
    :param q_aca: pointing quaternion for obsid
    :rtype: recarray of the matching star or None
    """

    for agasc_star in field_agasc:
        ra, dec = yagzag_to_radec(yang * 1.0 / 3600, zang * 1.0 / 3600, q_aca)
        # 3600*(sph_dist in degrees) for arcseconds
        dist = 3600 * Ska.astro.sph_dist(agasc_star['RA_PMCORR'],
                                         agasc_star['DEC_PMCORR'], ra, dec)
        if dist <= ID_DIST_LIMIT:
            return agasc_star

    return None
Пример #4
0
def test_yagzag_to_radec():
    yag = 1800.00
    zag = 2700.10
    q_att = Quat([0, 0, 0])
    ra, dec = yagzag_to_radec(yag, zag, q_att)
    assert np.allclose([ra, dec], [0.50, 0.75], rtol=0, atol=0.00001)
Пример #5
0
    def process_monitors(self):
        """Process monitor window requests"""
        if self.monitors is None:
            return

        # Add columns for each of the three coordinate representations. The
        # original list input for monitors has been turned into a Table by the
        # Meta processing.
        monitors = self.monitors
        monitors['id'] = 0
        monitors['ra'] = 0.0
        monitors['dec'] = 0.0
        monitors['yang'] = 0.0
        monitors['zang'] = 0.0
        monitors['row'] = 0.0
        monitors['col'] = 0.0

        for monitor in monitors:
            if monitor['coord_type'] == MonCoord.RADEC:
                # RA, Dec
                monitor['ra'], monitor['dec'] = monitor['coord0'], monitor['coord1']
                monitor['yang'], monitor['zang'] = radec_to_yagzag(
                    monitor['ra'], monitor['dec'], self.att)
                monitor['row'], monitor['col'] = yagzag_to_pixels(
                    monitor['yang'], monitor['zang'], allow_bad=True)

            elif monitor['coord_type'] == MonCoord.ROWCOL:
                # Row, col
                monitor['row'], monitor['col'] = monitor['coord0'], monitor['coord1']
                monitor['yang'], monitor['zang'] = pixels_to_yagzag(
                    monitor['row'], monitor['col'], allow_bad=True, flight=True)
                monitor['ra'], monitor['dec'] = yagzag_to_radec(
                    monitor['yang'], monitor['zang'], self.att)

            elif monitor['coord_type'] == MonCoord.YAGZAG:
                # Yag, zag
                monitor['yang'], monitor['zang'] = monitor['coord0'], monitor['coord1']
                monitor['row'], monitor['col'] = yagzag_to_pixels(
                    monitor['yang'], monitor['zang'], allow_bad=True)
                monitor['ra'], monitor['dec'] = yagzag_to_radec(
                    monitor['yang'], monitor['zang'], self.att)

        # Process bona fide monitor windows according to function
        mon_id = 1000
        for monitor in self.monitors:
            if monitor['function'] in (MonFunc.GUIDE, MonFunc.MON_TRACK):
                # Try to get star at MON position
                dist = np.linalg.norm([self.stars['yang'] - monitor['yang'],
                                       self.stars['zang'] - monitor['zang']], axis=0)
                idx = np.argmin(dist)
                if dist[idx] < 2.0:
                    star = self.stars[idx]
                    monitor['id'] = star['id']
                    monitor['mag'] = star['mag']
                elif monitor['function'] == MonFunc.GUIDE:
                    raise BadMonitorError('no acceptable AGASC star within '
                                          '2 arcsec of monitor position')

            if monitor['function'] in (MonFunc.MON_FIXED, MonFunc.MON_TRACK):
                if monitor['id'] == 0:
                    monitor['id'] = mon_id
                    mon_id += 1

                # Make a stub row for a MON entry using zero everywhere. This
                # also works for str (giving '0').
                mon = {col.name: col.dtype.type(0) for col in self.itercols()}
                # These type codes get fixed later in merge_catalog
                mon['type'] = 'MFX' if monitor['function'] == MonFunc.MON_FIXED else 'MTR'
                mon['sz'] = '8x8'
                mon['dim'] = -999  # Set an obviously bad value for DTS, gets fixed later.
                mon['res'] = 0
                mon['halfw'] = 20
                mon['maxmag'] = ACA.monitor_maxmag
                for name in ('id', 'mag', 'yang', 'zang', 'row', 'col', 'ra', 'dec'):
                    mon[name] = monitor[name]

                # Finally add the MON as a row in table
                self.add_row(mon)

            elif monitor['function'] != MonFunc.GUIDE:
                raise ValueError(f'unexpected monitor function {monitor["function"]}')