Пример #1
0
 def test_deconvolve_and_restore_cube_mmclean_facets(self):
     self.actualSetUp(add_errors=True)
     dirty_imagelist = invert_list_rsexecute_workflow(self.vis_list, self.model_imagelist, context='2d',
                                                       dopsf=False, normalize=True)
     psf_imagelist = invert_list_rsexecute_workflow(self.vis_list, self.model_imagelist, context='2d',
                                                     dopsf=True, normalize=True)
     dirty_imagelist = rsexecute.persist(dirty_imagelist)
     psf_imagelist = rsexecute.persist(psf_imagelist)
     dec_imagelist = deconvolve_list_rsexecute_workflow(dirty_imagelist, psf_imagelist, self.model_imagelist,
                                                         niter=1000,
                                                         fractional_threshold=0.1, scales=[0, 3, 10],
                                                         algorithm='mmclean', nmoment=3, nchan=self.freqwin,
                                                         threshold=0.01, gain=0.7, deconvolve_facets=8,
                                                         deconvolve_overlap=8, deconvolve_taper='tukey')
     dec_imagelist = rsexecute.persist(dec_imagelist)
     residual_imagelist = residual_list_rsexecute_workflow(self.vis_list, model_imagelist=dec_imagelist,
                                                            context='2d')
     residual_imagelist = rsexecute.persist(residual_imagelist)
     restored_list = restore_list_rsexecute_workflow(model_imagelist=dec_imagelist, psf_imagelist=psf_imagelist,
                                                      residual_imagelist=residual_imagelist,
                                                      empty=self.model_imagelist)
     
     restored = rsexecute.compute(restored_list, sync=True)[0]
     
     if self.persist: export_image_to_fits(restored, '%s/test_imaging_%s_overlap_mmclean_restored.fits'
                          % (self.dir, rsexecute.type()))
Пример #2
0
 def test_deconvolve_spectral(self):
     self.actualSetUp(add_errors=True)
     dirty_imagelist = invert_list_rsexecute_workflow(self.vis_list, self.model_imagelist, context='2d',
                                                       dopsf=False, normalize=True)
     psf_imagelist = invert_list_rsexecute_workflow(self.vis_list, self.model_imagelist,
                                                     context='2d',
                                                     dopsf=True, normalize=True)
     dirty_imagelist = rsexecute.persist(dirty_imagelist)
     psf_imagelist = rsexecute.persist(psf_imagelist)
     deconvolved = deconvolve_list_rsexecute_workflow(dirty_imagelist, psf_imagelist, self.model_imagelist,
                                                       niter=1000,
                                                       fractional_threshold=0.1, scales=[0, 3, 10],
                                                       threshold=0.1, gain=0.7)
     deconvolved = rsexecute.persist(deconvolved)
     deconvolved = rsexecute.compute(deconvolved, sync=True)
     
     if self.persist: export_image_to_fits(deconvolved[0], '%s/test_imaging_%s_deconvolve_spectral.fits' %
                          (self.dir, rsexecute.type()))
