Ejemplo n.º 1
0
    def lightcurve_fromdb(self, starid):
        """
        extract a single lightcurve from the database
        and return epoch (hjd), magnitude and error
        """
        from datasource import DataSource
        import numpy as np

        import log
        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = """SELECT frames.hjd, phot.mag_auto, phot.magerr_auto, phot.flags
                FROM frames, matched, phot
                WHERE id LIKE '%s'
                AND filter LIKE 'rp'
                AND frames.objid = matched.objid
                AND (phot.objid,phot.star) = (matched.objid,matched.star)
                ORDER BY hjd;""" % (starid)
        # AND hjd>2455473.5 AND hjd<2455477 AND frames.good
        log.log('/work1/jwe/NGC1647/analysis.log', 'fetching star %s' % starid)
        # AND frames.good
        #          AND hjd>2455470 AND hjd<2455510
        data = wifsip.query(query)
        wifsip.close()
        hjd = np.array([d[0] for d in data])
        mag = np.array([d[1] for d in data])
        err = np.array([d[2] for d in data])
        return (hjd, mag, err)
Ejemplo n.º 2
0
    def make_cmd(self):
        import pylab as plt
        import numpy as np
        from datasource import DataSource

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = "SELECT vmag, bv FROM ngc1647stars;"

        data = wifsip.query(query)
        wifsip.close()
        vmag = np.array([d[0] for d in data])
        bv = np.array([d[1] for d in data])
        plt.scatter(bv, vmag, edgecolor='none', alpha=0.75)

        k = 8 / (2.0 - 0.32)
        d = 20 - 2.0 * k
        x = np.linspace(0.0, 2.5, 10)
        y = k * x + d
        plt.plot(x, y, linestyle='dashed', color='k')
        plt.ylim(21.0, 8.0)
        plt.xlim(0.0, 2.2)
        plt.xlabel('B - V')
        plt.ylabel('V [mag]')
        plt.grid()
        plt.savefig('/work1/jwe/Dropbox/NGC1647/plots/ngc1647cmd.pdf')
        #plt.show()
        plt.close()
Ejemplo n.º 3
0
def make_cmd():
    import pylab as plt
    import numpy as np
    from datasource import DataSource

    wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
    query = "UPDATE m48stars SET bv = (bmag-vmag)+(0.761837-0.060177);"

    wifsip.execute(query)
    query = "SELECT vmag+0.060177, bv FROM m48stars WHERE NOT bv is NULL and nv>1 and nb>1;"

    data = wifsip.query(query)
    wifsip.close()
    vmag = np.array([d[0] for d in data])
    bv = np.array([d[1] for d in data])
    plt.scatter(bv, vmag, edgecolor='none', alpha=0.75, s=4, c='k')

    plt.ylim(22.0, 7.0)
    plt.xlim(-0.2, 2.0)
    plt.xlabel('B - V')
    plt.ylabel('V [mag]')
    plt.title('M 48')
    plt.grid()
    plt.savefig('/work2/jwe/m48/m48cmd.pdf')
    #plt.show()
    plt.close()
Ejemplo n.º 4
0
 def doimport(self):
     '''import the file and shove it into the database'''
     from datasource import DataSource
     from astronomy import hms2dd, dms2dd
     from StringIO import StringIO
     f = open(self.filename, 'r')
     lines = f.readlines()
     f.close()
     
     # skip header information and compendium
     lines = lines[71:247]
     print lines[0]
     values = ''
     for l in lines:
         id = l[0:9].strip()
         ra = hms2dd(l[9:19].strip())
         dec = dms2dd(l[20:31].strip())
         s = l[32:33]
         try:
             ucac2 = int(l[34:42])
         except ValueError:
             ucac2 = None
         tyc2 = l[43:54]
         v = float(l[56:61])
         remarks = l[62:].rstrip()
         print id,ra,dec,s,ucac2,tyc2,v,remarks
         values += '%s\t%f\t%f\t%s\t%s\t%s\t%f\t%s\n' % (id,ra,dec,s,ucac2,tyc2,v,remarks)
         values = values.replace('None', '\N') 
     f = StringIO(values)
     print values
     wifsip = DataSource(host = 'pina', database = 'wifsip', user = '******')
     wifsip.cursor.copy_from(f, 'ngc2281ref', 
                             columns=('id','ra','dec','s','ucac2','tyc2','vmag', 'remarks'))
     wifsip.commit()
     wifsip.close()
