Imaging and deconvolution demonstrationΒΆ

This script makes a fake data set and then deconvolves it. Finally the full and residual visibility are plotted.

%matplotlib inline

import os
import sys

sys.path.append(os.path.join('..', '..'))

from data_models.parameters import arl_path
results_dir = arl_path('test_results')


from matplotlib import pylab

pylab.rcParams['figure.figsize'] = (8.0, 8.0)
pylab.rcParams['image.cmap'] = 'rainbow'

import numpy

from astropy.coordinates import SkyCoord
from astropy import units as u
from astropy.wcs.utils import pixel_to_skycoord

from matplotlib import pyplot as plt

from processing_components.image import  image_raster_iter

from processing_components.visibility import create_visibility
from processing_components.skycomponent import create_skycomponent
from processing_components.image import show_image, export_image_to_fits
from processing_components.image import  deconvolve_cube, restore_cube
from processing_components.visibility import  vis_timeslice_iter
from processing_components.simulation.configurations import create_named_configuration
from processing_components.simulation.testing_support import create_test_image
from processing_components.imaging import create_image_from_visibility
from processing_components.imaging import advise_wide_field

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

from data_models.polarisation import PolarisationFrame

import logging

log = logging.getLogger()
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler(sys.stdout))

mpl_logger = logging.getLogger("matplotlib")
mpl_logger.setLevel(logging.WARNING)
pylab.rcParams['figure.figsize'] = (12.0, 12.0)
pylab.rcParams['image.cmap'] = 'rainbow'

Construct LOW core configuration

lowr3 = create_named_configuration('LOWBD2', rmax=750.0)
create_named_configuration: LOWBD2
    (<Quantity -2565018.31203579 m>, <Quantity 5085711.90373391 m>, <Quantity -2861033.10788063 m>)
    GeodeticLocation(lon=<Longitude 116.76444824 deg>, lat=<Latitude -26.82472208 deg>, height=<Quantity 300. m>)
