def get_fov(self, radius, fermi_frame=False):
        """
        Returns
        -------
        array of RA and DEC

        """

        steps = 500

        if fermi_frame:
            fermi = self._center

            poly = SphericalPolygon.from_cone(fermi.lon.value,
                                              fermi.lat.value,
                                              radius,
                                              steps=steps)

        else:

            j2000 = self._center.icrs

            poly = SphericalPolygon.from_cone(j2000.ra.value,
                                              j2000.dec.value,
                                              radius,
                                              steps=steps)

        # ra, dec
        return [p for p in poly.to_radec()][0]
Example #2
0
    def get_fov(self, radius, fermi_frame=False):
        """
        Returns
        -------
        array of RA and DEC

        """

        steps = 500

        if fermi_frame:
            fermi = self._center

            poly = SphericalPolygon.from_cone(fermi.lon.value,
                                              fermi.lat.value,
                                              radius,
                                              steps=steps)


        else:

            j2000 = self._center.icrs

            poly = SphericalPolygon.from_cone(j2000.ra.value,
                                              j2000.dec.value,
                                              radius,
                                              steps=steps)

        # ra, dec
        return [p for p in poly.to_radec()][0]
Example #3
0
	def get_earth_point_with_time(self,t):
		
		earth_radius = 6371. * u.km
		if self.sc_pos_f is not None and self.time_band is not None:
			x_f, y_f, z_f = self.sc_pos_f
			try:
				n = len(t)
				t = np.array(t)
				tband = t.max() - t.min()
				tband_sl = self.time_band[1] - self.time_band[0]
				if tband <= tband_sl + 2:
					t[t <= self.time_band[0]] = self.time_band[0] + 0.00001
					t[t >= self.time_band[1]] = self.time_band[1] - 0.00001
				else:
					t[t <= self.time_band[0]] = np.nan
					t[t >= self.time_band[1]] = np.nan
					
				x = x_f(t) * self.pos_unit
				y = y_f(t) * self.pos_unit
				z = z_f(t) * self.pos_unit
				earth_point_list = []
				for i in range(n):
					position = cartesian_to_spherical(x[i],y[i],z[i])
					xyz_position = SkyCoord(position[2].deg,position[1].deg,frame='icrs',unit='deg')
					fermi_radius = np.sqrt(x[i]**2 + y[i]**2 + z[i]**2)
					radius_deg = np.rad2deg(np.arcsin((earth_radius / fermi_radius).to(u.dimensionless_unscaled)).value)
					poly = SphericalPolygon.from_cone(position[2].deg,position[1].deg,radius_deg,steps=180)
					x_,y_ = np.array(list(poly.to_radec())[0])
					earth_point_list.append([xyz_position,radius_deg,x_,y_])
				return earth_point_list
			except 	(TypeError):
				
				if (t<=self.time_band[0]):
					if (self.time_band[0]-t<=1):
						t = self.time_band[0]+0.00001
					else:
						t = np.nan
				if t>=self.time_band[1]:
					if (t-self.time_band[0]<=1):
						t = self.time_band[1]-0.00001
					else:
						t = np.nan
				x = x_f(t) * self.pos_unit
				y = y_f(t) * self.pos_unit
				z = z_f(t) * self.pos_unit
				position = cartesian_to_spherical(x,y,z)
				xyz_position = SkyCoord(position[2].deg,position[1].deg,frame='icrs',unit='deg')
				fermi_radius = np.sqrt(x**2 + y**2 + z**2)
				radius_deg = np.rad2deg(np.arcsin((earth_radius / fermi_radius).to(u.dimensionless_unscaled)).value)
				poly = SphericalPolygon.from_cone(position[2].deg,position[1].deg,radius_deg,steps=180)
				x_,y_ = np.array(list(poly.to_radec())[0])
				return xyz_position,radius_deg,x_,y_
		else:
			return None
