Exemplo n.º 1
0
def main(options, args):
    dir = args[0].rstrip('/')
    p = Popen('ls %s' % dir, shell=True, stdout=PIPE, stderr=PIPE)
    filelist = p.communicate()[0].split()
    #filelist = os.listdir(dir)
    aperNums = getAperNumbers(filelist, dir)
    # create dictionary of apertures
    aperlist = {} 
    for i in aperNums:
        aperlist[i] = Aperture(i)




    print "\tReading in data..."
    pb = progressbarClass(len(filelist))
    # read in data to aperture objects
    for i, file in enumerate(filelist):
        
        fptr = open(dir + '/' + file)
        data = []
        for line in fptr.readlines():
            if '#' not in line:
                data.append(line.rstrip('\n'))

        fptr.close()

        for line in data:
            vals = line.split()
            num = vals[0] 
            coords = float(vals[1]), float(vals[2])
            flux = {'sky': float(vals[5]), 'aper': float(vals[6])}
            err = float(vals[4])
            mag = float(vals[3])

            aperlist[num].addLine((coords[0], coords[1], flux['sky'], flux['aper'], err, mag))

        pb.progress(i)

    _mkdir('plots')

    # Plotting section 
    if options.coords and not options.lc:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.subplot(211)
            plt.title('Coordinates')
            plt.plot(aper.xcoord, 'rx')
            plt.subplot(212)
            plt.plot(aper.ycoord, 'rx')

    elif options.lc and not options.coords:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.subplot(211)
            plt.title('Lightcurve for object %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f_{aperture} - f_{sky}$')
            #plt.plot(aper.sky, 'bx')
            plt.errorbar(arange(len(filelist)), aper.flux, yerr = aper.getErrors(),  fmt='bx')

            plt.subplot(212)
            plt.ylabel('Sky')
            plt.plot(aper.sky, 'rx')
    
    elif options.lc and options.coords:
        print "\n\n\tMaking plots..."
        pb = progressbarClass(len(aperlist.values()))
        for i, aper in enumerate(aperlist.itervalues()):

            plt.figure(aper.num)
            plt.subplot(411)
            plt.title('Lightcurve for object %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f_{aperture} - f_{sky}$')
            #plt.plot(aper.sky, 'bx')
            plt.errorbar(arange(len(filelist)), aper.flux, yerr = aper.getErrors(),  fmt='bx')

            plt.subplot(412)
            plt.ylabel('Sky')
            plt.plot(aper.sky, 'rx')

            plt.subplot(413)
            plt.ylabel('X')
            plt.plot(aper.xcoord, 'go')
            plt.subplot(414)
            plt.ylabel('Y')
            plt.plot(aper.ycoord, 'go')
            plt.savefig('plots/aper%s.png'  % aper.num)
            plt.close()
            pb.progress(i)

    elif options.hist:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Distribution for aperture %s' % aper.num)
            plt.xlabel('Counts')
            plt.ylabel('Frequency')
            plt.hist(aper.flux, int(options.hist))


    elif options.err:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Error scatter plot for aperture %s' % aper.num)
            plt.xlabel('Counts')
            plt.ylabel('Error in counts')
            plt.scatter(aper.flux, aper.getErrors())

    elif options.residuals:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Residuals for aperture %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f - \bar{f}$')
            plt.axhline(linewidth=1, alpha=0.75, color='b')
            plt.plot(aper.residuals(), 'rx')