Ejemplo n.º 5
0
    def make_cmd(self):
        import pylab as plt
        import numpy as np
        from datasource import DataSource

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = "SELECT vmag, bv FROM ngc2281stars where vmag>0.0 and bv>0.0;"

        data = wifsip.query(query)
        wifsip.close()
        vmag = np.array([d[0] for d in data])
        bv = np.array([d[1] for d in data])
        plt.scatter(bv - self.ebv, vmag, edgecolor='none', alpha=0.75)

        k = (21.0 - 10.5) / (1.8 - 0.0)
        d = 10.5
        x = np.linspace(0.0, 2.5, 10)
        y = k * x + d
        plt.plot(x, y, linestyle='dashed', color='k')
        plt.ylim(21.0, 10.0)
        plt.xlim(0.0, 2.2)
        plt.title('NGC 2281')
        plt.xlabel('(B - V)$_0$')
        plt.ylabel('V [mag]')
        plt.grid()
        plt.savefig('/work1/jwe/Dropbox/NGC2281/plots/ngc2281cmd.pdf')
        #plt.show()
        plt.close()
Ejemplo n.º 6
0
    def lightcurve_fromdb(self):
        """
        extract a single lightcurve from the database
        and return epoch (hjd), magnitude and error
        """
        from datasource import DataSource
        import numpy as np

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = """SELECT frames.hjd, phot.mag_isocor, phot.magerr_isocor
                FROM frames, matched, phot
                WHERE id LIKE '%s'
                AND filter LIKE 'rp'
                AND frames.objid = matched.objid
                AND (phot.objid,phot.star) = (matched.objid,matched.star)
                
                ORDER BY hjd;""" % (self.id)
        # AND hjd>2455473.5 AND hjd<2455477 AND frames.good

        # AND frames.good
        #          AND hjd>2455470 AND hjd<2455510
        data = wifsip.query(query)
        wifsip.close()
        self.hjd = np.array([d[0] for d in data])
        self.mag = np.array([d[1] for d in data])
        self.err = np.array([d[2] for d in data])
        self.hjd -= self.hjd[0]
Ejemplo n.º 7
0
    def buildtable(self):
        """
        builds the table of stars
        """
        import numpy as np

        epochs = len(self.objids)
        stars = len(self.stars)
        if fileexists('/work2/jwe/NGC2281/' + self.filter + 'array.npy'):
            m = np.load('/work2/jwe/NGC2281/' + self.filter + 'array.npy')
        else:
            from datasource import DataSource
            from framecal import FrameCal

            fc = FrameCal(self.filter)

            m = np.zeros([epochs, stars])
            # objid is specific to a filter so we only need to query the objid
            wifsip = DataSource(host='pina', database='wifsip', user='******')
            for objid in self.objids:
                k = self.objids.index(objid)
                print k, epochs, objid,
                query = """SELECT matched.id, phot.mag_auto, phot.mag_errauto 
                        FROM phot, matched
                        WHERE phot.objid like '%s'
                        AND (matched.objid,matched.star) = (phot.objid,phot.star)
                        AND phot.flags = 0;""" % objid
                result = wifsip.query(query)
                starids = [s[0] for s in result]
                mags = [s[1] for s in result]
                err = [s[2] for s in result]

                slope, intercept, _, _, _ = fc.calframe(objid)
                print len(mags)
                for starid in starids:
                    i = self.stars.index(starid)
                    m[k, i] = mags[starids.index(starid)] * slope + intercept
            np.save('/work2/jwe/NGC2281/' + self.filter + 'array.npy', m)
            wifsip.close()

        i = np.where(m == 0.0)
        m[i] = np.nan
        from scipy import stats
        # calculate the observed average for the stars
        avg = stats.nanmean(m, axis=0)
        for k in range(epochs):
            print k, epochs, self.objids[k]

            # calculate the mean of offsets
            off = stats.nanmedian(m[k, :] - avg)
            # correct epoch for mean of offsets
            m[k, :] += off

        # calculate new corrected means
        avg = stats.nanmean(m, axis=0)
        std = stats.nanstd(m, axis=0)
        for i in range(len(self.stars)):
            print self.stars[i], avg[i], std[i]
