示例#1
0
    def test_copy_ms(self):
        if run_ms_tests == False:
            return

        msfile = rascil_path("data/vis/ASKAP_example.ms")
        msoutfile = rascil_path("test_results/test_export_ms_ASKAP_output.ms")

        v = create_blockvisibility_from_ms(msfile)
        export_blockvisibility_to_ms(
            msoutfile,
            v)  # vis_by_channel.append(integrate_visibility_by_channel(v[0]))
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. ")
示例#3
0
    def test_export_ms(self):
        if run_ms_tests == False:
            return

        msoutfile = rascil_path("test_results/test_export_ms_ASKAP_output.ms")

        from astropy.coordinates import SkyCoord
        from astropy import units as u

        from rascil.processing_components.image.operations import show_image, export_image_to_fits
        from rascil.processing_components.simulation import create_named_configuration
        from rascil.processing_components.simulation import create_test_image
        from rascil.processing_components.imaging.base import create_image_from_visibility
        from rascil.processing_components.imaging.base import advise_wide_field

        from rascil.workflows.serial.imaging.imaging_serial import invert_list_serial_workflow, predict_list_serial_workflow

        from rascil.data_models.polarisation import PolarisationFrame

        lowr3 = create_named_configuration('LOWBD2', rmax=750.0)

        times = numpy.zeros([1])
        frequency = numpy.array([1e8])
        channelbandwidth = numpy.array([1e6])
        phasecentre = SkyCoord(ra=+15.0 * u.deg,
                               dec=-45.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')

        bvis = create_blockvisibility(
            lowr3,
            times,
            frequency,
            phasecentre=phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            channel_bandwidth=channelbandwidth)

        vt = convert_blockvisibility_to_visibility(bvis)

        advice = advise_wide_field(vt,
                                   guard_band_image=3.0,
                                   delA=0.1,
                                   facets=1,
                                   wprojection_planes=1,
                                   oversampling_synthesised_beam=4.0)
        cellsize = advice['cellsize']

        m31image = create_test_image(frequency=frequency, cellsize=cellsize)
        nchan, npol, ny, nx = m31image.data.shape
        m31image.wcs.wcs.crval[0] = vt.phasecentre.ra.deg
        m31image.wcs.wcs.crval[1] = vt.phasecentre.dec.deg
        m31image.wcs.wcs.crpix[0] = float(nx // 2)
        m31image.wcs.wcs.crpix[1] = float(ny // 2)
        vt = predict_list_serial_workflow([vt], [m31image], context='2d')[0]
        # uvdist = numpy.sqrt(vt.data['uvw'][:, 0] ** 2 + vt.data['uvw'][:, 1] ** 2)
        #
        # model = create_image_from_visibility(vt, cellsize=cellsize, npixel=512)
        # dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0]
        # psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0]
        #
        # show_image(dirty)
        # print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" % (dirty.data.max(), dirty.data.min(), sumwt))
        #
        # print("Max, min in PSF         = %.6f, %.6f, sumwt = %f" % (psf.data.max(), psf.data.min(), sumwt))
        # results_dir="/Users/f.wang"
        # export_image_to_fits(dirty, '%s/imaging_dirty.fits' % (results_dir))
        # export_image_to_fits(psf, '%s/imaging_psf.fits' % (results_dir))

        v = convert_visibility_to_blockvisibility(vt)
        vis_list = []
        vis_list.append(v)
        export_blockvisibility_to_ms(msoutfile, vis_list, source_name='M31')
示例#4
0
                    strength=1.2e-5,
                    freq_min=145,
                    freq_max=156,
                    width=0.1,
                    strength_std=1e-6)
    # rfi_arr=rfi_1+rfi_2+rfi_3+rfi_4+rfi_impulse(fqs=frequency,lsts=times,chance=0.01)+rfi_5+rfi_6
    rfi_arr = rfi_1 + rfi_impulse(fqs=frequency, lsts=times,
                                  chance=0.01) + rfi_5 + rfi_6
    vis = simulate_rfi_block(vis,
                             emitter_location=observatory,
                             attenuation=2e-5,
                             emitter=rfi_arr)

    vis = addnoise_visibility(vis)
    a = vis.data['vis']
    a = a[:, 0, 0, :, 0]
    a = numpy.abs(a)

    # numpy.save('/home/sunhaomin/re_map/re_map/SKA_rfi/ska_1.npy',a)
    # plt.imshow(a)
    # plt.show()
    # plt.close()
    # print(a)
    # numpy.save('/home/sunhaomin/1.npy',a)
    # print(type(vis))
    vis_list = []
    vis_list.append(vis)

    export_blockvisibility_to_ms(msoutfile, vis_list, source_name='TEST')
    print('Done.')
示例#5
0
 def test_export_ms(self):
     self.actualSetUp()
     msoutfile = "%s/test_imaging_ms_%dfreqwin.ms" % (self.dir,
                                                      len(self.frequency))
     export_blockvisibility_to_ms(msoutfile, [self.bvis], source_name='M31')