User Tools

Site Tools


parseltongue:self_cal_source

function: self_cal_source

################################################################################
# Run a series of IMAGR clean and CALIB self-cal's on a Single Source Dataset
def self_cal_source(aips_data,
                    source_name='',
                    flagver = 0,
                    bpver = -1,
                    refant = 1,
                    timerange=[0,0,0,0],
                    imsize = 512,
                    cellsize=1,
                    robust=8,
                    previous_image_max = 0.0,
                    previous_image_rms = 0.0,
                    calib_parameters = None,
                    calib_class_name = 'CALIB',
                    use_initial_point_source_calibration=1,
                    image_sequence_number = 1,
                    save_final_image = 0,
                    save_final_calib_output=0,
                    processing_name = ''
                    ):
    """Runs a series of IMAGR/CALIB steps to self-cal a source
 
source_name       # I  Used mostly for possible generation of file names
                  #    may leave blank
 
 
calib_parameters  # I  A list of dictionaries giving the CALIB parameters.
 
There is no gainuse variable, as this is assumed to be a single source file
which has been split off and the calibration (CL) table applied.  Similarly, this
routine does not pay attention to a possible BP table for bandpass corrections,
which it assumes have also been applied.
    """
    assert(type(calib_parameters) == type([0])), "Need a list here"
    # If there are existing SN tables, warn the user that they are about
    # to be deleted
    if((__debug__) and (aips_data.table_highver('AIPS SN') > 0)):
        warnings.warn("'%s': SN tables exist. Hit Enter to delete."\
                      %self_cal_source.func_name)
        if(pause_before_overwrite): pause_prog('Continue?')
    # AIPS stupidly forces SNVER to be 0 for single-source files.  So
    # I have to check which version is to be used myself
    snver_use = 0
    # check that the specified flag table is present
    assert(check_table_version_valid(aips_data, 'AIPS FG', flagver))
    # Create the IMAGR file variable
    imagr_image = make_selfcal_imagr_outfile(aips_data, source_name,
                                             image_sequence_number)
    # IMAGR will need to run on a dataset
    calib_out = aips_data
    # check for valid image max and RMS
    if(previous_image_max <= 0.0): previous_image_max = 1
    if(previous_image_rms <= 0.0): previous_image_rms = 0
 
 
 
    # Run through the list of SELFCAL steps
    for step in xrange(-1,len(calib_parameters)):
        if __debug__: print 'Entering step', step, 'of the SELFCAL process'
        # Get the right list of calibration parameters.  If this is step -1
        # and we are not doing a point source CALIB run, then skip
        if(step < 0):
            step = 0
            if not(use_initial_point_source_calibration): continue
        cal_par = calib_parameters[step]
        if __debug__: print cal_par
        # Now, check whether or not we are making a new image
        if( not(use_initial_point_source_calibration) and
            (cal_par['run_imagr']) ):
            flagver_use = check_selfcal_flagver(calib_out, flagver)
            flux_level = max(math.fabs(previous_image_max*cal_par['imagr_flux_fraction']),
                             previous_image_rms*cal_par['imagr_noise_cutoff'])
            run_imagr(calib_out,
                      cellsize,
                      imsize,
                      source_name,
                      imagr_image,
                      calib_out.table_highver('AIPS SN'),
                      cal_par['niter'],
                      timerange,
                      flagver_use,
                      bpver,
                      'I',             # Stokes
                      flux_level,
                      cal_par['dotv'],
                      cal_par['clbox'],
                      robust
                      )
            # Get the image statistics for next time
            (previous_image_max, junk1, junk2, previous_image_rms) \
                = get_small_source_stats_main(imagr_image, imsize/4, imsize/4,
                                              imsize/2)
            if __debug__:
                # print out the CC table
                print_cc(imagr_image, processing_name)
        # End of running imagr part
        # set up the data files
        calib_in = make_selfcal_calib_data_in(aips_data, source_name,
                                              calib_class_name,
                                              cal_par['sequence_in'])
        if( not(calib_out == calib_in) and not(calib_out == aips_data) ):
            if(calib_out.exists()): calib_out.zap()
        calib_out = make_selfcal_calib_data_out(calib_in, source_name,
                                                calib_class_name,
                                                cal_par['sequence_out'])
        #print aips_data
        #print calib_in
        #print calib_out
 
        flagver_use = check_selfcal_flagver(calib_in, flagver)
 
        if not(use_initial_point_source_calibration):
            run_calib(calib_in,
                      refant,
                      cal_par['solint'],
                      cal_par['solsub'],
                      source_name,
                      0,                  # gainuse
                      timerange,
                      flagver_use,
                      bpver,
                      imagr_image,
                      cal_par['ncomp'],
                      cal_par['flux'],
                      None,               # smodel
                      cal_par['aparm'],
                      cal_par['soltype'],
                      cal_par['solmode'],
                      snver_use,
                      1,                  # save_data
                      calib_out
                      )
        else:
            run_calib(calib_in,
                      refant,
                      cal_par['solint'],
                      cal_par['solsub'],
                      source_name,
                      0,                  # gainuse
                      timerange,
                      flagver_use,
                      bpver,
                      None,               # image_data
                      None,               # ncomp
                      None,               # flux
                      previous_image_max, # smodel
                      cal_par['aparm'],
                      cal_par['soltype'],
                      cal_par['solmode'],
                      snver_use,
                      1,                  # save_data
                      calib_out
                      )
            use_initial_point_source_calibration = 0
            calib_out.zap()
            calib_out = calib_in
        if(cal_par['show_SN_table']):
            snplot('SN', calib_in.table_highver('AIPS SN'), 'PHAS',opcode='ALSI',
                   snuvdata=calib_in, nplots=len(calib_in.antennas))
            #pause_prog('Check SN table')
            if(is_solmode_doing_amplitude_single(cal_par['solmode'])):
                snplot('SN',calib_in.table_highver('AIPS SN'),'AMP',opcode='ALSI',
                       snuvdata=calib_in, nplots=len(calib_in.antennas))
                #pause_prog('Check SN table')
    # end of for step in xrange over calib steps
 
    # clean up all of the CALIB files
    for step in xrange(0,len(calib_parameters)):
        calib_in =\
            make_selfcal_calib_data_in_nocheck(aips_data, source_name,
                         calib_class_name, calib_parameters[step]['sequence_in'])
        if( not(calib_out == calib_in) and not(calib_in == aips_data) ):
            if(calib_in.exists()): calib_in.zap()
 
 
 
 
 
    # Clean up after ourselves.  If we are not keeping the last CALIB output
    # file, then delete it, unless it is the original data file for some reason.
    if not(save_final_calib_output):
        if(calib_out == aips_data): pass
        else:
            if(calib_out.exists()): calib_out.zap()
    if not(save_final_image):
        if(imagr_image.exists()): imagr_image.zap()
    # return some stuff to the caller, in case they want them
    return calib_out,imagr_image,previous_image_max,previous_image_rms
parseltongue/self_cal_source.txt · Last modified: 2007/07/09 15:14 by 127.0.0.1