Ejemplo n.º 8
0
    def make_cpd(self):
        import pylab as plt
        import numpy as np
        from datasource import DataSource

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = """SELECT bv, period, theta 
                    FROM ngc1647stars 
                    WHERE vmag>4.762*bv + 10.4762 and theta>0.5;"""
        data = wifsip.query(query)

        bv = np.array([d[0] for d in data])
        period = np.array([d[1] for d in data])
        theta = np.array([d[2] for d in data])

        query = """SELECT bv, period, theta 
                    FROM ngc1647stars 
                    WHERE vmag<4.762*bv + 10.4762 
                    AND theta>0.5;"""
        data = wifsip.query(query)
        wifsip.close()
        bv_ms = np.array([d[0] for d in data])
        period_ms = np.array([d[1] for d in data])
        theta_ms = np.array([d[2] for d in data])

        import gyroage

        bv170 = np.linspace(0.5, 1.6, num=20)
        P = gyroage.gyroperiod(bv170, 170.0)
        P01 = gyroage.gyroperiod(bv170, 170.0, P0=0.1)
        P33 = gyroage.gyroperiod(bv170, 170.0, P0=3.3)

        plt.plot(bv170, P, color='r')
        plt.plot(bv170, P01, color='r', linestyle='dashed')
        plt.plot(bv170, P33, color='r', linestyle='dashed')

        plt.scatter(bv - self.ebv,
                    period,
                    s=(1.0 - theta) * 40.,
                    edgecolor='none',
                    alpha=0.5)
        plt.scatter(bv_ms - self.ebv,
                    period_ms,
                    s=(1.0 - theta_ms) * 40.,
                    edgecolor='none',
                    alpha=0.75,
                    facecolor='green')
        plt.xlabel('(B - V)$_0$')
        plt.ylabel('period [days]')
        plt.ylim(0.0, 10.0)
        plt.xlim(0.0, 2.2)
        plt.grid()
        plt.savefig('/work1/jwe/Dropbox/NGC1647/plots/ngc1647cpd.pdf')
        plt.show()
        plt.close()
Ejemplo n.º 9
0
    def calibrate(self):
        # B: m=0.9777689; c=1.7573974; r=0.9991517
        # V: m=0.9545878; c=1.004512; r=0.9996585
        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        if filter == 'B':
            query = """UPDATE ngc1647stars SET Bmag = Bmag*0.9777689+1.7573974;"""
        elif filter == 'V':
            query = """UPDATE ngc1647stars SET Vmag = Vmag*0.9545878+1.004512;"""
        wifsip.execute(query)
        wifsip.execute('UPDATE ngc1647stars SET bv = Bmag-Vmag;')
        wifsip.close()
Ejemplo n.º 10
0
    def update_db(self):
        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        query = """INSERT INTO ngc2281stars
            SELECT distinct matched.id
            FROM frames, phot, matched
            WHERE frames.object like 'NGC 2281 BVI %%'
            AND frames.filter like '%s'
            AND frames.objid = phot.objid
            AND (matched.objid,matched.star) = (phot.objid,phot.star)
            AND matched.id NOT IN (SELECT id FROM ngc2281stars);""" % self.filter
        wifsip.execute(query)
        wifsip.close()