create_configuration_from_file: Maximum radius 750.0 m includes 236 antennas/stations
print(lowr3.xyz)
[[-2566715.76343079  5087507.98933145 -2865249.74542954]
 [-2566917.55774179  5087396.82932732 -2865029.92175911]
 [-2566767.64449879  5087463.93769549 -2865162.63143219]
 [-2566998.42494379  5087461.95681092 -2865158.71414809]
 [-2566815.87583079  5087432.4155484  -2865100.29503585]
 [-2566875.23076279  5087354.89797998 -2864947.00072334]
 [-2566872.40315079  5087406.12723061 -2865048.30876121]
 [-2566860.24566679  5087456.31825995 -2865147.56367198]
 [-2566729.00462579  5087407.55218624 -2865051.12667201]
 [-2567017.05977679  5087413.10529604 -2865062.10818455]
 [-2566960.58228279  5087412.41445943 -2865060.74202555]
 [-2566673.29943079  5087375.24982681 -2864987.24737236]
 [-2566853.29497379  5087483.87357926 -2865202.05549642]
 [-2566810.78114779  5087471.64931766 -2865177.88149541]
 [-2566900.85365779  5087430.21656409 -2865095.94645017]
 [-2567080.43813779  5087435.2210518  -2865105.84303902]
 [-2566807.56738579  5087396.35602863 -2865028.98579068]
 [-2566678.97956679  5087404.69609223 -2865045.47862375]
 [-2566903.95531079  5087459.98267183 -2865154.81020346]
 [-2566794.41338679  5087448.05632976 -2865131.22535109]
 [-2566668.41650679  5087429.62803232 -2865094.7826034 ]
 [-2566638.18472879  5087462.17996977 -2865159.15545428]
 [-2566762.64946679  5087486.35586805 -2865206.96432886]
 [-2566906.60853279  5087371.82656111 -2864980.47771778]
 [-2566732.85366479  5087369.47130951 -2864975.82010684]
 [-2566954.54090979  5087359.10595439 -2864955.32217302]
 [-2566839.84201979  5087378.42744905 -2864993.53125647]
 [-2566819.62521879  5087518.80493883 -2865271.13375649]
 [-2566909.38631779  5087491.0393898  -2865216.22619377]
 [-2566774.00973979  5087380.72705139 -2864998.07881861]
 [-2566728.43162879  5087474.87303277 -2865184.25653015]
 [-2566772.26583779  5087351.83109398 -2864940.93582489]
 [-2566925.21845179  5087512.96458953 -2865259.58421553]
 [-2566629.47767779  5087405.94173369 -2865047.9419331 ]
 [-2566947.11687179  5087470.37725704 -2865175.36594103]
 [-2567014.68059679  5087490.93933359 -2865216.02832833]
 [-2566763.03561679  5087433.73707463 -2865102.90841059]
 [-2566988.12346879  5087438.20362118 -2865111.74119775]
 [-2566769.91157079  5087520.47778566 -2865274.44188275]
 [-2567078.80634479  5087409.70901179 -2865055.39188693]
 [-2566946.14526979  5087429.52235474 -2865094.57362145]
 [-2566617.64406079  5087424.17554055 -2865084.00006732]
 [-2567082.85468779  5087466.56950655 -2865167.83595131]
 [-2566787.07654379  5087418.03108806 -2865071.8491493 ]
 [-2566927.92149979  5087531.61998083 -2865296.47605105]
 [-2567048.88597779  5087389.05643496 -2865014.55053147]
 [-2566670.88288079  5087495.21982095 -2865224.49317546]
 [-2567052.24921679  5087449.70837835 -2865134.49234794]
 [-2566837.11405979  5087339.36399984 -2864916.28161212]
 [-2566631.44579579  5087485.05289097 -2865204.38763586]
 [-2566811.34168679  5087363.89121826 -2864964.78523734]
 [-2566876.80027379  5087507.30580259 -2865248.39372193]
 [-2566989.23209179  5087386.7292889  -2865009.94850045]
 [-2566719.46299279  5087425.40038376 -2865086.42224725]
 [-2566602.90809379  5087444.80675731 -2865124.79918234]
 [-2567038.92082679  5087476.02648804 -2865186.53753736]
 [-2566802.73428779  5087496.54303355 -2865227.10988507]
 [-2566964.89220979  5087499.23892526 -2865232.44112641]
 [-2566855.47485079  5087423.6651422  -2865082.99073273]
 [-2566697.24070579  5087455.484647   -2865145.91516666]
 [-2567009.76030379  5087512.2068618  -2865258.0857765 ]
 [-2566971.95501079  5087522.56153689 -2865278.5625901 ]
 [-2566946.94248179  5087450.52063123 -2865136.09861281]
 [-2567001.57642279  5087362.95923593 -2864962.94220234]
 [-2566917.60756779  5087342.1290313  -2864921.74958029]
 [-2566862.00202479  5087534.41649056 -2865302.00626886]
 [-2567032.64278179  5087433.26152775 -2865101.96799626]
 [-2566727.78389479  5087349.54385804 -2864936.41271783]
 [-2566712.03895579  5087386.75289761 -2865009.99518767]
 [-2566879.50332079  5087386.14075714 -2865008.78465367]
 [-2566674.78174679  5087476.11586376 -2865186.71428168]
 [-2566638.45877079  5087386.3937079  -2865009.28487463]
 [-2566803.43184879  5087536.46539079 -2865306.05805684]
 [-2567060.54520479  5087491.56833775 -2865217.27221099]
 [-2566739.99120479  5087449.4655458  -2865134.01213617]
 [-2566609.32315979  5087518.86789538 -2865271.25825577]
 [-2566602.79598579  5087537.5705041  -2865308.24346575]
 [-2567086.94039979  5087317.98180038 -2864873.99739664]
 [-2566685.66867379  5087541.28157111 -2865315.58225976]
 [-2567202.93475879  5087388.04969149 -2865012.55965313]
 [-2566752.34799179  5087584.50802597 -2865401.06442613]
 [-2567017.03486379  5087546.39286051 -2865325.69005351]
 [-2566498.69752579  5087366.64051104 -2864970.22208158]
 [-2567057.06985879  5087534.07528818 -2865301.33152653]
 [-2566601.26384379  5087348.50844631 -2864934.36514677]
 [-2566957.82940979  5087558.75371524 -2865350.1341733 ]
 [-2567139.08305279  5087478.94385223 -2865192.30675002]
 [-2566783.26487379  5087562.41644075 -2865357.37736991]
 [-2567035.30845979  5087332.32691286 -2864902.36547114]
 [-2567214.81820179  5087409.11429682 -2865054.21581261]
 [-2567057.96672179  5087557.68682568 -2865348.02435349]
 [-2567187.38912279  5087427.96136825 -2865091.48670379]
 [-2567001.06570879  5087293.87335548 -2864826.32191401]
 [-2566502.09813279  5087500.75213251 -2865235.43355859]
 [-2567136.66650379  5087406.08338593 -2865048.22205648]
 [-2567172.40402679  5087355.94350902 -2864949.06830181]
 [-2566733.63842079  5087324.80303625 -2864887.48668281]
 [-2566521.15648479  5087412.3076582  -2865060.53082155]
 [-2566703.68068479  5087567.40069249 -2865367.23394126]
 [-2566707.21831379  5087525.70655676 -2865284.78200162]
 [-2566931.62106179  5087296.41691491 -2864831.35191175]
 [-2566979.92713179  5087327.03462293 -2864891.89974107]
 [-2566546.99113879  5087489.09953945 -2865212.39005659]
 [-2566641.36112079  5087315.26735907 -2864868.62947266]
 [-2566905.26323679  5087319.86712602 -2864877.72570887]
 [-2567141.62416679  5087338.47080262 -2864914.51527635]
 [-2566548.31152179  5087388.68431657 -2865013.81465142]
 [-2567123.47513479  5087455.84608536 -2865146.62992649]
 [-2566679.88888679  5087306.58103397 -2864851.45189265]
 [-2566784.11191179  5087304.45175169 -2864847.24114571]
 [-2567079.15512479  5087508.14672283 -2865250.05667774]
 [-2566838.58391879  5087562.27422623 -2865357.09613461]
 [-2566986.51658879  5087575.84306094 -2865383.92908656]
 [-2567126.15326879  5087363.46232653 -2864963.93708555]
 [-2567197.91481379  5087496.53122942 -2865227.0865419 ]
 [-2567054.10522579  5087370.72257235 -2864978.2945327 ]
 [-2566654.90126979  5087521.52668788 -2865276.51613185]
 [-2566877.41063979  5087284.94307374 -2864808.66189929]
 [-2566571.01960979  5087363.13349054 -2864963.2867983 ]
 [-2566585.03310379  5087472.47787151 -2865179.51999614]
 [-2567141.72381779  5087381.80124824 -2865000.20308891]
 [-2566835.66911279  5087303.66310751 -2864845.68156806]
 [-2566629.78908879  5087364.34484326 -2864965.6823002 ]
 [-2566499.64421479  5087442.60440026 -2865120.44392692]
 [-2567103.03411879  5087539.13092877 -2865311.32927238]
 [-2566543.10472979  5087518.55760945 -2865270.64465205]
 [-2567154.55394979  5087537.6767435  -2865308.45355873]
 [-2567120.18663479  5087522.25855826 -2865277.96343687]
 [-2567191.41255279  5087475.95509964 -2865186.39636375]
 [-2566902.03701879  5087575.87622559 -2865383.99467107]
 [-2566569.68677079  5087405.18175733 -2865046.43904728]
 [-2566639.85389179  5087549.55418133 -2865331.94170088]
 [-2566556.00960079  5087337.86428353 -2864913.31585887]
 [-2566736.24181679  5087297.86997562 -2864834.22540157]
 [-2567201.15348779  5087457.02314888 -2865148.95762004]
 [-2566469.16330879  5087471.67967139 -2865177.94152122]
 [-2567077.77245979  5087340.964896   -2864919.44745285]
 [-2566819.10204879  5087278.98524273 -2864796.88003321]
 [-2567016.91029979  5087315.18697701 -2864868.47051369]
 [-2567122.10492679  5087503.16528156 -2865240.2056642 ]
 [-2566556.34592479  5087539.09326684 -2865311.25479431]
 [-2566877.69713779  5087554.08424671 -2865340.90009924]
 [-2566639.24352579  5087567.49456549 -2865367.41957915]
 [-2566481.23359779  5087421.08841813 -2865077.89515048]
 [-2566576.89904879  5087503.72683187 -2865241.31615401]
 [-2566635.09553179  5087333.78109767 -2864905.24118391]
 [-2566538.42110879  5087432.19520001 -2865099.85928748]
 [-2566856.82014579  5087321.37920873 -2864880.7159172 ]
 [-2566597.98780079  5087324.10938917 -2864886.114966  ]
 [-2566593.96437079  5087382.08399091 -2865000.76222464]
 [-2567239.63142779  5087425.27390838 -2865086.17213677]
 [-2567252.47401679  5087480.99612474 -2865196.36520683]
 [-2566329.87540779  5087469.09676457 -2865172.83371231]
 [-2567331.98346679  5087497.60261581 -2865229.20525438]
 [-2566771.16967179  5087238.03984061 -2864715.90874636]
 [-2566742.88109879  5087623.48547174 -2865478.143995  ]
 [-2567062.47595279  5087612.75530553 -2865456.92463161]
 [-2566902.97125179  5087616.99981733 -2865465.31833553]
 [-2566364.49185179  5087509.75661311 -2865253.24030473]
 [-2567281.33558579  5087531.99153694 -2865297.21081919]
 [-2566904.35391679  5087226.03367876 -2864692.16604694]
 [-2567172.97702279  5087324.2504796  -2864886.39397835]
 [-2566451.62464279  5087551.3006652  -2865335.39544755]
 [-2566589.99076679  5087605.00264914 -2865441.59342147]
 [-2566333.00197379  5087429.60948227 -2865094.74591988]
 [-2566739.19399279  5087251.26466247 -2864742.06139817]
 [-2566667.02138479  5087584.70139246 -2865401.44681664]
 [-2567270.97182879  5087381.24812977 -2864999.10927343]
 [-2566437.11289079  5087504.56044482 -2865242.96465934]
 [-2567286.08148879  5087361.70628718 -2864960.4644425 ]
 [-2566634.33568879  5087596.63223136 -2865425.0405617 ]
 [-2566680.82311979  5087608.07628061 -2865447.67165939]
 [-2566838.16039979  5087650.24877414 -2865531.06957205]
 [-2566515.70056479  5087560.47827676 -2865353.5445676 ]
 [-2567068.60452079  5087255.39506574 -2864750.22944759]
 [-2567240.15459879  5087335.36513105 -2864908.37367777]
 [-2566978.37007679  5087621.05208673 -2865473.33187188]
 [-2567256.52235979  5087445.86802549 -2865126.89788563]
 [-2566848.62380879  5087247.95044709 -2864735.50739527]
 [-2566446.10643979  5087369.09581839 -2864975.07755706]
 [-2566439.54189679  5087404.52914492 -2865045.14847828]
 [-2567233.85164079  5087365.18857397 -2864967.35081382]
 [-2566563.40872579  5087259.83125766 -2864759.00220716]
 [-2567116.89813479  5087617.27019359 -2865465.85301618]
 [-2567171.55698879  5087556.30852565 -2865345.29870613]
 [-2567262.65092779  5087405.86584846 -2865047.79186681]
 [-2566422.25235979  5087481.69145818 -2865197.74025851]
 [-2566379.78835879  5087436.06646932 -2865107.5148884 ]
 [-2566403.86665579  5087362.68211419 -2864962.39418223]
 [-2566346.89090379  5087404.48642433 -2865045.0639965 ]
 [-2566798.64857579  5087606.4332257  -2865444.42244789]
 [-2567221.93082879  5087575.44789567 -2865383.1476303 ]
 [-2566943.59169979  5087236.82174287 -2864713.4999059 ]
 [-2567120.73471779  5087585.66204306 -2865403.34654436]
 [-2566590.94991279  5087273.99761825 -2864787.01679213]
 [-2566526.06432179  5087303.0043119  -2864844.37877152]
 [-2566840.01640979  5087599.90653707 -2865431.51564151]
 [-2566377.78287179  5087466.25247514 -2865167.20900812]
 [-2567273.71224479  5087316.61024582 -2864871.28508873]
 [-2566538.49584779  5087468.56331979 -2865171.77880241]
 [-2566981.48418679  5087645.12736698 -2865520.94177   ]
 [-2566943.72872079  5087599.66314225 -2865431.03431783]
 [-2567363.85949379  5087435.49255215 -2865106.37994261]
 [-2566746.40627079  5087641.75412961 -2865514.27104859]
 [-2567296.38296379  5087429.49818421 -2865094.52582319]
 [-2566736.29164179  5087603.93632186 -2865439.48471358]
 [-2566663.42147379  5087224.33553686 -2864688.80789858]
 [-2566715.11569579  5087217.09889974 -2864674.49713865]
 [-2566656.78219279  5087251.21013776 -2864741.95357322]
 [-2566700.55411879  5087261.42316061 -2864762.15026344]
 [-2566699.52023479  5087237.50021263 -2864714.84160892]
 [-2566619.27585479  5087239.68570644 -2864719.16351656]
 [-2567120.29874279  5087153.17770975 -2864548.09024697]
 [-2567031.98259079  5087154.17321091 -2864550.05889317]
 [-2567105.50049379  5087130.12266391 -2864502.49790611]
 [-2567127.07504579  5087177.56440048 -2864596.31597265]
 [-2567042.63284579  5087174.04726222 -2864589.36068107]
 [-2567161.49218679  5087163.50652794 -2864568.51592744]
 [-2567375.81767579  5087452.72523647 -2865140.45831412]
 [-2567415.87758279  5087473.34745957 -2865181.23964378]
 [-2567372.72847879  5087479.7718438  -2865193.94413883]
 [-2567311.57981979  5087473.83200056 -2865182.19784436]
 [-2567420.90998479  5087499.44803134 -2865232.85464264]
 [-2567328.19670979  5087454.94220856 -2865144.8424714 ]
 [-2567318.58033879  5087675.62253464 -2865581.2472705 ]
 [-2567324.92066579  5087657.77770985 -2865545.95836499]
 [-2567273.93646079  5087652.81032135 -2865536.13514141]
 [-2567361.55505279  5087643.93906115 -2865518.59184432]
 [-2567377.36227379  5087671.65851686 -2865573.40825552]
 [-2567269.26529679  5087675.85019032 -2865581.69746936]
 [-2566498.22418079  5087593.77388916 -2865419.38806755]
 [-2566565.90001379  5087589.59739302 -2865411.12886751]
 [-2566455.54842079  5087615.71089347 -2865462.76943338]
 [-2566437.51149679  5087586.81662197 -2865405.62977363]
 [-2566546.64235879  5087614.52989493 -2865460.43395818]
 [-2566528.72999979  5087577.78572176 -2865387.77078155]]