Пример #3
0
    # Define a function to be executed by Dask to load the data, combine it, and select
    # only the short baselines. We load each channel separately.
    def load_ms(c):
        v1 = create_visibility_from_ms(input_vis[0], start_chan=c,
                                       end_chan=c)[0]
        v2 = create_visibility_from_ms(input_vis[1], start_chan=c,
                                       end_chan=c)[0]
        vf = append_visibility(v1, v2)
        vf = convert_visibility_to_stokes(vf)
        vf.configuration.diameter[...] = 35.0
        rows = vis_select_uvrange(vf, 0.0, uvmax=uvmax)
        return create_visibility_from_rows(vf, rows)

    # Construct the graph to load the data and persist the graph on the Dask cluster.
    vis_list = [rsexecute.execute(load_ms)(c) for c in range(nchan)]
    vis_list = rsexecute.persist(vis_list)

    # Construct the graph to define the model images and persist the graph to the cluster
    model_list = [
        rsexecute.execute(create_image_from_visibility)(
            v,
            npixel=npixel,
            cellsize=cellsize,
            polarisation_frame=PolarisationFrame("stokesIQUV"),
            nchan=1) for v in vis_list
    ]
    model_list = rsexecute.persist(model_list)

    # Construct the graphs to make the dirty image and psf, and persist these to the cluster
    dirty_list = invert_list_rsexecute_workflow(
        vis_list,
Пример #4
0
def weight_list_rsexecute_workflow(vis_list, model_imagelist, gcfcf=None, weighting='uniform', **kwargs):
    """ Weight the visibility data
    
    This is done collectively so the weights are summed over all vis_lists and then
    corrected

    :param vis_list:
    :param model_imagelist: Model required to determine weighting parameters
    :param weighting: Type of weighting
    :param kwargs: Parameters for functions in graphs
    :return: List of vis_graphs

    For example::

         vis_list = weight_list_rsexecute_workflow(vis_list, model_list, weighting='uniform')

   """
    centre = len(model_imagelist) // 2
    
    if gcfcf is None:
        gcfcf = [rsexecute.execute(create_pswf_convolutionfunction)(model_imagelist[centre])]
        
    def to_vis(v):
        if isinstance(v, BlockVisibility):
            av = convert_blockvisibility_to_visibility(v)
            return av
        else:
            return v
    
    avis_list = [rsexecute.execute(to_vis, nout=1)(vis) for vis in vis_list]
    
    def grid_wt(vis, model, g):
        if vis is not None:
            if model is not None:
                griddata = create_griddata_from_image(model)
                griddata = grid_weight_to_griddata(vis, griddata, g[0][1])
                return griddata
            else:
                return None
        else:
            return None
    
    weight_list = [rsexecute.execute(grid_wt, pure=True, nout=1)(avis_list[i], model_imagelist[i],
                                                                  gcfcf)
                   for i in range(len(vis_list))]
    
    merged_weight_grid = rsexecute.execute(griddata_merge_weights, nout=1)(weight_list)
    merged_weight_grid = rsexecute.persist(merged_weight_grid, broadcast=True)
    
    def re_weight(vis, model, gd, g):
        if gd is not None:
            if vis is not None:
                # Ensure that the griddata has the right axes so that the convolution
                # function mapping works
                agd = create_griddata_from_image(model)
                agd.data = gd[0].data
                vis = griddata_reweight(vis, agd, g[0][1])
                return vis
            else:
                return None
        else:
            return vis
    
    avis_list = [rsexecute.execute(re_weight, nout=1)(v, model_imagelist[i], merged_weight_grid, gcfcf)
              for i, v in enumerate(avis_list)]

    def to_bvis(v, ov):
        if isinstance(ov, BlockVisibility):
            av = convert_visibility_to_blockvisibility(v)
            return av
        else:
            return v

    result = [rsexecute.execute(to_bvis, nout=1)(vis, ovis) for vis, ovis in zip(avis_list, vis_list)]

    return rsexecute.optimize(result)
    blockvis_list = simulate_list_rsexecute_workflow(
        'LOWBD2',
        rmax=rmax,
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        times=times,
        phasecentre=phasecentre,
        order='frequency',
        format='blockvis')
    print('%d elements in vis_list' % len(blockvis_list))
    print('About to make visibility')
    vis_list = [
        rsexecute.execute(convert_blockvisibility_to_visibility, nout=1)(bv)
        for bv in blockvis_list
    ]
    vis_list = rsexecute.persist(vis_list)

    # The vis data are on the workers so we run the advice function on the workers
    # without transfering the data back to the host.
    advice_list = [
        rsexecute.execute(advise_wide_field)(v,
                                             guard_band_image=8.0,
                                             delA=0.02,
                                             wprojection_planes=1)
        for _, v in enumerate(vis_list)
    ]
    advice_list = rsexecute.compute(advice_list, sync=True)

    advice_low = advice_list[0]
    advice_high = advice_list[-1]
Пример #6
0
    channel_bandwidth = [1e7]
    phasecentre = SkyCoord(ra=ra * u.deg,
                           dec=declination * u.deg,
                           frame='icrs',
                           equinox='J2000')

    bvis_graph = create_standard_mid_simulation_rsexecute_workflow(
        band,
        rmax,
        phasecentre,
        time_range,
        time_chunk,
        integration_time,
        zerow=zerow)
    future_bvis_list = rsexecute.persist(bvis_graph)
    bvis_list0 = rsexecute.compute(bvis_graph[0], sync=True)
    nchunks = len(bvis_graph)
    memory_use['bvis_list'] = nchunks * bvis_list0.size()

    memory_use['vis_list'] = nchunks * bvis_list0.size()

    # We need the HWHM of the primary beam, and the location of the nulls
    HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(pbtype, frequency)

    HWHM = HWHM_deg * numpy.pi / 180.0

    FOV_deg = 4.0 * 1.36e9 / frequency[0]
    print('%s: HWHM beam = %g deg' % (pbtype, HWHM_deg))

    advice_list = rsexecute.execute(advise_wide_field)(bvis_list0,
Пример #7
0
 def actualSetUp(self, add_errors=False, freqwin=7, block=False, dospectral=True, dopol=False,
                 zerow=True):
     
     self.npixel = 256
     self.low = create_named_configuration('LOWBD2', rmax=750.0)
     self.freqwin = freqwin
     self.vis_list = list()
     self.ntimes = 5
     cellsize = 0.001
     self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0
     self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
     
     if freqwin > 1:
         self.channelwidth = numpy.array(freqwin * [self.frequency[1] - self.frequency[0]])
     else:
         self.channelwidth = numpy.array([1e6])
     
     if dopol:
         self.vis_pol = PolarisationFrame('linear')
         self.image_pol = PolarisationFrame('stokesIQUV')
         f = numpy.array([100.0, 20.0, -10.0, 1.0])
     else:
         self.vis_pol = PolarisationFrame('stokesI')
         self.image_pol = PolarisationFrame('stokesI')
         f = numpy.array([100.0])
     
     if dospectral:
         flux = numpy.array([f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
     else:
         flux = numpy.array([f])
     
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis_list = [rsexecute.execute(ingest_unittest_visibility)(self.low,
                                                                     [self.frequency[freqwin]],
                                                                     [self.channelwidth[freqwin]],
                                                                     self.times,
                                                                     self.vis_pol,
                                                                     self.phasecentre, block=block,
                                                                     zerow=zerow)
                      for freqwin, _ in enumerate(self.frequency)]
     
     self.model_imagelist = [rsexecute.execute(create_unittest_model, nout=freqwin)(self.vis_list[freqwin],
                                                                                     self.image_pol,
                                                                                     cellsize=cellsize,
                                                                                     npixel=self.npixel)
                             for freqwin, _ in enumerate(self.frequency)]
     
     self.componentlist = [rsexecute.execute(create_unittest_components)(self.model_imagelist[freqwin],
                                                                          flux[freqwin, :][numpy.newaxis, :])
                           for freqwin, _ in enumerate(self.frequency)]
     
     self.model_imagelist = [rsexecute.execute(insert_skycomponent, nout=1)(self.model_imagelist[freqwin],
                                                                             self.componentlist[freqwin])
                             for freqwin, _ in enumerate(self.frequency)]
     
     self.vis_list = [rsexecute.execute(predict_skycomponent_visibility)(self.vis_list[freqwin],
                                                                          self.componentlist[freqwin])
                      for freqwin, _ in enumerate(self.frequency)]
     
     # Calculate the model convolved with a Gaussian.
     
     self.model_imagelist = rsexecute.compute(self.model_imagelist, sync=True)
     model = self.model_imagelist[0]
     
     self.cmodel = smooth_image(model)
     if self.persist: export_image_to_fits(model, '%s/test_imaging_rsexecute_deconvolved_model.fits' % self.dir)
     if self.persist: export_image_to_fits(self.cmodel, '%s/test_imaging_rsexecute_deconvolved_cmodel.fits' % self.dir)
     
     if add_errors and block:
         self.vis_list = [rsexecute.execute(insert_unittest_errors)(self.vis_list[i])
                          for i, _ in enumerate(self.frequency)]
     
     #        self.vis_list = rsexecute.compute(self.vis_list, sync=True)
     self.vis_list = rsexecute.persist(self.vis_list)
     self.model_imagelist = rsexecute.scatter(self.model_imagelist)
Пример #8
0
    elif band == 'B2':
        frequency = [1.36e9]
    elif band == 'Ku':
        frequency = [12.179e9]
    else:
        raise ValueError("Unknown band %s" % band)

    channel_bandwidth = [1e7]
    phasecentre = SkyCoord(ra=ra * u.deg,
                           dec=declination * u.deg,
                           frame='icrs',
                           equinox='J2000')

    bvis_graph = create_standard_mid_simulation_rsexecute_workflow(
        band, rmax, phasecentre, time_range, time_chunk, integration_time)
    future_bvis_list = rsexecute.persist(bvis_graph)
    bvis_list0 = rsexecute.compute(bvis_graph[0], sync=True)
    nchunks = len(bvis_graph)
    memory_use['bvis_list'] = nchunks * bvis_list0.size()

    vis_graph = [
        rsexecute.execute(convert_blockvisibility_to_visibility)(bv)
        for bv in future_bvis_list
    ]
    future_vis_list = rsexecute.persist(vis_graph, sync=True)

    vis_list0 = rsexecute.compute(vis_graph[0], sync=True)
    memory_use['vis_list'] = nchunks * vis_list0.size()

    # We need the HWHM of the primary beam, and the location of the nulls
    HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(pbtype, frequency)
Пример #9
0
def simulate(parameters):
    """Simulate visibility data.

    :param parameters: pipeline parameters (dict)

    """
    # Get parameters, setting default value if not present
    freq_min = parameters.get("freq_min", 0.9e8)
    freq_max = parameters.get("freq_max", 1.1e8)
    nfreqwin = parameters.get("nfreqwin", 8)
    ntimes = parameters.get("ntimes", 5)
    rmax = parameters.get("rmax", 750.0)
    ra = parameters.get("ra", 0.0)
    dec = parameters.get("dec", -30.0)
    dir_vis = "/buffer/" + parameters.get("buffer_vis")

    frequency = numpy.linspace(freq_min, freq_max, nfreqwin)
    channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]])
    times = numpy.linspace(-numpy.pi / 6.0, numpy.pi / 6.0, ntimes)
    phasecentre = SkyCoord(ra=ra * u.deg,
                           dec=dec * u.deg,
                           frame="icrs",
                           equinox="J2000")

    npixel = 1024
    cellsize = 0.0005

    rsexecute.run(init_logging)

    vis_list = simulate_list_rsexecute_workflow(
        "LOWBD2",
        rmax=rmax,
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        times=times,
        phasecentre=phasecentre,
        order="frequency",
        format="blockvis",
    )
    vis_list = rsexecute.persist(vis_list)

    model_list = [
        rsexecute.execute(create_low_test_image_from_gleam)(
            npixel=npixel,
            frequency=[frequency[f]],
            channel_bandwidth=[channel_bandwidth[f]],
            cellsize=cellsize,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            flux_limit=3.0,
            applybeam=True,
        ) for f in range(nfreqwin)
    ]

    def print_max(v):
        print(numpy.max(numpy.abs(v.vis)))
        return v

    imaging_context = "ng"
    vis_slices = 1
    print("Using {}".format(imaging_context))

    predicted_vislist = predict_list_rsexecute_workflow(
        vis_list,
        model_list,
        context=imaging_context,
        vis_slices=vis_slices,
        verbosity=2,
    )
    corrupted_vislist = corrupt_list_rsexecute_workflow(predicted_vislist,
                                                        phase_error=1.0,
                                                        seed=180555)
    corrupted_vislist = [
        rsexecute.execute(print_max)(v) for v in corrupted_vislist
    ]
    export_list = [
        rsexecute.execute(export_blockvisibility_to_ms)(
            "{}/ska_pipeline_simulation_vislist_{}.ms".format(dir_vis, v),
            [corrupted_vislist[v]],
        ) for v, _ in enumerate(corrupted_vislist)
    ]

    print(
        "About to run predict and corrupt to get corrupted visibility, and write files"
    )
    rsexecute.compute(export_list, sync=True)
Пример #10
0
    def simulation(self,
                   args,
                   time_series='wind',
                   band='B2',
                   context='singlesource',
                   vp_directory=''):

        ra = args.ra
        declination = args.declination
        use_radec = args.use_radec == "True"
        integration_time = args.integration_time
        time_range = args.time_range
        time_chunk = args.time_chunk
        offset_dir = args.offset_dir
        pbtype = args.pbtype
        pbradius = args.pbradius
        rmax = args.rmax
        flux_limit = args.flux_limit
        npixel = args.npixel
        shared_directory = args.shared_directory
        vp_directory = args.vp_directory

        # Simulation specific parameters
        global_pe = numpy.array(args.global_pe)
        static_pe = numpy.array(args.static_pe)
        dynamic_pe = args.dynamic_pe

        seed = args.seed
        basename = os.path.basename(os.getcwd())

        use_dask = False
        rsexecute.set_client(use_dask=use_dask)

        # Set up details of simulated observation
        nfreqwin = 1
        if band == 'B1':
            frequency = [0.765e9]
        elif band == 'B2':
            frequency = [1.36e9]
        elif band == 'Ku':
            frequency = [12.179e9]
        else:
            raise ValueError("Unknown band %s" % band)

        phasecentre = SkyCoord(ra=ra * u.deg,
                               dec=declination * u.deg,
                               frame='icrs',
                               equinox='J2000')

        bvis_graph = create_standard_mid_simulation_rsexecute_workflow(
            band, rmax, phasecentre, time_range, time_chunk, integration_time,
            shared_directory)
        future_bvis_list = rsexecute.persist(bvis_graph)
        vis_graph = [
            rsexecute.execute(convert_blockvisibility_to_visibility)(bv)
            for bv in future_bvis_list
        ]
        future_vis_list = rsexecute.persist(vis_graph, sync=True)

        # We need the HWHM of the primary beam, and the location of the nulls
        HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(
            pbtype, frequency)

        HWHM = HWHM_deg * numpy.pi / 180.0

        FOV_deg = 8.0 * 1.36e9 / frequency[0]

        advice_list = rsexecute.execute(advise_wide_field)(
            future_vis_list[0], guard_band_image=1.0, delA=0.02, verbose=False)
        advice = rsexecute.compute(advice_list, sync=True)
        pb_npixel = 1024
        d2r = numpy.pi / 180.0
        pb_cellsize = d2r * FOV_deg / pb_npixel
        cellsize = advice['cellsize']

        # Now construct the components
        original_components, offset_direction = create_simulation_components(
            context, phasecentre, frequency, pbtype, offset_dir, flux_limit,
            pbradius * HWHM, pb_npixel, pb_cellsize)

        vp_list = [
            rsexecute.execute(create_image_from_visibility)(
                bv,
                npixel=pb_npixel,
                frequency=frequency,
                nchan=nfreqwin,
                cellsize=pb_cellsize,
                phasecentre=phasecentre,
                override_cellsize=False) for bv in future_bvis_list
        ]
        vp_list = [
            rsexecute.execute(create_vp)(vp,
                                         pbtype,
                                         pointingcentre=phasecentre,
                                         use_local=not use_radec)
            for vp in vp_list
        ]
        future_vp_list = rsexecute.persist(vp_list)

        # Make one image per component
        future_model_list = [
            rsexecute.execute(create_image_from_visibility)(
                future_vis_list[0],
                npixel=npixel,
                frequency=frequency,
                nchan=nfreqwin,
                cellsize=cellsize,
                phasecentre=offset_direction,
                polarisation_frame=PolarisationFrame("stokesI"))
            for i, _ in enumerate(original_components)
        ]

        a2r = numpy.pi / (3600.0 * 1800)

        no_error_gtl = None
        error_gtl = None
        if time_series == '':
            global_pointing_error = global_pe
            static_pointing_error = static_pe
            pointing_error = dynamic_pe

            no_error_gtl, error_gtl = \
                create_pointing_errors_gaintable_rsexecute_workflow(future_bvis_list, original_components,
                                                                     sub_vp_list=future_vp_list,
                                                                     use_radec=use_radec,
                                                                     pointing_error=a2r * pointing_error,
                                                                     static_pointing_error=a2r * static_pointing_error,
                                                                     global_pointing_error=a2r * global_pointing_error,
                                                                     seed=seed,
                                                                     show=False, basename=basename)

        elif time_series == 'wind':

            no_error_gtl, error_gtl = \
                create_pointing_errors_gaintable_rsexecute_workflow(future_bvis_list, original_components,
                                                                     sub_vp_list=future_vp_list,
                                                                     use_radec=use_radec,
                                                                     time_series=time_series,
                                                                     time_series_type='precision',
                                                                     seed=seed,
                                                                     show=False, basename=basename)
        elif time_series == 'gravity':
            no_error_gtl, error_gtl = \
                create_surface_errors_gaintable_rsexecute_workflow(band, future_bvis_list, original_components,
                                                                    vp_directory=vp_directory, use_radec=use_radec,
                                                                    show=False, basename=basename)
        else:
            raise ValueError("Unknown type of error %s" % time_series)

        # Now make all the residual images
        vis_comp_chunk_dirty_list = \
            calculate_residual_from_gaintables_rsexecute_workflow(future_bvis_list, original_components,
                                                                   future_model_list,
                                                                   no_error_gtl, error_gtl)

        # Add the resulting images
        error_dirty_list = sum_invert_results_rsexecute(
            vis_comp_chunk_dirty_list)

        # Actually compute the graph assembled above
        error_dirty, sumwt = rsexecute.compute(error_dirty_list, sync=True)

        return error_dirty, sumwt
Пример #11
0
def ical(parameters):
    """Iterative self-calibration.

    Calibrate visibilities and produce continuum image.

    :param parameters: pipeline parameters (dict)

    """
    # Get parameters, setting default value if not present
    nfreqwin = parameters.get("nfreqwin", 8)
    dir_vis = "/buffer/" + parameters.get("buffer_vis")
    dir_img = "/buffer/" + parameters.get("buffer_img")

    cellsize = 0.0005
    npixel = 1024
    pol_frame = PolarisationFrame("stokesI")
    centre = nfreqwin // 2

    rsexecute.run(init_logging)

    # Load data from simulation
    vis_list = [
        rsexecute.execute(create_blockvisibility_from_ms)(
            "{}/ska_pipeline_simulation_vislist_{}.ms".format(dir_vis, v))[0]
        for v in range(nfreqwin)
    ]

    print("Reading visibilities")
    vis_list = rsexecute.persist(vis_list)

    model_list = [
        rsexecute.execute(create_image_from_visibility)(
            v, npixel=npixel, cellsize=cellsize, polarisation_frame=pol_frame)
        for v in vis_list
    ]

    print("Creating model images")
    model_list = rsexecute.persist(model_list)

    imaging_context = "ng"
    vis_slices = 1

    controls = create_calibration_controls()

    controls["T"]["first_selfcal"] = 1
    controls["T"]["phase_only"] = True
    controls["T"]["timeslice"] = "auto"

    controls["G"]["first_selfcal"] = 3
    controls["G"]["timeslice"] = "auto"

    controls["B"]["first_selfcal"] = 4
    controls["B"]["timeslice"] = 1e5

    ical_list = ical_list_rsexecute_workflow(
        vis_list,
        model_imagelist=model_list,
        context=imaging_context,
        vis_slice=vis_slices,
        scales=[0, 3, 10],
        algorithm="mmclean",
        nmoment=2,
        niter=1000,
        fractional_threshold=0.1,
        threshold=0.1,
        nmajor=5,
        gain=0.25,
        deconvolve_facets=1,
        deconvolve_overlap=0,
        restore_facets=8,
        timeslice="auto",
        psf_support=128,
        global_solution=False,
        calibration_context="T",
        do_selfcal=True,
    )

    print("About to run ICAL workflow")
    result = rsexecute.compute(ical_list, sync=True)

    print("Writing images")
    deconvolved = result[0][centre]
    residual = result[1][centre][0]
    restored = result[2][centre]
    export_form = "{}/ska_pipeline_ical_{}.fits"
    export_list = [
        rsexecute.execute(export_image_to_fits)(deconvolved,
                                                export_form.format(
                                                    dir_img, "deconvolved")),
        rsexecute.execute(export_image_to_fits)(residual,
                                                export_form.format(
                                                    dir_img, "residual")),
        rsexecute.execute(export_image_to_fits)(restored,
                                                export_form.format(
                                                    dir_img, "restored")),
    ]
    rsexecute.compute(export_list, sync=True)
Пример #12
0
    times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
    phasecentre = SkyCoord(ra=+30.0 * u.deg,
                           dec=-45.0 * u.deg,
                           frame='icrs',
                           equinox='J2000')

    vis_list = simulate_list_rsexecute_workflow(
        'LOWBD2',
        rmax=rmax,
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        times=times,
        phasecentre=phasecentre,
        order='frequency',
        format='blockvis')
    vis_list = rsexecute.persist(vis_list)

    npixel = 1024
    cellsize = 0.0005

    dprepb_model = [
        rsexecute.execute(create_low_test_image_from_gleam)(
            npixel=npixel,
            frequency=[frequency[f]],
            channel_bandwidth=[channel_bandwidth[f]],
            cellsize=cellsize,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            flux_limit=3.0,
            applybeam=True) for f, freq in enumerate(frequency)
    ]
Пример #13
0
    def test_apply_voltage_pattern_image_pointsource(self):
        self.createVis(rmax=1e3)
        telescope = 'MID_FEKO_B2'
        vpol = PolarisationFrame("linear")
        self.times = numpy.linspace(-4, +4, 8) * numpy.pi / 12.0
        bvis = create_blockvisibility(self.config,
                                      self.times,
                                      self.frequency,
                                      channel_bandwidth=self.channel_bandwidth,
                                      phasecentre=self.phasecentre,
                                      weight=1.0,
                                      polarisation_frame=vpol,
                                      zerow=True)
        cellsize = advise_wide_field(bvis)['cellsize']

        pbmodel = create_image_from_visibility(
            bvis,
            cellsize=self.cellsize,
            npixel=self.npixel,
            override_cellsize=False,
            polarisation_frame=PolarisationFrame("stokesIQUV"))
        vpbeam = create_vp(pbmodel, telescope=telescope, use_local=False)
        vpbeam.wcs.wcs.ctype[0] = 'RA---SIN'
        vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN'
        vpbeam.wcs.wcs.crval[0] = pbmodel.wcs.wcs.crval[0]
        vpbeam.wcs.wcs.crval[1] = pbmodel.wcs.wcs.crval[1]

        s3_components = create_test_skycomponents_from_s3(
            flux_limit=0.1,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=1.5 * numpy.pi / 180.0)

        for comp in s3_components:
            comp.polarisation_frame = PolarisationFrame('stokesIQUV')
            comp.flux = numpy.array([[comp.flux[0, 0], 0.0, 0.0, 0.0]])

        s3_components = filter_skycomponents_by_flux(s3_components, 0.0, 10.0)

        from rascil.processing_components.image import show_image
        import matplotlib.pyplot as plt
        plt.clf()
        show_image(vpbeam, components=s3_components)
        plt.show(block=False)

        vpcomp = apply_voltage_pattern_to_skycomponent(s3_components, vpbeam)
        bvis.data['vis'][...] = 0.0 + 0.0j
        bvis = dft_skycomponent_visibility(bvis, vpcomp)

        rec_comp = idft_visibility_skycomponent(bvis, vpcomp)[0]

        stokes_comp = list()
        for comp in rec_comp:
            stokes_comp.append(
                convert_pol_frame(comp.flux[0], PolarisationFrame("linear"),
                                  PolarisationFrame("stokesIQUV")))

        stokesI = numpy.abs(
            numpy.array([comp_flux[0] for comp_flux in stokes_comp]).real)
        stokesQ = numpy.abs(
            numpy.array([comp_flux[1] for comp_flux in stokes_comp]).real)
        stokesU = numpy.abs(
            numpy.array([comp_flux[2] for comp_flux in stokes_comp]).real)
        stokesV = numpy.abs(
            numpy.array([comp_flux[3] for comp_flux in stokes_comp]).real)
        plt.clf()
        plt.loglog(stokesI, stokesQ, '.', label='Q')
        plt.loglog(stokesI, stokesU, '.', label='U')
        plt.loglog(stokesI, stokesV, '.', label='V')
        plt.xlabel("Stokes Flux I (Jy)")
        plt.ylabel("Flux (Jy)")
        plt.legend()
        plt.savefig('%s/test_primary_beams_pol_rsexecute_stokes_errors.png' %
                    self.dir)
        plt.show(block=False)

        split_times = False
        if split_times:
            bvis_list = list()
            for rows in vis_timeslice_iter(bvis, vis_slices=8):
                bvis_list.append(create_visibility_from_rows(bvis, rows))
        else:
            bvis_list = [bvis]

        bvis_list = rsexecute.scatter(bvis_list)

        model_list = \
            [rsexecute.execute(create_image_from_visibility, nout=1)(bv, cellsize=cellsize, npixel=4096,
                                                                     phasecentre=self.phasecentre,
                                                                     override_cellsize=False,
                                                                     polarisation_frame=PolarisationFrame("stokesIQUV"))
             for bv in bvis_list]

        model_list = rsexecute.persist(model_list)
        bvis_list = weight_list_rsexecute_workflow(bvis_list, model_list)

        continuum_imaging_list = \
            continuum_imaging_list_rsexecute_workflow(bvis_list, model_list,
                                                      context='2d',
                                                      algorithm='hogbom',
                                                      facets=1,
                                                      niter=1000,
                                                      fractional_threshold=0.1,
                                                      threshold=1e-4,
                                                      nmajor=5, gain=0.1,
                                                      deconvolve_facets=4,
                                                      deconvolve_overlap=32,
                                                      deconvolve_taper='tukey',
                                                      psf_support=64,
                                                      restore_facets=4, psfwidth=1.0)
        clean, residual, restored = rsexecute.compute(continuum_imaging_list,
                                                      sync=True)
        centre = 0
        if self.persist:
            export_image_to_fits(
                clean[centre],
                '%s/test_primary_beams_pol_rsexecute_clean.fits' % self.dir)
            export_image_to_fits(
                residual[centre][0],
                '%s/test_primary_beams_pol_rsexecute_residual.fits' % self.dir)
            export_image_to_fits(
                restored[centre],
                '%s/test_primary_beams_pol_rsexecute_restored.fits' % self.dir)

        plt.clf()
        show_image(restored[centre])
        plt.show(block=False)

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 0.9953017707113947) < 1.0e-7, str(qa)
        assert numpy.abs(qa.data['min'] +
                         0.0036396480874570846) < 1.0e-7, str(qa)