Ejemplo n.º 11
0
    def store(self, star, period=None, theta=None):
        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        query = "UPDATE ngc1647stars"
        if not period is None:
            query += " SET period=%f" % period
        if not theta is None:
            query += ",  theta=%f" % theta
        query += " WHERE id like '%s';" % star
        try:
            wifsip.execute(query)
        finally:
            wifsip.close()
Ejemplo n.º 12
0
    def store(self, star, period=None, theta=None):
        from datasource import DataSource
        from numpy import isnan

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        query = "UPDATE ngc2281stars"
        if not period is None:
            query += " SET period=%f" % period
        if not ((theta is None) or isnan(theta)):
            query += ",  theta=%f" % theta
        query += " WHERE id like '%s';" % star
        try:
            wifsip.execute(query)
            wifsip.commit()
        finally:
            wifsip.close()
Ejemplo n.º 13
0
    def phot(self):
        """
        builds the table of stars
        """
        import numpy as np
        from scipy import stats

        epochs = len(self.objids)
        stars = len(self.stars)
        from datasource import DataSource

        m = np.zeros([epochs, stars])
        # objid is specific to a filter so we only need to query the objid
        wifsip = DataSource(host='pina', database='wifsip', user='******')
        for star in self.stars:
            print star,
            query = """SELECT mag_auto, magerr_auto 
                    FROM frames, phot, matched
                    WHERE matched.id like '%s'
                    AND frames.filter like '%s'
                    AND frames.objid = phot.objid
                    AND (matched.objid,matched.star) = (phot.objid,phot.star)
                    AND phot.flags = 0
                    AND magerr_auto > 0.0;""" % (star, self.filter)
            result = wifsip.query(query)
            mags = np.array([s[0] for s in result])
            err = np.array([s[1] for s in result])
            m = stats.nanmean(mags)
            s = stats.nanstd(mags)
            merr = stats.nanmean(err)
            stderr = stats.nanstd(err)
            #print mags
            #print err
            if len(mags) > 1:
                print '%4d %.3f %.3f %.3f %.3f' % (len(mags), m, s, merr,
                                                   stderr),
                mags = mags[err <= merr + stderr]
                err = err[err <= merr + stderr]
                avg = np.average(mags, weights=1. / err)
                std = np.sqrt(np.average(abs(mags - avg)**2, weights=1. / err))
                #std = np.std(mags)
                print '%4d %.3f %.3f' % (len(mags), avg, std)
                self.update_star(wifsip, star, avg, std, len(mags))
            else:
                print 'none (%.3f, %.3f)' % (m, s)

        wifsip.close()
Ejemplo n.º 14
0
    def update_db(self):
        from datasource import DataSource
        import StringIO

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        columns = ['star', 'rem', 'vmag', 'bv', 'ub', 'n', 'code', 'ra', 'dec']
        values = ''
        for s in self.stars:
            values += '%s\t%s\t%.2f\t%.2f\t%.2f\t%d\t%d\t%f\t%f\n' % \
            (s['star'], s['rem'], s['V'], s['B-V'], s['U-B'], s['n'], s['code'],
             s['RA'], s['Dec'])
        f = StringIO.StringIO(values)
        print values
        try:
            wifsip.cursor.copy_from(f, 'turner', columns=columns)
        finally:
            wifsip.commit()
        wifsip.close()
Ejemplo n.º 15
0
    def create_db(self):
        query = """DROP TABLE IF EXISTS turner;
CREATE TABLE turner( 
 star  varchar(12), 
 rem   varchar(2),
 vmag  real,
 bv    real,
 ub    real,
 n     integer,
 code  integer,
 ra    float,
 dec   float,
 coord point,
 PRIMARY KEY (star,rem));"""
        from datasource import DataSource
        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        wifsip.execute(query)
        wifsip.close()
