Example #1
0
def get_standard(arf, base_standards_dir=None, analytic=None):
    """Given an archive file name return the name of the 
        standard profile to use for TOA fitting.

        Input:
            arf: An ArchiveFile object for which we want to get a standard.
            base_stddir: The base directory containing standard profiles.
                (Default: Use value from configuration file.)
            analytic: True if an analytic profile should be returned.
                (Default: Use value from configuration file.)

        Output:
            std: The name of the standard profile.
    """
    if base_standards_dir is None:
        base_standards_dir = config.cfg.base_standards_dir
    if analytic is None:
        analytic = config.cfg.analytic

    if analytic:
        fn = utils.get_outfn("%(name)s_%(telescop)s_%(rcvr)s_%(backend)s.m",
                             arf)
    else:
        fn = utils.get_outfn("%(name)s_%(telescop)s_%(rcvr)s_%(backend)s.std",
                             arf)
    fn = fn.capitalize()  # J/B should be capitalized, all the rest lower case
    path = os.path.join(base_standards_dir, arf['telescop'].lower(), \
                            arf['rcvr'].lower(), arf['backend'].lower())
    fn = os.path.join(path, fn)

    return fn
Example #2
0
    def __init__(self, infns, outfn, is_asterix=False, maketoas=True):
        """Given a list of PSRCHIVE file names create a
            ReductionJob object.

            Input:
                infns: A list of input PSRCHIVE archive file names.
                outfn: The name of the reduced archive output.
                is_asterix: If the data is from Effelsberg's Asterix backend.
                    If True, the header information will be corrected.
                    (Default: False)
                maketoas: Whether or not TOAs should be made.
                    (Default: True)

            Output:
                job: The Reduction job object.
        """
        self.infns = infns
        self.outfn = outfn
        self.basenm = os.path.splitext(self.outfn)[0]

        self.is_asterix = is_asterix # Hopefully only temporary
        self.maketoas = maketoas

        logfn = utils.get_outfn(self.basenm+'.log', infns[0])
        self.log = ReductionLog(infns, logfn)
Example #3
0
def main():
    print ""
    print "          toas.py"
    print "     Patrick  Lazarus"
    print ""
    file_list = args + options.from_glob
    to_exclude = options.excluded_files + options.excluded_by_glob
    to_time = utils.exclude_files(file_list, to_exclude)
    print "Number of input files: %d" % len(to_time)

    to_time = [utils.ArchiveFile(fn) for fn in to_time]

    # Read configurations
    for arf in to_time:
        config.cfg.load_configs_for_archive(arf)
        stdfn = get_standard(arf)
        if not os.path.isfile(stdfn):
            raise errors.StandardProfileError("The standard profile (%s) " \
                                            "cannot be found!" % stdfn)
        toastrs = get_toas(arf, stdfn)
        for toastr in toastrs:
            flagstrs = [
                utils.get_outfn(flag, arf) for flag in config.cfg.flags
            ]
            if flagstrs:
                toastr = toastr + " " + " ".join(flagstrs)
            print toastr
Example #4
0
def clean_archive(inarf, outfn, clean_re=None, *args, **kwargs):
    import psrchive  # Temporarily, because python bindings
    # are not available on all computers

    if clean_re is None:
        clean_re = config.cfg.clean_strategy
    try:
        outfn = utils.get_outfn(outfn, inarf)
        shutil.copy(inarf.fn, outfn)

        outarf = utils.ArchiveFile(outfn)

        trim_edge_channels(outarf)
        prune_band(outarf)
        remove_bad_channels(outarf)
        remove_bad_subints(outarf)

        matching_cleaners = [
            clnr for clnr in cleaners
            if clean_re and re.search(clean_re, clnr)
        ]
        if len(matching_cleaners) == 1:
            ar = psrchive.Archive_load(outarf.fn)
            cleaner = eval(matching_cleaners[0])
            utils.print_info(
                "Cleaning using '%s(...)'." % matching_cleaners[0], 2)
            cleaner(ar, *args, **kwargs)
            ar.unload(outfn)
        elif len(matching_cleaners) == 0:
            utils.print_info("No cleaning strategy selected. Skipping...", 2)
        else:
            raise errors.CleanError("Bad cleaner selection. " \
                                    "'%s' has %d matches." % \
                                    (clean_re, len(matching_cleaners)))
    except:
        # An error prevented cleaning from being successful
        # Remove the output file because it may confuse the user
        if os.path.exists(outfn):
            os.remove(outfn)
        raise
    return outarf
Example #5
0
def main():
    print ""
    print "         clean.py"
    print "     Patrick  Lazarus"
    print ""
    file_list = args.files + args.from_glob
    to_exclude = args.excluded_files + args.excluded_by_glob
    to_clean = utils.exclude_files(file_list, to_exclude)
    print "Number of input files: %d" % len(to_clean)

    # Read configurations
    for infn in to_clean:
        inarf = utils.ArchiveFile(infn)
        config.cfg.load_configs_for_archive(inarf)
        outfn = utils.get_outfn(args.outfn, inarf)
        shutil.copy(inarf.fn, outfn)

        outarf = utils.ArchiveFile(outfn)
        ar = outarf.get_archive()

        try:
            for name, cfgstrs in args.cleaner_queue:
                # Set up the cleaner
                cleaner = cleaners.load_cleaner(name)
                for cfgstr in cfgstrs:
                    cleaner.parse_config_string(cfgstr)
                cleaner.run(ar)
        except:
            # An error prevented cleaning from being successful
            # Remove the output file because it may confuse the user
            #if os.path.exists(outfn):
            #    os.remove(outfn)
            raise
        finally:
            ar.unload(outfn)
            print "Cleaned archive: %s" % outfn
Example #6
0
#!/usr/bin/env python

import sys
import os.path

import utils

if "-h" in sys.argv or "--help" in sys.argv or len(sys.argv) < 3:
    sys.stderr.write("Usage: %s OUTNAME INFILE\n" % \
                        os.path.split(sys.argv[0])[-1])
    sys.exit(1)

arf = utils.ArchiveFile(sys.argv[2])
print utils.get_outfn(sys.argv[1], arf)