示例#1
0
    def test_iter_interval(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        interval = 32
        for chunk in reader.readvis(items=['time'], interval=interval):
            nrow = chunk['time'].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()), chunk['time'].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            times = chunk['time']
            mintimeidx = times.argmin()
            maxtimeidx = times.argmax()
            timemin = times[mintimeidx]
            timemax = times[maxtimeidx]
            time_interval = timemax - timemin
            self.assertLessEqual(time_interval, interval)

        nrow_total_expected = self._expected_nrows()

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#2
0
    def test_iter_columns(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        columns = ['ANTENNA1']
        items = ['antenna1']
        antenna_list = []
        for chunk in reader.readvis(items=items,
                                    columns=columns,
                                    adddefault=False):
            nrow = chunk[items[0]].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()), chunk[items[0]].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            antenna = chunk['antenna1']
            self.assertTrue(numpy.all(antenna == antenna[0]))

            self.assertFalse(antenna[0] in antenna_list)

            antenna_list.append(antenna[0])

        nrow_total_expected = self._expected_nrows()

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#3
0
    def test_items(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        items = ['antenna1', 'antenna2', 'uvw', 'time']
        for chunk in reader.readvis(items=items):
            nrow = chunk[items[0]].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()),
                list(chunk.values())[0].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            # chunk has additional field 'chunk_id'
            self.assertEqual(len(chunk), len(items) + 1)
            for item in items:
                self.assertTrue(item in chunk)

        nrow_total_expected = self._expected_nrows()

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#4
0
    def test_msselect(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis, spw='1')
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        for chunk in reader.readvis(items=['data_desc_id']):
            nrow = chunk['data_desc_id'].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()),
                chunk['data_desc_id'].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            self.assertTrue('data_desc_id' in chunk)
            dd = chunk['data_desc_id']
            self.assertTrue(numpy.all(dd == 1))

        nrow_total_expected = self._expected_nrows('DATA_DESC_ID==1')

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#5
0
    def _test_lsr_freq(self, mfr='TOPO'):
        chunk = {}
        ndds = len(self.dd_spw_map)
        with casa.OpenTableForRead(os.path.join(self.vis, 'FIELD')) as tb:
            nfields = tb.nrows()
        with casa.OpenTableForReadWrite(
                os.path.join(self.vis, 'SPECTRAL_WINDOW')) as tb:
            mfrs = tb.getcol('MEAS_FREQ_REF')
            self.assertTrue(
                mfr in visconverter.VisibilityConverter.frequency_reference)
            mfr_id = visconverter.VisibilityConverter.frequency_reference.index(
                mfr)
            if not numpy.all(mfrs == mfr_id):
                mfrs[:] = mfr_id
                tb.putcol('MEAS_FREQ_REF', mfrs)

        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        imageparam = paramcontainer.ImageParamContainer(
            imagename=self.imagename, phasecenter=str(self.field_id))
        converter = visconverter.VisibilityConverter(visparam, imageparam)

        nchunk = 1
        chunk['time'] = numpy.empty(nchunk, dtype=numpy.float64)
        chunk['data_desc_id'] = numpy.empty(nchunk, dtype=numpy.int32)
        chunk['field_id'] = numpy.empty_like(chunk['data_desc_id'])
        with casa.OpenTableForRead(self.vis) as tb:
            chunk['time'][:] = tb.getcell('TIME', 0)
        for field_id in range(nfields):
            chunk['field_id'][0] = field_id
            for dd_id in range(ndds):
                chunk['data_desc_id'][0] = dd_id
                lsr_freq = converter.get_lsr_frequency(chunk)
                #print lsr_freq
                spw_id = self.dd_spw_map[dd_id]
                nchan = self.nchans[spw_id]
                self.assertEqual(nchan + 1, len(lsr_freq))
                self.assertEqual(mfrs[spw_id], mfr_id)

                # special case for LSRK
                with casa.OpenTableForRead(
                        os.path.join(self.vis, 'SPECTRAL_WINDOW')) as tb:
                    chan_freq = tb.getcell('CHAN_FREQ', spw_id)
                    chan_width = tb.getcell('CHAN_WIDTH', spw_id)
                expected = numpy.empty(nchan + 1, dtype=numpy.float64)
                expected[:-1] = chan_freq - chan_width / 2.0
                expected[-1] = chan_freq[-1] + chan_width[-1] / 2.0
                if mfr == 'LSRK':
                    self.assertTrue(numpy.all(lsr_freq == expected))
                else:
                    expected = self._convert(chunk['time'][0], field_id, mfr,
                                             expected)
                    self.assertMaxDiffLess(expected, lsr_freq, 1e-15)
