Exemplo n.º 1
0
def add_plane(ax, color='black', plane=None, projection=None):
  
  if plane==None or projection==None:
    return
  
  alpha = np.arange(0.,360,2)
  delta = alpha*0.
  
  tran = wcs.Transformation(plane + " j2000 j2000", projection)
  alpha, delta = tran((alpha,delta))
  
  for i in range(len(alpha)):
    if alpha[i] >180:
      alpha[i] -= 360.
  
  ind = np.argsort(alpha)
  alpha = alpha[ind]
  delta = delta[ind]
  
  X = []
  Y = [] 
  
  for i in range(len(alpha)/2):
      x, y = xymap_aitoff(alpha[i], delta[i])
      X.append(x)
      Y.append(y)
      
  ax.plot(X, Y, '-', color=color)   
  X = []
  Y = []    
  for i in range(len(alpha)/2, len(alpha)):
      x, y = xymap_aitoff(alpha[i], delta[i])
      X.append(x)
      Y.append(y)     
  ax.plot(X, Y, '-', color=color)   
Exemplo n.º 2
0
  def in_motion(event):
     #print 'you pressed', event.key, event.button, event.xdata, event.ydata, event.key, event.inaxes
     a = event.xdata
     b = event.ydata
     if event.inaxes == ax: 
       
        Ux.set_text("X: "+'{:.2f}'.format(a))
        Uy.set_text("Y: "+'{:.2f}'.format(b))
        
        if mode=="equatorial":
	  RA, DEC = transform_inv(alpha, delta, a, b)
          tran = wcs.Transformation("equatorial j2000 j2000", "galactic")
          gl, gb = tran((RA,DEC))
          tran = wcs.Transformation("equatorial j2000 j2000", "supergalactic")
          sgl, sgb = tran((RA,DEC))

	elif mode=="galactic":
	  gl, gb  = transform_inv(alpha, delta, a, b)
	  tran = wcs.Transformation("galactic j2000 j2000", "equatorial")
	  RA, DEC = tran((gl,gb))
	  tran = wcs.Transformation("galactic j2000 j2000", "supergalactic")
	  sgl, sgb = tran((gl,gb))
	  
	elif mode=="supergalactic":
	  sgl, sgb  = transform_inv(alpha, delta, a, b)
	  tran = wcs.Transformation("supergalactic j2000 j2000", "equatorial")
	  RA, DEC = tran((sgl,sgb))
	  tran = wcs.Transformation("supergalactic j2000 j2000", "galactic")
	  gl, gb = tran((sgl,sgb))


        c = SkyCoord(ra=RA, dec=DEC, unit=(u.degree, u.degree))
	wcs_hmsdms =  c.to_string('hmsdms', precision=4, sep=':')
	wcs_hmsdms = wcs_hmsdms.split(" ")        
	Ura.set_text("RA: "+'{:.4f}'.format(RA))
	Udec.set_text("DEC: "+'{:.4f}'.format(DEC))  
        Ualf.set_text(r"$\alpha: $"+wcs_hmsdms[0])
	Udelt.set_text(r"$\delta: $"+wcs_hmsdms[1]) 
        Ugl.set_text("l: "+'{:.4f}'.format(gl))
	Ugb.set_text("b: "+'{:.4f}'.format(gb)) 
	if sgl < 0: sgl += 360.
	Usgl.set_text("SGL: "+'{:.4f}'.format(sgl))
	Usgb.set_text("SGB: "+'{:.4f}'.format(sgb))

        
        draw()
     else:
        Ux.set_text(" ")
        Uy.set_text(" ")
        Ura.set_text(" ")
        Udec.set_text(" ")
        Ualf.set_text(" ")
	Udelt.set_text(" ")
	Ugl.set_text(" ")
	Ugb.set_text(" ")	
	Usgl.set_text(" ")
	Usgb.set_text(" ")
        draw()
