diff --git a/cluster.py b/cluster.py index 3a51db60810b548d5fd2c776751b41f5c6537ebe..fc51a994e797f13904d0237f9cf65cc7dedc4819 100755 --- a/cluster.py +++ b/cluster.py @@ -456,7 +456,7 @@ def main(img, resid, model, auto=True, add_manual=False, nclusters=5, boxsize=25 nbright=80, cluster_radius=5, cluster_overlap=1.6): path = os.path.split(os.path.abspath(img))[0] - output = os.path.join(path, 'clustered.txt') + output = os.path.spitext(img)[0]+'-clustered.txt' df = pd.read_csv(model, skipinitialspace=True) df['ra'] = df.Ra.apply(ra2deg) @@ -492,6 +492,7 @@ def main(img, resid, model, auto=True, add_manual=False, nclusters=5, boxsize=25 write_df(df, clusters, output=output) fig.tight_layout() fig.savefig(path+'/clustering.png') + return output ### if __name__ == "__main__": diff --git a/imcal.py b/imcal.py index 5a616319e7e2b32e606973f8d8502725c56c9067..f7e52368b6300daacb67c652e5b3f2cde16ddce5 100755 --- a/imcal.py +++ b/imcal.py @@ -26,6 +26,8 @@ from astropy.time import Time import astropy.units as u from astropy.io import fits +from cluster import main as cluster + _POOL_TIME = 300 # SECONDS _MAX_TIME = 1 * 3600 # SECONDS @@ -325,6 +327,8 @@ def main(msin, outbase=None, cfgfile='imcal.yml'): img2 = outbase + '_2' img3 = outbase + '_3' img_final = outbase + img_ddsub = outbase + '-ddsub' + img_ddcal = outbase + '-ddcal' mask0 = 'mask0.fits' mask1 = 'mask1.fits' @@ -337,13 +341,15 @@ def main(msin, outbase=None, cfgfile='imcal.yml'): dical1 = outbase + '_dical1.MS' dical2 = outbase + '_dical2.MS' dical3 = outbase + '_dical3.MS' + ddsub = outbase + '_ddsub.MS' h5_1 = outbase + '_dical1.h5' h5_2 = outbase + '_dical2.h5' h5_3 = outbase + '_dical3.h5' + h5_dd = outbase + '_dd.h5' - if os.path.exists(img_final+'-image.fits'): + if os.path.exists(img_ddcal+'-image.fits'): logging.info('The final image exists. Exiting...') return 0 @@ -398,6 +404,31 @@ def main(msin, outbase=None, cfgfile='imcal.yml'): if (not os.path.exists(img_final +'-image.fits')) and (not os.path.exists(img_final +'-MFS-image.fits')): wsclean(dical3, outname=img_final, **cfg['clean4']) + +# Cluster + if (not os.path.exists(img_final +'-clustered.txt')): + clustered_model = cluster(img_final+'-image.fits', img_final+'-residual.fits', img_final+'-sources.txt', **cfg['cluster']) + +# Makesourcedb + clustered_sdb = makesourcedb(clustered_model, img_final+'-clustered.sourcedb') + +# DDE calibration + peeling everything + if (not os.path.exists(ddsub)): + ddsub, h5out = ddecal(dical3, clustered_sdb, msout=ddsub, h5out=h5_dd, + solint=120, mode='diagonal') + +# view the solutions and save figure + view_sols(h5_dd) + + if (not os.path.exists(img_ddsub+'-image.fits')): + wsclean(ddsub, outname=img_ddsub, **cfg['clean4']) + + aomodel = bbs2model(img_final+'-sources.txt', img_final+'-model.ao') + + render(img_ddsub+'-image.fits', aomodel, out=img_ddcal+'-image.fits') + + + return 0 diff --git a/imcal.yml b/imcal.yml index c52f0829a6e923860438b483c836353a294ba06a..6fc221375cd6413666073f27da0aa711bf4026ca 100644 --- a/imcal.yml +++ b/imcal.yml @@ -64,7 +64,7 @@ dical3: solint: 800 mode: 'diagonal' uvlambdamin: 500 # Ignore baselines / channels with UV < uvlambdamin wavelengths. - cal_nchan: 30 # number of chans with the same solutions + cal_nchan: 31 # number of chans with the same solutions clean4: imagesize: 3072 @@ -76,27 +76,38 @@ clean4: fitsmask: 'mask2.fits' kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3 -weight briggs 0.0' -### END - ####################### CLUSTERING ####################### -#cluster: -# nbright: 80 # number of brightest clean components (CC) to check for artefacts -# boxsize: 250 # the boxsize around CC in pixels where to check for artefacts -# nclusters: 10 # number of clusters ('auto' -- to set automatically) -# cluster_radius: 5 # arcmin -# cluster_overlap: 1.6 # if lower than 2 clusters can intersect -# auto: True -# add_manual: False -# +cluster: + nbright: 80 # number of brightest clean components (CC) to check for artefacts + boxsize: 250 # the boxsize around CC in pixels where to check for artefacts + nclusters: 10 # number of clusters ('auto' -- to set automatically) + cluster_radius: 5 # arcmin + cluster_overlap: 1.6 # if lower than 2 clusters can intersect + auto: True + add_manual: False + ######################## DD CALIBRATION ####################### -#ddcal: # see DPPP/DDECal documentation -# solint: 120 # Solution interval in timesteps (1 ~ 30sec for Apertif). -# mode: 'diagonal' # Type of constraint to apply. -# nchan: 15 # Number of channels in each channel block, for which the solution is assumed to be constant. -# startchan: 0 -# nchan: 192 -# uvlambdamin: 500 # Ignore baselines / channels with UV < uvlambdamin wavelengths. -# +ddcal: # see DPPP/DDECal documentation + solint: 120 # Solution interval in timesteps (1 ~ 30sec for Apertif). + mode: 'diagonal' # Type of constraint to apply. + nfreq: 15 # Number of channels in each channel block, for which the solution is assumed to be constant. + startchan: 0 + nchan: 0 + uvlambdamin: 500 # Ignore baselines / channels with UV < uvlambdamin wavelengths. + +clean5: + imagesize: 3072 + pixelsize: 3 + multifreq: 8 + automask: 4.5 + autothresh: 0.5 + multiscale: True + fitsmask: 'mask2.fits' + kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3 -weight briggs 0.0' + +### END + + ## TODO: #plotsols: #