def c_cal (goto_step=1):
  """Calibration for C-config data"""
  ## initial calibration
  if goto_step > 1:
    info("########## restarting calibration from step $goto_step");
  # Calibration step -- this is just a user-defined label used in filenames (etc. "blahblah_s1"), which serves to keep the output from each step
  # of a pipeline separate. If this is numeric, then functions such as stefcal.stefcal() will increment it automatically first thing. Otherwise you can set
  # it yourself to some more fancy label. Here we also provide a way to hop to  particular step via goto_step
  v.STEP = goto_step-1;
  
  if goto_step < 2:
    # set the superglobal LSM
    v.LSM = LSM0
    info("########## solving for G with initial LSM");
    # no w-proj for dirty map to save time
    stefcal.stefcal(stefcal_reset_all=True,
        dirty=dict(wprojplanes=0,npix=NPIX),
        restore=dict(npix=NPIX,threshold=CLEAN_THRESH[0],wprojplanes=128));
    info("########## running source finder and updating model");
    ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
    ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
    lsm.pybdsm_search(thresh_pix=THRESH_PIX,thresh_isl=THRESH_ISL,select="r.gt.30s");
    ### merge new sources into sky model, give it a new name ($LSM1)
    lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f");
  
  if goto_step < 3:
    info("########## solving for G+dE with updated LSM (initial+pybdsm)");
    v.LSM = LSM1
    # now, set dE tags on sources
    lsm.transfer_tags(LSMREF,LSM,tags="dE",tolerance=45*ARCSEC);
    stefcal.stefcal(stefcal_reset_all=True,diffgains=True,dirty=dict(wprojplanes=0,npix=NPIX));
    
  if goto_step < 4:
    info("########## re-solving for G to apply IFR solutions");
    v.LSM = LSM1
    stefcal.stefcal(diffgains=True,diffgain_apply_only=True,
      dirty=dict(wprojplanes=0,npix=NPIX),
      restore=dict(npix=NPIX,threshold=CLEAN_THRESH[1]));
    
    info("########## adding clean components to LSM");
    ff = pyfits.open(imager.MODEL_IMAGE);
    dd = ff[0].data;
    dd *= 1.0769     # scale up to compensate for selfcal flux suppression
    # dd[dd<0] = 0;  # remove negative components
    ff.writeto(LSM_CCMODEL,clobber=True);
    # add model image to LSM
    lsm.tigger_convert("$LSM $LSM2 --add-brick=ccmodel:$LSM_CCMODEL:2 -f");

  if goto_step < 5:
    info("########## re-running DD solutions");
    v.LSM = LSM2
    # make final image
    stefcal.stefcal(dirty=dict(wprojplanes=0,npix=NPIX),diffgains=True,
      restore=dict(npix=NPIX,threshold=CLEAN_THRESH[2]),
      label="dE"); 

  # make per-channel cube
  makecube(NPIX);
  # make noise images     
  makenoise();
예제 #2
0
def runcal(goto_step=1):
    ## initial calibration
    if goto_step > 1:
        info("########## restarting calibration from step $goto_step")
    # Calibration step -- this is just a user-defined label used in filenames (etc. "blahblah_s1"), which serves to keep the output from each step
    # of a pipeline separate. If this is numeric, then functions such as stefcal.stefcal() will increment it automatically first thing. Otherwise you can set
    # it yourself to some more fancy label. Here we also provide a way to hop to  particular step via goto_step
    v.STEP = goto_step - 1

    if goto_step < 2:
        # set the superglobal LSM
        v.LSM = LSM0
        info("########## solving for G with initial LSM")
        # no w-proj for dirty map to save time
        stefcal.stefcal(stefcal_reset_ifr_gains=True,
                        dirty=dict(wprojplanes=0),
                        restore=True)
        info("########## running source finder and updating model")
        ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
        lsm.pybdsm_search(threshold=7)
        ### merge new sources into sky model, give it a new name ($LSM1)
        lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f")

    if goto_step < 3:
        info("########## solving for G with updated LSM (initial+pybdsm)")
        v.LSM = LSM1
        stefcal.stefcal(dirty=dict(wprojplanes=0))

    if goto_step < 4:
        info("########## re-solving for G to apply IFR solutions")
        stefcal.stefcal(dirty=dict(wprojplanes=0), restore=True)

        info("########## adding clean components to LSM")
        CCMODEL = II("ccmodel-ddid${ms.DDID}.fits")
        # note the per-style variable interpolation done by the II() function
        ff = pyfits.open(imager.MODEL_IMAGE)
        dd = ff[0].data
        dd *= 1.0769  # scale up to compensate for selfcal flux suppression
        # dd[dd<0] = 0;  # remove negative components
        ff.writeto(CCMODEL, clobber=True)
        # add model image to LSM
        lsm.tigger_convert("$LSM $LSM2 --add-brick=ccmodel:$CCMODEL:2 -f")

    if goto_step < 5:
        info("########## solving for G with updated LSM (inital+pybdsm+cc)")
        v.LSM = LSM2
        stefcal.stefcal(dirty=dict(wprojplanes=0))

    if goto_step < 6:
        info("########## running DD solutions")
        v.LSM = LSM2
        # now, set dE tags on sources
        lsm.transfer_tags(LSMREF, LSM, tags="dE", tolerance=45 * ARCSEC)

        # make final image
        stefcal.stefcal(dirty=dict(wprojplanes=0),
                        diffgains=True,
                        restore=True,
                        label="dE")