def sky_cone(ra_c, dec_c, theta, steps=50, include_center=True):
    """
    Get ra and dec coordinates of a cone on the sky.
    Parameters
    ----------
    ra_c, dec_c: float
        Center of cone in degrees.
    theta: astropy Quantity, float, or int
        Angular radius of cone. Must be in arcsec
        if not a Quantity object.
    steps: int, optional
        Number of steps in the cone.
    include_center: bool, optional
        If True, include center point in cone.
    Returns
    -------
    ra, dec: ndarry
        Coordinates of cone.
    """
    if isinstance(theta, float) or isinstance(theta, int):
        theta = theta * u.Unit('arcsec')

    cone = SphericalPolygon.from_cone(ra_c,
                                      dec_c,
                                      theta.to('deg').value,
                                      steps=steps)
    ra, dec = list(cone.to_lonlat())[0]
    ra = np.mod(ra - 360., 360.0)
    if include_center:
        ra = np.concatenate([ra, [ra_c]])
        dec = np.concatenate([dec, [dec_c]])
    return ra, dec
Example #5
0
def get_fov(conter,radius = 10.):
		fov_point_list = []
		for conter_i in conter:
			poly = SphericalPolygon.from_cone(conter_i.ra.value,conter_i.dec.value,radius,steps=100)
			x,y = [p for p in poly.to_radec()][0]
			fov_point_list.append([radius,x,y])
		return fov_point_list
Example #6
0
	def get_fov(self,conter,radius = 10.):
		fov_point_list = []
		for conter_i in conter:
			poly = SphericalPolygon.from_cone(conter_i.ra.value,conter_i.dec.value,radius,steps=180)
			x,y = np.array(list(poly.to_radec())[0])
			fov_point_list.append([radius,x,y])
		return fov_point_list
Example #7
0
 def get_earth_point(self, index=None):
     if self.sc_pos is not None:
         earth_point_list = []
         if index is not None:
             sc_pos_list = self.sc_pos[index]
         else:
             sc_pos_list = self.sc_pos
         for sc_pos in sc_pos_list:
             position = cartesian_to_spherical(-sc_pos[0], -sc_pos[1],
                                               -sc_pos[2])
             xyz_position = SkyCoord(position[2].deg,
                                     position[1].deg,
                                     frame='icrs',
                                     unit='deg')
             earth_radius = 6371. * u.km
             fermi_radius = np.sqrt((sc_pos**2).sum())
             radius_deg = np.rad2deg(
                 np.arcsin((earth_radius / fermi_radius).to(
                     u.dimensionless_unscaled)).value)
             poly = SphericalPolygon.from_cone(position[2].deg,
                                               position[1].deg,
                                               radius_deg,
                                               steps=100)
             x, y = [p for p in poly.to_radec()][0]
             earth_point_list.append([xyz_position, radius_deg, x, y])
         return earth_point_list
     else:
         print('No satellite position!')
         return None
Example #8
0
    def contains_point(self, point):

        steps = 300
        j2000 = self.center.icrs
        poly = SphericalPolygon.from_cone(j2000.ra.value,
                                          j2000.dec.value,
                                          self.radius,
                                          steps=steps)
        return poly.contains_point(point.cartesian.xyz.value)
Example #9
0
	def get_fov(self,radius):
		'''这里是计算出探头标注'''
		if radius >= 60:
			steps = 500
		elif radius >= 30:
			steps = 300
		else:
			steps = 250
		j2000 = self.center.icrs
		poly = SphericalPolygon.from_cone(j2000.ra.value,j2000.dec.value,radius,steps = steps)
		re =  [p for p in poly.to_radec()][0]
		return re
Example #10
0
def makeQueryRegion(ra, dec, size):
    region = None

    if size[1] is None:
        # Then we have a radius, not a box.
        radius = size[0]
        region = SphericalPolygon.from_cone(ra, dec, radius)
    else:
        # Make a box.
        radius = None
        # Figure out this stupid shape later...

    return region
Example #11
0
def makeQueryRegion(ra, dec, size):
    region = None

    if size[1] is None:
        # Then we have a radius, not a box.
        radius = size[0]
        region = SphericalPolygon.from_cone(ra, dec, radius)
    else:
        # Make a box.
        radius = None
        # Figure out this stupid shape later...

    return region
Example #12
0
 def get_fov(self, radius):
     if radius >= 60:
         steps = 5000  ## could be modified to speed up the plotting
     elif radius >= 30:
         steps = 400  ## could be modified to speed up the plotting
     else:
         steps = 100  ## could be modified to speed up the plotting
     j2000 = self.center.icrs
     poly = SphericalPolygon.from_cone(j2000.ra.value,
                                       j2000.dec.value,
                                       radius,
                                       steps=steps)
     re = [p for p in poly.to_radec()][0]
     return re
