Beispiel #1
0
    def plot_colorcolor(self):
        import matplotlib.pyplot as plt
        from functions import scaleto
        iso = np.genfromtxt('/home/jwe/data/iso_00.500_Gyr.dat', names=True)
        ra = self.table['RA_J2000']
        dec = self.table['DEC_J2000']
        mra = np.mean(self.table['RA_J2000'])
        mde = np.mean(self.table['DEC_J2000'])
        d = np.sqrt((ra - mra)**2 + (dec - mde)**2) * 60.

        bv = self.table['Bmag'] - self.table['Vmag']
        vi = self.table['Vmag'] - self.table['Imag']
        vmag = self.table['Vmag']
        s = scaleto(vmag, (40., 1.))
        i = np.where(d < 8.)
        plt.scatter(bv[i] - 0.182,
                    vi[i] - 0.3,
                    marker='o',
                    edgecolor='none',
                    c=d[i],
                    s=s[i],
                    alpha=0.25)
        #plt.scatter(iso['BV'],iso['VI'],marker='o',edgecolor='none', s=scaleto(iso['M_V'],(40.1,1.)), alpha=0.5)
        plt.plot(iso['BV'], iso['VI'], 'k')
        #plt.colorbar()
        plt.xlabel('B - V')
        plt.ylabel('V - I')

        plt.savefig(config.resultpath + 'ngc6633gab_bv_vi.pdf')
        plt.close()
Beispiel #2
0
    def array_toimage(self, matrix=None, filename=None):
        from PIL import Image  # @UnresolvedImport
        from functions import scaleto

        if matrix is None:
            m1 = self.mag
        else:
            m1 = matrix

        if filename is None:
            filename = 'mag%sarray.png' % self.filtercol

        m1[np.isnan(m1)] = 0.0
        simg = scaleto(m1, [0.0, 255.0])

        simg = np.rint(simg)
        simg = simg.astype('uint8')
        im = Image.fromarray(simg)

        im.save(config.plotpath + filename)
Beispiel #3
0
    def priorities(self, verbose = False):
        """updates the priorities in the m67 table"""

        def makeplot(bv, v, p, filename=None):
            """plot the priorities"""
            import matplotlib
            matplotlib.use('Agg')
            from matplotlib import pyplot
            pyplot.scatter(bv, v, c=p, edgecolor='none', alpha=0.75)
            pyplot.xlim(0.4,1.0)
            pyplot.ylim(16.5,12.0)
            pyplot.title('M 67')
            pyplot.xlabel('B - V')
            pyplot.ylabel('V mag')
            
            if filename is None: 
                pyplot.show()    
            else:
                pyplot.savefig(filename, dpi=300)
            pyplot.close()

        def plotradec(ra, dec, p, filename=None):
            """plot the priorities"""
            import matplotlib
            matplotlib.use('Agg')
            from matplotlib import pyplot
            pyplot.scatter(ra, dec, c=p, edgecolor='none', alpha=0.75)
            pyplot.title('M 67')
            pyplot.xlabel('R.A.')
            pyplot.ylabel('Dec')
            
            if filename is None: 
                pyplot.show()    
            else:
                pyplot.savefig(filename, dpi=300)
            pyplot.close()

        print('calculate priorities ...')
        self.wifsip.execute("UPDATE m67 SET priority=NULL, pointing=NULL;")
        self.wifsip.execute("""UPDATE m67 
            SET priority=1.0 
            WHERE bmag-vmag>0.6 and bmag-vmag<1.0
            AND vmag>13.5 and vmag<16 and pmb>0;""")
        
        data = self.wifsip.query("""SELECT seq, vmag, bmag-vmag, pmb 
                               FROM m67
                               WHERE bmag-vmag>0.6 AND bmag-vmag<0.75
                               AND vmag>13.5 and vmag<16
                               ORDER BY pmb DESC;""")
        seq = [d[0] for d in data]
        v = np.array([d[1] for d in data])
        bv = np.array([d[2] for d in data])
        pmb = np.array([d[3] for d in data])
        
        p1 = scaleto(pmb, [0.0, 1.0])

        print(len(seq), 'stars brighter V<16')
        for i in range(len(seq)):
            if verbose:
                print('%4d: %.3f --> %.3f' % (seq[i], v[i], p1[i]))
            self.wifsip.execute("""UPDATE m67
                          SET priority = priority * %f
                          WHERE seq = %d;""" % (p1[i], seq[i]), commit=False)
        self.wifsip.commit()   
        
        data = self.wifsip.query("""SELECT bmag-vmag, vmag, priority
                               FROM m67
                               WHERE priority > 0.0
                               ORDER BY seq;""")
        
        bv = np.array([d[0] for d in data])
        vmag = np.array([d[1] for d in data])
        p = np.array([d[2] for d in data])
        makeplot(bv,vmag, p, filename=config.plotpath+'priorities.pdf')
