Example #1
0
def runPipeline():

    # the terminal object is used for printing to the screen
    term = Terminal()

    # create instance of CommandLine object to parse input, then
    # parse all the input parameters and store them as attributes in
    # cl_params structure
    cl = commandline.CommandLine()
    cl_params = cl.read(sys)

    # create a directory for storing log files
    mkdir_p('log')

    # instantiate a log object for log files and screen output
    log = Logging(cl_params, 'pipeline')

    # print a command summary to log file/terminal
    command_summary(cl_params, term, log)

    log.doMessage('INFO', '{t.underline}Start '
                  'calibration.{t.normal}'.format(t=term))

    # calibrated_maps will contain a list of tuples each with a
    # MappingPipeline instance, window id, feed id and polarization id
    calibrated_maps = []

    # check to see if the infile parameter is a directory.  This is the
    # default case for vegas data processing.  If we have a directory of
    # files, we calibrate each input file separately, then perform the
    # imaging step on all the calibrated outputs.
    if os.path.isdir(cl_params.infilename):
        log.doMessage('INFO', 'Infile name is a directory')
        input_directory = cl_params.infilename

        # calibrate one raw SDFITS file at a time
        for infilename in glob.glob(input_directory + '/' +
                                    os.path.basename(input_directory) +
                                    '*.fits'):
            log.doMessage('INFO', '\nCalibrating', infilename.rstrip('.fits'))
            # change the infilename in the params structure to the
            #  current infile in the directory for each iteration
            cl_params.infilename = infilename
            calibrated_maps_this_file = calibrate_file(term, log, cl_params)
            calibrated_maps.extend(calibrated_maps_this_file)
    else:
            calibrated_maps_this_file = calibrate_file(term, log, cl_params)
            calibrated_maps.extend(calibrated_maps_this_file)

    # if we are doing imaging
    if not cl_params.imagingoff:

        # instantiate an Imaging object
        imag = Imaging()
        # image all the calibrated maps
        imag.run(log, term, cl_params, calibrated_maps)

    sys.stdout.write('\n')
Example #2
0
def runPipeline():

    # the blessings.Terminal object is used for printing to the screen
    terminal = blessings.Terminal()
    term = terminal

    # create instance of CommandLine object to parse input, then
    # parse all the input parameters and store them as attributes in
    # cl_params structure
    cl = commandline.CommandLine()
    cl_params = cl.read(sys)

    # create a directory for storing log files
    mkdir_p('log')

    # instantiate a log object for log files and screen output
    log = Logging(cl_params, 'pipeline')

    # print a command summary to log file/terminal
    command_summary(cl_params, term, log)

    if not cl_params.imagingoff:

        # instantiate an Imaging object
        imag = Imaging.Imaging()

    else:
        imag = None

    log.doMessage('INFO', '{t.underline}Start '
                  'calibration.{t.normal}'.format(t=term))

    # calibrated_maps will contain a list of tuples each with a
    # MappingPipeline instance, window id, feed id and polarization id
    calibrated_maps = []

    # check to see if the infile parameter is a directory.  This is the
    # default case for vegas data processing.  If we have a directory of
    # files, we calibrate each input file separately, then perform the
    # imaging step on all the calibrated outputs.
    if os.path.isdir(cl_params.infilename):
        log.doMessage('INFO', 'Infile name is a directory')
        input_directory = cl_params.infilename

        # Instantiate a SdFits object for I/O and interpreting the
        #  contents of the index file
        sdf = SdFits()

        # generate a name for the index file based on the name of the
        #  raw SDFITS file.  The index file simply has a different extension
        directory_name = os.path.basename(cl_params.infilename.rstrip('/'))
        indexfile = cl_params.infilename + '/' + directory_name + '.index'
        try:
            # create a structure that lists the raw SDFITS rows for
            #  each scan/window/feed/polarization
            row_list, summary = sdf.parseSdfitsIndex(indexfile, cl_params.mapscans)
        except IOError:
            log.doMessage('ERR', 'Could not open index file', indexfile)
            sys.exit()

        quitcal = False
        if cl_params.window and set(cl_params.window).isdisjoint(set(row_list.windows())):
            log.doMessage('ERR', 'no given WINDOW(S)', cl_params.window, 'in dataset')
            quitcal = True
        if cl_params.feed and set(cl_params.feed).isdisjoint(set(row_list.feeds())):
            log.doMessage('ERR', 'no given FEED(S)', cl_params.feed, 'in dataset')
            quitcal = True
        if cl_params.pol and set(cl_params.pol).isdisjoint(set(row_list.pols())):
            log.doMessage('ERR', 'no given POL(S)', cl_params.pol, 'in dataset')
            quitcal = True
        if cl_params.mapscans and set(cl_params.mapscans).isdisjoint(set(row_list.scans())):
            log.doMessage('ERR', 'no given MAPSCAN(S)', cl_params.mapscans, 'in dataset')
            quitcal = True
        if cl_params.refscans and set(cl_params.refscans).isdisjoint(set(row_list.scans())):
            log.doMessage('ERR', 'no given REFSCAN(S)', cl_params.refscans, 'in dataset')
            quitcal = True

        if quitcal:
            sys.exit(12)

        # calibrate one raw SDFITS file at a time
        for infilename in glob.glob(input_directory + '/' +
                                    os.path.basename(input_directory) +
                                    '*.fits'):
            log.doMessage('DBG', 'Attempting to calibrate', os.path.basename(infilename).rstrip('.fits'))
            # change the infilename in the params structure to the
            #  current infile in the directory for each iteration
            cl_params.infilename = infilename

            # copy the cl_params structure so we can modify it during calibration
            # for each seperate file.
            commandline_options = copy.deepcopy(cl_params)
            calibrated_maps_this_file = calibrate_file(term, log, commandline_options)
            if calibrated_maps_this_file:
                calibrated_maps.extend(calibrated_maps_this_file)
    else:
        commandline_options = copy.deepcopy(cl_params)
        calibrated_maps_this_file = calibrate_file(term, log, commandline_options)
        if calibrated_maps_this_file:
            calibrated_maps.extend(calibrated_maps_this_file)

    if not calibrated_maps:
        log.doMessage('ERR', 'No calibrated spectra.  Check inputs and try again')
        sys.exit(-1)

    # if we are doing imaging
    if not cl_params.imagingoff:

        # image all the calibrated maps
        import itertools
        calibrated_maps = list(itertools.chain(*calibrated_maps))

        imag.run(log, term, cl_params, calibrated_maps)

    sys.stdout.write('\n')