Example #13
0
    def plot_earth(self, t, satellite, **kwargs):

        if 'facecolor' not in kwargs:
            kwargs['facecolor'] = '#90d7ec'
        if 'edgecolor' not in kwargs:
            kwargs['edgecolor'] = '#90d7ec'

        try:
            met, ra, dec, radius = satellite.get_earth_point(t)
            for i in range(len(met)):
                poly = SphericalPolygon.from_cone(ra[i],
                                                  dec[i],
                                                  radius[i],
                                                  steps=180)
                x_, y_ = np.array(list(poly.to_radec())[0])
                earth = self.Polygon(list(zip(x_, y_))[::-1], **kwargs)
                self.ax.add_patch(earth)
        except (TypeError):
            met, ra, dec, radius = satellite.get_earth_point(t)
            poly = SphericalPolygon.from_cone(ra, dec, radius, steps=180)
            x_, y_ = np.array(list(poly.to_radec())[0])
            earth = self.Polygon(list(zip(x_, y_))[::-1], **kwargs)
            self.ax.add_patch(earth)
 def get_good_detector_centers(self, source=None):
     good_detector_centers = []
     good_detector_index = []
     if source is not None:
         for index, center in enumerate(self.detectors.center_all):
             steps = 250
             j2000 = center.icrs
             poly = SphericalPolygon.from_cone(j2000.ra.value,
                                               j2000.dec.value,
                                               self.radius,
                                               steps=steps)
             if (poly.contains_point(source.cartesian.xyz.value)):
                 good_detector_centers.append(center)
                 good_detector_index.append(index)
     else:
         print('No source! return []')
     return good_detector_index, good_detector_centers
 def get_fov(self, radius):
     if radius >= 60:
         steps = 500
     elif (radius >= 30):
         steps = 300
     else:
         steps = 250
     j2000 = self.center_all.icrs
     c = []
     for index, center in enumerate(j2000):
         print(str(index))
         poly = SphericalPolygon.from_cone(center.ra.value,
                                           center.dec.value,
                                           radius,
                                           steps=steps)
         re = [p for p in poly.to_radec()][0]
         #print(re)
         c.append(re)
     return c
Example #16
0
    def plot_detector(self,
                      t,
                      satellite,
                      radius=10.0,
                      good_detector_list=None,
                      detector_color=None,
                      detector_color_highlight=None,
                      **kwargs):

        namelist = satellite.detectors.name
        try:
            len(t)
            print('only the first of t will be ploted')
            dete_point = satellite(t)
            for index, dete in enumerate(namelist):

                color = self.detector_color
                if detector_color is not None:
                    try:
                        color = detector_color[index]
                    except (TypeError):
                        color = detector_color

                if good_detector_list is not None:
                    if dete in good_detector_list:
                        color = self.detector_color_highlight
                        if detector_color_highlight is not None:
                            try:
                                color = detector_color_highlight[index]
                            except (TypeError):
                                color = detector_color_highlight
                ra, dec = dete_point[dete][0]
                poly = SphericalPolygon.from_cone(ra, dec, radius, steps=180)
                x_, y_ = np.array(list(poly.to_radec())[0])
                dete_p = self.Polygon(list(zip(x_, y_))[::-1],
                                      facecolor=color,
                                      edgecolor=color,
                                      linewidth=0.2 * self.size,
                                      alpha=0.5,
                                      **kwargs)
                self.ax.add_patch(dete_p)
                self.text(ra,
                          dec,
                          str(dete),
                          color='k',
                          va='center',
                          ha='center',
                          size=self.size,
                          **kwargs)
        except (TypeError):
            dete_point = satellite(t)
            for index, dete in enumerate(namelist):
                color = self.detector_color
                if detector_color is not None:
                    try:
                        color = detector_color[index]
                    except (TypeError):
                        color = detector_color
                if good_detector_list is not None:
                    if dete in good_detector_list:
                        color = self.detector_color_highlight
                        if detector_color_highlight is not None:
                            try:
                                color = detector_color_highlight[index]
                            except (TypeError):
                                color = detector_color_highlight
                ra, dec = dete_point[dete]
                poly = SphericalPolygon.from_cone(ra, dec, radius, steps=180)
                x_, y_ = np.array(list(poly.to_radec())[0])
                dete_p = self.Polygon(list(zip(x_, y_))[::-1],
                                      facecolor=color,
                                      edgecolor=color,
                                      linewidth=0.2 * self.size,
                                      alpha=0.5,
                                      **kwargs)
                self.ax.add_patch(dete_p)
                self.text(ra,
                          dec,
                          str(dete),
                          color='k',
                          va='center',
                          ha='center',
                          size=self.size,
                          **kwargs)