We create the visibility. This just makes the uvw, time, antenna1, antenna2, weight columns in a table

times = numpy.zeros([1])
frequency = numpy.array([1e8])
channel_bandwidth = numpy.array([1e6])
phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
vt = create_visibility(lowr3, times, frequency, channel_bandwidth=channel_bandwidth,
                       weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame('stokesI'))
create_visibility: 27730 rows, 0.003 GB
create_visibility: flagged 0/27730 visibilities below elevation limit 0.261799 (rad)
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']
advise_wide_field: Maximum wavelength 2.998 (meters)
advise_wide_field: Minimum wavelength 2.998 (meters)
advise_wide_field: Maximum baseline 383.3 (wavelengths)
advise_wide_field: Maximum w 125.8 (wavelengths)
advise_wide_field: Station/dish diameter 35.0 (meters)
advise_wide_field: Primary beam 0.0857 (rad) 4.91 (deg) 1.77e+04 (asec)
advise_wide_field: Image field of view 0.257 (rad) 14.7 (deg) 5.3e+04 (asec)
advise_wide_field: Synthesized beam 0.00261 (rad) 0.149 (deg) 538 (asec)
advise_wide_field: Cellsize 0.000652 (rad) 0.0374 (deg) 135 (asec)
advice_wide_field: Npixels per side = 394
advice_wide_field: Npixels (power of 2) per side = 512
advice_wide_field: Npixels (power of 2, 3) per side = 512
advice_wide_field: Npixels (power of 2, 3, 4, 5) per side = 396
advice_wide_field: W sampling for full image = 2.2 (wavelengths)
advice_wide_field: W sampling for primary beam = 19.4 (wavelengths)
advice_wide_field: Time sampling for full image = 154.7 (s)
advice_wide_field: Time sampling for primary beam = 1392.3 (s)
advice_wide_field: Frequency sampling for full image = 179047.9 (Hz)
advice_wide_field: Frequency sampling for primary beam = 1611431.2 (Hz)
advice_wide_field: Number of planes in w stack 12 (primary beam)
advice_wide_field: Number of planes in w projection 12 (primary beam)
advice_wide_field: W support = 2 (pixels) (primary beam)