Beispiel #4
0
    def priorities(self, verbose = False):
        """updates the priorieties in the m48stars table"""
        import numpy as np
        from functions import scaleto
        
        print 'calculate priorities ...'
        self.wifsip.execute("UPDATE m48stars SET priority=NULL;")
        self.wifsip.execute("""UPDATE m48stars 
            SET priority=1.0 
            WHERE vmag<16.5 
            AND NOT tab IS NULL;""")
        
        data = self.wifsip.query("""SELECT tab, vmag 
                               FROM m48stars
                               WHERE not bv is null AND vmag<16.5
                               ORDER BY tab;""")
        tab = [d[0] for d in data]
        v = np.array([d[1] for d in data])
        p1 = scaleto(v,[1.0, 0.8])
        print len(tab),'stars brighter V<16.5'
        for i in range(len(tab)):
            if verbose: print '%4d: %.3f --> %.3f' % (tab[i], v[i],p1[i])
            self.wifsip.execute("""UPDATE m48stars
                          SET priority = priority * %f
                          WHERE tab = %d;""" % (p1[i], tab[i]), commit=False)
        self.wifsip.commit()   

        lengood = self.wifsip.query("select count(starid) from m48stars where good;")
        print lengood[0],'stars with periods'
        
        self.wifsip.execute("""UPDATE m48stars
                          SET priority = priority * 0.5
                          WHERE NOT good;""")
        self.wifsip.commit()   

        iso = IsoChrone('/work2/jwe/m48/data/output256520738433.dat')
        x = iso['V'] + self.dm
        y = iso['B-V'] + self.ebv
        data = self.wifsip.query("""SELECT tab, vmag, bv 
                               FROM m48stars 
                               WHERE not bv is null AND vmag<16.5
                               ORDER BY tab;""")
        tab = [d[0] for d in data]
        v= np.array([d[1] for d in data])
        bv = np.array([d[2] for d in data])
        p = np.zeros(len(tab))
        print len(tab),'stars for isochrone priority'
        
        for i in range(len(tab)):
            p[i] = np.min(abs(x-v[i])+abs(y-bv[i]))
            
        p[p > 0.4] = 0.4
        p = scaleto(p, [1.0, 0.0])
        for t in tab:
            i = tab.index(t)
            if verbose: 
                print '%d: V=%.3f B-V=%.3f p=%.3f' % (t, v[i], bv[i], p[i])
            self.wifsip.execute("""UPDATE m48stars
                              SET priority = priority * %f
                              WHERE tab = %d;""" % (p[i], t), commit=False)
        self.wifsip.commit()   

        data = self.wifsip.query("""SELECT tab, ra, dec
                               FROM m48stars
                               WHERE not ra is NULL AND not dec is NULL
                               AND priority > 0.0
                               ORDER BY TAB;""")
        tab = [d[0] for d in data]
        print len(tab),'stars for distance priority'
        ra = np.array([d[1] for d in data])
        dec = np.array([d[2] for d in data])
        dist = np.sqrt((ra-self.center[0])**2+(dec-self.center[1])**2)
        # only rank stars where distance greater than 0.5 degrees
        i = np.where(dist > 0.5)
        p = scaleto(dist, [1.0, 0.0])
        for t in tab:
            i = tab.index(t)
            try:
                if verbose:
                    print '%d: d=%.3f p=%.3f' % (t,dist[i],p[i])
                self.wifsip.execute("""UPDATE m48stars
                              SET priority = priority * %f
                              WHERE tab = %d;""" % (p[i], t), commit=False)
            except TypeError:
                print t
        self.wifsip.commit() 
Beispiel #5
0
    from PIL import Image  # @UnresolvedImport
    import numpy as np
    import pyfits
    import pylab as plt

    fitsfile = '/work2/jwe/stella/wifsip/m48/coadd.fits'
    fileout = '/work1/jwe/Dropbox/Documents/Poster/AIP2014/m48.jpg'

    try:
        hdulist = pyfits.open(fitsfile)
        hdr = hdulist[0].header
        img = hdulist[0].data
    except IOError:
        exit()
    finally:
        hdulist.close()

    fimg = np.flipud(img)
    background = np.mean(fimg)
    print background
    cimg = np.clip(fimg, background, 65535)
    limg = np.log10(cimg)
    simg = scaleto(limg, [255.0, 0.0])
    print
    plt.hist(simg.flatten(), bins=256, log=True)
    plt.show()
    a = np.rint(simg)
    b = a.astype('uint8')
    im = Image.fromarray(b)
    im.save(fileout)