def runcal (goto_step=1):
  ## initial calibration
  if goto_step > 1:
    info("########## restarting calibration from step $goto_step");
  # Calibration step -- this is just a user-defined label used in filenames (etc. "blahblah_s1"), which serves to keep the output from each step
  # of a pipeline separate. If this is numeric, then functions such as stefcal.stefcal() will increment it automatically first thing. Otherwise you can set
  # it yourself to some more fancy label. Here we also provide a way to hop to  particular step via goto_step
  v.STEP = goto_step-1;
  
  if goto_step < 2:
    # set the superglobal LSM
    v.LSM = LSM0
    info("########## solving for G with initial LSM");
    # no w-proj for dirty map to save time
    stefcal.stefcal(stefcal_reset_ifr_gains=True,dirty=dict(wprojplanes=0),restore=True);
    info("########## running source finder and updating model");
    ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
    lsm.pybdsm_search(threshold=7);
    ### merge new sources into sky model, give it a new name ($LSM1)
    lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f");
  
  if goto_step < 3:
    info("########## solving for G with updated LSM (initial+pybdsm)");
    v.LSM = LSM1
    stefcal.stefcal(dirty=dict(wprojplanes=0));
    
  if goto_step < 4:
    info("########## re-solving for G to apply IFR solutions");
    stefcal.stefcal(dirty=dict(wprojplanes=0),restore=True);
    
    info("########## adding clean components to LSM");
    CCMODEL = II("ccmodel-ddid${ms.DDID}.fits");  # note the per-style variable interpolation done by the II() function
    ff = pyfits.open(imager.MODEL_IMAGE);
    dd = ff[0].data;
    dd *= 1.0769     # scale up to compensate for selfcal flux suppression
    # dd[dd<0] = 0;  # remove negative components
    ff.writeto(CCMODEL,clobber=True);
    # add model image to LSM
    lsm.tigger_convert("$LSM $LSM2 --add-brick=ccmodel:$CCMODEL:2 -f");

  if goto_step < 5:          
    info("########## solving for G with updated LSM (inital+pybdsm+cc)");
    v.LSM = LSM2
    stefcal.stefcal(dirty=dict(wprojplanes=0));
    
  if goto_step < 6:
    info("########## running DD solutions");
    v.LSM = LSM2
    # now, set dE tags on sources
    lsm.transfer_tags(LSMREF,LSM,tags="dE",tolerance=45*ARCSEC);
  
    # make final image
    stefcal.stefcal(dirty=dict(wprojplanes=0),diffgains=True,restore=True,label="dE"); 