Ejemplo n.º 16
0
    def todatabase(self):
        """
        puts Gabriels data on the stella database
        """
        import StringIO

        filename = '/work2/jwe/Projects/NGC6633/data/tallrefavgcal_fields.dat'
        with open(filename, 'rt') as infile:
            lines = infile.readlines()

        valarray = []
        field = 0
        lastid = 0
        for l in lines[1:]:
            splitted = l.rstrip('\n').replace('NaN', '000').split()
            curid = int(splitted[0])
            if curid < lastid:
                field += 1
            lastid = curid
            splitted[0] = str(field * 100000 + curid)
            print splitted[0]
            assert (len(splitted) == 9)
            #print '(%s,%s)' % (splitted[1], splitted[2])
            splitted.append('(%s,%s)' % (splitted[1], splitted[2]))
            valline = '\t'.join(splitted)
            valarray.append(valline)

        values = '\n'.join(valarray)

        f = StringIO.StringIO(values)

        from datasource import DataSource

        columns = [
            'id', 'ra_j2000', 'dec_j2000', 'imag', 's_imag', 'vmag', 's_vmag',
            'bmag', 's_bmag', 'coord'
        ]

        stellads = DataSource(database=config.dbname,
                              user=config.dbuser,
                              host=config.dbhost)
        stellads.cursor.copy_from(f, 'ngc6633gab', columns=columns, null='nan')
        stellads.commit()
        stellads.close()
Ejemplo n.º 17
0
    def make_cpd(self):
        import pylab as plt
        import numpy as np
        from datasource import DataSource

        wifsip = DataSource(database='wifsip', user='******', host='pina.aip.de')
        query = """SELECT bv, period, theta 
                    FROM ngc2281stars
                    WHERE bv >-1.0 AND period>0
                    and vmag < 5.8333*(bv-0.09)+10.5;"""
        data = wifsip.query(query)

        bv = np.array([d[0] for d in data])
        period = np.array([d[1] for d in data])
        theta = np.array([d[2] for d in data])

        wifsip.close()

        import gyroage

        bv358 = np.linspace(0.5, 1.6, num=40)
        #P = gyroage.gyroperiod(bv358, 358.1)
        #P01 = gyroage.gyroperiod(bv358, 358.1, P0=0.1)
        #P33 = gyroage.gyroperiod(bv358, 358.1, P0=3.3)

        PI, PC = gyroage.gyroperiod(bv358, 358.1)

        plt.plot(bv358, PI, color='r')
        plt.plot(bv358, PC, color='r', linestyle='dashed')

        plt.scatter(bv - self.ebv,
                    period,
                    s=40. * (1.0 - theta)**2,
                    edgecolor='none',
                    alpha=0.75)
        plt.title('NGC 2281')
        plt.xlabel('(B - V)$_0$')
        plt.ylabel('period [days]')
        plt.ylim(0.0, 20.0)
        plt.xlim(0.0, 2.2)
        plt.grid()
        plt.savefig('/work1/jwe/Dropbox/NGC2281/plots/ngc2281cpd.pdf')
        #plt.show()
        plt.close()
Ejemplo n.º 18
0
 def update(self, filename):
     '''update the V and B-V according to Pesch 1961'''
     from datasource import DataSource
     f = open(filename, 'r')
     lines = f.readlines()
     f.close()
     lines = lines[1:]
     wifsip = DataSource(host = 'pina', database = 'wifsip', user = '******')
     for l in lines:
         ls = l.split()
         star = ls[2]
         v = ls[3]
         bv = ls[4]
         ub = ls[5]
         n = ls[6]
         code = ls[7]
         print star,v,bv,ub,n,code
         query = "UPDATE ngc2281ref SET vmag=%s, bv=%s WHERE id like '%s'" % (v,bv,star)
         wifsip.execute(query)
     wifsip.close() 
