|
| 1 | +""" Unit tests for calibration solution |
| 2 | +
|
| 3 | +
|
| 4 | +""" |
| 5 | +import logging |
| 6 | +import unittest |
| 7 | + |
| 8 | +import astropy.units as u |
| 9 | +import matplotlib.pyplot as plt |
| 10 | +import numpy |
| 11 | +from astropy.coordinates import SkyCoord |
| 12 | + |
| 13 | +from data_models.memory_data_models import Skycomponent |
| 14 | +from data_models.polarisation import PolarisationFrame |
| 15 | +from processing_components.calibration.operations import create_gaintable_from_blockvisibility, \ |
| 16 | + gaintable_summary, gaintable_plot |
| 17 | +from processing_components.imaging.base import predict_skycomponent_visibility |
| 18 | +from processing_components.simulation.configurations import create_named_configuration |
| 19 | +from processing_components.simulation.testing_support import simulate_gaintable |
| 20 | +from processing_components.visibility.base import create_blockvisibility |
| 21 | + |
| 22 | +log = logging.getLogger(__name__) |
| 23 | + |
| 24 | + |
| 25 | +class TestCalibrationPlot(unittest.TestCase): |
| 26 | + def setUp(self): |
| 27 | + numpy.random.seed(180555) |
| 28 | + |
| 29 | + def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear', f=None, vnchan=3, ntimes=30): |
| 30 | + self.lowcore = create_named_configuration('LOWBD2', rmax=50.0) |
| 31 | + self.times = (numpy.pi / 43200.0) * numpy.linspace(0.0, 30.0, ntimes) |
| 32 | + self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) |
| 33 | + self.channel_bandwidth = numpy.array(vnchan * [self.frequency[1] - self.frequency[0]]) |
| 34 | + |
| 35 | + if f is None: |
| 36 | + f = [100.0, 50.0, -10.0, 40.0] |
| 37 | + |
| 38 | + if sky_pol_frame == 'stokesI': |
| 39 | + f = [100.0] |
| 40 | + |
| 41 | + self.flux = numpy.outer(numpy.array([numpy.power(freq / 1e8, -0.7) for freq in self.frequency]), f) |
| 42 | + |
| 43 | + # The phase centre is absolute and the component is specified relative (for now). |
| 44 | + # This means that the component should end up at the position phasecentre+compredirection |
| 45 | + self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') |
| 46 | + self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') |
| 47 | + self.comp = Skycomponent(direction=self.compabsdirection, frequency=self.frequency, flux=self.flux, |
| 48 | + polarisation_frame=PolarisationFrame(sky_pol_frame)) |
| 49 | + self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, |
| 50 | + channel_bandwidth=self.channel_bandwidth, weight=1.0, |
| 51 | + polarisation_frame=PolarisationFrame(data_pol_frame)) |
| 52 | + self.vis = predict_skycomponent_visibility(self.vis, self.comp) |
| 53 | + |
| 54 | + def test_plot_gaintable_scalar(self): |
| 55 | + self.actualSetup('stokesI', 'stokesI', f=[100.0]) |
| 56 | + gt = create_gaintable_from_blockvisibility(self.vis) |
| 57 | + log.info("Created gain table: %s" % (gaintable_summary(gt))) |
| 58 | + gt = simulate_gaintable(gt, phase_error=0.1, amplitude_error=0.1) |
| 59 | + plt.clf() |
| 60 | + fig, ax = plt.subplots(1, 1) |
| 61 | + gaintable_plot(gt, ax, value='amp') |
| 62 | + plt.show(block=False) |
| 63 | + fig, ax = plt.subplots(1, 1) |
| 64 | + gaintable_plot(gt, ax, value='phase') |
| 65 | + plt.show(block=False) |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == '__main__': |
| 69 | + unittest.main() |
0 commit comments