def jointcal (goto_step=1,last_step=10,lsmbase=None,STEPS=None):
  """Calibration for joint C and D-config data"""
  info(">>>>>>>>>>>>> output directory is $OUTDIR. Please set OUTDIR explicitly to override");

  # setup LSM filenames based on the full MS
  # note that these get interpolated once and for all here (and the _Template definitions above
  # get cancelled due to the explicit assignment here). The reason for doing it like this
  # is because I don't want these names to be changing due to the templates every time the 
  # MS changes in a per(MS) call.
  v.FULLMS = MS
  LSM1 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm.lsm.html");
  LSM2 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm2.lsm.html");
  LSM3 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm2+cc.lsm.html");
  LSM_CCMODEL = II("$DESTDIR/$LSMBASE$SUFFIX+ccmodel.fits");
  saveconf()

  stefcal.STEFCAL_DIFFGAIN_SMOOTHING = DE_SMOOTHING if not DE_INTERVALS else None;
  stefcal.STEFCAL_DIFFGAIN_INTERVALS = DE_INTERVALS;
  if DE_INTERVALS and TILE:
    stefcal.STEFCAL_TDLOPTS = "ms_sel.tile_size=%d"%(TILE*DE_INTERVALS[0]);

  # make MS list from sub-MSs
  import glob
  v.MS_List = glob.glob(MS+"/SUBMSS/*MS");
  info("MS list is $MS_List");
  if not MS_List:
    abort("No sub-MSs found");
  
  imager.npix = NPIX = 4096
  imager.cellsize = "2arcsec"
  imager.wprojplanes = 128
  imager.CLEAN_ALGORITHM = "csclean"
  v.LSMREF = "${MS:BASE}.refmodel.lsm.html"
  THRESH_PIX,THRESH_ISL = (50,10),(15,5)
  CLEAN_THRESH = ".4mJy",".1mJy",".05mJy"
  stefcal.STEFCAL_STEP_INCR = 0 # precvent stefcal from auto-incrementing v.STEP: we set the step counter explicitly here
  
  if STEPS is None:
    STEPS = list(numpy.arange(goto_step,last_step+.1,.5));
  STEPS = map(float,STEPS);

  if STEPS[0] != 1:
    info("########## restarting calibration from step %.1f"%STEPS[0]);

  if lsmbase:
    LSMBASE = lsmbase;

  ## initial calibration
  
  if 1. in STEPS:
    info("########## step 1: solving for G with initial LSM");
    v.LSM,v.STEP = LSM0,1
    per_ms(jointcal_g);
    
  if 1.5 in STEPS:
    info("########## step 1.5: making joint image");
    v.LSM,v.STEP = LSM0,1
    v.MS = FULLMS
    # initial model is total flux only, made from a 2x size image to catch distant sources
    imager.make_image(dirty=False,stokes="I",restore=dict(npix=NPIX*2,threshold=CLEAN_THRESH[0],wprojplanes=128),restore_lsm=False);
    info("########## running source finder and updating model");
    ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
    ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
    lsm.pybdsm_search(thresh_pix=THRESH_PIX[0],thresh_isl=THRESH_ISL[0],select="r.gt.30s",pol=False);
    ### merge new sources into sky model, give it a new name ($LSM1)
    lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f");

  # if 2. in STEPS:
  #   info("########## step 2: repeating G solution");
  #   v.LSM,v.STEP = LSM1,2
  #   v.MS = FULLMS  
  #   per_ms(jointcal_g);
    
  if 2. in STEPS:
    info("########## step 2: initial dE solution");
    v.LSM,v.STEP = LSM1,2
    v.MS = FULLMS  
    # now, set dE tags on sources
    lsm.transfer_tags(LSMREF,LSM,tags="dE",tolerance=45*ARCSEC);
    per_ms(jointcal_de_reset);

  if 3. in STEPS:
    info("########## step 3: re-solving for G to apply IFR solutions");
    v.LSM,v.STEP = LSM1,3
    v.MS = FULLMS
    per_ms(jointcal_de_apply);
    info("########## running source finder and updating model");
    v.MS = FULLMS
    imager.make_image(dirty=False,stokes="IV",restore=dict(npix=NPIX,threshold=CLEAN_THRESH[1],wprojplanes=128),restore_lsm=False);
    ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
    ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
    lsm.pybdsm_search(thresh_pix=THRESH_PIX[1],thresh_isl=THRESH_ISL[1],select="r.gt.30s");
    ### merge new sources into sky model, give it a new name ($LSM1)
    lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM2 --rename -f");

  if 4. in STEPS:
    info("########## step 4: solving for G+dE with updated LSM (initial+pybdsm^2)");
    v.MS = FULLMS
    v.LSM,v.STEP = LSM2,4
    lsm.transfer_tags(LSMREF,LSM,tags="dE",tolerance=45*ARCSEC);
    per_ms(jointcal_de);
    v.MS = FULLMS
    imager.make_image(dirty=False,stokes="IV",restore=dict(npix=NPIX,threshold=CLEAN_THRESH[1],wprojplanes=128),restore_lsm=False);
    info("########## adding clean components to LSM");
    ff = pyfits.open(imager.MODEL_IMAGE);
    dd = ff[0].data;
    dd *= 1.0769     # scale up to compensate for selfcal flux suppression
    # dd[dd<0] = 0;  # remove negative components
    ff.writeto(LSM_CCMODEL,clobber=True);
    # add model image to LSM
    lsm.tigger_convert("$LSM $LSM3 --add-brick=ccmodel:$LSM_CCMODEL:2 -f");

  if 5. in STEPS:
    info("########## step 5: re-running DD solutions");
    v.MS = FULLMS
    v.LSM,v.STEP = LSM3,5
    per_ms(jointcal_de_final);
    
  if 5.5 in STEPS:
    info("########## step 5.5: making joint image");
    v.MS = FULLMS
    v.LSM,v.STEP = LSM3,5
    imager.make_image(dirty=False,stokes="IQUV",restore=dict(npix=NPIX,threshold=CLEAN_THRESH[2],wprojplanes=128),restore_lsm=True);
    
  if 6. in STEPS:
    info("########## step 6: noise sim");
    per_ms(lambda:makecube(stokes="IQUV"));
    v.LSM,v.STEP = LSM3,5
    v.MS = FULLMS;
    makecube(stokes="IQUV");
    makenoise();
