Exemplo n.º 1
0
def process_rawfile(rawfile, output_dir,
                    reduce,
                    script,
                    file_logging=True
                    ):
    """
    A convenience function applying sensible defaults to reduce a rawfile.

    Args:
    rawfile: Name of a file in the ami data dir, e.g. "SWIFT121101-121101.raw"
    output_dir: Folder where UVFITS for the target and calibrator will be output.
    reduce: instance of ami.Reduce
    array: 'LA' or 'SA' (Default: LA)
    script: Reduction commands.

    Returns:
        - A dictionary containing information about the rawfile,
          e.g. pointing, calibrator name, rain modulation.
          See also: ``ami.keys``
    """
    r = reduce
    if file_logging:
        file_logdir = output_dir
    else:
        file_logdir = None
    r.set_active_file(rawfile, file_logdir)
    r.run_script(script)
    r.update_flagging_info()
    write_command_overrides = {}
    if r.ami_version=='legacy':
        write_command_overrides['channels'] = '3-8'
    if r.files[rawfile]['raster']:
        write_command_overrides['fits_or_multi'] = 'multi'
        write_command_overrides['offsets'] = 'all'

    r.write_files(rawfile, output_dir,
                  write_command_overrides=write_command_overrides)

    r.files[rawfile][keys.obs_name] = os.path.splitext(rawfile)[0]
    info_filename = os.path.splitext(rawfile)[0] + '.json'
    with open(os.path.join(output_dir, info_filename), 'w') as f:
        json.dump(make_serializable(r.files[rawfile]), f,
                  sort_keys=True, indent=4)
    return r.files[rawfile]