def test_divide_visibility(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vis.data['vis'][..., :] = [2.0 + 0.0j, 0.0j, 0.0j, 2.0 + 0.0j] self.othervis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.othervis.data['vis'][..., :] = [ 1.0 + 0.0j, 0.0j, 0.0j, 1.0 + 0.0j ] self.ratiovis = divide_visibility(self.vis, self.othervis) assert self.ratiovis.nvis == self.vis.nvis assert numpy.max(numpy.abs(self.ratiovis.vis)) == 2.0, numpy.max( numpy.abs(self.ratiovis.vis))
def test_phase_rotation_block(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) # Predict visibilities with new phase centre independently ha_diff = -(self.compabsdirection.ra - self.phasecentre.ra).to( u.rad).value vispred = create_blockvisibility( self.lowcore, self.times + ha_diff, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.compabsdirection, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vismodel2 = predict_skycomponent_visibility(vispred, self.comp) # Should yield the same results as rotation rotatedvis = phaserotate_visibility( self.vismodel, newphasecentre=self.compabsdirection, tangent=False) assert_allclose(rotatedvis.vis, vismodel2.vis, rtol=3e-6) assert_allclose(rotatedvis.uvw, vismodel2.uvw, rtol=3e-6)
def test_elevation_block(self): self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=+15.0 * u.deg, frame='icrs', equinox='J2000') self.times = (numpy.pi / 43200.0) * numpy.arange( -43200, +43200, 3600.0) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV"), elevation_limit=numpy.pi * 15.0 / 180.0) n_elevation_limit = len(numpy.unique(self.vis.time)) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV"), elevation_limit=None) assert len(numpy.unique(self.vis.time)) >= n_elevation_limit
def ingest_unittest_visibility(config, frequency, channel_bandwidth, times, vis_pol, phasecentre, block=False, zerow=False): if block: vt = create_blockvisibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol, zerow=zerow) else: vt = create_visibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol, zerow=zerow) vt.data['vis'][...] = 0.0 return vt
def test_readwritegaintable(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1) config = { "buffer": { "directory": self.dir }, "gaintable": { "name": "test_buffergaintable.hdf", "data_model": "GainTable" } } bdm = BufferGainTable(config["buffer"], config["gaintable"], gt) bdm.sync() new_bdm = BufferGainTable(config["buffer"], config["gaintable"]) new_bdm.sync() newgt = bdm.memory_data_model assert gt.data.shape == newgt.data.shape assert numpy.max(numpy.abs(gt.gain - newgt.gain)) < 1e-15
def test_readwriteskymodel_no_image(self): vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_gaintable_from_blockvisibility(vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1) sm = SkyModel(components=[self.comp], gaintable=gt) config = { "buffer": { "directory": self.dir }, "skymodel": { "name": "test_bufferskymodel.hdf", "data_model": "SkyModel" } } bdm = BufferSkyModel(config["buffer"], config["skymodel"], sm) bdm.sync() new_bdm = BufferSkyModel(config["buffer"], config["skymodel"]) new_bdm.sync() newsm = bdm.memory_data_model assert newsm.components[0].flux.shape == self.comp.flux.shape assert newsm.gaintable.data.shape == gt.data.shape
def test_readwritepointingtable(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) pt = create_pointingtable_from_blockvisibility(self.vis, timeslice='auto') pt = simulate_pointingtable(pt, pointing_error=0.1) config = { "buffer": { "directory": self.dir }, "pointingtable": { "name": "test_bufferpointingtable.hdf", "data_model": "PointingTable" } } bdm = BufferPointingTable(config["buffer"], config["pointingtable"], pt) bdm.sync() new_bdm = BufferPointingTable(config["buffer"], config["pointingtable"]) new_bdm.sync() newpt = bdm.memory_data_model assert pt.data.shape == newpt.data.shape assert numpy.max(numpy.abs(pt.pointing - newpt.pointing)) < 1e-15
def setUp(self): self.persist = os.getenv("RASCIL_PERSIST", False) from rascil.data_models.parameters import rascil_path dec = -40.0 * u.deg self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = rascil_path('test_results') self.times = numpy.linspace(-10.0, 10.0, 3) * numpy.pi / (3600.0 * 12.0) self.frequency = numpy.array([1e8, 1.5e8, 2.0e8]) self.channel_bandwidth = numpy.array([5e7, 5e7, 5e7]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=dec, frame='icrs', equinox='J2000') self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'] *= 0.0 # Create model self.model = create_image( npixel=512, cellsize=0.000015, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def test_readwriteblockvisibility(self): self.vis = create_blockvisibility( self.mid, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) self.vis = dft_skycomponent_visibility(self.vis, self.comp) export_blockvisibility_to_hdf5( self.vis, '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir) newvis = import_blockvisibility_from_hdf5( '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir) for key in self.vis.data.dtype.fields: assert numpy.max( numpy.abs(newvis.data[key] - self.vis.data[key])) < 1e-15 assert numpy.array_equal(newvis.frequency, self.vis.frequency) assert newvis.data.shape == self.vis.data.shape assert numpy.max(numpy.abs(self.vis.vis - newvis.vis)) < 1e-15 assert numpy.max(numpy.abs(self.vis.uvw - newvis.uvw)) < 1e-15 assert numpy.abs(newvis.configuration.location.x.value - self.vis.configuration.location.x.value) < 1e-15 assert numpy.abs(newvis.configuration.location.y.value - self.vis.configuration.location.y.value) < 1e-15 assert numpy.abs(newvis.configuration.location.z.value - self.vis.configuration.location.z.value) < 1e-15 assert numpy.max( numpy.abs(newvis.configuration.xyz - self.vis.configuration.xyz)) < 1e-15
def test_create_gaintable_from_pointingtable_GRASP(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('linear')) comp = create_skycomponent( direction=self.phasecentre, flux=[[1.0, 0.0, 0.0, 0.0]], frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesIQUV')) pt = create_pointingtable_from_blockvisibility(self.vis) pt = simulate_pointingtable(pt, pointing_error=0.0, static_pointing_error=None, global_pointing_error=[0.0, 0.01]) vp = create_vp(self.model, 'MID_GRASP') gt = simulate_gaintable_from_pointingtable(self.vis, [comp], pt, vp) if self.doplot: import matplotlib.pyplot as plt plt.clf() plt.plot(gt[0].time, numpy.real(1.0 / gt[0].gain[:, 0, 0, 0, 0]), '.') plt.plot(gt[0].time, numpy.imag(1.0 / gt[0].gain[:, 0, 0, 0, 0]), '.') plt.title( 'test_create_gaintable_from_pointingtable_global_dynamic') plt.show(block=False) assert gt[0].gain.shape == (self.ntimes, self.nants, 1, 2, 2), gt[0].gain.shape
def setUp(self): from rascil.data_models.parameters import rascil_path self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = rascil_path('test_results') self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e6]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'] *= 0.0 # Create model self.model = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.frequency) self.model.data[self.model.data > 1.0] = 1.0 self.mask = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.frequency) self.mask.data[self.mask.data > 0.1] = 1.0 self.mask.data[self.mask.data <= 0.1] = 0.0
def setUp(self): from rascil.data_models.parameters import rascil_path self.doplot = False self.midcore = create_named_configuration('MID', rmax=300.0) self.nants = len(self.midcore.names) self.dir = rascil_path('test_results') self.ntimes = 30 self.times = numpy.linspace(-5.0, 5.0, self.ntimes) * numpy.pi / (12.0) self.frequency = numpy.array([1e9]) self.channel_bandwidth = numpy.array([1e7]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'] *= 0.0 # Create model self.model = create_image( npixel=512, cellsize=0.00015, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def test_convert_blockvisibility_stokes(self): for pol in ['linear', 'circular']: vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame(pol)) visi = convert_blockvisibility_to_stokes(vis) assert visi.polarisation_frame.type == 'stokesIQUV' assert visi.npol == 4
def test_plotazel(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) plt.clf() plot_azel([self.vis]) plt.show(block=False)
def test_convert_blockvisibility(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, channel_bandwidth=self.channel_bandwidth) vis = convert_blockvisibility_to_visibility(self.vis) assert vis.nvis == len(vis.time) assert numpy.unique(vis.time).size == self.vis.time.size # pylint: disable=no-member
def actualSetUp(self, times=None): if times is not None: self.times = times self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.gaintable = create_gaintable_from_blockvisibility(self.vis)
def test_addnoise_blockvisibility(self): self.vis = create_blockvisibility( self.config, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesIQUV'), channel_bandwidth=self.channel_bandwidth) original = copy_visibility(self.vis) self.vis = addnoise_visibility(self.vis) actual = numpy.std(numpy.abs(self.vis.vis - original.vis)) assert abs(actual - 0.01077958403015586) < 1e-4, actual
def test_readwriteskymodel(self): self.vis = create_blockvisibility(self.mid, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) im = create_test_image() gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') sm = SkyModel(components=[self.comp], image=im, gaintable=gt) export_skymodel_to_hdf5(sm, '%s/test_data_model_helpers_skymodel.hdf' % self.dir) newsm = import_skymodel_from_hdf5('%s/test_data_model_helpers_skymodel.hdf' % self.dir) assert newsm.components[0].flux.shape == self.comp.flux.shape assert newsm.image.data.shape == im.data.shape assert numpy.max(numpy.abs(newsm.image.data - im.data)) < 1e-15
def test_phase_rotation_inverse_block(self): self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = dft_skycomponent_visibility(self.vis, self.comp) there = SkyCoord(ra=+250.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') # Phase rotating back should not make a difference original_vis = self.vismodel.vis original_uvw = self.vismodel.uvw rotatedvis = phaserotate_visibility(phaserotate_visibility(self.vismodel, there, tangent=False, inverse=True), self.phasecentre, tangent=False, inverse=True) assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7) assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear', f=None, vnchan=1): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.linspace(0.0, 30.0, 3) self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) if vnchan > 1: self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) else: self.channel_bandwidth = numpy.array([2e7]) if f is None: f = [100.0, 50.0, -10.0, 40.0] if sky_pol_frame == 'stokesI': f = [100.0] self.flux = numpy.outer( numpy.array( [numpy.power(freq / 1e8, -0.7) for freq in self.frequency]), f) # The phase centre is absolute and the component is specified relative (for now). # This means that the component should end up at the position phasecentre+compredirection self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.comp = Skycomponent( direction=self.compabsdirection, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame(sky_pol_frame)) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, channel_bandwidth=self.channel_bandwidth, weight=1.0, polarisation_frame=PolarisationFrame(data_pol_frame)) self.vis = dft_skycomponent_visibility(self.vis, self.comp)
def test_readwritepointingtable(self): self.vis = create_blockvisibility(self.mid, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_pointingtable_from_blockvisibility(self.vis, timeslice='auto') gt = simulate_pointingtable(gt, pointing_error=0.001) export_pointingtable_to_hdf5(gt, '%s/test_data_model_helpers_pointingtable.hdf' % self.dir) newgt = import_pointingtable_from_hdf5('%s/test_data_model_helpers_pointingtable.hdf' % self.dir) for key in gt.data.dtype.fields: assert numpy.max(numpy.abs(newgt.data[key] - gt.data[key])) < 1e-15 assert gt.data.shape == newgt.data.shape assert numpy.max(numpy.abs(gt.pointing - newgt.pointing)) < 1e-15
def test_coalesce_decoalesce_singletime(self): self.times = numpy.array([0.0]) self.blockvis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) # Fill in the vis values so each can be uniquely identified self.blockvis.data['vis'] = range(self.blockvis.nvis) cvis = coalesce_visibility(self.blockvis, time_coal=1.0) assert numpy.min(cvis.frequency) == numpy.min(self.frequency) assert numpy.min(cvis.frequency) > 0.0 dvis = decoalesce_visibility(cvis) assert dvis.nvis == self.blockvis.nvis
def actualSetUp(self, times=None): if times is not None: self.times = times self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.vis.data['vis'][:, 0] = self.vis.time self.blockvis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.blockvis.data['vis'][...] = 1.0
def test_dft_idft_stokesiquv_blockvisibility(self): for vpol in [ PolarisationFrame("linear"), PolarisationFrame("circular") ]: self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = dft_skycomponent_visibility(self.vis, self.comp) rcomp, weights = idft_visibility_skycomponent( self.vismodel, self.comp) assert_allclose(self.comp.flux, numpy.real(rcomp[0].flux), rtol=1e-11)
def test_readwriteblockvisibility(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0, meta={"RASCIL": 0.0}) self.vis = predict_skycomponent_visibility(self.vis, self.comp) config = { "buffer": { "directory": self.dir }, "vislist": { "name": "test_bufferblockvisibility.hdf", "data_model": "BlockVisibility" } } bdm = BufferBlockVisibility(config["buffer"], config["vislist"], self.vis) bdm.sync() new_bdm = BufferBlockVisibility(config["buffer"], config["vislist"]) new_bdm.sync() newvis = bdm.memory_data_model assert isinstance(newvis, BlockVisibility) assert numpy.array_equal(newvis.frequency, self.vis.frequency) assert newvis.data.shape == self.vis.data.shape assert numpy.max(numpy.abs(self.vis.vis - newvis.vis)) < 1e-15 assert numpy.max(numpy.abs(self.vis.uvw - newvis.uvw)) < 1e-15 assert numpy.abs(newvis.configuration.location.x.value - self.vis.configuration.location.x.value) < 1e-15 assert numpy.abs(newvis.configuration.location.y.value - self.vis.configuration.location.y.value) < 1e-15 assert numpy.abs(newvis.configuration.location.z.value - self.vis.configuration.location.z.value) < 1e-15 assert numpy.max( numpy.abs(newvis.configuration.xyz - self.vis.configuration.xyz)) < 1e-15 assert newvis.meta == self.vis.meta
def setUp(self): self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 30 * 3.76, 3.76) df = 27343.75000 self.frequency = numpy.array([1e8 - df, 1e8, 1e8 + df]) self.channel_bandwidth = numpy.array([27343.75, 27343.75, 27343.75]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.blockvis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth, meta={"RASCIL": 0.1})
def actualSetup(self, atmosphere="ionosphere"): dec = -40.0 * u.deg self.times = numpy.linspace(-10.0, 10.0, 3) * numpy.pi / (3600.0 * 12.0) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=dec, frame='icrs', equinox='J2000') if atmosphere == "ionosphere": self.core = create_named_configuration('LOWBD2', rmax=300.0) self.frequency = numpy.array([1.0e8]) self.channel_bandwidth = numpy.array([5e7]) self.cellsize = 0.000015 else: self.core = create_named_configuration('MID', rmax=300.0) self.frequency = numpy.array([1.36e9]) self.channel_bandwidth = numpy.array([1e8]) self.cellsize = 0.00015 self.vis = create_blockvisibility( self.core, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'] *= 0.0 # Create model self.model = create_image( npixel=512, cellsize=0.000015, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def test_predict_sky_components_coalesce(self): sc = create_low_test_skycomponents_from_gleam( flux_limit=10.0, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, kind='cubic', phasecentre=SkyCoord("17h20m31s", "-00d58m45s"), radius=0.1) self.config = create_named_configuration('LOWBD2-CORE') self.phasecentre = SkyCoord("17h20m31s", "-00d58m45s") sampling_time = 3.76 self.times = numpy.arange(0.0, +300 * sampling_time, sampling_time) self.vis = create_blockvisibility( self.config, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) self.vis = dft_skycomponent_visibility(self.vis, sc) cvt = convert_blockvisibility_to_visibility(self.vis) assert cvt.cindex is not None
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear'): self.lowcore = create_named_configuration('LOWBD2', rmax=100.0) self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 3000.0, 60.0) vnchan = 3 self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) # Define the component and give it some spectral behaviour f = numpy.array([100.0, 20.0, -10.0, 1.0]) self.flux = numpy.array([f, 0.8 * f, 0.6 * f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') if sky_pol_frame == 'stokesI': self.flux = self.flux[:, 0][:, numpy.newaxis] self.comp = Skycomponent( direction=self.compabsdirection, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame(sky_pol_frame)) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, channel_bandwidth=self.channel_bandwidth, weight=1.0, polarisation_frame=PolarisationFrame(data_pol_frame)) self.vis = dft_skycomponent_visibility(self.vis, self.comp)
def main(args): log = logging.getLogger('muser') if len(args.log) > 0: log.setLevel(level=logging.DEBUG) logging.basicConfig( format= '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s', level=logging.DEBUG) console = logging.StreamHandler() console.setLevel(logging.DEBUG) fh = logging.FileHandler(args.log, mode='w') fh.setLevel(logging.DEBUG) # 为logger对象添加句柄 log.addHandler(console) log.addHandler(fh) if args.muser == 1: muser_array = 'MUSER1' else: muser_array = 'MUSER2' start_time = args.start end_time = args.end fringe = args.fringe if args.nolimit == 0: nolimit = None else: nolimit = args.nolimit location = EarthLocation(lon=115.2505 * u.deg, lat=42.211833333 * u.deg, height=1365.0 * u.m) muser = MuserData(sub_array=args.muser) if not muser.init_data_environment(): print("No data environment prepared, exit.") return -1 if not muser.search_first_file(frame_time=args.start): print("Cannot find observational data or not a MUSER file.") return -1 data_file_name = os.path.basename(muser.current_file_name) print("Checking MUSER File Information V20200801") print("First Observational Time {}".format(muser.current_frame_time.isot)) # Check data print("Filename {} is a valid MUSER Data File.".format(data_file_name)) print("Current Observational Time {}".format( muser.current_frame_utc_time.isot)) print("Observational Mode: {} \nFrequency {}".format( "LOOP" if muser.is_loop_mode else "Non Loop", muser.frequency)) print("Sub Band: {} - Sub Channel {}".format(muser.sub_band, muser.sub_channels)) # count total frames muser.search_frame(search_time=start_time) total_frames = muser.count_frame_number(start_time, end_time) print("Total {} frames will be processed.".format(total_frames)) # Load Phase Calibration Data print("Loading Phase Calibration File") phase_cal = MuserPhase(muser.sub_array, muser.is_loop_mode, muser.current_frame_time) if not phase_cal.load_calibration_data(): print("Cannot find phase calibration file. ") exit(1) # # Create configuration of RASCIL # xx,yy,zz = locxyz2itrf(42.211833333,115.2505,0,0,1365) muser_core = create_configuration(muser_array) # for x,y,z in muser_core.xyz: # x,y,z = locxyz2itrf(42.211833333,115.2505,x,y,z+1365) # print('{},{},{}'.format(x-xx,y-yy,z-zz)) freq = [] if muser.is_loop_mode: if muser.sub_array == 1: for i in range(64): freq.append(400e6 + 25e6 * i) channelbandwidth = numpy.array([25e6] * 64) else: for i in range(33 * 16): freq.append(2e9 + 25e6 * i) channelbandwidth = numpy.array([25e6] * 16 * 33) else: if muser.sub_array == 1: for i in range(16): freq.append(muser.frequency + 25e6 * i) channelbandwidth = numpy.array([25e6] * 16) else: for i in range(16): freq.append(muser.frequency + 25e6 * i) channelbandwidth = numpy.array([25e6] * 16) frequency = numpy.array(freq) integration_time = [] # numpy.array([0.025]) times = [] utc_times = [] # Re-Search file if not muser.search_first_file(frame_time=args.start): print("Cannot find observational data or not a MUSER file.") return -1 if not muser.search_frame(search_time=start_time): print("Cannot locate the specified frame") return -1 log.info("Search file : {}".format(start_time)) count = 0 # total_frames = 1 if muser.is_loop_mode: vis_data = numpy.zeros((total_frames, muser.antennas, muser.antennas, muser.sub_channels * muser.frame_number, 2), dtype='complex') else: vis_data = numpy.zeros( (total_frames, muser.antennas, muser.antennas, 16, 1), dtype='complex') while count < total_frames: if not muser.read_full_frame(read_data=True): print("File reading error. ") exit(1) # Delay processing for the Sun if fringe: muser.delay_process('sun') if muser.is_loop_mode: obs_time = muser.first_frame_utc_time + 0.0125 * u.second else: obs_time = muser.first_frame_utc_time + 0.0015625 * u.second utc_times.append(obs_time) print("No.{} : Observation time (UTC) {}".format(count, obs_time)) # Compute the position of the Sun Alpha, Delta, ha, Thete_z, Phi = get_sun(obs_time) times.append([(ha * u.deg).to('rad').value ]) #[local_ha.to('rad').value]) integration_time.append(0.025) phasecentre = SkyCoord(ra=Alpha * u.deg, dec=Delta * u.deg, frame='icrs', equinox='J2000') # visshape = [ntimes, nants, nants, nchan, npol] utc_time = Time('%04d-%02d-%02dT00:00:00' % (muser.current_frame_utc_time.datetime.year, muser.current_frame_utc_time.datetime.month, muser.current_frame_utc_time.datetime.day), format='isot') # Phase Calibration muser.phase_calibration(phase_cal.phase_data) # Inject data into blockvisibility if muser.is_loop_mode: vis_data[count, :, :, :, 1] = deepcopy(muser.block_full_data[:, :, :, 0]) vis_data[count, :, :, :, 0] = deepcopy(muser.block_full_data[:, :, :, 1]) else: vis_data[count, :, :, :, 0] = deepcopy(muser.block_full_data[:, :, :, 0]) count = count + 1 times = numpy.array(times) integration_time = numpy.array(integration_time) if muser.is_loop_mode: bvis = create_blockvisibility( muser_core, times, frequency, phasecentre=phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('circularnp'), channel_bandwidth=channelbandwidth, integration_time=integration_time, source='SUN', elevation_limit=nolimit, utc_time=utc_times) else: bvis = create_blockvisibility( muser_core, times, frequency, phasecentre=phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=channelbandwidth, integration_time=integration_time, source='SUN', elevation_limit=nolimit, utc_time=utc_times) bvis.data['vis'] = copy.deepcopy(vis_data) bvis.vis[...] = copy.deepcopy(vis_data[...]) vis_list = [] vis_list.append(bvis) # Output results if len(args.output) == 0: output_time = Time(start_time, format='isot').datetime file_name = 'CSRH_%04d%02d%02d-%02d%02d%02d' % ( output_time.year, output_time.month, output_time.day, output_time.hour, output_time.minute, output_time.second) export_file_name = muser_output_path( file_name) + '.ms' #data_file_name else: export_file_name = muser_output_path(args.output) + '.ms' export_blockvisibility_to_ms(export_file_name, vis_list, source_name='SUN') print("Export file: {}".format(export_file_name)) print("Done. ")