def phase_precal_selfcal_pipeline(goto_step=3.):
    useStep = 1
    skipCalMSlist = [
        'zen.2455819.25927.uvcRREM', 'zen.2455819.27319.uvcRREM',
        'zen.2455819.32190.uvcRREM', 'zen.2455819.34278.uvcRREM',
        'zen.2455819.34974.uvcRREM', 'zen.2455819.38454.uvcRREM',
        'zen.2455819.40542.uvcRREM', 'zen.2455819.41238.uvcRREM',
        'zen.2455819.41934.uvcRREM', 'zen.2455819.42630.uvcRREM',
        'zen.2455819.73947.uvcRREM', 'zen.2455819.74643.uvcRREM',
        'zen.2455819.75339.uvcRREM', 'zen.2455819.76035.uvcRREM',
        'zen.2455819.78819.uvcRREM', 'zen.2455819.79515.uvcRREM',
        'zen.2455819.80211.uvcRREM', 'zen.2455819.80906.uvcRREM'
    ]  #MS files to skip calibration on
    skipCleanMSlist = ['zen.2455819.79515.uvcRREM'
                       ]  #problematic MS files when imaging multi-freq

    if not os.path.isdir(v.DESTDIR):
        os.makedirs(v.DESTDIR)

    if goto_step <= 0.:
        v.STEP = 1
        info("########## adding columns %i" % v.STEP)
        for msFile in sorted(v.MS_List):
            pyrap.tables.addImagingColumns(msFile)

    #copy data to corrected data column to run clean
    if goto_step <= 0.5:
        v.STEP = 1
        info("########## copying data to corrected data column step %i" %
             v.STEP)
        pper("MS", copy_data_to_corrected_data)

    #run a basic clean to perform source finding on
    if goto_step <= 1:
        v.STEP = 1
        info("########## making initial clean image step %i" % v.STEP)
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 100.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': 1
        }
        for msFile in sorted(v.MS_List):
            msBase = msFile.split('/')[-1].split('.MS')[0]
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #derive a shallow depth sky model from the clean'd image
    if goto_step <= 1.5:
        v.STEP = 1
        fitsfiles = glob.glob(v.DESTDIR + '/*_s1-image.fits')
        for ff in sorted(fitsfiles):
            olsm = ff.split('-image.fits')[0] + '.lsm'
            lsm.pybdsm_search(image=ff,
                              output=olsm,
                              thresh_pix=20,
                              thresh_isl=15)
            lsm.tigger_convert(olsm)

    #run stefcal using the sky model, produce a Stokes I image for source finding
    if goto_step <= 2:
        v.STEP = 2
        lsm0files = glob.glob(v.DESTDIR + '/*_s1.lsm.html')
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 100.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': 1
        }
        for msFile in sorted(v.MS_List):
            msBase = msFile.split('/')[-1].split('.MS')[0]
            if msBase in skipCalMSlist:
                info('Skipping this MS file')
            else:
                x.sh('export LC_NUMERIC=en_GB.utf8')
                lsm0 = filter(lambda x: x.split('/')[-1].startswith(msBase),
                              lsm0files)[0]
                v.LSM = lsm0
                v.MS = msFile
                stefcal.STEFCAL_STEP_INCR = 0  # we set the step counter explicitly
                info(
                    "########## initial calibration of %s using sky model %s step %i"
                    % (msFile, lsm0, v.STEP))
                stefcal.stefcal(output='CORR_DATA',
                                dirty=False,
                                restore=False,
                                section='calico-stefcal')
            info("########## making clean image step %i" % v.STEP)
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #derive a deeper depth sky model from the clean'd image
    if goto_step <= 2.5:
        v.STEP = 2
        fitsfiles = glob.glob(v.DESTDIR + '/*_s2-image.fits')
        for ff in sorted(fitsfiles):
            olsm = ff.split('-image.fits')[0] + '.lsm'
            lsm.pybdsm_search(image=ff,
                              output=olsm,
                              thresh_pix=10,
                              thresh_isl=7)
            lsm.tigger_convert(olsm)

    #generate multi-frequency, complex images for image domain corrections
    if goto_step <= 3:
        v.STEP = 3
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            #'niter': 1000,
            'niter': 1,
            'threshold': 100.,
            'pol': 'xx,xy,yx,yy',
            'weight': 'natural',
            #'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': nsubbands,
            'joinpolarizations': None
        }
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase = msFile.split('/')[-1].split('.MS')[0]
            if msBase in skipCleanMSlist: wscleanDict['niter'] = 1
            else: wscleanDict['niter'] = 1
            #else: wscleanDict['niter']=1000
            info("########## making clean image step %i" % v.STEP)
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)
def selfcal_loop_pipeline(goto_step=0.):

    if not os.path.isdir(v.DESTDIR):
        os.makedirs(v.DESTDIR)

    #copy data to corrected data column to run clean
    if goto_step <= 0.:
        v.STEP = 1
        info("########## adding columns %i" % v.STEP)
        for msFile in sorted(v.MS_List):
            pyrap.tables.addImagingColumns(msFile)

    if goto_step <= 0.5:
        v.STEP = 1
        info("########## copying data to corrected data column step %i" %
             v.STEP)
        pper("MS", copy_data_to_corrected_data)

    #run a basic clean to perform source finding on
    if goto_step <= 1:
        v.STEP = 1
        info("########## making initial clean image step %i" % v.STEP)
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': 1
        }
        for msFile in sorted(v.MS_List):
            msBase = msFile.split('/')[-1].split('.MS')[0]
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #derive an initial sky model from the clean'd image
    if goto_step <= 1.5:
        v.STEP = 1
        fitsfiles = glob.glob(v.DESTDIR + '/*_s1-image.fits')
        for ff in sorted(fitsfiles):
            olsm = ff.split('-image.fits')[0] + '.lsm'
            lsm.pybdsm_search(image=ff,
                              output=olsm,
                              thresh_pix=20,
                              thresh_isl=15)
            lsm.tigger_convert(olsm)

    #run stefcal using the initial sky model
    if goto_step <= 2:
        v.STEP = 2
        lsm0files = glob.glob(v.DESTDIR + '/*_s1.lsm.html')
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 500,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': 1
        }
        for msFile in sorted(v.MS_List):
            msBase = msFile.split('/')[-1].split('.MS')[0]
            lsm0 = filter(lambda x: x.split('/')[-1].startswith(msBase),
                          lsm0files)[0]
            v.LSM = lsm0
            v.MS = msFile
            stefcal.STEFCAL_STEP_INCR = 0  # we set the step counter explicitly
            info(
                "########## initial calibration of %s using sky model %s step %i"
                % (msFile, lsm0, v.STEP))
            stefcal.stefcal(output='CORR_DATA',
                            dirty=False,
                            restore=False,
                            section='calico-stefcal')
            info("########## making clean image step %i" % v.STEP)
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #derive an second sky model from the clean'd image
    if goto_step <= 2.5:
        v.STEP = 2
        fitsfiles = glob.glob(v.DESTDIR + '/*_s2-image.fits')
        for ff in sorted(fitsfiles):
            olsm = ff.split('-image.fits')[0] + '.lsm'
            lsm.pybdsm_search(image=ff,
                              output=olsm,
                              thresh_pix=15,
                              thresh_isl=10)
            lsm.tigger_convert(olsm)

    #run stefcal using the second sky model
    if goto_step <= 3:
        v.STEP = 3
        lsm1files = glob.glob(v.DESTDIR + '/*_s2.lsm.html')
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 1000,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': 1
        }
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase = msFile.split('/')[-1].split('.MS')[0]
            lsm1 = filter(lambda x: x.split('/')[-1].startswith(msBase),
                          lsm1files)[0]
            v.LSM = lsm1
            v.MS = msFile
            stefcal.STEFCAL_STEP_INCR = 0  # we set the step counter explicitly
            info(
                "########## second calibration of %s using sky model %s step %i"
                % (msFile, lsm1, v.STEP))
            stefcal.stefcal(output='CORR_DATA',
                            dirty=False,
                            restore=False,
                            section='calico-stefcal')
            info("########## making clean image step %i" % v.STEP)
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #derive an sky model from the clean'd image
    if goto_step <= 3.5:
        v.STEP = 3
        fitsfiles = glob.glob(v.DESTDIR + '/*_s3-image.fits')
        for ff in sorted(fitsfiles):
            olsm = ff.split('-image.fits')[0] + '.lsm'
            lsm.pybdsm_search(image=ff,
                              output=olsm,
                              thresh_pix=12,
                              thresh_isl=5)
            lsm.tigger_convert(olsm)

    #run stefcal using the third sky model and produce final complex, multi-frequency images
    if goto_step <= 4:
        v.STEP = 4
        lsm2files = glob.glob(v.DESTDIR + '/*_s3.lsm.html')
        wscleanDict = {
            'name': 'wsclean',
            'datacolumn': 'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 1000,
            'threshold': 1.,
            'pol': 'xx,xy,yx,yy',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers': 32,
            'channelrange': '%i %i' % (startChan, endChan),
            'channelsout': nsubbands,
            'joinpolarizations': None
        }
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase = msFile.split('/')[-1].split('.MS')[0]
            lsm2 = filter(lambda x: x.split('/')[-1].startswith(msBase),
                          lsm2files)[0]
            v.LSM = lsm2
            v.MS = msFile
            stefcal.STEFCAL_STEP_INCR = 0  # we set the step counter explicitly
            info(
                "########## second calibration of %s using sky model %s step %i"
                % (msFile, lsm2, v.STEP))
            stefcal.stefcal(output='CORR_DATA',
                            dirty=False,
                            restore=False,
                            section='calico-stefcal')
            wscleanDict['name'] = msBase + '_s%i' % v.STEP
            run_wsclean(msFile, wscleanDict)
        fitsfiles = glob.glob('*.fits')
        for ff in fitsfiles:
            shutil.move(ff, v.DESTDIR)

    #clean up
    if goto_step <= 5:
        gaulfiles = glob.glob('*.gaul')
        for gf in gaulfiles:
            shutil.move(gf, v.DESTDIR)