Ejemplo n.º 19
0
    def todatabase(self):
        from datasource import DataSource
        import StringIO

        values = ''

        for t in self.table:
            values = values + 'APASS%(recno)d\t%(RAJ2000).6f\t%(DEJ2000).6f\t%(Bmag).3f\t%(Vmag).3f\t%(rmag).3f\t%(imag).3f\n' % t

        wifsip = DataSource(database='stella',
                            user='******',
                            host='pera.aip.de')
        f = StringIO.StringIO(values)
        columns = ['starid', 'ra', 'dec', '"B"', '"V"', '"R"', '"I"']
        wifsip.cursor.copy_from(f,
                                'referencestars',
                                columns=columns,
                                null='nan')
        wifsip.commit()
        wifsip.close()
Ejemplo n.º 20
0
    def get_frames(self):
        if fileexists('/work2/jwe/NGC2281/' + self.filter + 'frames.txt'):
            self.objids = loadfromfile('/work2/jwe/NGC2281/' + self.filter +
                                       'frames.txt')
            print len(self.objids), 'frames'
            return

        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        query = """SELECT frames.objid 
                    FROM frames
                    WHERE frames.object like 'NGC 2281 BVI %%'
                    AND frames.filter like '%s';""" % self.filter
        result = wifsip.query(query)
        self.objids = [s[0] for s in result]
        savetofile('/work2/jwe/NGC2281/' + self.filter + 'frames.txt',
                   self.objids)
        print len(self.objids), 'frames'
        wifsip.close()
Ejemplo n.º 21
0
 def create_table(self):
     '''
     makes the database table
     '''
     from datasource import DataSource
     stellads = DataSource(database=config.dbname,
                           user=config.dbuser,
                           host=config.dbhost)
     query = """CREATE TABLE ngc6633gab (
     id integer,
     ra_j2000 double precision,
     dec_j2000 double precision,
     bmag real,
     s_bmag real,
     vmag real,
     s_vmag real,
     imag real,
     s_imag real,
     coord point,
     PRIMARY KEY (id)
     );
     CREATE INDEX idx_ngc6633gab_coord ON ngc6633 USING GIST (circle(coord,0));"""
     stellads.execute(query)
     stellads.close()
Ejemplo n.º 22
0
    def get_stars(self):

        if fileexists('/work2/jwe/NGC2281/' + self.filter + 'stars.txt'):
            self.stars = loadfromfile('/work2/jwe/NGC2281/' + self.filter +
                                      'stars.txt')
            print len(self.stars), 'stars'
            return

        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        query = """SELECT distinct matched.id
            FROM frames, phot, matched
            WHERE frames.object like 'NGC 2281 BVI %%'
            AND frames.filter like '%s'
            AND frames.objid = phot.objid
            AND (matched.objid,matched.star) = (phot.objid,phot.star);""" % self.filter
        result = wifsip.query(query)
        self.stars = [s[0] for s in result]
        savetofile('/work2/jwe/NGC2281/' + self.filter + 'stars.txt',
                   self.stars)
        wifsip.close()

        print len(self.stars), 'stars'