Example #3
0
def runPipeline():

    # the blessings.Terminal object is used for printing to the screen
    terminal = blessings.Terminal()
    term = terminal

    # create instance of CommandLine object to parse input, then
    # parse all the input parameters and store them as attributes in
    # cl_params structure
    cl = commandline.CommandLine()
    cl_params = cl.read(sys)

    # create a directory for storing log files
    mkdir_p('log')

    # instantiate a log object for log files and screen output
    log = Logging(cl_params, 'pipeline')

    # print a command summary to log file/terminal
    command_summary(cl_params, term, log)

    if not cl_params.imagingoff:

        # instantiate an Imaging object
        imag = Imaging.Imaging()

    else:
        imag = None

    log.doMessage(
        'INFO', '{t.underline}Start '
        'calibration.{t.normal}'.format(t=term))

    # calibrated_maps will contain a list of tuples each with a
    # MappingPipeline instance, window id, feed id and polarization id
    calibrated_maps = []

    # check to see if the infile parameter is a directory.  This is the
    # default case for vegas data processing.  If we have a directory of
    # files, we calibrate each input file separately, then perform the
    # imaging step on all the calibrated outputs.
    if os.path.isdir(cl_params.infilename):
        log.doMessage('INFO', 'Infile name is a directory')
        input_directory = cl_params.infilename

        # Instantiate a SdFits object for I/O and interpreting the
        #  contents of the index file
        sdf = SdFits()

        # generate a name for the index file based on the name of the
        #  raw SDFITS file.  The index file simply has a different extension
        directory_name = os.path.basename(cl_params.infilename.rstrip('/'))
        indexfile = cl_params.infilename + '/' + directory_name + '.index'
        try:
            # create a structure that lists the raw SDFITS rows for
            #  each scan/window/feed/polarization
            row_list, summary = sdf.parseSdfitsIndex(indexfile,
                                                     cl_params.mapscans)
        except IOError:
            log.doMessage('ERR', 'Could not open index file', indexfile)
            sys.exit()

        quitcal = False
        if cl_params.window and set(cl_params.window).isdisjoint(
                set(row_list.windows())):
            log.doMessage('ERR', 'no given WINDOW(S)', cl_params.window,
                          'in dataset')
            quitcal = True
        if cl_params.feed and set(cl_params.feed).isdisjoint(
                set(row_list.feeds())):
            log.doMessage('ERR', 'no given FEED(S)', cl_params.feed,
                          'in dataset')
            quitcal = True
        if cl_params.pol and set(cl_params.pol).isdisjoint(set(
                row_list.pols())):
            log.doMessage('ERR', 'no given POL(S)', cl_params.pol,
                          'in dataset')
            quitcal = True
        if cl_params.mapscans and set(cl_params.mapscans).isdisjoint(
                set(row_list.scans())):
            log.doMessage('ERR', 'no given MAPSCAN(S)', cl_params.mapscans,
                          'in dataset')
            quitcal = True
        if cl_params.refscans and set(cl_params.refscans).isdisjoint(
                set(row_list.scans())):
            log.doMessage('ERR', 'no given REFSCAN(S)', cl_params.refscans,
                          'in dataset')
            quitcal = True

        if quitcal:
            sys.exit(12)

        # calibrate one raw SDFITS file at a time
        for infilename in glob.glob(input_directory + '/' +
                                    os.path.basename(input_directory) +
                                    '*.fits'):
            log.doMessage('DBG', 'Attempting to calibrate',
                          os.path.basename(infilename).rstrip('.fits'))
            # change the infilename in the params structure to the
            #  current infile in the directory for each iteration
            cl_params.infilename = infilename

            # copy the cl_params structure so we can modify it during calibration
            # for each seperate file.
            commandline_options = copy.deepcopy(cl_params)
            calibrated_maps_this_file = calibrate_file(term, log,
                                                       commandline_options)
            if calibrated_maps_this_file:
                calibrated_maps.extend(calibrated_maps_this_file)
    else:
        commandline_options = copy.deepcopy(cl_params)
        calibrated_maps_this_file = calibrate_file(term, log,
                                                   commandline_options)
        if calibrated_maps_this_file:
            calibrated_maps.extend(calibrated_maps_this_file)

    if not calibrated_maps:
        log.doMessage('ERR',
                      'No calibrated spectra.  Check inputs and try again')
        sys.exit(-1)

    # if we are doing imaging
    if not cl_params.imagingoff:

        # image all the calibrated maps
        import itertools
        calibrated_maps = list(itertools.chain(*calibrated_maps))

        imag.run(log, term, cl_params, calibrated_maps)

    sys.stdout.write('\n')