def phase_precal_selfcal_pipeline(goto_step=3.):
    useStep=1
    skipCalMSlist=[ 'zen.2455819.25927.uvcRREM',
                    'zen.2455819.27319.uvcRREM',
                    'zen.2455819.32190.uvcRREM',
                    'zen.2455819.34278.uvcRREM',
                    'zen.2455819.34974.uvcRREM',
                    'zen.2455819.38454.uvcRREM',
                    'zen.2455819.40542.uvcRREM',
                    'zen.2455819.41238.uvcRREM',
                    'zen.2455819.41934.uvcRREM',
                    'zen.2455819.42630.uvcRREM',
                    'zen.2455819.73947.uvcRREM',
                    'zen.2455819.74643.uvcRREM',
                    'zen.2455819.75339.uvcRREM',
                    'zen.2455819.76035.uvcRREM',
                    'zen.2455819.78819.uvcRREM',
                    'zen.2455819.79515.uvcRREM',
                    'zen.2455819.80211.uvcRREM',
                    'zen.2455819.80906.uvcRREM'] #MS files to skip calibration on
    skipCleanMSlist=['zen.2455819.79515.uvcRREM'] #problematic MS files when imaging multi-freq

    if not os.path.isdir(v.DESTDIR):
        os.makedirs(v.DESTDIR)

    if goto_step <= 0.:
        v.STEP=1
        info("########## adding columns %i"%v.STEP)
        for msFile in sorted(v.MS_List):pyrap.tables.addImagingColumns(msFile)

    #copy data to corrected data column to run clean
    if goto_step <= 0.5:
        v.STEP=1
        info("########## copying data to corrected data column step %i"%v.STEP)
        pper("MS",copy_data_to_corrected_data)

    #run a basic clean to perform source finding on
    if goto_step <= 1:
        v.STEP=1
        info("########## making initial clean image step %i"%v.STEP)
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 100.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': 1}
        for msFile in sorted(v.MS_List):
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #derive a shallow depth sky model from the clean'd image
    if goto_step <= 1.5:
        v.STEP=1
        fitsfiles=glob.glob(v.DESTDIR+'/*_s1-image.fits')
        for ff in sorted(fitsfiles):
            olsm=ff.split('-image.fits')[0]+'.lsm'
            lsm.pybdsm_search(image=ff,output=olsm,thresh_pix=20,thresh_isl=15)
            lsm.tigger_convert(olsm)

    #run stefcal using the sky model, produce a Stokes I image for source finding
    if goto_step <= 2:
        v.STEP=2
        lsm0files=glob.glob(v.DESTDIR+'/*_s1.lsm.html')
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 100.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': 1}
        for msFile in sorted(v.MS_List):
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            if msBase in skipCalMSlist:
                info('Skipping this MS file')
            else:
                x.sh('export LC_NUMERIC=en_GB.utf8')
                lsm0=filter(lambda x: x.split('/')[-1].startswith(msBase),lsm0files)[0]
                v.LSM=lsm0
                v.MS=msFile
                stefcal.STEFCAL_STEP_INCR = 0 # we set the step counter explicitly
                info("########## initial calibration of %s using sky model %s step %i"%(msFile,lsm0,v.STEP))
                stefcal.stefcal(output='CORR_DATA',dirty=False,restore=False,section='calico-stefcal')
            info("########## making clean image step %i"%v.STEP)
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #derive a deeper depth sky model from the clean'd image
    if goto_step <= 2.5:
        v.STEP=2
        fitsfiles=glob.glob(v.DESTDIR+'/*_s2-image.fits')
        for ff in sorted(fitsfiles):
            olsm=ff.split('-image.fits')[0]+'.lsm'
            lsm.pybdsm_search(image=ff,output=olsm,thresh_pix=10,thresh_isl=7)
            lsm.tigger_convert(olsm)

    #generate multi-frequency, complex images for image domain corrections
    if goto_step <= 3:
        v.STEP=3
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            #'niter': 1000,
            'niter': 1,
            'threshold': 100.,
            'pol': 'xx,xy,yx,yy',
            'weight': 'natural',
            #'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': nsubbands,
            'joinpolarizations': None}
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            if msBase in skipCleanMSlist: wscleanDict['niter']=1
            else: wscleanDict['niter']=1
            #else: wscleanDict['niter']=1000
            info("########## making clean image step %i"%v.STEP)
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)
def selfcal_loop_pipeline(goto_step=0.):

    if not os.path.isdir(v.DESTDIR):
        os.makedirs(v.DESTDIR)

    #copy data to corrected data column to run clean
    if goto_step <= 0.:
        v.STEP=1
        info("########## adding columns %i"%v.STEP)
        for msFile in sorted(v.MS_List):pyrap.tables.addImagingColumns(msFile)

    if goto_step <= 0.5:
        v.STEP=1
        info("########## copying data to corrected data column step %i"%v.STEP)
        pper("MS",copy_data_to_corrected_data)

    #run a basic clean to perform source finding on
    if goto_step <= 1:
        v.STEP=1
        info("########## making initial clean image step %i"%v.STEP)
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 250,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': 1}
        for msFile in sorted(v.MS_List):
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #derive an initial sky model from the clean'd image
    if goto_step <= 1.5:
        v.STEP=1
        fitsfiles=glob.glob(v.DESTDIR+'/*_s1-image.fits')
        for ff in sorted(fitsfiles):
            olsm=ff.split('-image.fits')[0]+'.lsm'
            lsm.pybdsm_search(image=ff,output=olsm,thresh_pix=20,thresh_isl=15)
            lsm.tigger_convert(olsm)

    #run stefcal using the initial sky model
    if goto_step <= 2:
        v.STEP=2
        lsm0files=glob.glob(v.DESTDIR+'/*_s1.lsm.html')
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 500,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': 1}
        for msFile in sorted(v.MS_List):
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            lsm0=filter(lambda x: x.split('/')[-1].startswith(msBase),lsm0files)[0]
            v.LSM=lsm0
            v.MS=msFile
            stefcal.STEFCAL_STEP_INCR = 0 # we set the step counter explicitly
            info("########## initial calibration of %s using sky model %s step %i"%(msFile,lsm0,v.STEP))
            stefcal.stefcal(output='CORR_DATA',dirty=False,restore=False,section='calico-stefcal')
            info("########## making clean image step %i"%v.STEP)
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #derive an second sky model from the clean'd image
    if goto_step <= 2.5:
        v.STEP=2
        fitsfiles=glob.glob(v.DESTDIR+'/*_s2-image.fits')
        for ff in sorted(fitsfiles):
            olsm=ff.split('-image.fits')[0]+'.lsm'
            lsm.pybdsm_search(image=ff,output=olsm,thresh_pix=15,thresh_isl=10)
            lsm.tigger_convert(olsm)

    #run stefcal using the second sky model
    if goto_step <= 3:
        v.STEP=3
        lsm1files=glob.glob(v.DESTDIR+'/*_s2.lsm.html')
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 1000,
            'threshold': 1.,
            'pol': 'I',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': 1}
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            lsm1=filter(lambda x: x.split('/')[-1].startswith(msBase),lsm1files)[0]
            v.LSM=lsm1
            v.MS=msFile
            stefcal.STEFCAL_STEP_INCR = 0 # we set the step counter explicitly
            info("########## second calibration of %s using sky model %s step %i"%(msFile,lsm1,v.STEP))
            stefcal.stefcal(output='CORR_DATA',dirty=False,restore=False,section='calico-stefcal')
            info("########## making clean image step %i"%v.STEP)
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #derive an sky model from the clean'd image
    if goto_step <= 3.5:
        v.STEP=3
        fitsfiles=glob.glob(v.DESTDIR+'/*_s3-image.fits')
        for ff in sorted(fitsfiles):
            olsm=ff.split('-image.fits')[0]+'.lsm'
            lsm.pybdsm_search(image=ff,output=olsm,thresh_pix=12,thresh_isl=5)
            lsm.tigger_convert(olsm)

    #run stefcal using the third sky model and produce final complex, multi-frequency images
    if goto_step <= 4:
        v.STEP=4
        lsm2files=glob.glob(v.DESTDIR+'/*_s3.lsm.html')
        wscleanDict={
            'name':'wsclean',
            'datacolumn':'CORRECTED_DATA',
            'size': '1024 1024',
            #'scale': 330./3600.,
            'scale': 0.11,
            'niter': 1000,
            'threshold': 1.,
            'pol': 'xx,xy,yx,yy',
            #'weight': 'natural',
            'weight': 'briggs 0.0',
            'nwlayers':32,
            'channelrange': '%i %i'%(startChan,endChan),
            'channelsout': nsubbands,
            'joinpolarizations': None}
        for msFile in sorted(v.MS_List):
            x.sh('export LC_NUMERIC=en_GB.utf8')
            msBase=msFile.split('/')[-1].split('.MS')[0] 
            lsm2=filter(lambda x: x.split('/')[-1].startswith(msBase),lsm2files)[0]
            v.LSM=lsm2
            v.MS=msFile
            stefcal.STEFCAL_STEP_INCR = 0 # we set the step counter explicitly
            info("########## second calibration of %s using sky model %s step %i"%(msFile,lsm2,v.STEP))
            stefcal.stefcal(output='CORR_DATA',dirty=False,restore=False,section='calico-stefcal')
            wscleanDict['name']=msBase+'_s%i'%v.STEP
            run_wsclean(msFile,wscleanDict)
        fitsfiles=glob.glob('*.fits')
        for ff in fitsfiles: shutil.move(ff,v.DESTDIR)

    #clean up
    if goto_step <= 5:
        gaulfiles=glob.glob('*.gaul')
        for gf in gaulfiles: shutil.move(gf,v.DESTDIR)
