Пример #1
0
 def test_left_right(self):
     # Extend yi[0] and yi[-1] at edges
     y = complex_interp(sorted(self.x), self.xi, self.yi)
     assert_allclose(y[0], self.yi[0], rtol=1e-14)
     assert_allclose(y[-1], self.yi[-1], rtol=1e-14)
     # Explicit edge values
     y = complex_interp(sorted(self.x), self.xi, self.yi, left=0, right=1j)
     assert_allclose(y[0], 0, rtol=1e-14)
     assert_allclose(y[-1], 1j, rtol=1e-14)
Пример #2
0
 def test_basic(self):
     y = complex_interp(self.x, self.xi, self.yi)
     mag_y = np.interp(self.x, self.xi, np.abs(self.yi))
     assert_allclose(np.abs(y), mag_y, rtol=1e-14)
     phase_y = np.interp(self.x, self.xi, np.unwrap(np.angle(self.yi)))
     assert_allclose(np.mod(np.angle(y), 2 * np.pi),
                     np.mod(phase_y, 2 * np.pi), rtol=1e-14)
Пример #3
0
def bandpass_corrections(pol, ant):
    """Figure out N_CHANS bandpass corrections given `pol`, `ant` indices."""
    bp = create_bandpass(pol, ant)
    valid = np.isfinite(bp)
    if valid.any():
        bp = complex_interp(FREQS, CAL_FREQS[valid], bp[valid],
                            left=INVALID_GAIN, right=INVALID_GAIN)
    else:
        bp = np.full(N_CHANS, INVALID_GAIN)
    return np.reciprocal(bp)
Пример #4
0
def gain_corrections(pol, ant, multi_channel=False, targets=False, fluxes=False):
    """Figure out N_DUMPS gain corrections given `pol` and `ant` indices."""
    dumps = np.arange(N_DUMPS)
    events = np.array(GAIN_EVENTS)
    gains = create_gain(pol, ant, multi_channel, targets, fluxes)
    gains = np.atleast_2d(gains.T)
    targets = TARGET_SENSOR if targets else CategoricalData([0], [0, len(dumps)])
    smooth_gains = np.full((N_DUMPS, gains.shape[0]), INVALID_GAIN, dtype=gains.dtype)
    for chan, gains_per_chan in enumerate(gains):
        for target in set(targets):
            on_target = (targets == target)
            valid = np.isfinite(gains_per_chan) & on_target[events]
            smooth_gains[on_target, chan] = INVALID_GAIN if not valid.any() else \
                complex_interp(dumps[on_target], events[valid], gains_per_chan[valid])
    return np.reciprocal(smooth_gains)
Пример #5
0
 def test_complex64_interpolation(self):
     yi = self.yi_unit.astype(np.complex64)
     y = complex_interp(self.x, self.xi, yi)
     assert_equal(y.dtype, yi.dtype)
     assert_allclose(np.abs(y), 1.0, rtol=1e-7)
Пример #6
0
 def test_phase_only_interpolation(self):
     y = complex_interp(self.x, self.xi, self.yi_unit)
     assert_allclose(np.abs(y), 1.0, rtol=1e-14)
Пример #7
0
 def test_correct_wrap(self):
     xi = np.arange(2)
     yi = np.array([-1 + 1j, -2 - 2j])
     x = 0.5
     y = -0.5 * (np.sqrt(2) + np.sqrt(8))  # np.interp has y = -1.5-0.5j
     assert_allclose(complex_interp(x, xi, yi), y, rtol=1e-14)
Пример #8
0
 def test_exact_values(self):
     y = complex_interp(self.xi, self.xi, self.yi)
     assert_allclose(y, self.yi, rtol=1e-14)