'parallel_gridding': 2, 'auto_mask': 2.5 } else: kwargs = { 'baseline_averaging': '', 'parallel_gridding': 2, 'auto_mask': 2.0, 'fits_mask': maskname } #kwargs = {'temp_dir':'./', 'pol':'I', 'fits_mask':maskname, \ # 'use_idg':'', 'grid_with_beam':'', 'use_differential_lofar_beam':'', 'beam_aterm_update':600, 'auto_mask':2.0} lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=imgsizepix, scale='10arcsec', \ weight='briggs -0.3', niter=1000000, no_update_model_required='', minuv_l=30, maxuv_l=4500, mgain=0.85, \ parallel_deconvolution=512, local_rms='', auto_threshold=1.5, \ multiscale='', multiscale_scale_bias=0.6, \ join_channels='', fit_spectral_pol=3, channels_out=MSs.getChout(4.e6), deconvolution_channels=3, **kwargs) os.system('cat logs/wsclean-c' + str(c) + '.log | grep "background noise"') w.done('imaging_c%02i' % c) ### DONE if c == 0: # make a mask for next cycle im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) im.makeMask(threshisl=5) maskname = imagename + '-mask.fits'
imagenameM = 'img/wideM-' + str(c) with w.if_todo('imaging_c%02i' % c): logger.info('Cleaning (cycle: ' + str(c) + ')...') if c == 0: # make temp mask for cycle 0, in cycle 1 use the maske made from cycle 0 image lib_util.run_wsclean(s, 'wsclean-c' + str(c) + '.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix, scale='10arcsec', weight='briggs -0.3', niter=1000000, no_update_model_required='', minuv_l=30, parallel_gridding=2, baseline_averaging='', maxuv_l=4500, mgain=0.85, parallel_deconvolution=512, local_rms='', auto_threshold=4, join_channels='', fit_spectral_pol=cc_fit_order, channels_out=MSs.getChout(4.e6), deconvolution_channels=cc_fit_order) im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) im.makeMask(threshpix=5) kwargs = { 'do_predict': True,
def clean(p, MSs, size, res='normal', apply_beam=False): """ p = patch name mss = list of mss to clean size = in deg of the image """ # set pixscale and imsize pixscale = MSs.resolution if res == 'normal': pixscale = float('%.1f' % (pixscale / 2.5)) elif res == 'high': pixscale = float('%.1f' % (pixscale / 3.5)) elif res == 'low': pass # no change imsize = [0, 0] imsize[0] = int(size[0] * 1.1 / (pixscale / 3600.)) # add 10% imsize[1] = int(size[1] * 1.1 / (pixscale / 3600.)) # add 10% imsize[0] += imsize[0] % 2 imsize[1] += imsize[1] % 2 if imsize[0] < 64: imsize[0] == 64 if imsize[1] < 64: imsize[1] == 64 logger.debug('Image size: ' + str(imsize) + ' - Pixel scale: ' + str(pixscale)) if res == 'normal': weight = 'briggs -0.1' maxuv_l = None elif res == 'high': weight = 'briggs -0.6' maxuv_l = None elif res == 'low': weight = 'briggs 0' maxuv_l = 3500 # clean 1 logger.info('Cleaning (' + str(p) + ')...') imagename = 'img/ddcal-' + str(p) lib_util.run_wsclean(s, 'wscleanA-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, size=imsize, scale=str(pixscale)+'arcsec', \ weight=weight, niter=10000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, \ baseline_averaging='', parallel_deconvolution=512, auto_threshold=5, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) # make mask im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) im.makeMask(threshpix=3) # clean 2 logger.info('Cleaning w/ mask (' + str(p) + ')...') imagename = 'img/ddcalM-' + str(p) if apply_beam: lib_util.run_wsclean(s, 'wscleanB-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=imsize, scale=str(pixscale)+'arcsec', \ weight=weight, niter=100000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, \ use_idg='', grid_with_beam='', use_differential_lofar_beam='', beam_aterm_update=400, \ multiscale='', multiscale_scales='0,10,20,40,80', \ parallel_deconvolution=512, local_rms='', auto_threshold=0.75, auto_mask=1.5, fits_mask=im.maskname, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) else: lib_util.run_wsclean(s, 'wscleanB-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, size=imsize, save_source_list='', scale=str(pixscale)+'arcsec', \ weight=weight, niter=100000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, \ multiscale='', multiscale_scales='0,10,20,40,80', baseline_averaging='', parallel_deconvolution=512, local_rms='', auto_threshold=0.75, auto_mask=1.5, fits_mask=im.maskname, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) os.system('cat logs/wscleanA-' + str(p) + '.log logs/wscleanB-' + str(p) + '.log | grep "background noise"')
# correct phases - MS:DATA -> MS:CORRECTED_DATA logger.info('Correcting Gp...') MSs.run('DPPP '+parset_dir+'/DPPP-cor.parset msin=$pathMS cor.parmdb=self/solutions/cal-tec'+str(c)+'.h5 cor.correction=tec000', \ log='$nameMS_corGp-c'+str(c)+'.log', commandType='DPPP') # set image size at 1.5 * FWHM imgsizepix = int(1.5 * MSs.getListObj()[0].getFWHM() / (2. / 3600)) imgsizepix += imgsizepix % 2 # make even if c >= 2: imgsizepix *= 2 # last cycle make a very large image to catch source in the sidelobes # clean mask clean logger.info('Cleaning (cycle: ' + str(c) + ')...') imagename = 'img/wide-' + str(c) lib_util.run_wsclean(s, 'wscleanA-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix, scale='2arcsec', \ weight='briggs 0.', niter=10000, no_update_model_required='', mgain=0.9, \ baseline_averaging=5, parallel_deconvolution=256, auto_threshold=20, \ join_channels='', fit_spectral_pol=2, channels_out=8) # make mask im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) im.makeMask(threshisl=4, atrous_do=False) # baseline averaging possible as we cut longest baselines (also it is in time, where smearing is less problematic) # TODO: add -parallel-deconvolution=256 when source lists can be saved (https://sourceforge.net/p/wsclean/tickets/141/) logger.info('Cleaning w/ mask (cycle: ' + str(c) + ')...') imagename = 'img/wideM-' + str(c) lib_util.run_wsclean(s, 'wscleanB-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=imgsizepix, scale='2arcsec', \ weight='briggs 0.', niter=100000, no_update_model_required='', mgain=0.9, \ #multiscale='', multiscale_scales='0,5,10,20,40', \ baseline_averaging=5, auto_threshold=1, fits_mask=im.maskname, \ join_channels='', fit_spectral_pol=2, channels_out=8)
with w.if_todo('sub-field'): # Low res image logger.info('Cleaning wide 1...') imagename = 'img/img-wide' lib_util.run_wsclean(s, 'wsclean-wide.log', MSs.getStrWsclean(), name=imagename, parallel_gridding=4, baseline_averaging='', size=2500, scale='10arcsec', weight='briggs -0.7', taper_gaussian='30arcsec', niter=1000000, no_update_model_required='', minuv_l=30, mgain=0.75, nmiter=0, auto_threshold=5, local_rms='', local_rms_method='rms-with-min', join_channels='', fit_spectral_pol=2, channels_out=2) os.system('cat logs/wsclean-wide.log | grep "background noise"') # makemask im = lib_img.Image(imagename + '-MFS-image.fits', userReg=region) im.makeMask(threshpix=5, rmsbox=(50, 5))
# Plot solutions lib_util.run_losoto(s, 'g-c'+str(c), [ms+'/cal-g-c'+str(c)+'.h5' for ms in MSs.getListStr()], \ [parset_dir+'/losoto-amp.parset', parset_dir+'/losoto-plot-amp.parset', parset_dir+'/losoto-plot-ph.parset']) os.system('mv plots-g-c' + str(c) + ' ddcal/plots') os.system('mv cal-g-c' + str(c) + '.h5 ddcal/solutions') ### DONE ########################################################### # use idg and A-term to correct the data, single image if aterm_imaging: #wsclean -mem 90.0 -scale 0.0004166666666666667 -aterm-config /beegfs/rafferty/Data/LOFAR/Screens/Factor_sim/pipelines/image_1/sector_3/chunk9.ms.make_aterm_config -multiscale-scales 0 -size 1500 1500 -deconvolution-channels 4 -fits-mask /beegfs/rafferty/Data/LOFAR/Screens/Factor_sim/pipelines/image_1/sector_3/chunk9.ms.premask -j 6 -auto-mask 3.6 -idg-mode hybrid -channels-out 12 -local-rms-window 50 -mgain 0.5 -minuv-l 80.0 -fit-spectral-pol 3 -maxuv-l 1000000.0 -weighting-rank-filter 3 -aterm-kernel-size 32 -temp-dir /tmp -name /beegfs/rafferty/Data/LOFAR/Screens/Factor_sim/pipelines/image_1/sector_3/chunk9.ms.image -padding 1.2 -pol I -multiscale-shape gaussian -auto-threshold 1.0 -local-rms-method rms-with-min -weight briggs -0.5 -niter 13635 -no-update-model-required -multiscale -fit-beam -reorder -save-source-list -local-rms -join-channels -use-idg -apply-primary-beam -nmiter 4 lib_util.run_wsclean(s, 'wscleanDD-c%02i.log' %c, MSs.getStrWsclean(), name='img/wideDD-c%02i' %c, save_source_list='', size=imsize, scale=str(pixscale)+'arcsec', \ weight=weight, niter=100000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, \ use_idg='', grid_with_beam='', use_differential_lofar_beam='', beam_aterm_update=400, \ multiscale='', multiscale_scales='0,10,20,40,80', \ parallel_deconvolution=512, local_rms='', auto_threshold=0.75, auto_mask=1.5, fits_mask=im.maskname, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) # TODO: put proper names os.system('cp img/wideDD-c%02i.MFS-image.fits ddcal/images/c%02i' % (c, c)) mosaic_image = lib_img.Image('ddcal/images/c%02i/mos-MFS-image.fits' % c, userReg=userReg) ########################################################### # facet imaging else: ###########################################################
def clean(p, MSs, res='normal', size=[1, 1], empty=False, imagereg=None): """ p = patch name mss = list of mss to clean size = in deg of the image """ # set pixscale and imsize pixscale = MSs.resolution if res == 'normal': pixscale = float('%.1f' % (pixscale / 2.5)) elif res == 'high': pixscale = float('%.1f' % (pixscale / 3.5)) elif res == 'low': pass # no change imsize = [ int(size[0] * 1.5 / (pixscale / 3600.)), int(size[1] * 1.5 / (pixscale / 3600.)) ] # add 50% imsize[0] += imsize[0] % 2 imsize[1] += imsize[1] % 2 if imsize[0] < 256: imsize[0] = 256 if imsize[1] < 256: imsize[1] = 256 logger.debug('Image size: ' + str(imsize) + ' - Pixel scale: ' + str(pixscale)) if res == 'normal': weight = 'briggs -0.3' maxuv_l = None elif res == 'high': weight = 'briggs -0.6' maxuv_l = None elif res == 'low': weight = 'briggs 0' maxuv_l = 3500 else: logger.error('Wrong "res": %s.' % str(res)) sys.exit() if empty: logger.info('Cleaning empty (' + str(p) + ')...') imagename = 'img/empty-' + str(p) lib_util.run_wsclean(s, 'wscleanE-' + str(p) + '.log', MSs.getStrWsclean(), name=imagename, data_column='SUBTRACTED_DATA', size=imsize, scale=str(pixscale) + 'arcsec', weight=weight, niter=0, no_update_model_required='', minuv_l=30, mgain=0, baseline_averaging='') else: # clean 1 logger.info('Cleaning (' + str(p) + ')...') imagename = 'img/extract-' + str(p) lib_util.run_wsclean(s, 'wscleanA-' + str(p) + '.log', MSs.getStrWsclean(), name=imagename, size=imsize, scale=str(pixscale) + 'arcsec', weight=weight, niter=10000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, baseline_averaging='', parallel_deconvolution=512, auto_threshold=5, join_channels='', fit_spectral_pol=3, channels_out=ch_out, deconvolution_channels=3) # make mask im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) try: im.makeMask(threshpix=10, rmsbox=(70, 5)) except: logger.warning('Fail to create mask for %s.' % imagename + '-MFS-image.fits') return if imagereg is not None: lib_img.blank_image_reg(im.maskname, imagereg, inverse=True, blankval=0.) # clean 2 # TODO: add deconvolution_channels when bug fixed logger.info('Cleaning w/ mask (' + str(p) + ')...') imagenameM = 'img/extractM-' + str(p) lib_util.run_wsclean( s, 'wscleanB-' + str(p) + '.log', MSs.getStrWsclean(), name=imagenameM, do_predict=True, size=imsize, scale=str(pixscale) + 'arcsec', weight=weight, niter=100000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, reuse_psf=imagename, reuse_dirty=imagename, mgain=0.85, multiscale='', baseline_averaging='', parallel_deconvolution=512, auto_threshold=0.7, auto_mask=1.5, fits_mask=im.maskname, join_channels='', fit_spectral_pol=3, channels_out=ch_out) # , deconvolution_channels=3) os.system('cat logs/wscleanB-' + str(p) + '.log | grep "background noise"')
logger.info('Flag...') MSs.run('DPPP ' + parset_dir + '/DPPP-flag2.parset msin=$pathMS', log='$nameMS_flag2.log', commandType='DPPP') lib_util.check_rm('img') os.makedirs('img') imgsizepix = MSs.getListObj()[0].getFWHM() * 3600 / 5 logger.info('Cleaning low-res...') imagename = 'img/calLR' lib_util.run_wsclean(s, 'wscleanLR.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix/5, scale='60arcsec', \ weight='briggs 0.', taper_gaussian='240arcsec', niter=10000, no_update_model_required='', minuv_l=30, maxuv_l=2000, mgain=0.85, \ use_idg='', grid_with_beam='', use_differential_lofar_beam='', beam_aterm_update=400, \ parallel_deconvolution=512, \ auto_mask=10, auto_threshold=1, pol='IQUV', join_polarizations='', join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) logger.info('Cleaning normal...') imagename = 'img/cal' lib_util.run_wsclean(s, 'wscleanA.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix, scale='5arcsec', \ weight='briggs 0.', niter=10000, no_update_model_required='', minuv_l=30, mgain=0.85, \ baseline_averaging='', parallel_deconvolution=512, \ auto_threshold=20, join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) # make mask im = lib_img.Image(imagename + '-MFS-image.fits') im.makeMask(threshisl=3) logger.info('Cleaning w/ mask...')
'w') as file: # Use file to refer to the file object file.write('aterms = [diagonal, beam]') file.write('diagonal.images = [' + ' '.join( sorted(glob.glob('ddcal/c%02i/aterm/TC*fits' % cmaj))) + ']') file.write( 'diagonal.window = tukey\n diagonal.update_interval = 48.066724' ) file.write( 'beam.differential = true\n beam.update_interval = 120\n beam.usechannelfreq = true' ) # run the imager lib_util.run_wsclean(s, 'wsclean-c'+str(cmaj)+'.log', MSs.getStrWsclean(), name=imagename, size='6000 6000', save_source_list='', scale='5arcsec', \ weight='briggs -0.3', niter=2000, no_update_model_required='', minuv_l=30, mgain=0.85, \ multiscale='', multiscale_scale_bias=0.65, multiscale_scales='0,10,20,40,80', parallel_deconvolution=512, local_rms='', auto_threshold=0.5, auto_mask=1.5, \ join_channels='', fit_spectral_pol=3, channels_out=ch_out_idg, deconvolution_channels=3, \ temp_dir='./', pol='I', use_idg='', aterm_config=aterm_config_file, aterm_kernel_size=45, nmiter=4 ) sys.exit('Not implemente further on...') else: ddf_parms = { 'Data_MS': MSs.getStrDDF(), 'Data_ColName': 'CORRECTED_DATA', 'Data_Sort': 1, 'Output_Mode': 'Clean', 'Deconv_CycleFactor': 0, 'Deconv_MaxMinorIter': 1000000, 'Deconv_RMSFactor': 2.0,
logger.info('BP correction...') if c == 0 and lofar_system == 'lba': MSs.run('DPPP '+parset_dir+'/DPPP-cor.parset msin=$pathMS cor.updateweights=True cor.parmdb=cal-bp-c'+str(c)+'.h5 cor.correction=fulljones \ cor.soltab=\[amplitude000,phase000\]' , \ log='$nameMS_corBP3.log', commandType='DPPP') else: MSs.run('DPPP '+parset_dir+'/DPPP-cor.parset msin=$pathMS cor.updateweights=False cor.parmdb=cal-bp-c'+str(c)+'.h5 cor.correction=fulljones \ cor.soltab=\[amplitude000,phase000\]' , \ log='$nameMS_corBP3.log', commandType='DPPP') logger.info('Cleaning (cycle %02i)...' % c) imagename = 'img/img-c%02i' % c if patch == 'CygA': lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1000, scale='1.5arcsec', \ weight='briggs -1.4', niter=50000, no_update_model_required='', nmiter=50, mgain=0.5, \ multiscale='', multiscale_scale_bias=0.5, multiscale_scales='0,5,10,20,40', \ fits_mask='/home/fdg/scripts/LiLF/parsets/LOFAR_ateam/masks/CygA.fits', \ baseline_averaging=5, auto_threshold=1, \ join_channels='', deconvolution_channels=8, fit_spectral_pol=4, channels_out=61) elif patch == 'CasA': lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1300, scale='2arcsec', \ weight='briggs -1.2', niter=75000, no_update_model_required='', nmiter=50, mgain=0.5, \ multiscale='', multiscale_scale_bias=0.7, multiscale_scales='0,5,10,20,40,80', \ fits_mask='/home/fdg/scripts/LiLF/parsets/LOFAR_ateam/masks/CasA.fits', \ baseline_averaging=5, auto_threshold=1, \ join_channels='', deconvolution_channels=8, fit_spectral_pol=4, channels_out=61) elif patch == 'TauA': lib_util.run_wsclean(s, 'wscleanA-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1500, scale='1arcsec', \ weight='briggs -1.2', niter=30, update_model_required='', mgain=0.3, \ fits_mask='/home/fdg/scripts/LiLF/parsets/LOFAR_ateam/masks/pulsar.fits', \
#imagename = 'img/wide-'+str(c) #lib_util.run_wsclean(s, 'wscleanA-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix, scale='10arcsec', \ # weight='briggs 0.', niter=10000, no_update_model_required='', minuv_l=30, maxuv_l=5000, mgain=0.85, \ # baseline_averaging=5, parallel_deconvolution=256, auto_threshold=3, \ # join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) ## make mask #im = lib_img.Image(imagename+'-MFS-image.fits', userReg=userReg, beamReg=beamReg) #im.makeMask(threshisl = 4, only_beam=True) # baseline averaging possible as we cut longest baselines (also it is in time, where smearing is less problematic) logger.info('Cleaning (cycle: ' + str(c) + ')...') imagename = 'img/wideM-' + str(c) lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), do_predict=c==0, name=imagename, save_source_list='', size=imgsizepix, scale='10arcsec', \ weight='briggs -0.3', niter=1000000, no_update_model_required='', minuv_l=30, maxuv_l=4500, mgain=0.85, \ parallel_deconvolution=256, baseline_averaging=5, local_rms='', auto_threshold=1.5, auto_mask=2.5, \ multiscale='', multiscale_scale_bias=0.75, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) os.system('cat logs/wsclean-c' + str(c) + '.log | grep "background noise"') # add model and remove first sidelobe if c == 0: # TEST: reclean low-resolution #logger.info('TEST: Cleaning low resolution...') #imagename_lr = 'img/TESTpre-wide-lr' #lib_util.run_wsclean(s, 'wscleanLR-pre.log', MSs.getStrWsclean(), name=imagename_lr, temp_dir='./', size=imgsizepix, scale='30arcsec', \ # weight='briggs 0.', niter=50000, no_update_model_required='', minuv_l=30, maxuvw_m=5000, mgain=0.8, \ # parallel_deconvolution=256, baseline_averaging=5, auto_mask=3, auto_threshold=0.5, \ # join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3)
# Correct BP CORRECTED_DATA -> CORRECTED_DATA logger.info('BP correction...') if c == 0 and lofar_system == 'lba': MSs.run('DPPP '+parset_dir+'/DPPP-cor.parset msin=$pathMS cor.updateweights=True cor.parmdb=cal-iono-c'+str(c)+'.h5 cor.correction=amplitude000', \ log='$nameMS_corAMP3.log', commandType='DPPP') else: MSs.run('DPPP '+parset_dir+'/DPPP-cor.parset msin=$pathMS cor.updateweights=False cor.parmdb=cal-iono-c'+str(c)+'.h5 cor.correction=amplitude000', \ log='$nameMS_corAMP3.log', commandType='DPPP') logger.info('Cleaning (cycle %i)...' % c) imagename = 'img/img-c' + str(c) if patch == 'CygA': lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1000, scale='1.5arcsec', \ weight='briggs -1.5', niter=50000, no_update_model_required='', mgain=0.5, \ use_weights_as_taper='',\ multiscale='', multiscale_scale_bias=0.7, \ fits_mask='/home/fdg/scripts/LiLF/parsets/LOFAR_ateam/masks/CygA.fits', \ baseline_averaging=5, auto_threshold=1, \ join_channels='', deconvolution_channels=10, fit_spectral_pol=7, channels_out=61) elif patch == 'CasA': lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1300, scale='2arcsec', \ weight='briggs -1.2', niter=75000, no_update_model_required='', mgain=0.5, \ multiscale='', multiscale_scale_bias=0.7, \ fits_mask='/home/fdg/scripts/LiLF/parsets/LOFAR_ateam/masks/CasA.fits', \ baseline_averaging=5, auto_threshold=1, \ join_channels='', deconvolution_channels=10, fit_spectral_pol=7, channels_out=61) elif patch == 'TauA': lib_util.run_wsclean(s, 'wscleanA-c'+str(c)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=1200, scale='2arcsec', \ weight='briggs -1.2', niter=150, update_model_required='', mgain=0.5, \
lib_util.check_rm('img') os.makedirs('img') imgsizepix = int(MSs.getListObj()[0].getFWHM() * 3600 / 5) logger.info('Cleaning normal...') imagename = 'img/cal' lib_util.run_wsclean(s, 'wscleanA.log', MSs.getStrWsclean(), name=imagename, size=imgsizepix, scale='5arcsec', weight='briggs 0.', niter=10000, no_update_model_required='', minuv_l=30, mgain=0.85, baseline_averaging='', parallel_deconvolution=512, auto_threshold=20, join_channels='', fit_spectral_pol=3, channels_out=12, deconvolution_channels=3) # make mask im = lib_img.Image(imagename + '-MFS-image.fits') im.makeMask(threshpix=5) logger.info('Cleaning w/ mask...') lib_util.run_wsclean(s,
lib_util.run_losoto(s, 'Ga-c'+str(c), [ms+'/calGa.h5' for ms in MSs.getListStr()], \ [parset_dir+'/losoto-plot-ph.parset', parset_dir+'/losoto-plot-amp.parset', parset_dir+'/losoto-amp.parset']) # Correct CORRECTED_DATA -> CORRECTED_DATA logger.info('Correction AMP...') MSs.run('DPPP ' + parset_dir + '/DPPP-cor.parset msin=$pathMS msin.datacolumn=CORRECTED_DATA cor.parmdb=cal-Ga-c'+str(c)+'.h5 cor.correction=amplitudeSmooth', \ log='$nameMS_corAMP-c'+str(c)+'.log', commandType='DPPP') ################################################# # 2: Cleaning logger.info('Cleaning (cycle: ' + str(c) + ')...') imagename = 'img/imgM-%02i' % c # if next is a "cont" then I need the do_predict lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), do_predict=True, name=imagename, size=2000, scale='1arcsec', \ weight='briggs -1', niter=1000000, no_update_model_required='', minuv_l=30, mgain=0.2, nmiter=0, \ auto_threshold=3, local_rms='', \ join_channels='', fit_spectral_pol=2, channels_out=2 ) os.system( 'cp -r img/imgM-%02i-MFS-image.fits img/imgMbkp-%02i-MFS-image.fits' % (c, c)) os.system( 'cp -r img/imgM-%02i-MFS-model.fits img/imgMbkp-%02i-MFS-model.fits' % (c, c)) os.system( 'cp -r img/imgM-%02i-MFS-residual.fits img/imgMbkp-%02i-MFS-residual.fits' % (c, c)) lib_util.run_wsclean(s, 'wsclean-c'+str(c)+'.log', MSs.getStrWsclean(), do_predict=True, cont=True, name=imagename, size=2000, scale='1arcsec', \ weight='briggs -1', niter=1000000, no_update_model_required='', minuv_l=30, mgain=0.7, nmiter=0, \ auto_threshold=0.5, auto_mask=2.5, local_rms='', \ multiscale='', multiscale_scale_bias=0.7, \ join_channels='', fit_spectral_pol=2, channels_out=2 )
def clean(p, MSs, size, res='normal', apply_beam=False): """ p = patch name mss = list of mss to clean size = in deg of the image """ # set pixscale and imsize pixscale = MSs.getListObj()[0].getResolution() if res == 'normal': pixscale = float('%.1f' % (pixscale / 2.)) elif res == 'high': pixscale = float('%.1f' % (pixscale / 4.)) elif res == 'low': pass # no change imsize = [0, 0] imsize[0] = int(size[0] * 1.05 / (pixscale / 3600.)) # add 5% imsize[1] = int(size[1] * 1.05 / (pixscale / 3600.)) # add 5% imsize[0] += imsize[0] % 2 imsize[1] += imsize[1] % 2 if imsize[0] < 64: imsize[0] == 64 if imsize[1] < 64: imsize[1] == 64 logger.debug('Image size: ' + str(imsize) + ' - Pixel scale: ' + str(pixscale)) if res == 'normal': weight = 'briggs 0' maxuv_l = None elif res == 'high': weight = 'briggs -0.7' maxuv_l = None elif res == 'low': weight = 'briggs 0' maxuv_l = 3500 # clean 1 logger.info('Cleaning (' + str(p) + ')...') imagename = 'img/ddcal-' + str(p) lib_util.run_wsclean(s, 'wscleanA-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, size=imsize, scale=str(pixscale)+'arcsec', \ weight=weight, niter=10000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.8, \ baseline_averaging=5, parallel_deconvolution=256, auto_threshold=3, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) # make mask im = lib_img.Image(imagename + '-MFS-image.fits', userReg=userReg) im.makeMask(threshisl=4) # clean 2 # TODO: add -parallel-deconvolution when source lists can be saved (https://sourceforge.net/p/wsclean/tickets/141/) logger.info('Cleaning w/ mask (' + str(p) + ')...') imagename = 'img/ddcalM-' + str(p) if apply_beam: lib_util.run_wsclean(s, 'wscleanB-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, save_source_list='', size=imsize, scale=str(pixscale)+'arcsec', \ weight=weight, niter=100000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.8, \ use_idg='', grid_with_beam='', use_differential_lofar_beam='', beam_aterm_update=400, \ multiscale='', \ auto_threshold=0.5, fits_mask=im.maskname, \ join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) logger.info('Cleaning V (' + str(p) + ')...') imagename = 'img/ddcalV-' + str(p) lib_util.run_wsclean(s, 'wscleanV-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, size=imgsize, scale=str(pixscale)+'srcsec', pol='V', \ weight='briggs 0.', niter=1000, no_update_model_required='', minuv_l=30, maxuv_l=5000, \ baseline_averaging=5) else: lib_util.run_wsclean(s, 'wscleanB-'+str(p)+'.log', MSs.getStrWsclean(), name=imagename, size=imsize, save_source_list='', scale=str(pixscale)+'arcsec', \ weight=weight, niter=50000, no_update_model_required='', minuv_l=30, maxuv_l=maxuv_l, mgain=0.85, \ multiscale='', \ auto_threshold=0.5, fits_mask=im.maskname, \ baseline_averaging=5, join_channels='', fit_spectral_pol=3, channels_out=9, deconvolution_channels=3) os.system('cat logs/wscleanA-' + str(p) + '.log logs/wscleanB-' + str(p) + '.log | grep "background noise"')