Exemplo n.º 2
0
def main(options, args):
    dir = args[0].rstrip('/')
    p = Popen('ls %s' % dir, shell=True, stdout=PIPE, stderr=PIPE)
    filelist = p.communicate()[0].split()
    #filelist = os.listdir(dir)
    aperNums = getAperNumbers(filelist, dir)
    # create dictionary of apertures
    aperlist = {}
    for i in aperNums:
        aperlist[i] = Aperture(i)

    print "\tReading in data..."
    pb = progressbarClass(len(filelist))
    # read in data to aperture objects
    for i, file in enumerate(filelist):

        fptr = open(dir + '/' + file)
        data = []
        for line in fptr.readlines():
            if '#' not in line:
                data.append(line.rstrip('\n'))

        fptr.close()

        for line in data:
            vals = line.split()
            num = vals[0]
            coords = float(vals[1]), float(vals[2])
            flux = {'sky': float(vals[5]), 'aper': float(vals[6])}
            err = float(vals[4])
            mag = float(vals[3])

            aperlist[num].addLine(
                (coords[0], coords[1], flux['sky'], flux['aper'], err, mag))

        pb.progress(i)

    _mkdir('plots')

    # Plotting section
    if options.coords and not options.lc:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.subplot(211)
            plt.title('Coordinates')
            plt.plot(aper.xcoord, 'rx')
            plt.subplot(212)
            plt.plot(aper.ycoord, 'rx')

    elif options.lc and not options.coords:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.subplot(211)
            plt.title('Lightcurve for object %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f_{aperture} - f_{sky}$')
            #plt.plot(aper.sky, 'bx')
            plt.errorbar(arange(len(filelist)),
                         aper.flux,
                         yerr=aper.getErrors(),
                         fmt='bx')

            plt.subplot(212)
            plt.ylabel('Sky')
            plt.plot(aper.sky, 'rx')

    elif options.lc and options.coords:
        print "\n\n\tMaking plots..."
        pb = progressbarClass(len(aperlist.values()))
        for i, aper in enumerate(aperlist.itervalues()):

            plt.figure(aper.num)
            plt.subplot(411)
            plt.title('Lightcurve for object %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f_{aperture} - f_{sky}$')
            #plt.plot(aper.sky, 'bx')
            plt.errorbar(arange(len(filelist)),
                         aper.flux,
                         yerr=aper.getErrors(),
                         fmt='bx')

            plt.subplot(412)
            plt.ylabel('Sky')
            plt.plot(aper.sky, 'rx')

            plt.subplot(413)
            plt.ylabel('X')
            plt.plot(aper.xcoord, 'go')
            plt.subplot(414)
            plt.ylabel('Y')
            plt.plot(aper.ycoord, 'go')
            plt.savefig('plots/aper%s.png' % aper.num)
            plt.close()
            pb.progress(i)

    elif options.hist:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Distribution for aperture %s' % aper.num)
            plt.xlabel('Counts')
            plt.ylabel('Frequency')
            plt.hist(aper.flux, int(options.hist))

    elif options.err:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Error scatter plot for aperture %s' % aper.num)
            plt.xlabel('Counts')
            plt.ylabel('Error in counts')
            plt.scatter(aper.flux, aper.getErrors())

    elif options.residuals:
        for aper in aperlist.itervalues():
            plt.figure(aper.num)
            plt.title('Residuals for aperture %s' % aper.num)
            plt.xlabel('Frame')
            plt.ylabel(r'$f - \bar{f}$')
            plt.axhline(linewidth=1, alpha=0.75, color='b')
            plt.plot(aper.residuals(), 'rx')