Ejemplo n.º 23
0
    def phot(self):
        """
        builds the table of stars
        """
        import numpy as np
        from scipy import stats

        epochs = len(self.objids)
        stars = len(self.stars)
        from datasource import DataSource
        from framecal import FrameCal

        fc = FrameCal(self.filter)
        fc.frameslist()
        fc.calframes()

        m = np.zeros([epochs, stars])
        # objid is specific to a filter so we only need to query the objid
        wifsip = DataSource(host='pina', database='wifsip', user='******')
        for star in self.stars:
            print star,
            query = """SELECT frames.objid, mag_auto, magerr_auto 
                    FROM frames, phot, matched
                    WHERE matched.id like '%s'
                    AND frames.filter like '%s'
                    AND frames.objid = phot.objid
                    AND (matched.objid,matched.star) = (phot.objid,phot.star)
                    AND phot.flags = 0
                    AND frames.good
                    AND magerr_auto > 0.0;""" % (star, self.filter)
            result = wifsip.query(query)
            objids = ([s[0] for s in result])
            mags = np.array([s[1] for s in result])
            err = np.array([s[2] for s in result])

            #print mags
            #print err
            if len(mags) > 1:
                for objid in objids:
                    i = objids.index(objid)
                    try:
                        slope, intercept, _, _, _ = fc.calframe(objid)
                        mags[i] = mags[i] * slope + intercept
                    except KeyError:
                        mags[i] = np.NaN
                m = stats.nanmean(mags)
                s = stats.nanstd(mags)
                merr = stats.nanmean(err)
                stderr = stats.nanstd(err)

                print '%4d %.3f %.3f %.3f %.3f' % (len(mags), m, s, merr,
                                                   stderr),
                mags = mags[err <= merr + stderr]
                err = err[err <= merr + stderr]
                avg = np.average(mags, weights=1. / err)
                std = np.sqrt(np.average(abs(mags - avg)**2, weights=1. / err))
                #std = np.std(mags)

                print '%4d %.3f %.3f' % (len(mags), avg, std)
                self.update_star(wifsip, star, avg, std, len(mags))
            else:
                print 'none'

        wifsip.close()