예제 #9
0
def jointcal(goto_step=1, last_step=10, lsmbase=None, STEPS=None):
    """Calibration for joint C and D-config data"""
    info(
        ">>>>>>>>>>>>> output directory is $OUTDIR. Please set OUTDIR explicitly to override"
    )

    # setup LSM filenames based on the full MS
    # note that these get interpolated once and for all here (and the _Template definitions above
    # get cancelled due to the explicit assignment here). The reason for doing it like this
    # is because I don't want these names to be changing due to the templates every time the
    # MS changes in a per(MS) call.
    v.FULLMS = MS
    LSM1 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm.lsm.html")
    LSM2 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm2.lsm.html")
    LSM3 = II("$DESTDIR/$LSMBASE$SUFFIX+pybdsm2+cc.lsm.html")
    LSM_CCMODEL = II("$DESTDIR/$LSMBASE$SUFFIX+ccmodel.fits")
    saveconf()

    stefcal.STEFCAL_DIFFGAIN_SMOOTHING = DE_SMOOTHING if not DE_INTERVALS else None
    stefcal.STEFCAL_DIFFGAIN_INTERVALS = DE_INTERVALS
    if DE_INTERVALS and TILE:
        stefcal.STEFCAL_TDLOPTS = "ms_sel.tile_size=%d" % (TILE *
                                                           DE_INTERVALS[0])

    # make MS list from sub-MSs
    import glob
    v.MS_List = glob.glob(MS + "/SUBMSS/*MS")
    info("MS list is $MS_List")
    if not MS_List:
        abort("No sub-MSs found")

    imager.npix = NPIX = 4096
    imager.cellsize = "2arcsec"
    imager.wprojplanes = 128
    imager.CLEAN_ALGORITHM = "csclean"
    v.LSMREF = "${MS:BASE}.refmodel.lsm.html"
    THRESH_PIX, THRESH_ISL = (50, 10), (15, 5)
    CLEAN_THRESH = ".4mJy", ".1mJy", ".05mJy"
    stefcal.STEFCAL_STEP_INCR = 0  # precvent stefcal from auto-incrementing v.STEP: we set the step counter explicitly here

    if STEPS is None:
        STEPS = list(numpy.arange(goto_step, last_step + .1, .5))
    STEPS = map(float, STEPS)

    if STEPS[0] != 1:
        info("########## restarting calibration from step %.1f" % STEPS[0])

    if lsmbase:
        LSMBASE = lsmbase

    ## initial calibration

    if 1. in STEPS:
        info("########## step 1: solving for G with initial LSM")
        v.LSM, v.STEP = LSM0, 1
        per_ms(jointcal_g)

    if 1.5 in STEPS:
        info("########## step 1.5: making joint image")
        v.LSM, v.STEP = LSM0, 1
        v.MS = FULLMS
        # initial model is total flux only, made from a 2x size image to catch distant sources
        imager.make_image(dirty=False,
                          stokes="I",
                          restore=dict(npix=NPIX * 2,
                                       threshold=CLEAN_THRESH[0],
                                       wprojplanes=128),
                          restore_lsm=False)
        info("########## running source finder and updating model")
        ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
        ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
        lsm.pybdsm_search(thresh_pix=THRESH_PIX[0],
                          thresh_isl=THRESH_ISL[0],
                          select="r.gt.30s",
                          pol=False)
        ### merge new sources into sky model, give it a new name ($LSM1)
        lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f")

    # if 2. in STEPS:
    #   info("########## step 2: repeating G solution");
    #   v.LSM,v.STEP = LSM1,2
    #   v.MS = FULLMS
    #   per_ms(jointcal_g);

    if 2. in STEPS:
        info("########## step 2: initial dE solution")
        v.LSM, v.STEP = LSM1, 2
        v.MS = FULLMS
        # now, set dE tags on sources
        lsm.transfer_tags(LSMREF, LSM, tags="dE", tolerance=45 * ARCSEC)
        per_ms(jointcal_de_reset)

    if 3. in STEPS:
        info("########## step 3: re-solving for G to apply IFR solutions")
        v.LSM, v.STEP = LSM1, 3
        v.MS = FULLMS
        per_ms(jointcal_de_apply)
        info("########## running source finder and updating model")
        v.MS = FULLMS
        imager.make_image(dirty=False,
                          stokes="IV",
                          restore=dict(npix=NPIX,
                                       threshold=CLEAN_THRESH[1],
                                       wprojplanes=128),
                          restore_lsm=False)
        ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
        ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
        lsm.pybdsm_search(thresh_pix=THRESH_PIX[1],
                          thresh_isl=THRESH_ISL[1],
                          select="r.gt.30s")
        ### merge new sources into sky model, give it a new name ($LSM1)
        lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM2 --rename -f")

    if 4. in STEPS:
        info(
            "########## step 4: solving for G+dE with updated LSM (initial+pybdsm^2)"
        )
        v.MS = FULLMS
        v.LSM, v.STEP = LSM2, 4
        lsm.transfer_tags(LSMREF, LSM, tags="dE", tolerance=45 * ARCSEC)
        per_ms(jointcal_de)
        v.MS = FULLMS
        imager.make_image(dirty=False,
                          stokes="IV",
                          restore=dict(npix=NPIX,
                                       threshold=CLEAN_THRESH[1],
                                       wprojplanes=128),
                          restore_lsm=False)
        info("########## adding clean components to LSM")
        ff = pyfits.open(imager.MODEL_IMAGE)
        dd = ff[0].data
        dd *= 1.0769  # scale up to compensate for selfcal flux suppression
        # dd[dd<0] = 0;  # remove negative components
        ff.writeto(LSM_CCMODEL, clobber=True)
        # add model image to LSM
        lsm.tigger_convert("$LSM $LSM3 --add-brick=ccmodel:$LSM_CCMODEL:2 -f")

    if 5. in STEPS:
        info("########## step 5: re-running DD solutions")
        v.MS = FULLMS
        v.LSM, v.STEP = LSM3, 5
        per_ms(jointcal_de_final)

    if 5.5 in STEPS:
        info("########## step 5.5: making joint image")
        v.MS = FULLMS
        v.LSM, v.STEP = LSM3, 5
        imager.make_image(dirty=False,
                          stokes="IQUV",
                          restore=dict(npix=NPIX,
                                       threshold=CLEAN_THRESH[2],
                                       wprojplanes=128),
                          restore_lsm=True)

    if 6. in STEPS:
        info("########## step 6: noise sim")
        per_ms(lambda: makecube(stokes="IQUV"))
        v.LSM, v.STEP = LSM3, 5
        v.MS = FULLMS
        makecube(stokes="IQUV")
        makenoise()