Plot the synthesized uv coverage.

plt.clf()
plt.plot(vt.data['uvw'][:,0], vt.data['uvw'][:,1], '.', color='b')
plt.plot(-vt.data['uvw'][:,0], -vt.data['uvw'][:,1], '.', color='b')
plt.xlim([-400.0, 400.0])
plt.ylim([-400.0, 400.0])
plt.show()
../_images/imaging_serial_11_0.png

Read the venerable test image, constructing an image

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)

fig=show_image(m31image)
import_image_from_fits: created >f4 image of shape (256, 256), size 0.000 (GB)
import_image_from_fits: Max, min in /home/jenkins-slave/workspace/ce-library_feature-improved-docs/data/models/M31.MOD = 1.006458, 0.000000
replicate_image: replicating shape (256, 256) to (1, 1, 256, 256)
../_images/imaging_serial_13_1.png
vt = predict_list_serial_workflow([vt], [m31image], context='2d')[0]

# To check that we got the prediction right, plot the amplitude of the visibility.
uvdist=numpy.sqrt(vt.data['uvw'][:,0]**2+vt.data['uvw'][:,1]**2)
plt.clf()
plt.plot(uvdist, numpy.abs(vt.data['vis']), '.')
plt.xlabel('uvdist')
plt.ylabel('Amp Visibility')
plt.show()
shift_vis_from_image: shifting phasecentre from image phase centre <SkyCoord (ICRS): (ra, dec) in deg
    (14.94718025, -44.96261426)> to visibility phasecentre <SkyCoord (ICRS): (ra, dec) in deg
    (15., -45.)>
