def plot_globular_clusters(ax, plot_colorbar=False, scat_kwargs=None, galactic=True): #Harris's Globular cluster compilation gcfilen = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib', 'globular_cluster_params.harris2010.tableI.csv') gc_l, gc_b, gc_Rhel = scipy.genfromtxt(gcfilen, missing_values="", usecols=(5 - 1, 6 - 1, 7 - 1), unpack=True, delimiter=',', dtype=np.float) gc_RA, gc_DEC = bovyc.lb_to_radec(gc_l, gc_b, degree=True).T #set a few plotting and labelling defaults scatter_kwargs = dict(marker='x', s=70., vmin=0., zorder=0) #but override whichever are user-supplied (doing it this way I ensure using my own defaults and not matplotlib's #if user supplies values for some (but not all) keywords if scat_kwargs is not None: for key in scat_kwargs.keys(): scatter_kwargs[key] = scat_kwargs[key] #Plot globular cluster layer if galactic: cc = ax.scatter(gc_l, gc_b, c=gc_Rhel, **scatter_kwargs) else: cc = ax.scatter(gc_RA, gc_DEC, c=gc_Rhel, **scatter_kwargs) if plot_colorbar: plt.colorbar(cc, ax=ax)
def __init__(self,lon,lat,name,Dist=None,vrad=None,pmlon=None,pmlat=None,cootype='gal',degree=True,is_pml_star=True, xyz_sun=[8.5,0.,0.],vel_sun=[10.3,232.6,5.9],vxyz_gal=(),Rhel=None): self.deg=degree self._f=np.pi/180. self.name=name self.sname=name[:8] #Bovy's library assumes Sun's position is positive. Flip X-axis is done later sign=1. #Save Sun's position self.xsun, self.ysun, self.zsun= xyz_sun self.vxsun, self.vysun, self.vzsun= vel_sun self.xsun, self.vxsun = sign*self.xsun, sign*self.vxsun #Rhel is kept for backwards compatibility if Rhel is not None and 'GC' in cootype: sys.exit('ERROR: Rhel not compatible with cootype=GC (distance provided should be galactocentric)') elif Rhel is not None: Dist,self.Rhel=Rhel,Rhel if 'GC' in cootype: if Dist is not None: self.Rgal=Dist else: sys.exit('ERROR: Distance is mandatory to instantiate a Footprint in Galactocentric coords (cootype=GC)') self.phi,self.theta=lon,lat if vxyz_gal: self.vx,self.vy,self.vz=vxyz_gal #Compute and set all heliocentric attributes self.compute_heliocentric_coords(degree=degree) else: if 'gal' in cootype: self.l,self.b=lon,lat mm=bovyc.lb_to_radec(self.l,self.b,degree=self.deg) if self.l.size>1: self.ra,self.dec=mm.T else: self.ra,self.dec=mm else: self.ra,self.dec=lon,lat mm=bovyc.radec_to_lb(self.ra,self.dec,degree=self.deg) if self.ra.size>1: self.l,self.b=mm.T else: self.l,self.b=mm if Dist is not None: self.Rhel=Dist if vrad is not None: self.vrad=vrad if 'gal' in cootype: if pmlon is not None: if is_pml_star: self.pmlstar,self.pml=pmlon,pmlon/np.cos(_f*self.b) else: self.pmlstar,self.pml=pmlon*np.cos(self._f*self.b),pmlon if pmlat is not None: self.pmb=pmlat else: if pmlon is not None: if is_pml_star: self.pmrastar,self.pmra=pmlon,pmlon/np.cos(_f*self.dec) else: self.pmrastar,self.pmra=pmlon*np.cos(self._f*self.dec),pmlon if pmlat is not None: self.pmdec=pmlat #Set galactocentric attributes if hasattr(self,'Rhel') : self.compute_galactocentric_coords(degree=degree) #Set center attributes self.compute_sky_center()
def compute_heliocentric_coords(self, verbose=False, degree=True): #Set Galactocentric Cartesian coords xg, yg, zg = bovyc.lbd_to_XYZ(self.phi, self.theta, self.Rgal, degree=degree).T self.x, self.y, self.z = -xg, yg, zg #Convert to Heliocentric self.xhel, self.yhel, self.zhel = bovyc.galcenrect_to_XYZ( self.x, self.y, self.z, Xsun=self.xsun, Ysun=self.ysun, Zsun=self.zsun) #Save Heliocentric galactic and equatorial self.l, self.b, self.Rhel = bovyc.XYZ_to_lbd(self.xhel, self.yhel, self.zhel, degree=degree).T self.ra, self.dec = bovyc.lb_to_radec(self.l, self.b, degree=degree).T #Set kinematic attributes, if vels available if hasattr(self, 'vx') and hasattr(self, 'vy') and hasattr(self, 'vz'): #Cartesian Heliocentric m = bovyc.galcenrect_to_vxvyvz( self.vx, self.vy, self.vz, vsun=[self.vxsun, self.vysun, self.vzsun]) self.vxhel, self.vyhel, self.vzhel = m #Spherical Heliocentric Galactic m = bovyc.vxvyvz_to_vrpmllpmbb(self.vxhel, self.vyhel, self.vzhel, self.l, self.b, self.Rhel, XYZ=False, degree=degree) self.vrad, self.pmlstar, self.pmb = m.T self.pml = self.pmlstar / np.cos(self.b * self._f) #Spherical Heliocentric Equatorial self.pmrastar, self.pmdec = pmllpmbb_to_pmrapmdec(self.pml, self.pmb, self.l, self.b, degree=degree, epoch=2000.0) self.pmra = self.pmrastar / np.cos(self.dec * self._f)
def compute_sky_center(self): #Set defaults #Need to get cartesian coords to do vector-average (this works whether or not Rhel exists) mm=bovyc.lbd_to_XYZ(self.l,self.b,np.ones_like(self.l),degree=True) if self.l.size>1: _xx,_yy,_zz=mm.T else: _xx,_yy,_zz=mm _xc,_yc,_zc=_xx.sum(),_yy.sum(),_zz.sum() self.cl,self.cb=bovyc.XYZ_to_lbd(_xc,_yc,_zc,degree=True)[:2] self.cra,self.cdec=bovyc.lb_to_radec(self.cl,self.cb,degree=True) if hasattr(self,'phi') and hasattr(self,'theta'): _xgc,_ygc,_zgc=self.x.sum(),self.y.sum(),self.z.sum() self.cphi,self.ctheta=bovyc.XYZ_to_lbd(_xgc,_ygc,_zgc,degree=True)[:2]
def init_by_poles(self,gcstep=0.1,verbose=False): lib_poles_filen=os.path.join(os.path.dirname(os.path.realpath(__file__)),'lib','lib_by_pole.dat') name,pole_coot,c_coot=scipy.genfromtxt(lib_poles_filen,usecols=(0,3,6),unpack=True,dtype='S') pole_dat=scipy.genfromtxt(lib_poles_filen,usecols=(1,2,4,5,7,8,9,10),filling_values=-999.) pole_lons,pole_lats,clons,clats,dlons,dlats,ros,rfs=pole_dat.T for i in np.arange(len(pole_lons)): #Convert central coords to the same as pole coords for consistency if verbose: print 'Reading pole-list for %s' % (name[i]) #If center coords are given, make sure they're in the same system as pole coords if (clons[i]!=-999. and clats[i]!=-999.): if c_coot[i] in pole_coot[i]: center=[clons[i],clats[i]] #If in the same system, just save if verbose: print ' same system, center:',center else: if 'gal' in c_coot[i]: clons[i],clats[i]=bovyc.lb_to_radec(clons[i],clats[i],degree=True) else: clons[i],clats[i]=bovyc.radec_to_lb(clons[i],clats[i],degree=True) center=[clons[i],clats[i]] if verbose: print ' computed center',center else: center=None if dlons[i]<-90: dlons[i]=None if dlats[i]<0.: dlats[i]=0. #Get realization of great-circle, given stream's orbital pole [and optionally center,length and width] gc_lons,gc_lats=gcutils.get_gc_for_pole(pole_lons[i],pole_lats[i],degree=True,center=center, dlon=dlons[i],dlat=dlats[i],step=gcstep) #Do linear interpolation for the distance, not much better to do if ros[i]==rfs[i]: D=ros[i]*np.ones_like(gc_lons) elif rfs[i]>ros[i]>0.: D=scipy.interp(gc_lons,[lono[i],lonf[i]],[ros[i],rfs[i]]) else: D=-1*np.ones_like(gc_lons) #Create footprint appropriately depending on coord type, this will define the l,b,ra,dec attributes appropriately footprint=Footprint(gc_lons,gc_lats,name[i],Dist=D,degree=True,cootype=pole_coot[i]) #Store self[name[i]]=footprint
def __init__(self, lon, lat, name, Dist=None, vrad=None, pmlon=None, pmlat=None, cootype='gal', degree=True, is_pml_star=True, xyz_sun=[8.5, 0., 0.], vel_sun=[10.3, 232.6, 5.9], vxyz_gal=(), Rhel=None): self.deg = degree self._f = np.pi / 180. self.name = name self.sname = name[:8] #Bovy's library assumes Sun's position is positive. Flip X-axis is done later sign = 1. #Save Sun's position self.xsun, self.ysun, self.zsun = xyz_sun self.vxsun, self.vysun, self.vzsun = vel_sun self.xsun, self.vxsun = sign * self.xsun, sign * self.vxsun #Rhel is kept for backwards compatibility if Rhel is not None and 'GC' in cootype: sys.exit( 'ERROR: Rhel not compatible with cootype=GC (distance provided should be galactocentric)' ) elif Rhel is not None: Dist, self.Rhel = Rhel, Rhel if 'GC' in cootype: if Dist is not None: self.Rgal = Dist else: sys.exit( 'ERROR: Distance is mandatory to instantiate a Footprint in Galactocentric coords (cootype=GC)' ) self.phi, self.theta = lon, lat if vxyz_gal: self.vx, self.vy, self.vz = vxyz_gal #Compute and set all heliocentric attributes self.compute_heliocentric_coords(degree=degree) else: if 'gal' in cootype: self.l, self.b = lon, lat mm = bovyc.lb_to_radec(self.l, self.b, degree=self.deg) if self.l.size > 1: self.ra, self.dec = mm.T else: self.ra, self.dec = mm else: self.ra, self.dec = lon, lat mm = bovyc.radec_to_lb(self.ra, self.dec, degree=self.deg) if self.ra.size > 1: self.l, self.b = mm.T else: self.l, self.b = mm if Dist is not None: self.Rhel = Dist if vrad is not None: self.vrad = vrad if 'gal' in cootype: if pmlon is not None: if is_pml_star: self.pmlstar, self.pml = pmlon, pmlon / np.cos( _f * self.b) else: self.pmlstar, self.pml = pmlon * np.cos( self._f * self.b), pmlon if pmlat is not None: self.pmb = pmlat else: if pmlon is not None: if is_pml_star: self.pmrastar, self.pmra = pmlon, pmlon / np.cos( _f * self.dec) else: self.pmrastar, self.pmra = pmlon * np.cos( self._f * self.dec), pmlon if pmlat is not None: self.pmdec = pmlat #Set galactocentric attributes if hasattr(self, 'Rhel'): self.compute_galactocentric_coords(degree=degree) #Set center attributes self.compute_sky_center() #Compute and Set end-point attributes try: self.compute_midplane_endpoints_1(verbose=False) self.mp = 1 except: self.compute_midplane_endpoints_2(verbose=False) self.mp = 2 #Set decent astropy Skycoord object as attribute self.sc = astropy.coordinates.SkyCoord(ra=self.ra * u.deg, dec=self.dec * u.deg) #Set great-circle gala-reference-frame for each stream based on its mid-plane end-points self.gcfr = gc.GreatCircleICRSFrame.from_endpoints( self.end_o, self.end_f) #Check that pole is not nan, use method_1 to correct it if it is, and recompute gcfr if not (self.gcfr.pole.ra >= 0): self.compute_midplane_endpoints_2(verbose=False, tol=0.1) self.mp = 2 self.gcfr = gc.GreatCircleICRSFrame.from_endpoints( self.end_o, self.end_f) #Flip if pole's dec is negative if self.gcfr.pole.dec < 0: self.gcfr = gc.GreatCircleICRSFrame.from_endpoints( self.end_f, self.end_o) #Provide phi1 and phi2 as "normal" Footprint attributes self.phi1 = self.sc.transform_to(self.gcfr).phi1 self.phi2 = self.sc.transform_to(self.gcfr).phi2
def __init__(self, lon, lat, name, Rhel=None, vrad=None, pmlon=None, pmlat=None, cootype='gal', degree=True, is_pml_star=True, xyz_sun=[8.5, 0., 0.], vel_sun=[10.3, 232.6, 5.9]): self.deg = degree self._f = np.pi / 180. self.name = name if 'gal' in cootype: self.l, self.b = lon, lat mm = bovyc.lb_to_radec(self.l, self.b, degree=self.deg) if self.l.size > 1: self.ra, self.dec = mm.T else: self.ra, self.dec = mm else: self.ra, self.dec = lon, lat mm = bovyc.radec_to_lb(self.ra, self.dec, degree=self.deg) if self.ra.size > 1: self.l, self.b = mm.T else: self.l, self.b = mm if Rhel is not None: self.Rhel = Rhel if vrad is not None: self.vrad = vrad if 'gal' in cootype: if pmlon is not None: if is_pml_star: self.pmlstar, self.pml = pmlon, pmlon / np.cos(_f * self.b) else: self.pmlstar, self.pml = pmlon * np.cos(_f * self.b), pmlon if pmlat is not None: self.pmb = pmlat else: if pmlon is not None: if is_pml_star: self.pmrastar, self.pmra = pmlon, pmlon / np.cos( _f * self.dec) else: self.pmrastar, self.pmra = pmlon * np.cos( _f * self.dec), pmlon if pmlat is not None: self.pmdec = pmlat #Bovy's library assumes Sun's position is positive. Flip X-axis if xsun<0 #if xyz_sun[0]<0.: sign=-1 #else: sign=+1 sign = 1. #Save Sun's position self.xsun, self.ysun, self.zsun = xyz_sun self.vxsun, self.vysun, self.vzsun = vel_sun self.xsun, self.vxsun = sign * self.xsun, sign * self.vxsun #Set galactocentric attributes if hasattr(self, 'Rhel'): self.compute_galactocentric_coords(degree=degree) #Set center attributes self.compute_sky_center()