Ejemplo n.º 24
0
               WHERE corotid = %d;""" % corotid
    wifsip.execute(query)


def set_bad(corotid):
    query = """UPDATE ngc2236
               SET good=False
               WHERE corotid = %d;""" % corotid
    wifsip.execute(query)


if __name__ == '__main__':
    from glob import glob
    from datasource import DataSource

    wifsip = DataSource(host='pina', database='wifsip', user='******')
    pdfs = glob('/work2/jwe/NGC2236/plots/good/*.pdf')
    for p in pdfs:
        cid = corotid(p)
        print p, cid, 'good'
        set_good(cid)

    pdfs = glob('/work2/jwe/NGC2236/plots/*.pdf')
    for p in pdfs:
        cid = corotid(p)
        print p, cid, 'bad'
        set_bad(cid)

    wifsip.commit()
    wifsip.close()
Ejemplo n.º 25
0
    def calibrate(self):
        from datasource import DataSource

        wifsip = DataSource(host='pina', database='wifsip', user='******')
        wifsip.execute('UPDATE ngc2281stars SET bv = Bmag-Vmag;')
        wifsip.close()
Ejemplo n.º 26
0
# for i in range(0, loopSize):
#     (testX, testY) = testSource.next(int(44100 * SKIP_HEAD_IN_SECONDS), BATCH_SIZE, PROCESS_AUDIO_FRAMES)
#     test_cross_entropy += cross_entropy.eval(feed_dict = {x:testX, y_:testY, keep_prob:1.0})
#     test_accuracy += accuracy.eval(feed_dict = {x:testX, y_:testY, keep_prob:1.0})
# print("=====> test result training accuracy %f cross_entropy %f" % (test_accuracy / loopSize, test_cross_entropy / loopSize))

#test_single_file
def findMostPredict(arr):
    result = -1
    max = 0
    countMap = dict()
    for item in arr:
        if not countMap.get(item):
            countMap.setdefault(item, 1)
        else:
            countMap[item] += 1
    for (k,v) in countMap.items():
        if v > max:
            max = v
            result = k
    return result
for i in range(0, 10):
    (testX, testY) = testSource.next(int(44100 * SKIP_HEAD_IN_SECONDS), REPEAT_SEGMENT_FOR_EACH_FILE, PROCESS_AUDIO_FRAMES)
    test_one_hot = y_conv.eval(feed_dict = {x:testX, y_:testY, keep_prob:1.0})
    test_result = np.argmax(test_one_hot, 1)
    actual_result = np.argmax(testY, 1)
    print("=====> test single file, test_result=", findMostPredict(test_result)," of ", test_result, " actual_result", findMostPredict(actual_result), " of ", actual_result)
sess.close()
testSource.close()
printDuration(start_time)
Ejemplo n.º 27
0
class ImportRef(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.data = []
        from datasource import DataSource
        self.wifsip = DataSource(database=config.dbname,
                                 user=config.dbuser,
                                 host=config.dbhost)

    def loadfromfile(self, filename=''):
        """
           1-  5  I5    ---     Seq       Sequential identification number
           7-  8  I2    h       RAh       Right ascension (J2000)
          10- 11  I2    min     RAm       Right ascension (J2000)
          13- 18  F6.3  s       RAs       Right ascension (J2000)
          20- 21  I2    deg     DEd       Declination (J2000)
          23- 24  I2    arcmin  DEm       Declination (J2000)
          26- 30  F5.2  arcsec  DEs       Declination (J2000)
          31- 39  F9.3  arcmin  xpos      x-frame coordinate in arcmin
          40- 48  F9.3  arcmin  ypos      y-frame coordinate in arcmin
          49- 57  F9.3  mag     b-y       ?=99.99 b-y color index
          58- 65  F8.4  mag   e_b-y       ?=9.99  error in b-y
          66- 74  F9.3  mag     Vmag      ?=99.99 V magnitude
          75- 82  F8.4  mag   e_Vmag      ?=9.99  error in Vmag
          83- 91  F9.3  mag     m1        ?=99.99 Stroemgren m1 color index
          92- 99  F8.4  mag   e_m1        ?=9.99  error in m1
         100-108  F9.3  mag     c1        ?=99.99 Stroemgren c1 color index
         109-116  F8.4  mag   e_c1        ?=9.99  error in c1
         117-125  F9.3  mag     Hb        ?=99.99 Stroemgren Hbeta color index
         126-133  F8.4  mag   e_Hb        ?=9.99  error in Hbeta
         135-136  A2    ---     Mem       [M NM] Membership label
        """
        self.names = [
            'Seq', 'RAh', 'RAm', 'RAs', 'DEd', 'DEm', 'DEs', 'xpos', 'ypos',
            'b-y', 'e_b-y', 'Vmag', 'e_Vmag', 'm1', 'e_m1', 'c1', 'e_c1', 'Hb',
            'e_Hb', 'Mem'
        ]
        print filename
        self.data = np.genfromtxt(filename,
                                  dtype=None,
                                  names=self.names,
                                  missing_values=('99.990', '9.9900'))

    def todatabase(self):
        import StringIO
        from astropy.coordinates import SkyCoord  # High-level coordinates @UnresolvedImport
        import astropy.units as u
        vallines = []
        for d in self.data:
            params = dict(zip(self.names, d))
            radec = '%(RAh)s %(RAm)s %(RAs)s %(DEd)s %(DEm)s %(DEs)s' % params
            c = SkyCoord(radec,
                         unit=(u.hourangle, u.deg))  # @UndefinedVariable
            params['ra'] = c.ra.deg
            params['dec'] = c.dec.deg
            params['starid'] = 'M67_BGJ%04d' % params['Seq']
            params['source'] = '2007A&A...470..585B'
            if params['b-y'] == 99.990: params['b-y'] = np.nan
            if params['m1'] == 99.990: params['m1'] = np.nan
            if params['c1'] == 99.990: params['c1'] = np.nan
            if params['Hb'] == 99.990: params['Hb'] = np.nan
            try:
                vallines.append(
                    '%(starid)s\t%(ra).7f\t%(dec).7f\t%(b-y).3f\t%(m1).3f\t%(c1).3f\t%(Hb).3f\t%(source)s'
                    % params)
            except TypeError:
                print params
        values = '\n'.join(vallines)
        # replace NULL values with \N
        values = values.replace('nan', '\\N')
        print values
        f = StringIO.StringIO(values)
        self.wifsip.cursor.copy_from(f,
                                     'referencestars',
                                     columns=('starid', 'ra', 'dec', '"b-y"',
                                              'm1', 'c1', 'beta', 'source'))
        self.wifsip.commit()
        self.wifsip.close()