Example #17
0
def get_circle(position,radius,lon_0,map_,facecolor='coral', edgecolor='coral',linewidth=0., alpha=1.):
	'''
	
	:param position:
	:param radius:
	:param lon_0:
	:param map_:
	:param facecolor:
	:param edgecolor:
	:param linewidth:
	:param alpha:
	:return:
	'''
	x0 = position.ra.value
	y0 = position.dec.value
	xx_dd = tranlation_lon_0([lon_0 - 180],x0 - 180)[0]
	poly = SphericalPolygon.from_cone(180,y0,radius,steps=200)
	x,y = [p for p in poly.to_radec()][0]
	
	poly_arr = np.array([89.9999,-89.9999])
	d_deg = np.abs(poly_arr-y0)
	d_l = poly_arr[d_deg<radius]

	add_x = np.zeros(100) + xx_dd
	add_y = np.linspace(-89.9999, 89.9999, 100)
	if d_l.size > 0:
		xx_dd180 = loop_data([xx_dd+180])[0]
		#print('pole_in.size > 0')
		if d_l[0] == 89.9999:
			#print('pole_in.dec.deg == 90.')
			x_n = []
			y_n = []
			n0 = x[0]
			y0 = y[0]
			for i in range(1, len(x)):
				
				if judge(x[i],n0,xx_dd,xx_dd180) == False :
					x_n.append(x[i])
					y_n.append(y[i])
					n0 = x[i]
					y0 = y[i]
				else:
					#print(x[i],n0,xx_dd,xx_dd180)
					#print('nnn0',n0,y0)
					#print('xxxi',x[i],y[i])
					indexs = np.where(add_y >= y0)[0]
					add_y_a = add_y[indexs]
					add_x_a = add_x[indexs]
					indexssort = np.argsort(add_y_a)
					ds = get_ra(n0,x[i])
					n_v = ds / np.abs(ds)
					#print('n_v',n_v)
					add_y_a1 = add_y_a[indexssort]
					add_x_a1 = add_x_a[indexssort] + 0.1*n_v
					#print('add_x',add_x_a,add_y_a)
					#print(n0,x[i],xx_dd)
					#print(n0 - xx_dd)
					for i in range(len(add_y_a1)):
						x_n.append(add_x_a1[i])
						y_n.append(add_y_a1[i])
					indexssort = np.argsort(-add_y_a)
					add_y_a2 = add_y_a[indexssort]
					add_x_a2 = add_x_a[indexssort] - 0.1*n_v
					#print('add_x',add_x_a,add_y_a)
					for i in range(len(add_y_a2)):
						x_n.append(add_x_a2[i])
						y_n.append(add_y_a2[i])
					n0 = x[i]
					y0 = y[i]
			#print(x_n)
			#print(y_n)
			x = [tranlation_lon_0(x_n, -x0 + 180)]
			y = [np.array(y_n)]
		else:
			#print('pole_in.dec.deg == 90. else')
			x_n = []
			y_n = []
			n0 = x[0]
			y0 = y[0]
			
			for i in range(1, len(x)):
				if judge(x[i],n0,xx_dd,xx_dd180) == False:
					
					x_n.append(x[i])
					y_n.append(y[i])
					n0 = x[i]
					y0 = y[i]
				else:
					#print('dddddd',x[i],n0,xx_dd,xx_dd180)
					#print(i)
					indexs = np.where(add_y <= y0)[0]
					add_y_a = add_y[indexs]
					#add_x_a = np.zeros(add_y_a.size) + n0
					add_x_a = add_x[indexs]
					indexssort = np.argsort(-add_y_a)
					ds = get_ra(n0,x[i])
					n_v = ds / np.abs(ds)
					add_y_a1 = add_y_a[indexssort]
					add_x_a1 = add_x_a[indexssort]+0.1*n_v
					
					#print(n0,x[i],xx_dd)
					#print(n0 - xx_dd)
					for i in range(len(add_y_a1)):
						#pass
						x_n.append(add_x_a1[i])
						y_n.append(add_y_a1[i])
					indexssort = np.argsort(add_y_a)
					add_y_a2 = add_y_a[indexssort]
					add_x_a2 = add_x_a[indexssort] - 0.1*n_v
				
					for i in range(len(add_y_a2)):
						x_n.append(add_x_a2[i])
						y_n.append(add_y_a2[i])
					n0 = x[i]
					y0 = y[i]

			x = [tranlation_lon_0(x_n, -x0 + 180)]
			y = [np.array(y_n)]
	else:
		#print('pole_in.size > 0 else')
		x_1 = []
		y_1 = []
		x_2 = []
		y_2 = []
		
		if len(x[x > xx_dd]) > len(x[x <= xx_dd]):
			#print('len(x[x > xx_dd]) > len(x[x <= xx_dd])')
			if len(x[x <= xx_dd]) > 0:
				#print('len(x[x <= xx_dd]) > 0')
				# x大于xx_dd
				for i in range(len(x)):
					# x小于xx_dd一律等于xx_dd+0.1
					if x[i] <= xx_dd:
						x_1.append(xx_dd + 0.1)
						y_1.append(y[i])
					else:
						x_1.append(x[i])
						y_1.append(y[i])
				
				aa = y[x <= xx_dd]
				amax = aa.max()
				amin = aa.min()
				for i in range(len(x)):
					# x大于xx_dd一律等于xx_dd-0.1
					if x[i] >= xx_dd:
						x_2.append(xx_dd - 0.1)
						if y[i] > amax:
							y_2.append(amax)
						elif y[i] < amin:
							y_2.append(amin)
						else:
							y_2.append(y[i])
					else:
						x_2.append(x[i])
						if y[i] > amax:
							y_2.append(amax)
						elif y[i] < amin:
							y_2.append(amin)
						else:
							y_2.append(y[i])
				x = [tranlation_lon_0(x_1, -x0 + 180),
				     tranlation_lon_0(x_2, -x0 + 180)]
				y = [np.array(y_1), np.array(y_2)]
			else:
				x = [tranlation_lon_0(x, -x0 + 180)]
				y = [y]
		else:
			#print('len(x[x > xx_dd]) > len(x[x <= xx_dd]) else')
			if len(x[x > xx_dd]) > 0:
				#print('len(x[x > xx_dd]) > 0')
				# 小于xx_dd为主
				for i in range(len(x)):
					if x[i] >= xx_dd:
						x_1.append(xx_dd - 0.1)
						y_1.append(y[i])
					else:
						x_1.append(x[i])
						y_1.append(y[i])
				
				aa = y[x >= xx_dd]
				amax = aa.max()
				amin = aa.min()
				for i in range(len(x)):
					if x[i] <= xx_dd:
						x_2.append(xx_dd + 0.1)
						if y[i] > amax:
							y_2.append(amax)
						elif y[i] < amin:
							y_2.append(amin)
						else:
							y_2.append(y[i])
					else:
						x_2.append(x[i])
						if y[i] > amax:
							y_2.append(amax)
						elif y[i] < amin:
							y_2.append(amin)
						else:
							y_2.append(y[i])
				x = [tranlation_lon_0(x_1, -x0 + 180),
				     tranlation_lon_0(x_2, -x0 + 180)]
				y = [np.array(y_1), np.array(y_2)]
			else:
				#print('len(x[x > xx_dd]) > 0 else')
				x = [tranlation_lon_0(x, -x0 + 180)]
				y = [y]
	poly_list = []
	for i in range(len(x)):
		x_, y_ = map_(x[i], y[i])
		poly1 = Polygon(list(zip(x_, y_)), facecolor=facecolor, edgecolor=edgecolor,linewidth=linewidth, alpha=alpha)
		poly_list.append(poly1)
	return poly_list