../_images/imaging_serial_14_1.png

Make the dirty image and point spread function

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))

export_image_to_fits(dirty, '%s/imaging_dirty.fits'%(results_dir))
export_image_to_fits(psf, '%s/imaging_psf.fits'%(results_dir))
create_image_from_visibility: Parsing parameters to get definition of WCS
create_image_from_visibility: Defining single channel Image at <SkyCoord (ICRS): (ra, dec) in deg
    (15., -45.)>, starting frequency 100000000.0 Hz, and bandwidth 999999.99999 Hz
create_image_from_visibility: uvmax = 363.929962 wavelengths
create_image_from_visibility: Critical cellsize = 0.001374 radians, 0.078718 degrees
create_image_from_visibility: Cellsize          = 0.000652292 radians, 0.0373736 degrees
create_image_from_visibility: image shape is [1, 1, 512, 512]
Max, min in dirty image = 14.043187, -3.380257, sumwt = 27730.000000
Max, min in PSF         = 0.999218, -0.010408, sumwt = 27730.000000
../_images/imaging_serial_16_1.png

Deconvolve using clean

comp, residual = deconvolve_cube(dirty, psf, niter=10000, threshold=0.001, fractional_threshold=0.001,
                                 window_shape='quarter', gain=0.7, scales=[0, 3, 10, 30])