Exemplo n.º 3
0
def main((options, args)):#

    parameters = {
            "biasle": "0",
            "centro": "true",
            "exsource": "constant",
            "etime": "1.0",
            "fixann": "false",
            "usemags": "false",
            "maxiter": "9",
            "maxshift": options.maxshift,
            "optima": "false",
            "padu": "1.2",
            "photon": "1",
            "positive": "true",
            "sature": "1.7E30",
            "search": options.search,
            "skyest": "2",
            "toler": "0.05",
            "usemask": "false"
            }

    srcdir = fitsDir(args[0])
    outputdir = options.opdir.rstrip('/')

    #check if options.opdir is a directory
    try:
        _mkdir(outputdir)
    except (OSError, c):
        print >> stderr, "Error: %s" % c
        exit(1)

    try:
        paramfile = open(outputdir + "/.cmd", mode="w")
    except IOError:
        print >> stderr, "Error writing parameters to %s" % ('/'.join((outputdir, 'cmd')))
        exit(1)

    #make parameter file read only
    p = Popen('chmod -w %s/.cmd' % outputdir, shell=True)
    p.communicate()

    for pair in parameters.iteritems():
        paramfile.write(" = ".join(pair) + "\n")

    paramfile.close()

    if not os.path.isfile(options.apfile):
        print >> stderr, "Error: initial aperture file '%s' must exist in current directory" % options.apfile
        exit(1)




    if not options.verbose:
        pb = progressbarClass(len(srcdir))

    for i, file in enumerate(srcdir):
        stub = file.rpartition('/')[2]
        sdf = stub.rstrip('.fits') + ".sdf"
        catfile = stub.partition('.')[0] + ".cat"
        cmd = 'source $STARLINK_DIR/etc/profile && convert && fits2ndf in=\"%s/%s\" out=\"%s/%s\"' % (srcdir, stub, srcdir, stub.partition('.')[0])
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()
        if len(error) != 0:
            print error

        #check for apfile existence
        if not os.path.isfile(options.apfile):
            print >> stderr, "Error: initial aperture file '%s' must exist in current directory" % options.apfile
            exit(1)

        cmd = 'source $STARLINK_DIR/etc/profile && photom && autophotom'
        cmd += ' in=%s/%s infile=%s outfile=%s/%s' % (srcdir, sdf, options.apfile, outputdir, catfile)
        for n, v in parameters.iteritems():
            cmd += ' ' + '='.join((n, v))
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        cmd = 'rm %s && cp %s/%s %s' % (options.apfile, outputdir, catfile, options.apfile)
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        cmd = 'rm -f %s/%s' % (srcdir, sdf)
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        if not options.verbose:
            pb.progress(i)
Exemplo n.º 4
0
def main((options, args)):  #

    parameters = {
        "biasle": "0",
        "centro": "true",
        "exsource": "constant",
        "etime": "1.0",
        "fixann": "false",
        "usemags": "false",
        "maxiter": "9",
        "maxshift": options.maxshift,
        "optima": "false",
        "padu": "1.2",
        "photon": "1",
        "positive": "true",
        "sature": "1.7E30",
        "search": options.search,
        "skyest": "2",
        "toler": "0.05",
        "usemask": "false"
    }

    srcdir = fitsDir(args[0])
    outputdir = options.opdir.rstrip('/')

    #check if options.opdir is a directory
    try:
        _mkdir(outputdir)
    except (OSError, c):
        print >> stderr, "Error: %s" % c
        exit(1)

    try:
        paramfile = open(outputdir + "/.cmd", mode="w")
    except IOError:
        print >> stderr, "Error writing parameters to %s" % ('/'.join(
            (outputdir, 'cmd')))
        exit(1)

    #make parameter file read only
    p = Popen('chmod -w %s/.cmd' % outputdir, shell=True)
    p.communicate()

    for pair in parameters.iteritems():
        paramfile.write(" = ".join(pair) + "\n")

    paramfile.close()

    if not os.path.isfile(options.apfile):
        print >> stderr, "Error: initial aperture file '%s' must exist in current directory" % options.apfile
        exit(1)

    if not options.verbose:
        pb = progressbarClass(len(srcdir))

    for i, file in enumerate(srcdir):
        stub = file.rpartition('/')[2]
        sdf = stub.rstrip('.fits') + ".sdf"
        catfile = stub.partition('.')[0] + ".cat"
        cmd = 'source $STARLINK_DIR/etc/profile && convert && fits2ndf in=\"%s/%s\" out=\"%s/%s\"' % (
            srcdir, stub, srcdir, stub.partition('.')[0])
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()
        if len(error) != 0:
            print error

        #check for apfile existence
        if not os.path.isfile(options.apfile):
            print >> stderr, "Error: initial aperture file '%s' must exist in current directory" % options.apfile
            exit(1)

        cmd = 'source $STARLINK_DIR/etc/profile && photom && autophotom'
        cmd += ' in=%s/%s infile=%s outfile=%s/%s' % (
            srcdir, sdf, options.apfile, outputdir, catfile)
        for n, v in parameters.iteritems():
            cmd += ' ' + '='.join((n, v))
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        cmd = 'rm %s && cp %s/%s %s' % (options.apfile, outputdir, catfile,
                                        options.apfile)
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        cmd = 'rm -f %s/%s' % (srcdir, sdf)
        if options.verbose:
            printoutput(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        result, error = p.communicate()

        if len(error) != 0:
            print error

        if not options.verbose:
            pb.progress(i)