def test_invert(self): uvfitsfile = rascil_path("data/vis/ASKAP_example.fits") nchan_ave = 32 nchan = 192 for schan in range(0, nchan, nchan_ave): max_chan = min(nchan, schan + nchan_ave) bv = create_blockvisibility_from_uvfits(uvfitsfile, range(schan, max_chan))[0] vis = convert_blockvisibility_to_visibility(bv) from rascil.processing_components.visibility.operations import convert_visibility_to_stokesI vis = convert_visibility_to_stokesI(vis) model = create_image_from_visibility( vis, npixel=256, polarisation_frame=PolarisationFrame('stokesI')) dirty, sumwt = invert_2d(vis, model, context='2d') assert (numpy.max(numpy.abs(dirty.data))) > 0.0 assert dirty.shape == (nchan_ave, 1, 256, 256) if self.doplot: import matplotlib.pyplot as plt from rascil.processing_components.image.operations import show_image show_image(dirty) plt.show(block=False) if self.persist: export_image_to_fits( dirty, '%s/test_visibility_uvfits_dirty.fits' % self.dir)
def test_crosssubtract_datamodel(self): self.actualSetUp(zerow=True) skymodel_vislist = predict_skymodel_list_serial_workflow( self.vis_list[0], self.skymodel_list, context='2d', docal=True) vobs = sum_predict_results(skymodel_vislist) skymodel_vislist = crosssubtract_datamodels_skymodel_list_serial_workflow( vobs, skymodel_vislist) result_skymodel = [ SkyModel(components=None, image=self.skymodel_list[-1].image) for v in skymodel_vislist ] results = invert_skymodel_list_serial_workflow(skymodel_vislist, result_skymodel, context='2d', docal=True) assert numpy.max(numpy.abs(results[0][0].data)) > 0.0 assert numpy.max(numpy.abs(results[0][1])) > 0.0 if self.plot: import matplotlib.pyplot as plt from rascil.processing_components.image.operations import show_image show_image(results[0][0], title='Dirty image after cross-subtraction', vmax=0.1, vmin=-0.01) plt.show(block=False)
def test_invertcal(self): self.actualSetUp(zerow=True) future_vis = rsexecute.scatter(self.vis_list[0]) future_skymodel = rsexecute.scatter(self.skymodel_list) skymodel_vislist = predict_skymodel_list_rsexecute_workflow(future_vis, future_skymodel, context='2d', docal=True) skymodel_vislist = rsexecute.compute(skymodel_vislist, sync=True) result_skymodel = [SkyModel(components=None, image=self.skymodel_list[-1].image) for v in skymodel_vislist] self.vis_list = rsexecute.scatter(self.vis_list) result_skymodel = invert_skymodel_list_rsexecute_workflow(skymodel_vislist, result_skymodel, context='2d', docal=True) results = rsexecute.compute(result_skymodel, sync=True) assert numpy.max(numpy.abs(results[0][0].data)) > 0.0 assert numpy.max(numpy.abs(results[0][1])) > 0.0 if self.plot: import matplotlib.pyplot as plt from rascil.processing_components.image.operations import show_image show_image(results[0][0], title='Dirty image, no cross-subtraction', vmax=0.1, vmin=-0.01) plt.show()
def create_simulation_components(context, phasecentre, frequency, pbtype, offset_dir, flux_limit, pbradius, pb_npixel, pb_cellsize, show=False): """ Construct components for simulation :param context: :param phasecentre: :param frequency: :param pbtype: :param offset_dir: :param flux_limit: :param pbradius: :param pb_npixel: :param pb_cellsize: :return: """ HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(pbtype, frequency) dec = phasecentre.dec.deg ra = phasecentre.ra.deg if context == 'singlesource': log.info("create_simulation_components: Constructing single component") offset = [HWHM_deg * offset_dir[0], HWHM_deg * offset_dir[1]] log.info( "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg" % (offset[0], offset[1])) # The point source is offset to approximately the halfpower point offset_direction = SkyCoord( ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * units.deg, dec=(dec + offset[1]) * units.deg, frame='icrs', equinox='J2000') original_components = [ Skycomponent(flux=[[1.0]], direction=offset_direction, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI')) ] elif context == 'null': log.info( "create_simulation_components: Constructing single component at the null" ) offset = [null_az_deg * offset_dir[0], null_el_deg * offset_dir[1]] HWHM = HWHM_deg * numpy.pi / 180.0 log.info( "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg" % (offset[0], offset[1])) # The point source is offset to approximately the null point offset_direction = SkyCoord( ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * units.deg, dec=(dec + offset[1]) * units.deg, frame='icrs', equinox='J2000') original_components = [ Skycomponent(flux=[[1.0]], direction=offset_direction, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI')) ] else: offset = [0.0, 0.0] # Make a skymodel from S3 max_flux = 0.0 total_flux = 0.0 log.info("create_simulation_components: Constructing s3sky components") from rascil.processing_components.simulation import create_test_skycomponents_from_s3 original_components = create_test_skycomponents_from_s3( flux_limit=flux_limit / 100.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI"), frequency=numpy.array(frequency), radius=pbradius) log.info( "create_simulation_components: %d components before application of primary beam" % (len(original_components))) pbmodel = create_image(npixel=pb_npixel, cellsize=pb_cellsize, phasecentre=phasecentre, frequency=frequency, polarisation_frame=PolarisationFrame("stokesI")) pb = create_pb(pbmodel, "MID_GAUSS", pointingcentre=phasecentre, use_local=False) pb_feko = create_pb(pbmodel, pbtype, pointingcentre=phasecentre, use_local=True) pb.data = pb_feko.data[:, 0, ...][:, numpy.newaxis, ...] pb_applied_components = [ copy_skycomponent(c) for c in original_components ] pb_applied_components = apply_beam_to_skycomponent( pb_applied_components, pb) filtered_components = [] for icomp, comp in enumerate(pb_applied_components): if comp.flux[0, 0] > flux_limit: total_flux += comp.flux[0, 0] if abs(comp.flux[0, 0]) > max_flux: max_flux = abs(comp.flux[0, 0]) filtered_components.append(original_components[icomp]) log.info( "create_simulation_components: %d components > %.3f Jy after application of primary beam" % (len(filtered_components), flux_limit)) log.info( "create_simulation_components: Strongest components is %g (Jy)" % max_flux) log.info( "create_simulation_components: Total flux in components is %g (Jy)" % total_flux) original_components = [ copy_skycomponent(c) for c in filtered_components ] if show: plt.clf() show_image(pb, components=original_components) plt.show(block=False) log.info("create_simulation_components: Created %d components" % len(original_components)) # Primary beam points to the phasecentre offset_direction = SkyCoord(ra=ra * units.deg, dec=dec * units.deg, frame='icrs', equinox='J2000') return original_components, offset_direction
def test_create_gradient(self): real_vp = import_image_from_fits(rascil_data_path('models/MID_GRASP_VP_real.fits')) gradx, grady = image_gradients(real_vp) gradxx, gradxy = image_gradients(gradx) gradyx, gradyy = image_gradients(grady) gradx.data *= real_vp.data grady.data *= real_vp.data gradxx.data *= real_vp.data gradxy.data *= real_vp.data gradyx.data *= real_vp.data gradyy.data *= real_vp.data if self.show: import matplotlib.pyplot as plt plt.clf() show_image(gradx, title='gradx') plt.show(block=False) plt.clf() show_image(grady, title='grady') plt.show(block=False) if self.persist: export_image_to_fits(gradx, "%s/test_image_gradients_gradx.fits" % (self.dir)) export_image_to_fits(grady, "%s/test_image_gradients_grady.fits" % (self.dir)) if self.show: import matplotlib.pyplot as plt plt.clf() show_image(gradxx, title='gradxx') plt.show(block=False) plt.clf() show_image(gradxy, title='gradxy') plt.show(block=False) plt.clf() show_image(gradyx, title='gradyx') plt.show(block=False) plt.clf() show_image(gradyy, title='gradyy') plt.show(block=False) if self.persist: export_image_to_fits(gradxx, "%s/test_image_gradients_gradxx.fits" % (self.dir)) export_image_to_fits(gradxy, "%s/test_image_gradients_gradxy.fits" % (self.dir)) export_image_to_fits(gradyx, "%s/test_image_gradients_gradyx.fits" % (self.dir)) export_image_to_fits(gradyy, "%s/test_image_gradients_gradyy.fits" % (self.dir))
# Calculate the model convolved with a Gaussian. cmodel = smooth_image(model) if persist: export_image_to_fits(model, '%s/test_imaging_2d_model.fits' % rdir) if persist: export_image_to_fits(cmodel, '%s/test_imaging_2d_cmodel.fits' % rdir) # In[4]: print(qa_image(model)) # In[5]: plt.rcParams['figure.figsize'] = 10, 10 show_image(cmodel) plt.savefig("cmodel.png") # In[6]: # Find nw based on w_min, w_max w_min = numpy.amin(vis.data['uvw'][:, 2]) w_max = numpy.amax(vis.data['uvw'][:, 2]) w_range = 2 * numpy.amax((numpy.abs(w_min), numpy.abs(w_max))) wstep = 3.0 nw = numpy.floor(w_range / wstep) nw = int(1.1 * nw) if nw % 2 == 0: nw = nw + 1 print(w_min, w_max, w_range, wstep, nw)
filtered_components = [] for icomp, comp in enumerate(pb_applied_components): if comp.flux[0, 0] > flux_limit: total_flux += comp.flux[0, 0] if abs(comp.flux[0, 0]) > max_flux: max_flux = abs(comp.flux[0, 0]) filtered_components.append(original_components[icomp]) print("%d components > %.3f Jy after application of primary beam" % (len(filtered_components), flux_limit)) print("Strongest components is %g (Jy)" % max_flux) print("Total flux in components is %g (Jy)" % total_flux) original_components = [ copy_skycomponent(c) for c in filtered_components ] plt.clf() show_image(pb, components=original_components) plt.show(block=False) print("Created %d components" % len(original_components)) # Primary beam points to the phasecentre offset_direction = SkyCoord(ra=+15.0 * u.deg, dec=declination * u.deg, frame='icrs', equinox='J2000') ses = [0.03, 0.1, 0.3, 1.0, 3.0] nants = len(mid.names) nbaselines = nants * (nants - 1) // 2 memory_use['model_list'] = 8 * npixel * npixel * len(frequency) * len(
def create_simulation_components( context, phasecentre, frequency, pbtype, offset_dir, flux_limit, pbradius, pb_npixel, pb_cellsize, show=False, fov=10, polarisation_frame=PolarisationFrame("stokesI"), filter_by_primary_beam=True, flux_max=10.0): """ Construct components for simulation :param context: singlesource or null or s3sky :param phasecentre: Centre of components :param frequency: Frequency :param pbtype: Type of primary beam :param offset_dir: Offset in ra, dec degrees :param flux_limit: Lower limit flux :param pbradius: Radius of components in radians :param pb_npixel: Number of pixels in the primary beam model :param pb_cellsize: Cellsize in primary beam model :param fov: FOV in degrees (used to select catalog) :param flux_max: Maximum flux in model before application of primary beam :param filter_by_primary_beam: Filter components by primary beam :param polarisation_frame: :param show: :return: """ HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(pbtype, frequency) dec = phasecentre.dec.deg ra = phasecentre.ra.deg if context == 'singlesource': log.info("create_simulation_components: Constructing single component") offset = [HWHM_deg * offset_dir[0], HWHM_deg * offset_dir[1]] log.info( "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg" % (offset[0], offset[1])) # The point source is offset to approximately the halfpower point odirection = SkyCoord( ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * units.deg, dec=(dec + offset[1]) * units.deg, frame='icrs', equinox='J2000') if polarisation_frame.type == "stokesIQUV": original_components = [ Skycomponent( flux=[[1.0, 0.0, 0.0, 0.0]], direction=odirection, frequency=frequency, polarisation_frame=PolarisationFrame('stokesIQUV')) ] else: original_components = [ Skycomponent(flux=[[1.0]], direction=odirection, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI')) ] offset_direction = odirection elif context == 'doublesource': original_components = [] log.info( "create_simulation_components: Constructing double components") for sign_offset in [(-1, 0), (1, 0)]: offset = [HWHM_deg * sign_offset[0], HWHM_deg * sign_offset[1]] log.info( "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg" % (offset[0], offset[1])) odirection = SkyCoord( ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * units.deg, dec=(dec + offset[1]) * units.deg, frame='icrs', equinox='J2000') if polarisation_frame.type == "stokesIQUV": original_components.append( Skycomponent( flux=[[1.0, 0.0, 0.0, 0.0]], direction=odirection, frequency=frequency, polarisation_frame=PolarisationFrame('stokesIQUV'))) else: original_components.append( Skycomponent( flux=[[1.0]], direction=odirection, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI'))) for o in original_components: print(o) offset_direction = odirection elif context == 'null': log.info( "create_simulation_components: Constructing single component at the null" ) offset = [null_az_deg * offset_dir[0], null_el_deg * offset_dir[1]] HWHM = HWHM_deg * numpy.pi / 180.0 log.info( "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg" % (offset[0], offset[1])) # The point source is offset to approximately the null point offset_direction = SkyCoord( ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) * units.deg, dec=(dec + offset[1]) * units.deg, frame='icrs', equinox='J2000') if polarisation_frame.type == "stokesIQUV": original_components = [ Skycomponent( flux=[[1.0, 0.0, 0.0, 0.0]], direction=offset_direction, frequency=frequency, polarisation_frame=PolarisationFrame('stokesIQUV')) ] else: original_components = [ Skycomponent(flux=[[1.0]], direction=offset_direction, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI')) ] else: offset = [0.0, 0.0] # Make a skymodel from S3 max_flux = 0.0 total_flux = 0.0 log.info("create_simulation_components: Constructing s3sky components") from rascil.processing_components.simulation import create_test_skycomponents_from_s3 all_components = create_test_skycomponents_from_s3( flux_limit=flux_limit / 100.0, phasecentre=phasecentre, polarisation_frame=polarisation_frame, frequency=numpy.array(frequency), radius=pbradius, fov=fov) original_components = filter_skycomponents_by_flux(all_components, flux_max=flux_max) log.info( "create_simulation_components: %d components before application of primary beam" % (len(original_components))) if filter_by_primary_beam: pbmodel = create_image( npixel=pb_npixel, cellsize=pb_cellsize, phasecentre=phasecentre, frequency=frequency, polarisation_frame=PolarisationFrame("stokesI")) stokesi_components = [ copy_skycomponent(o) for o in original_components ] for s in stokesi_components: s.flux = numpy.array([[s.flux[0, 0]]]) s.polarisation_frame = PolarisationFrame("stokesI") pb = create_pb(pbmodel, "MID_GAUSS", pointingcentre=phasecentre, use_local=False) pb_applied_components = [ copy_skycomponent(c) for c in stokesi_components ] pb_applied_components = apply_beam_to_skycomponent( pb_applied_components, pb) filtered_components = [] for icomp, comp in enumerate(pb_applied_components): if comp.flux[0, 0] > flux_limit: total_flux += comp.flux[0, 0] if abs(comp.flux[0, 0]) > max_flux: max_flux = abs(comp.flux[0, 0]) filtered_components.append(original_components[icomp]) log.info( "create_simulation_components: %d components > %.3f Jy after filtering with primary beam" % (len(filtered_components), flux_limit)) log.info( "create_simulation_components: Strongest components is %g (Jy)" % max_flux) log.info( "create_simulation_components: Total flux in components is %g (Jy)" % total_flux) original_components = [ copy_skycomponent(c) for c in filtered_components ] if show: plt.clf() show_image(pb, components=original_components) plt.show(block=False) log.info("create_simulation_components: Created %d components" % len(original_components)) # Primary beam points to the phasecentre offset_direction = SkyCoord(ra=ra * units.deg, dec=dec * units.deg, frame='icrs', equinox='J2000') return original_components, offset_direction
default=None, help='Second image') parser.add_argument('--outimage', type=str, default=None, help='Second image') parser.add_argument('--mode', type=str, default='pipeline', help='Imaging mode') args = parser.parse_args() pp.pprint(vars(args)) im1 = import_image_from_fits(args.image1) im2 = import_image_from_fits(args.image2) print(qa_image(im1, context='Image 1')) print(qa_image(im2, context='Image 2')) outim = copy_image(im1) outim.data -= im2.data print(qa_image(outim, context='Difference image')) export_image_to_fits(outim, args.outimage) plt.clf() show_image(outim) plt.savefig(args.outimage.replace('.fits', '.jpg')) plt.show(block=False)