Example #1
0
def main():
    pulsefiles = args + glob.glob(options.glob_expr)
    if len(pulsefiles) < 2:
        print pulsefiles
        sys.stderr.write("Only %d pulse files provided. Exiting!\n" % \
                                len(pulsefiles))
        sys.exit(1)

    print "Summing %d profiles" % len(pulsefiles)
   
    psum = pulse.read_pulse_from_file(pulsefiles[0]) + \
            pulse.read_pulse_from_file(pulsefiles[1])
    for pulsefile in pulsefiles[2:]:
        psum += pulse.read_pulse_from_file(pulsefile)

    # Do post processing
    for procstep in post_sum_processing:
        method_name, method_args = procstep
        method = eval('psum.%s' % method_name)
        if type(method_args)==types.TupleType:
            print "Applying %s with arguments %s" % (method_name, method_args)
            method(*method_args)
        elif method_args is None:
            print "Applying %s" % method_name
            method()
        else:
            print "Applying %s with argument %s" % (method_name, method_args)
            method(method_args)

    # Write to file
    psum.write_to_file(basefn=options.outname)
Example #2
0
def get_pulses(pulsefiles):
    """Given a list of pulse files
        return a list of Pulse objects.
    """
    pulses = []
    for pf in pulsefiles:
        pulses.append(pulse.read_pulse_from_file(pf))
    return pulses
Example #3
0
def get_pulses(pulsefiles):
    """Given a list of pulse files
        return a list of Pulse objects.
    """
    pulses = []
    for pf in pulsefiles:
        pulses.append(pulse.read_pulse_from_file(pf))
    return pulses
Example #4
0
def main():
    # Files can be provided as arguments, with "-g/--glob" option
    # or be contained in a file provided with "-f/--file" option.
    filenames = args + glob.glob(options.glob)
    if options.file is not None:
        if not os.path.exists(options.file):
            raise ValueError("File %s does not exist" % options.file)
        else:
            f = open(options.file, 'r')
            filenames += [fn.strip() for fn in f.readlines()]

    if not options.quiet:
        print "Number of files to consider: %d" % len(filenames)

    # Initialise lists to store energies
    on_energies = []
    off_energies = []

    # Collect energies
    for fn in filenames:
        if not os.path.exists(fn):
            continue
        prof = pulse.read_pulse_from_file(fn)
        (on, off) = prof.get_pulse_energies()
        on_energies.append(on)
        off_energies.append(off)

    on_mean = np.mean(on_energies)
    if not options.quiet:
        print "Average on-pulse energy: %f" % on_mean
    on = on_energies / on_mean
    off = off_energies / on_mean

    warnings.warn("Only plotting values with E/<E> > -5")
    on = on[on > -5]

    if not options.quiet:
        print "Number of pulses being plotted: %d" % len(on)

    # Plot results
    fig = plt.figure()
    myhist(on, bins=options.numbins, \
                color='k', linestyle='-', label="On Pulse")
    plt.xlabel("E/<E>")
    plt.ylabel("Number of Pulses")
    ymin, ymax = plt.ylim()
    plt.yscale("log")
    plt.ylim(0.5, ymax * 2)
    plt.title(options.title)
    plt.legend(loc="best")
    if options.annotate:
        fig.text(0.05, 0.02, "Total # pulses plotted: %d" % on.size, \
                    ha='left', va='center', size='small')
    plt.savefig(options.savefn)
    if options.interactive:
        plt.show()
def main():
    # Files can be provided as arguments, with "-g/--glob" option
    # or be contained in a file provided with "-f/--file" option.
    filenames = args + glob.glob(options.glob)
    if options.file is not None:
        if not os.path.exists(options.file):
            raise ValueError("File %s does not exist" % options.file)
        else:
            f = open(options.file, 'r')
            filenames += [fn.strip() for fn in f.readlines()]
    
    if not options.quiet:
        print "Number of files to consider: %d" % len(filenames)

    # Initialise lists to store energies
    on_energies = []
    off_energies = []

    # Collect energies
    for fn in filenames:
        if not os.path.exists(fn):
            continue
        prof = pulse.read_pulse_from_file(fn)
        (on, off) = prof.get_pulse_energies()
        on_energies.append(on)
        off_energies.append(off)
        
    on_mean = np.mean(on_energies)
    if not options.quiet:
        print "Average on-pulse energy: %f" % on_mean
    on = on_energies/on_mean
    off = off_energies/on_mean
    
    warnings.warn("Only plotting values with E/<E> > -5")
    on = on[on>-5]
    
    if not options.quiet:
        print "Number of pulses being plotted: %d" % len(on)
    
    # Plot results
    fig = plt.figure()
    myhist(on, bins=options.numbins, \
                color='k', linestyle='-', label="On Pulse")
    plt.xlabel("E/<E>")
    plt.ylabel("Number of Pulses")
    ymin, ymax = plt.ylim()
    plt.yscale("log")
    plt.ylim(0.5, ymax*2)
    plt.title(options.title)
    plt.legend(loc="best")
    if options.annotate:
        fig.text(0.05, 0.02, "Total # pulses plotted: %d" % on.size, \
                    ha='left', va='center', size='small')
    plt.savefig(options.savefn)
    if options.interactive:
        plt.show()