예제 #10
0
def c_cal(goto_step=1):
    """Calibration for C-config data"""
    ## initial calibration
    if goto_step > 1:
        info("########## restarting calibration from step $goto_step")
    # Calibration step -- this is just a user-defined label used in filenames (etc. "blahblah_s1"), which serves to keep the output from each step
    # of a pipeline separate. If this is numeric, then functions such as stefcal.stefcal() will increment it automatically first thing. Otherwise you can set
    # it yourself to some more fancy label. Here we also provide a way to hop to  particular step via goto_step
    v.STEP = goto_step - 1

    if goto_step < 2:
        # set the superglobal LSM
        v.LSM = LSM0
        info("########## solving for G with initial LSM")
        # no w-proj for dirty map to save time
        stefcal.stefcal(stefcal_reset_all=True,
                        dirty=dict(wprojplanes=0, npix=NPIX),
                        restore=dict(npix=NPIX,
                                     threshold=CLEAN_THRESH[0],
                                     wprojplanes=128))
        info("########## running source finder and updating model")
        ## now run pybdsm on restored image, output LSM will be given by variable cal.PYBDSM_OUTPUT
        ### NB: select on radius to exclude any artefacts picked up around 3C147 itself
        lsm.pybdsm_search(thresh_pix=THRESH_PIX,
                          thresh_isl=THRESH_ISL,
                          select="r.gt.30s")
        ### merge new sources into sky model, give it a new name ($LSM1)
        lsm.tigger_convert("$LSM -a ${lsm.PYBDSM_OUTPUT} $LSM1 --rename -f")

    if goto_step < 3:
        info("########## solving for G+dE with updated LSM (initial+pybdsm)")
        v.LSM = LSM1
        # now, set dE tags on sources
        lsm.transfer_tags(LSMREF, LSM, tags="dE", tolerance=45 * ARCSEC)
        stefcal.stefcal(stefcal_reset_all=True,
                        diffgains=True,
                        dirty=dict(wprojplanes=0, npix=NPIX))

    if goto_step < 4:
        info("########## re-solving for G to apply IFR solutions")
        v.LSM = LSM1
        stefcal.stefcal(diffgains=True,
                        diffgain_apply_only=True,
                        dirty=dict(wprojplanes=0, npix=NPIX),
                        restore=dict(npix=NPIX, threshold=CLEAN_THRESH[1]))

        info("########## adding clean components to LSM")
        ff = pyfits.open(imager.MODEL_IMAGE)
        dd = ff[0].data
        dd *= 1.0769  # scale up to compensate for selfcal flux suppression
        # dd[dd<0] = 0;  # remove negative components
        ff.writeto(LSM_CCMODEL, clobber=True)
        # add model image to LSM
        lsm.tigger_convert("$LSM $LSM2 --add-brick=ccmodel:$LSM_CCMODEL:2 -f")

    if goto_step < 5:
        info("########## re-running DD solutions")
        v.LSM = LSM2
        # make final image
        stefcal.stefcal(dirty=dict(wprojplanes=0, npix=NPIX),
                        diffgains=True,
                        restore=dict(npix=NPIX, threshold=CLEAN_THRESH[2]),
                        label="dE")

    # make per-channel cube
    makecube(NPIX)
    # make noise images
    makenoise()