restored = restore_cube(comp, psf, residual)

# Show the results

fig=show_image(comp)
plt.title('Solution')
fig=show_image(residual)
plt.title('Residual')
fig=show_image(restored)
plt.title('Restored')
deconvolve_cube : window is inner quarter
deconvolve_cube : Cleaning inner quarter of each sky plane
deconvolve_cube : PSF support = +/- 256 pixels
deconvolve_cube : PSF shape (1, 1, 512, 512)
deconvolve_cube : Multi-scale clean of each polarisation and channel separately
deconvolve_cube : Processing pol 0, channel 0
msclean : Peak of PSF = 0.9992177783230745 at (256, 256)
msclean : Peak of Dirty = 14.043187 Jy/beam at (296, 248)
msclean : Coupling matrix =
 [[1.         0.97147905 0.65793694 0.16093728]
 [0.97147905 0.94438729 0.64486321 0.16015474]
 [0.65793694 0.64486321 0.48833749 0.14897568]
 [0.16093728 0.16015474 0.14897568 0.09035157]]
msclean : Max abs in dirty Image = 14.054181 Jy/beam
msclean : Start of minor cycle
msclean : This minor cycle will stop at 10000 iterations or peak < 0.014054 (Jy/beam)
msclean : Timing for setup: 1.393 (s) for dirty shape (512, 512), PSF shape (512, 512) , scales [0, 3, 10, 30]
msclean : Minor cycle 0, peak [12.1549026  12.0872886  11.2104776   7.87106738] at [269, 261, 3]
msclean : Minor cycle 1000, peak [0.12706915 0.12545724 0.10532543 0.03441903] at [259, 255, 3]
msclean : Minor cycle 2000, peak [0.13836321 0.13242319 0.07130672 0.0123432 ] at [274, 241, 2]
msclean : At iteration 2076, absolute value of peak 0.012474 is below stopping threshold 0.014054
msclean : End of minor cycle
msclean : Timing for clean: 45.514 (s) for dirty shape (512, 512), PSF shape (512, 512) , scales [0, 3, 10, 30], 2077 iterations, time per clean 21.913 (ms)
restore_cube: psfwidth = Parameter('x_stddev', value=2.109685336948007)
Text(0.5, 1.0, 'Restored')
../_images/imaging_serial_18_2.png ../_images/imaging_serial_18_3.png ../_images/imaging_serial_18_4.png

Predict the visibility of the model

vtmodel = create_visibility(lowr3, times, frequency, channel_bandwidth=channel_bandwidth,
                            weight=1.0, phasecentre=phasecentre,
                            polarisation_frame=PolarisationFrame('stokesI'))
vtmodel=predict_list_serial_workflow([vtmodel], [comp], context='2d')[0]
create_visibility: 27730 rows, 0.003 GB
create_visibility: flagged 0/27730 visibilities below elevation limit 0.261799 (rad)

Now we will plot the original visibility and the residual visibility.

uvdist=numpy.sqrt(vt.data['uvw'][:,0]**2+vt.data['uvw'][:,1]**2)
plt.clf()
plt.plot(uvdist, numpy.abs(vt.data['vis'][:]-vtmodel.data['vis'][:]), '.', color='r',
         label='Residual')
plt.plot(uvdist, numpy.abs(vt.data['vis'][:]), '.', color='b', label='Original')

plt.xlabel('uvdist')
plt.ylabel('Amp Visibility')
plt.legend()
plt.show()
../_images/imaging_serial_22_0.png