示例#6
0
    def test_iter(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        reader = visreader.VisibilityReader(visparam)

        nrow_total = 0
        chunk_id = 0
        for chunk in reader.readvis(
                items=['time', 'data_desc_id', 'data', 'weight']):
            nrow = chunk['time'].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()),
                list(chunk.values())[0].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            nrow_total += nrow
            chunk_id += 1

            data_list = chunk['data']
            ddid_list = chunk['data_desc_id']
            weight_list = chunk['weight']

            for irow in range(nrow):
                data = data_list[..., irow]
                weight = weight_list[..., irow]
                ddid = ddid_list[irow]
                nchan = self.nchanmap[ddid]
                ncorr = self.ncorrmap[ddid]
                self.assertEqual(data.shape, (
                    ncorr,
                    nchan,
                ))
                self.assertEqual(weight.shape, (ncorr, ))

        print('LOG iterated {0} times in total'.format(chunk_id))
        print('LOG total number of rows {0}'.format(nrow_total))

        nrow_total_expected = self._expected_nrows()

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#7
0
    def test_msselect_chan(self):
        self.skipTest('Channel selection is not effective to ms iterator')
        visparam = paramcontainer.VisParamContainer(vis=self.vis, spw='0:0~9')
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        for chunk in reader.readvis(items=['time', 'data_desc_id', 'data']):
            nrow = chunk['time'].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()),
                list(chunk.values())[0].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            data_list = chunk['data']
            ddid_list = chunk['data_desc_id']

            for irow in range(nrow):
                data = data_list[:, :, irow]
                ddid = ddid_list[irow]
                self.assertEqual(ddid, 0)
                nchan = min(self.nchanmap[ddid], 10)
                print('nchan = {0}'.format(nchan))
                ncorr = self.ncorrmap[ddid]
                self.assertEqual(data.shape, (
                    ncorr,
                    nchan,
                ))

        print('LOG iterated {0} times in total'.format(chunk_id))
        print('LOG total number of rows {0}'.format(nrow_total))

        nrow_total_expected = self._expected_nrows('DATA_DESC_ID==0')

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)
示例#8
0
    def setUp(self):
        print('setUp: copying {0}...'.format(self.vis))
        shutil.copytree(os.path.join(self.datapath, self.vis), self.vis)

        self.assertTrue(os.path.exists(self.vis))

        with casa.OpenTableForRead(os.path.join(self.vis,
                                                'DATA_DESCRIPTION')) as tb:
            self.dd_spw_map = tb.getcol('SPECTRAL_WINDOW_ID')
            self.dd_pol_map = tb.getcol('POLARIZATION_ID')

        with casa.OpenTableForRead(os.path.join(self.vis,
                                                'SPECTRAL_WINDOW')) as tb:
            self.nchans = tb.getcol('NUM_CHAN')

        with casa.OpenTableForRead(os.path.join(self.vis,
                                                'POLARIZATION')) as tb:
            self.npols = tb.getcol('NUM_CORR')

        # avaliable FIELD_ID in MAIN table is only 6
        self.field_id = 6

        # default visparam
        self.visparam = paramcontainer.VisParamContainer(vis=self.vis)
示例#9
0
    def test_iter_nrow(self):
        visparam = paramcontainer.VisParamContainer(vis=self.vis)
        reader = visreader.VisibilityReader(visparam)

        chunk_id = 0
        nrow_total = 0
        nrow_chunk = 4
        for chunk in reader.readvis(nrow=nrow_chunk):
            nrow = chunk['time'].shape[-1]
            print('LOG chunk {0}: nrow={1} items={2} itemshape={3}'.format(
                chunk_id, nrow, list(chunk.keys()),
                list(chunk.values())[0].shape))

            self.verify_chunk_consistency(chunk, chunk_id)
            chunk_id += 1
            nrow_total += nrow

            self.assertLessEqual(nrow, nrow_chunk)

        nrow_total_expected = self._expected_nrows()

        print(
            'LOG number of rows for input ms {0}'.format(nrow_total_expected))
        self.assertEqual(nrow_total_expected, nrow_total)