Exemplo n.º 1
0
def load_strategy(ctx):
    """
    Creates a scanning strategy that covers the full sky
    
    :param ctx: The ctx instance with the paramterization
    
    :returns strategy: A list of CoordSpec with the scanning strategy for the full sky
    """
    start = ctx.strategy_start

    lat = np.radians(ctx.params.telescope_latitude)
    lon = np.radians(ctx.params.telescope_longitude)

    beam_nside = ctx.params.beam_nside
    thetas, phis = hp.pix2ang(beam_nside, np.arange(hp.nside2npix(beam_nside)))
    decs = sphere.theta2dec(thetas)
    ras = sphere.phi2ra(phis)

    strategy = []
    for sec, (ra, dec) in enumerate(itertools.izip(ras, decs)):
        date = start + timedelta(seconds=sec)
        radec = sidereal.RADec(ra, dec)
        h = radec.hourAngle(date, lon)
        altaz = radec.altAz(h, lat)
        strategy.append(CoordSpec(sec, altaz.alt + np.pi, altaz.az, ra, dec))

    return strategy
    def test_transform(self):
        nside = 2**4

        params = Struct(beam_nside=nside)

        strategy_coord = CoordSpec(0, 0, 0, 0, 0)

        beam_size = 0.041
        angles = np.arange(-1, 1, 10) * beam_size / 2
        beam_spec = BeamSpec(angles, angles, 0)

        time_steps = 2

        idx = np.arange(hp.nside2npix(nside))
        thetas, phis = hp.pix2ang(nside, idx)
        tree = sphere.ArcKDTree(thetas, phis)

        ctx = Struct(
            params=params,
            strategy_coords=[strategy_coord for _ in range(time_steps)],
            beam_spec=beam_spec,
            arc_tree=tree)

        plugin = coord_transform.Plugin(ctx)
        plugin()

        assert ctx.beams is not None
        assert len(ctx.beams) == time_steps
