def plot_cmd(self, show=False, mark_active=False): from dbtable import DBTable # @UnresolvedImport alls = DBTable(self.wifsip, 'm48stars', condition='NOT bv is NULL') good = DBTable(self.wifsip, 'm48stars', condition='good and provisional is null') prov = DBTable(self.wifsip, 'm48stars', condition='provisional') iso_v, iso_bv = self.load_isochrone() plt.plot(iso_bv, iso_v, 'g', alpha=0.3, lw=5.0,label='800 Myr iso') plt.scatter(alls['bv']-self.ebv,alls['vmag'], edgecolor='none', alpha=0.75, s=4, c='k') if mark_active: plt.scatter(good['bv']-self.ebv, good['vmag'], marker='o',edgecolor='r', facecolor='r', s=30, label='rotators') plt.scatter(prov['bv']-self.ebv, prov['vmag'], marker='o',edgecolor='r', facecolor='none', s=30, label='provisional') plt.legend() plt.title('M48 Color Magnitude Diagram') plt.ylim(20.0, 10.0) plt.xlim(0.0, 2.0) plt.xlabel('(B - V)$_0$') plt.ylabel('V [mag]') plt.grid() if show: plt.show() else: if mark_active: plt.savefig(config.plotpath+'m48cmd_active.eps') plt.savefig(config.plotpath+'m48cmd_active.pdf') plt.savefig(config.plotpath+'m48cmd_active.png', dpi=300) else: plt.savefig(config.plotpath+'m48cmd.eps') plt.savefig(config.plotpath+'m48cmd.pdf') plt.close()
def calibratebv(self): '''drop view ngc6633match; create view ngc6633match as SELECT ngc6633ref.starid, ngc6633.vmag, ngc6633.bmag, ngc6633ref.vmag "vmag_ref", ngc6633ref.bmag "bmag_ref" FROM ngc6633, ngc6633ref WHERE circle(ngc6633.coord,0) <@ circle(ngc6633ref.coord, 1.0/3600.0);''' from dbtable import DBTable match = DBTable( self.wifsip, 'ngc6633match', condition= 'NOT vmag_ref IS NULL AND NOT bmag_ref IS NULL AND vmag>12') vmag = match['vmag'] bmag = match['bmag'] bv = bmag - vmag vmagref = match['vmag_ref'] bmagref = match['bmag_ref'] bvref = bmagref - vmagref A = np.vstack([vmag, bv, np.ones(len(vmag))]).T vcorr = np.linalg.lstsq(A, vmagref)[0] B = np.vstack([bmag, bv, np.ones(len(bmag))]).T bcorr = np.linalg.lstsq(B, bmagref)[0] print vcorr print bcorr
def plot_cmd(self, show=False, mark_active=False, isochrone=True): from dbtable import DBTable vc = [ 0.98976977, 0.01785897, 0.07519376] bc = [ 0.99106353, 0.01346018, 0.07998822] alls = DBTable(self.wifsip, 'ngc6633', condition='NOT bv is NULL AND vmag<20') good = DBTable(self.wifsip, 'ngc6633', condition='good') members = DBTable(self.wifsip, 'ngc6633', condition='member') #prov = DBTable(self.wifsip, 'ngc6633', condition='provisional') vmag = vc[0]*alls['vmag'] + vc[1]*alls['bv'] + vc[2] bmag = bc[0]*alls['bmag'] + bc[1]*alls['bv'] + bc[2] bv = bmag - vmag plt.style.use('aanda.mplstyle') suffix = '' if isochrone: print 'Av = %f' % (3.1*self.ebv) iso_v, iso_bv = self.load_isochrone() plt.plot(iso_bv+self.ebv, iso_v+self.dm+(3.1*self.ebv), 'b', alpha=0.3, lw=5.0,label='600 Myr iso') # suffix = suffix + '_iso' plt.scatter(bv, vmag, edgecolor='none', alpha=0.75, s=2, c='k') if mark_active: plt.scatter(good['bv'], good['vmag'], marker='o',edgecolor='r', facecolor='r', s=20, label='rotators') suffix = suffix + '_active' plt.scatter(members['bv'], members['vmag'], marker='o', edgecolor='g', facecolor='none', s=20, label='members') plt.legend(loc='lower left') plt.title('NGC6633 Color Magnitude Diagram') plt.ylim(20.0, 7.0) plt.xlim(0.0, 1.7) plt.xlabel('B - V') plt.ylabel('V [mag]') plt.minorticks_on() plt.grid() if show: plt.show() else: plt.savefig(config.plotpath+'ngc6633cmd%s.pdf' % suffix) plt.close()
def plot_cpd(self, show=False, gyrochrone=False): from dbtable import DBTable members = DBTable(self.wifsip, 'ngc6633', condition='member') good = DBTable(self.wifsip, 'ngc6633', condition='good and period>0') nonmembers = DBTable(self.wifsip, 'ngc6633', condition='NOT member') import gyroage from functions import logspace bvgyro = logspace(0.5, 1.5, num=100) age = 550 P = gyroage.gyroperiod(bvgyro, age, version=2010) plt.style.use('aanda.mplstyle') if gyrochrone: plt.plot(bvgyro, P, color='b', label='%d Myr'% age) plt.scatter(good['bv']-self.ebv, good['period'], marker='o',edgecolor='r', facecolor='r', s=20, label='rotators') plt.scatter(members['bv']-self.ebv, members['period'], marker='o',edgecolor='k', facecolor='r', s=20, label='members') plt.scatter(nonmembers['bv']-self.ebv, nonmembers['period'], marker='x',edgecolor='k', facecolor='k', s=20, label='nonmembers') plt.xlabel('(B - V)$_0$') plt.ylabel('period [days]') plt.ylim(0.0, 15.0) plt.xlim(0.4, 1.6) plt.legend() plt.title('NGC 6633 Color Period Diagram') #plt.grid() if show: plt.show() else: if gyrochrone: plt.savefig(config.plotpath+'ngc6633cpd_gyro.pdf') else: plt.savefig(config.plotpath+'ngc6633cpd.pdf') plt.close()
def getstars(self): """ build up a list of stars, that have been marked sa good """ from dbtable import DBTable query = """SELECT starid FROM ngc6633 WHERE good ORDER BY tab;""" result = self.wifsip.query(query) print '... %d stars found' % len(result) self.stars = DBTable(self.wifsip, 'ngc6633', condition='good')
def plot_cmpd(self, show=False, gyrochrone=False): """ make a 3d plot of the cmd and the cpd """ from dbtable import DBTable from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt members = DBTable(self.wifsip, 'ngc6633', condition='member and period>0') good = DBTable(self.wifsip, 'ngc6633', condition='good and period>0') nonmembers = DBTable(self.wifsip, 'ngc6633', condition='NOT member and period>0') import gyroage from functions import logspace bvgyro = logspace(0.5, 1.5, num=100) age = 550 P = gyroage.gyroperiod(bvgyro, age, version=2010) #plt.style.use('aanda.mplstyle') # if gyrochrone: # plt.plot(bvgyro, P, color='b', label='%d Myr'% age) # plt.scatter(good['bv']-self.ebv, good['period'], marker='o',edgecolor='r', facecolor='r', s=20, label='rotators') # plt.scatter(members['bv']-self.ebv, members['period'], marker='o',edgecolor='k', facecolor='r', s=20, label='members') # plt.scatter(nonmembers['bv']-self.ebv, nonmembers['period'], marker='x',edgecolor='k', facecolor='k', s=20, label='nonmembers') fig = plt.figure() ax = fig.gca(projection='3d') # Plot a sin curve using the x and y axes. #x = np.linspace(0, 1, 100) #y = np.sin(x * 2 * np.pi) / 2 + 0.5 #ax.plot(x, y, zs=0, zdir='z', label='curve in (x,y)') iso_v, iso_bv = self.load_isochrone() ax.plot(iso_bv+self.ebv, iso_v+self.dm+(3.1*self.ebv), zs=0, zdir='z', color='b', alpha=0.3, lw=5.0,label='600 Myr iso') ax.plot(bvgyro-self.ebv, np.ones(100)*7, P, color='b', label='%d Myr'% age) ax.scatter(good['bv']-self.ebv, good['vmag'], good['period'], marker='o',edgecolor='r', facecolor='r', s=20, label='rotators') ax.scatter(members['bv']-self.ebv, members['vmag'], members['period'], marker='o',edgecolor='k', facecolor='r', s=20, label='members') ax.scatter(nonmembers['bv']-self.ebv, nonmembers['vmag'],nonmembers['period'], marker='x',edgecolor='k', facecolor='k', s=20, label='nonmembers') for x,y,z in zip(good['bv']-self.ebv, good['vmag'], good['period']): ax.plot([x,x,],[y,y],[0,z],'0.5') # Make legend, set axes limits and labels #ax.legend() ax.set_xlim(0.2, 1.6) ax.set_ylim(20.0, 7.0) ax.set_zlim(0.0, 13.0) ax.set_xlabel('(B - V)$_0$') ax.set_ylabel('V [mag]') ax.set_zlabel('period [days]') # Customize the view angle so it's easier to see that the scatter points lie # on the plane y=0 #ax.view_init(elev=20., azim=-35) #ax.set_title('NGC 6633 Color Period Diagram') if show: plt.show() else: if gyrochrone: plt.savefig(config.plotpath+'ngc6633cmpd_gyro.pdf') else: plt.savefig(config.plotpath+'ngc6633cmpd.pdf')
def plot_map(self, show=False): ''' plots the map of the M48 observation including the BJG field ''' #import pywcsgrid2 import astro.coordinates as ast from dbtable import DBTable # @UnresolvedImport astars = DBTable(self.wifsip, 'ngc6633', condition='vmag<12.0 and good is NULL') gstars = DBTable(self.wifsip, 'ngc6633', condition='good') #pstars = DBTable(self.wifsip, 'NGC6633Star', condition='provisional') #set plot attributes plt.style.use('aanda.mplstyle') params = { u'figure.subplot.bottom' : 0.11, u'figure.subplot.left' : 0.11, u'figure.subplot.right' : 0.89, u'figure.subplot.top' : 0.89 } rcParams.update(params) fig = plt.figure() ax = fig.add_subplot(111) vmag = np.array(astars['vmag']) ax.set_aspect(1.) ax.scatter(astars['ra'],astars['dec'], marker='*', s=(12.-vmag)*15,facecolor='gray', edgecolor='none') #ax.scatter(pstars['ra'],pstars['dec'], marker='o',edgecolor='r', facecolor='none', s=10) ax.scatter(gstars['ra'],gstars['dec'], marker='o',edgecolor='r', facecolor='r', s=10) ra = np.array([8.24242, 8.21705, 8.20416])*15.0 de = np.array([-6.08887,-5.70876,-5.51204]) x = [ra[0],ra[2],ra[2],ra[1],ra[1],ra[0],ra[0]] y = [de[0],de[0],de[1],de[1],de[2],de[2],de[0]] cra, cdec = (276.88, 6.57) d2 = 0.5*1320.2/3600.0 fields = [(cra , cdec), (cra - d2, cdec + d2), (cra + d2, cdec + d2), (cra - d2, cdec - d2), (cra + d2, cdec - d2)] for field in fields: ra,dec = field ras = [ra-d2, ra+d2, ra+d2, ra-d2, ra-d2] das = [dec-d2, dec-d2, dec+d2, dec+d2, dec-d2] ax.plot(ras, das ,'g') ax.plot(x,y, 'k', linestyle='--',label='BJG 2005') #xticks = ax.get_xticks() print [ast.dd2hms(r) for r in ras] xticks = [ast.hms2dd((18,m,0)) for m in [30,29,28,27,26,15]] xlabels = ['$8^h%2d^m$' % m for m in [30,29,28,27,26,15]] plt.xticks(xticks, xlabels) declist = [(6,0),(6,15),(6,30),(6,45),(7,0)] yticks = [ast.dms2dd(dl) for dl in declist] ylabels = ['$%d^{\circ}%2d^m$' % dl for dl in declist] plt.yticks(yticks, ylabels, rotation=90) ax.grid() ax.set_ylim(cdec-0.4,cdec+0.4) ax.set_xlim(cra+0.4,cra-0.4) plt.xlabel('R.A. (J2000)') plt.ylabel('Dec. (J2000)') if show: plt.show() else: plt.savefig(config.plotpath+'ngc6633_map.pdf', transparent=True) plt.savefig(config.plotpath+'ngc6633_map.eps', transparent=True)
def plot_map(self, show=False): ''' plots the map of the M48 observation including the BJG field ''' #import pywcsgrid2 import astronomy as ast from dbtable import DBTable # @UnresolvedImport astars = DBTable(self.wifsip, 'm48stars', condition='vmag<12.0 and good is NULL') gstars = DBTable(self.wifsip, 'm48stars', condition='good and provisional is null') pstars = DBTable(self.wifsip, 'm48stars', condition='provisional') fig_width = 8.9/2.54 # width in inches, was 7.48in fig_height = 8.9/2.54 # height in inches, was 25.5 fig_size = [fig_width,fig_height] #set plot attributes params = {'backend': 'Agg', 'axes.labelsize': 8, 'axes.titlesize': 10, 'font.size': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'figure.figsize': fig_size, 'savefig.dpi' : 300, 'font.family': 'sans-serif', 'axes.linewidth' : 0.2, 'xtick.major.size' : -2, 'ytick.major.size' : -2, u'figure.subplot.bottom' : 0.11, u'figure.subplot.left' : 0.11, u'figure.subplot.right' : 0.89, u'figure.subplot.top' : 0.89 } rcParams.update(params) fig = plt.figure() ax = fig.add_subplot(111) vmag = np.array(astars['vmag']) ax.set_aspect(1.) ax.scatter(astars['ra'],astars['dec'], marker='*', s=(12.-vmag)*15,facecolor='gray', edgecolor='none') ax.scatter(pstars['ra'],pstars['dec'], marker='o',edgecolor='r', facecolor='none', s=10) ax.scatter(gstars['ra'],gstars['dec'], marker='o',edgecolor='r', facecolor='r', s=10) ra = np.array([8.24242, 8.21705, 8.20416])*15.0 de = np.array([-6.08887,-5.70876,-5.51204]) x = [ra[0],ra[2],ra[2],ra[1],ra[1],ra[0],ra[0]] y = [de[0],de[0],de[1],de[1],de[2],de[2],de[0]] cra, cdec = (123.42916666666666,-5.75) d2 = 0.5*1320.2/3600.0 fields = [(cra , cdec), (cra - d2, cdec + d2), (cra + d2, cdec + d2), (cra - d2, cdec - d2), (cra + d2, cdec - d2)] for field in fields: ra,dec = field ras = [ra-d2, ra+d2, ra+d2, ra-d2, ra-d2] das = [dec-d2, dec-d2, dec+d2, dec+d2, dec-d2] ax.plot(ras, das ,'g') ax.plot(x,y, 'k', linestyle='--',label='BJG 2005') #xticks = ax.get_xticks() xticks = [ast.hms2dd((8,m,0)) for m in [16,15,14,13,12]] xlabels = ['$8^h%2d^m$' % m for m in [16,15,14,13,12]] plt.xticks(xticks, xlabels) declist = [(-5,15),(-5,30),(-5,45),(-6,0),(-6,15)] yticks = [ast.dms2dd(dl) for dl in declist] ylabels = ['$%d^{\circ}%2d^m$' % dl for dl in declist] plt.yticks(yticks, ylabels, rotation=-90) ax.grid() ax.set_ylim(cdec-0.4,cdec+0.4) ax.set_xlim(cra+0.4,cra-0.4) plt.xlabel('R.A. (J2000)') plt.ylabel('Dec. (J2000)') if show: plt.show() else: plt.savefig(config.plotpath+'m48_map.pdf', transparent=True) plt.savefig(config.plotpath+'m48_map.eps', transparent=True)