示例#1
0
    def Vonoroi_SH(self, mesh_size=0.1):
        """
        Generates a equally spaced mesh on the Solar Horizont (SH).
        
        Computes the Voronoi diagram from a set of points given by pairs
        of (azimuth, zenit) values. This discretization completely
        covers all the Sun positions.
        
        The smaller mesh size, the better resolution obtained. It is 
        important to note that this heavily affects the performance.
        
        The generated information is stored in:
            * **.t2vor_map** (*ndarray*): Mapping between time vector and
              the Voronoi diagram.
            * **.vor_freq** (*ndarray*): Number of times a Sun position
              is inside each polygon in the Voronoi diagram.
            * **.vor_surf** (*``pyny.Surface``*): Voronoi diagram.
            * **.vor_centers** (*ndarray`*): Mass center of the 
              ``pyny.Polygons`` that form the Voronoi diagram.
        
        :param mesh_size: Mesh size for the square discretization of the
            Solar Horizont.
        :type mesh_size: float (in radians)
        :param plot: If True, generates a visualization of the Voronoi
            diagram.
        :type plot: bool
        :returns: None
        
        .. note:: In future versions this discretization will be
            improved substantially. For now, it is quite rigid and only
            admits square discretization.
        """
        from scipy.spatial import Voronoi
        from pyny3d.utils import sort_numpy
        state = pyny.Polygon.verify
        pyny.Polygon.verify = False

        # Sort and remove NaNs
        xy_sorted, order_back = sort_numpy(self.azimuth_zenit, col=1, 
                                           order_back=True)
        
        # New grid
        x1 = np.arange(-np.pi, np.pi, mesh_size)
        y1 = np.arange(-mesh_size*2, np.pi/2+mesh_size*2, mesh_size)
        x1, y1 = np.meshgrid(x1, y1)
        centers = np.array([x1.ravel(), y1.ravel()]).T
        
        # Voronoi
        vor = Voronoi(centers)
        
        # Setting the SH polygons
        pyny_polygons = [pyny.Polygon(vor.vertices[v], False)
                         for v in vor.regions[1:] if len(v) > 3]
        raw_surf = pyny.Surface(pyny_polygons)
                                 
        # Classify data into the polygons discretization
        map_ = raw_surf.classify(xy_sorted, edge=True, col=1, 
                                 already_sorted=True)
        map_ = map_[order_back]
        
        # Selecting polygons with points inside
        vor = []
        count = []
        for i, poly_i in enumerate(np.unique(map_)[1:]):
            vor.append(raw_surf[poly_i])
            bool_0 = map_==poly_i
            count.append(bool_0.sum())
            map_[bool_0] = i
                
        # Storing the information
        self.t2vor_map = map_
        self.vor_freq = np.array(count)
        self.vor_surf = pyny.Surface(vor)
        self.vor_centers = np.array([poly.get_centroid()[:2] 
                                     for poly in self.vor_surf])
        pyny.Polygon.verify = state
示例#2
0
    def Vonoroi_SH(self, mesh_size=0.1):
        """
        Generates a equally spaced mesh on the Solar Horizont (SH).
        
        Computes the Voronoi diagram from a set of points given by pairs
        of (azimuth, zenit) values. This discretization completely
        covers all the Sun positions.
        
        The smaller mesh size, the better resolution obtained. It is 
        important to note that this heavily affects the performance.
        
        The generated information is stored in:
            * **.t2vor_map** (*ndarray*): Mapping between time vector and
              the Voronoi diagram.
            * **.vor_freq** (*ndarray*): Number of times a Sun position
              is inside each polygon in the Voronoi diagram.
            * **.vor_surf** (*``pyny.Surface``*): Voronoi diagram.
            * **.vor_centers** (*ndarray`*): Mass center of the 
              ``pyny.Polygons`` that form the Voronoi diagram.
        
        :param mesh_size: Mesh size for the square discretization of the
            Solar Horizont.
        :type mesh_size: float (in radians)
        :param plot: If True, generates a visualization of the Voronoi
            diagram.
        :type plot: bool
        :returns: None
        
        .. note:: In future versions this discretization will be
            improved substantially. For now, it is quite rigid and only
            admits square discretization.
        """
        from scipy.spatial import Voronoi
        from pyny3d.utils import sort_numpy
        state = pyny.Polygon.verify
        pyny.Polygon.verify = False

        # Sort and remove NaNs
        xy_sorted, order_back = sort_numpy(self.azimuth_zenit, col=1, 
                                           order_back=True)
        
        # New grid
        x1 = np.arange(-np.pi, np.pi, mesh_size)
        y1 = np.arange(-mesh_size*2, np.pi/2+mesh_size*2, mesh_size)
        x1, y1 = np.meshgrid(x1, y1)
        centers = np.array([x1.ravel(), y1.ravel()]).T
        
        # Voronoi
        vor = Voronoi(centers)
        
        # Setting the SH polygons
        pyny_polygons = [pyny.Polygon(vor.vertices[v], False)
                         for v in vor.regions[1:] if len(v) > 3]
        raw_surf = pyny.Surface(pyny_polygons)
                                 
        # Classify data into the polygons discretization
        map_ = raw_surf.classify(xy_sorted, edge=True, col=1, 
                                 already_sorted=True)
        map_ = map_[order_back]
        
        # Selecting polygons with points inside
        vor = []
        count = []
        for i, poly_i in enumerate(np.unique(map_)[1:]):
            vor.append(raw_surf[poly_i])
            bool_0 = map_==poly_i
            count.append(bool_0.sum())
            map_[bool_0] = i
                
        # Storing the information
        self.t2vor_map = map_
        self.vor_freq = np.array(count)
        self.vor_surf = pyny.Surface(vor)
        self.vor_centers = np.array([poly.get_centroid()[:2] 
                                     for poly in self.vor_surf])
        pyny.Polygon.verify = state