Exemplo n.º 3
0
    def pixtosystem(self, idxs, system=None, coords='data'):

        if self.coordsys == 'raw':
            raise WCSError("No usable WCS")

        if system == None:
            system = 'icrs'

        # Get a coordinates object based on ra/dec wcs transform
        ra_deg, dec_deg = self.pixtoradec(idxs, coords=coords)
        self.logger.debug("ra, dec = %f, %f" % (ra_deg, dec_deg))

        # convert to alternate coord
        spec = self.conv_d[system]
        tran = kapwcs.Transformation(self._skyout, spec)
        lon_deg, lat_deg = tran((ra_deg, dec_deg))

        return lon_deg, lat_deg
Exemplo n.º 4
0
def add_plane(ax, color='black', plane=None, projection=None):

    if plane == None or projection == None:
        return

    alpha = np.arange(0., 360, 2)
    delta = alpha * 0.

    tran = wcs.Transformation(plane + " j2000 j2000", projection)
    alpha, delta = tran((alpha, delta))

    for i in range(len(alpha)):
        if alpha[i] > 180:
            alpha[i] -= 360.

    ind = np.argsort(alpha)
    alpha = alpha[ind]
    delta = delta[ind]
    ax.plot(alpha * pi / 180, delta * pi / 180, '-', color=color)
Exemplo n.º 5
0
def add_plane(p, color='black', plane=None, projection=None):
    from kapteyn import wcs

    if plane == None or projection == None:
        return
    alpha = np.arange(0., 360, 2)
    delta = alpha * 0.

    tran = wcs.Transformation(plane + " ", projection)
    alpha, delta = tran((alpha, delta))

    # for i in range(len(alpha)):
    #  if alpha[i] >180:
    ind = np.argsort(alpha)
    alpha = alpha[ind]
    delta = delta[ind]

    p.line(alpha, delta, line_width=2, color=color)
    p.line(alpha + 5, delta + 5, color='black', alpha=0.5)
    p.line(alpha - 5, delta - 5, color='black', alpha=0.5)
Exemplo n.º 6
0
    def datapt_to_system(self, datapt, system=None, coords='data',
                         naxispath=None):

        if self.coordsys == 'raw':
            raise common.WCSError("No usable WCS")

        if system is None:
            system = 'icrs'

        wcspt = self.datapt_to_wcspt(datapt, coords=coords,
                                     naxispath=naxispath)

        if self.coordsys == 'pixel':
            return wcspt

        # convert to alternate coord
        spec = self.conv_d[system]
        tran = kapwcs.Transformation(self._skyout, spec)

        return tran(wcspt)
Exemplo n.º 7
0
    def __set_coordinates(self, ra, dec):
        """
	set the coordinates l,b and the the maximum distance smax where |GMF| > 0

	Parameters
	----------
	ra: float
	    right ascension of source in degrees
	dec: float
	    declination of source in degrees

	Returns
	-------
	l: float
	    galactic longitude
	b: float
	    galactic latitude
	smax: float
	    maximum distance in kpc from sun considered here where |GMF| > 0
	"""

        # Transformation RA, DEC -> L,B
        tran = wcs.Transformation("EQ,fk5,J2000.0", "GAL")
        self.l, self.b = tran.transform(
            (ra, dec))  # return galactic coordinates in degrees
        self.l *= np.pi / 180.  # transform to radian
        self.b *= np.pi / 180.  # transform to radian
        d = self.d

        if self.galactic < 0.:  # if source is extragalactic, calculate maximum distance that beam traverses GMF to Earth
            cl = np.cos(self.l)
            cb = np.cos(self.b)
            sb = np.sin(self.b)
            self.smax = np.amin([
                self.zmax / np.abs(sb), 1. / np.abs(cb) *
                (-d * cl + np.sqrt(d**2 + cl**2 - d**2 * cb + self.rho_max**2))
            ])
        else:
            self.smax = self.galactic

        return self.l, self.b, self.smax