Пример #14
0
            return vis

    channels = []
    for i in range(0, len(ochannels) - 1, ngroup):
        channels.append([ochannels[i], ochannels[i + ngroup - 1]])
    print(channels)

    if single:
        channels = [channels[0]]
        log.info("Will read single range of channels %s" % channels)

    vis_list = [
        rsexecute.execute(read_convert)(target_ms, group_chan)
        for group_chan in channels
    ]
    vis_list = rsexecute.persist(vis_list)

    ####################################################################################################################

    log.info("\nSetup of images")
    phasecentre = SkyCoord(ra=0.0 * u.deg, dec=-27.0 * u.deg)

    advice = [
        rsexecute.execute(advise_wide_field)(v,
                                             guard_band_image=fov,
                                             delA=dela,
                                             verbose=(iv == 0))
        for iv, v in enumerate(vis_list)
    ]
    advice = rsexecute.compute(advice, sync=True)
Пример #15
0
    def _test(self, time_range=None, flux=None, test_vp=False, name=""):
        # Set up details of simulated observation

        npixel = 1024
        band = 'B2'
        frequency = [1.36e9]
        rmax = 1e3

        self.createVis(rmax=rmax)

        if time_range is None:
            time_range = [-0.01, 0.01]
        time_chunk = 1800.0
        integration_time = 1800.0
        imaging_context = "2d"
        cellsize = 1e-05
        vis_slices = 1
        telescope = "MID_FEKO_B2"

        result = dict()

        if flux is None:
            flux = [[1.0, 0.0, 0.0, 0.0]]
        else:
            flux = [flux]

        cellsize_deg = 180.0 * cellsize / numpy.pi
        offset = [0.0, 0.25 - 0.3309316221544 * cellsize_deg]
        ra = self.phasecentre.ra.deg
        dec = self.phasecentre.dec.deg
        print(ra, dec)
        odirection = SkyCoord(
            ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * u.deg,
            dec=(dec + offset[1]) * u.deg,
            frame='icrs',
            equinox='J2000')
        print(self.phasecentre)
        print(odirection)

        original_components = [
            Skycomponent(direction=odirection,
                         frequency=frequency,
                         flux=flux,
                         polarisation_frame=PolarisationFrame('stokesIQUV'))
        ]

        for method in ["fft", "dft"]:

            bvis_graph = create_standard_mid_simulation_rsexecute_workflow(
                band,
                rmax,
                self.phasecentre,
                time_range,
                time_chunk,
                integration_time,
                polarisation_frame=PolarisationFrame("linear"),
                zerow=True)  #imaging_context == "2d")
            bvis_graph = rsexecute.persist(bvis_graph)

            def find_vp_actual(telescope, normalise=True):
                vp = create_vp(telescope=telescope)
                if test_vp:
                    vp.data[:, 0, ...] = 1.0
                    vp.data[:, 1, ...] = 0.0
                    vp.data[:, 2, ...] = 0.0
                    vp.data[:, 3, ...] = 1.0
                if normalise:
                    g = numpy.zeros([4])
                    g[0] = numpy.max(numpy.abs(vp.data[:, 0, ...]))
                    g[3] = numpy.max(numpy.abs(vp.data[:, 3, ...]))
                    g[1] = g[2] = numpy.sqrt(g[0] * g[3])
                    for chan in range(4):
                        vp.data[:, chan, ...] /= g[chan]
                return vp

            future_model_list = [
                rsexecute.execute(create_image_from_visibility)(
                    bvis,
                    npixel=npixel,
                    frequency=frequency,
                    nchan=1,
                    cellsize=cellsize,
                    phasecentre=self.phasecentre,
                    polarisation_frame=PolarisationFrame("stokesIQUV"))
                for bvis in bvis_graph
            ]

            centre_model = \
                [rsexecute.execute(create_image_from_visibility)(v, npixel=npixel,
                                                                 nchan=1,
                                                                 cellsize=cellsize,
                                                                 phasecentre=self.phasecentre,
                                                                 polarisation_frame=PolarisationFrame("stokesIQUV"))
                 for v in bvis_graph]
            centre_model = rsexecute.persist(centre_model)

            # Now make all the residual images:
            if method == "dft":
                # The parallactic angle rotation is done when the voltage pattern is
                # converted to a gaintable
                def make_ejterm(model):
                    vp = find_vp_actual(telescope=telescope)
                    return vp

                vp_list = [
                    rsexecute.execute(make_ejterm)(centre_model[ibvis])
                    for ibvis, bvis in enumerate(bvis_graph)
                ]
                vp_list = rsexecute.persist(vp_list)
                gt_list = [
                    rsexecute.execute(simulate_gaintable_from_voltage_pattern)(
                        bvis,
                        original_components,
                        vp_list[ibv],
                        use_radec=False) for ibv, bvis in enumerate(bvis_graph)
                ]
                gt_list = rsexecute.persist(gt_list)
                dirty_list = \
                    calculate_residual_dft_rsexecute_workflow(bvis_graph, original_components,
                                                              future_model_list,
                                                              gt_list=gt_list,
                                                              context=imaging_context,
                                                              vis_slices=vis_slices,
                                                              do_wstacking=False)
                dirty_list = rsexecute.persist(dirty_list)

            else:

                def make_ejterm_rotated(model, bvis):
                    vp = find_vp_actual(telescope=telescope)
                    pa = numpy.average(
                        calculate_blockvisibility_parallactic_angles(bvis))
                    vp_rotated = convert_azelvp_to_radec(vp, model, -pa)
                    return vp_rotated

                vp_list = [
                    rsexecute.execute(make_ejterm_rotated)(centre_model[ibvis],
                                                           bvis)
                    for ibvis, bvis in enumerate(bvis_graph)
                ]
                vp_list = rsexecute.persist(vp_list)

                dirty_list = \
                    calculate_residual_fft_rsexecute_workflow(bvis_graph, original_components,
                                                              future_model_list, vp_list=vp_list,
                                                              context=imaging_context,
                                                              vis_slices=vis_slices,
                                                              do_wstacking=False)
                dirty_list = rsexecute.persist(dirty_list)

            dirty_list = rsexecute.compute(dirty_list, sync=True)

            for ipol, pol in enumerate(["I", "Q", "U", "V"]):
                result["model_{}".format(pol)] = flux[0][ipol]
                polimage = copy_image(dirty_list[0])
                polimage.data = polimage.data[:, ipol, ...][:, numpy.newaxis,
                                                            ...]
                qa = qa_image(polimage, context="Stokes " + pol)
                result["peak_{}_{}".format(method, pol)] = max(qa.data['min'],
                                                               qa.data['max'],
                                                               key=abs)
            export_image_to_fits(
                dirty_list[0],
                "{}/test_voltage_pattern_pol_rsexecute_{}_{}.fits".format(
                    self.dir, name, method))

        if self.verbose:
            print(name)
        for ipol, pol in enumerate(["I", "Q", "U", "V"]):
            result["peak_diff_{}".format(pol)] = result["peak_fft_{}".format(
                pol)] - result["peak_dft_{}".format(pol)]
            result["peak_modeldiff_{}".format(pol)] = result[
                "peak_dft_{}".format(pol)] - result["model_{}".format(pol)]
            if self.verbose:
                print(
                    "{} model: {:.2f} fft: {:.6f} dft: {:.6f} fft - dft: {:.6f} dft - model: {:.6f}"
                    .format(pol, result["model_{}".format(pol)],
                            result["peak_fft_{}".format(pol)],
                            result["peak_dft_{}".format(pol)],
                            result["peak_diff_{}".format(pol)],
                            result["peak_modeldiff_{}".format(pol)]))

        return result