Beispiel #6
0
    def priorities(self, verbose=False):
        """updates the priorities in the ngc2236 table"""
        import numpy as np
        from functions import scaleto

        def makeplot(bv, v, p, filename=None, isobv=None, isov=None):
            """plot the priorities"""
            from matplotlib import pyplot
            pyplot.scatter(bv, v, c=p, edgecolor='none', alpha=0.75)
            if not isobv is None:
                pyplot.plot(isobv, isov, 'k')
            pyplot.xlim(-0.2, 2.0)
            pyplot.ylim(16.5, 7.5)
            pyplot.title('NGC 2236')
            pyplot.xlabel('B - V')
            pyplot.ylabel('V mag')

            if filename is None:
                pyplot.show()
            else:
                pyplot.savefig(filename, dpi=300)
            pyplot.close()

        def plotradec(ra, dec, p, filename=None):
            """plot the priorities"""
            from matplotlib import pyplot
            pyplot.scatter(ra, dec, c=p, edgecolor='none', alpha=0.75)
            pyplot.title('NGC 2236')
            pyplot.xlabel('R.A.')
            pyplot.ylabel('Dec')

            if filename is None:
                pyplot.show()
            else:
                pyplot.savefig(filename, dpi=300)
            pyplot.close()

        print 'calculate priorities ...'
        self.wifsip.execute("UPDATE ngc2236 SET priority=NULL, pointing=NULL;")
        self.wifsip.execute("""UPDATE ngc2236 
            SET priority=1.0 
            WHERE vmag<16.5 
            AND NOT tab IS NULL;""")

        data = self.wifsip.query("""SELECT tab, vmag, bv 
                               FROM ngc2236
                               WHERE not bv is null AND vmag<16.5
                               ORDER BY tab;""")
        tab = [d[0] for d in data]
        v = np.array([d[1] for d in data])
        bv = np.array([d[2] for d in data])
        p1 = scaleto(v, [1.0, 0.8])
        makeplot(bv, v, p1, filename=config.plotpath + 'vmag_priorities.pdf')

        print len(tab), 'stars brighter V<16.5'
        for i in range(len(tab)):
            if verbose: print '%4d: %.3f --> %.3f' % (tab[i], v[i], p1[i])
            self.wifsip.execute("""UPDATE ngc2236
                          SET priority = priority * %f
                          WHERE tab = %d;""" % (p1[i], tab[i]),
                                commit=False)
        self.wifsip.commit()

        lengood = self.wifsip.query(
            "select count(starid) from ngc2236 where good;")
        print lengood[0][0], 'stars with periods'

        self.wifsip.execute("""UPDATE ngc2236
                          SET priority = priority * 0.8
                          WHERE NOT good;""")
        self.wifsip.commit()

        self.wifsip.execute("""UPDATE ngc2236
                          SET priority = priority * 0.5
                          WHERE period IS NULL;""")
        self.wifsip.commit()

        iso = IsoChrone(config.datapath + 'output885516794937.dat')
        x = iso['V'] + self.dm
        y = iso['B-V'] + self.ebv
        data = self.wifsip.query("""SELECT tab, vmag, bv 
                               FROM ngc2236 
                               WHERE not bv is null AND vmag<16.5
                               ORDER BY tab;""")
        tab = [d[0] for d in data]
        v = np.array([d[1] for d in data])
        bv = np.array([d[2] for d in data])
        p = np.zeros(len(tab))
        print len(tab), 'stars for isochrone priority'

        for i in range(len(tab)):
            p[i] = np.min(abs(x - v[i]) + abs(y - bv[i]))

        #p[p > 0.4] = 0.4
        p = scaleto(p, [1.0, 0.1])
        makeplot(bv,
                 v,
                 p,
                 filename=config.plotpath + 'iso_priorities.pdf',
                 isobv=y,
                 isov=x)
        for t in tab:
            i = tab.index(t)
            if verbose:
                print '%d: V=%.3f B-V=%.3f p=%.3f' % (t, v[i], bv[i], p[i])
            self.wifsip.execute("""UPDATE ngc2236
                              SET priority = priority * %f
                              WHERE tab = %d;""" % (p[i], t),
                                commit=False)
        self.wifsip.commit()

        data = self.wifsip.query("""SELECT tab, ra, dec
                               FROM ngc2236
                               WHERE not ra is NULL AND not dec is NULL
                               AND priority > 0.0
                               ORDER BY TAB;""")
        tab = [d[0] for d in data]
        print len(tab), 'stars for distance priority'
        ra = np.array([d[1] for d in data])
        dec = np.array([d[2] for d in data])
        dist = np.sqrt((ra - self.center[0])**2 + (dec - self.center[1])**2)
        from functions import gauss
        p = gauss(dist, 1.0, 0.0, 7.0 / 60.)
        #p = scaleto(dist, [1.0, 0.0])
        plotradec(ra,
                  dec,
                  p,
                  filename=config.plotpath + 'coord_priorities.pdf')
        for t in tab:
            i = tab.index(t)
            try:
                if verbose:
                    print '%d: d=%.3f p=%.3f' % (t, dist[i], p[i])
                self.wifsip.execute("""UPDATE ngc2236
                              SET priority = priority * %f
                              WHERE tab = %d;""" % (p[i], t),
                                    commit=False)
            except TypeError:
                print t
        self.wifsip.commit()

        data = self.wifsip.query("""SELECT bv,vmag, priority
                               FROM ngc2236
                               WHERE priority > 0.0
                               ORDER BY tab;""")

        bv = np.array([d[0] for d in data])
        vmag = np.array([d[1] for d in data])
        p = np.array([d[2] for d in data])
        makeplot(bv, vmag, p, filename=config.plotpath + 'priorities.pdf')