Exemplo n.º 3
0
def load_strategy(ctx):
    """
    Creates a crosshair in RA/DEC scanning strategy
    
    :param ctx: The ctx instance with the parameterization
    
    :returns strategy: A crosshair scanning strategy
    """
    
    start = ctx.strategy_start
    end   = ctx.strategy_end
    
    lat = np.radians(ctx.params.telescope_latitude)
    lon = np.radians(ctx.params.telescope_longitude)
    
    diff = int((end-start).total_seconds())
    step = ctx.params.strategy_step_size
    duration = int(diff // step)

#     ra_coords = [CoordSpec(durration//2 + t, 0, 0, ra, 0) for t, ra in enumerate(np.linspace(-np.pi, np.pi, durration//2))]
    
    strategy = []
    ra = 0
    for sec, dec in enumerate(np.linspace(-np.pi/2+EPS, np.pi/2-EPS, duration//2)):
        dt = sec*step
        date = start + timedelta(seconds=dt)
        radec = sidereal.RADec(ra, dec)
        h = radec.hourAngle(date, lon)
        altaz = radec.altAz(h, lat)
        strategy.append(CoordSpec(dt, altaz.alt + np.pi, altaz.az, ra, dec))

    dec_end = sec*step
    dec = 0
    for sec, ra in enumerate(np.linspace(-np.pi+EPS, np.pi, duration//2)):
        dt = dec_end+sec*step
        date = start + timedelta(seconds=dt)
        radec = sidereal.RADec(ra, dec)
        h = radec.hourAngle(date, lon)
        altaz = radec.altAz(h, lat)
        strategy.append(CoordSpec(dt, altaz.alt + np.pi, altaz.az, ra, dec))
    
    return strategy
Exemplo n.º 4
0
def load_strategy(ctx):
    """
    Creates a dummy scanning strategy by always centering on RA/DEC 0/0
    
    :param ctx: The ctx instance with the paramterization
    
    :returns strategy: A dummy scanning strategy
    """

    start = ctx.strategy_start
    end = ctx.strategy_end

    diff = int((end - start).total_seconds())
    step = ctx.params.strategy_step_size
    time = range(0, diff // step, step)
    return [CoordSpec(t, 0, 0, 0, 0) for t in time]
Exemplo n.º 5
0
    def test_add_background(self):

        tod_vx = np.random.uniform(1, 250, (100, 100))
        params = Struct(instrument="hide.spectrometer.M9703A",
                        elevation_model=[1, 0])
        freq = np.arange(100)
        els = np.linspace(0, np.pi / 2, 100)
        #         deg_els = np.degrees(els)
        strat = [CoordSpec(0., el, 0., 0., 0.) for el in els]
        ctx = Struct(params=params,
                     tod_vx=tod_vx.copy(),
                     frequencies=freq,
                     strategy_coords=strat)
        with patch("numpy.loadtxt") as load_txt_mock:
            load_txt_mock.return_value = np.vstack([freq, freq]).T
            plugin = Plugin(ctx)
            plugin()

        bg = freq.reshape(-1, 1) * els
        assert np.allclose(tod_vx + bg, ctx.tod_vx)
Exemplo n.º 6
0
    def test_add_rfi_phaseswitch(self):

        nf = 300
        nt = 600
        tod = np.zeros((nf, nt))

        wn = np.arange(nf) + 1
        frac = .2 * np.ones(nf)
        Amax = 10 * wn

        params = Struct(white_noise_scale=wn,
                        rfiamplitude=Amax,
                        rfideltaf=1,
                        rfideltat=1,
                        rfifrac=frac,
                        load_rfi_template=False,
                        rfiexponent=1,
                        rfienhance=1)

        strategy = [CoordSpec(t, 0, 0, 0, 0) for t in range(nt)]
        strategy_start = datetime(2016, 1, 1)
        ctx = Struct(params=params,
                     tod_vx=tod.copy(),
                     frequencies=wn,
                     strategy_coords=strategy,
                     strategy_start=strategy_start)

        plugin = add_rfi_phaseswitch.Plugin(ctx)
        assert np.allclose(plugin.getTime(), np.arange(nt) / 60. / 60.)

        plugin()

        assert np.sum(ctx.tod_vx) != 0
        assert np.all(ctx.tod_vx == ctx.tod_vx_rfi)

        ctx.params.rfiday = (3.0, 23.0)
        ctx.params.rfidamping = 0.0
        ctx.tod_vx = tod
        plugin = add_rfi_phaseswitch.Plugin(ctx)
        plugin()
        assert np.isclose(np.sum(ctx.tod_vx), 0)
Exemplo n.º 7
0
def load_strategy(ctx):
    """
    Creates a scanning strategy that uses drift mode i.e. the 
    telescope stares at the same position for 24 hours and then changes the altiude by a certain angle
    
    :param ctx: The ctx instance with the paramterization
    
    :returns strategy: A list of CoordSpec with the scanning strategy
    """

    start = ctx.strategy_start
    end = ctx.strategy_end

    diff = end - start

    lat_lon = sidereal.LatLon(np.radians(ctx.params.telescope_latitude),
                              np.radians(ctx.params.telescope_longitude))

    alt_delta = np.radians(ctx.params.alt_delta)
    az_pos = np.radians(ctx.params.azimuth_pointing)
    alt_pos = np.radians(ctx.params.altitude_start_pos)
    alt_max = np.radians(ctx.params.altitude_max_pos)

    strategy = []

    sec_per_day = 24 * 60 * 60
    duration = int(diff.total_seconds())
    for sec in range(0, duration, ctx.params.strategy_step_size):
        gst = sidereal.SiderealTime.fromDatetime(start +
                                                 timedelta(seconds=sec))
        radec = sidereal.AltAz(alt_pos, az_pos).raDec(gst.lst(lat_lon.lon),
                                                      lat_lon)

        strategy.append(CoordSpec(sec, alt_pos, az_pos, radec.ra, radec.dec))
        if sec % sec_per_day == 0 and sec != 0:
            alt_pos += alt_delta

        if alt_pos > alt_max:
            alt_pos = np.radians(ctx.params.altitude_start_pos)

    return strategy
Exemplo n.º 8
0
    def test_map_strategies(self):
        durration = 10
        time_range = 5
        params = Struct(time_range=time_range,
                        strategy_step_size=1,
                        verbose=False)
        ctx = Struct(
            params=params,
            strategy_start=parse_datetime("2015-01-01-00:00:00"),
            strategy=[CoordSpec(t, 0, 0, 0, 0) for t in xrange(durration)])

        plugin = map_strategy_plugin.Plugin(ctx)

        for idx, ctx in enumerate(plugin.getWorkload()):
            assert ctx is not None
            assert ctx.strategy_idx == idx
            assert ctx.strategy_coords is not None
            assert ctx.batch_start_date is not None
            assert len(ctx.strategy_coords) == time_range

        assert idx == (durration / time_range) - 1
Exemplo n.º 9
0
def _create_cood_spec(schedule_entry, sec, strategy_start, obs):
    time = schedule_entry.date + timedelta(seconds=sec)
    ra, dec = sphere.altaz_to_ra_dec(time, schedule_entry.az,
                                     schedule_entry.el, obs)
    total = (time - strategy_start).total_seconds()
    return CoordSpec(total, schedule_entry.el, schedule_entry.az, ra, dec)