@@ -579,26 +579,25 @@ def edge_node_array(self) -> np.ndarray:
579579 return self ._to_index_array (
580580 self .edge_node_connectivity , self .edge_dimension )
581581
582- logger .info ("Building edge_node_array" )
583- with utils .PerfTimer () as timer :
584- # Each edge is composed of two nodes. Each edge may be named twice,
585- # once for each face. To de-duplicate this, edges are built up using
586- # this dict-of-sets, where the dict index is the node with the
587- # lower index, and the set is the node indices of the other end.
588- low_highs : Dict [int , Set [int ]] = defaultdict (set )
589-
590- for face_index , node_pairs in self ._face_and_node_pair_iter ():
591- for pair in node_pairs :
592- low , high = sorted (pair )
593- low_highs [low ].add (high )
594- edge_node = np .array ([
595- [low , high ]
596- for low , highs in low_highs .items ()
597- for high in highs
598- ], dtype = self .sensible_dtype )
599- logger .debug ("Built edge_node_array in %f seconds" , timer .elapsed )
600-
601- return edge_node
582+ return self .make_edge_node_array ()
583+
584+ @utils .timed_func
585+ def make_edge_node_array (self ) -> np .ndarray :
586+ # Each edge is composed of two nodes. Each edge may be named twice,
587+ # once for each face. To de-duplicate this, edges are built up using
588+ # this dict-of-sets, where the dict index is the node with the
589+ # lower index, and the set is the node indices of the other end.
590+ low_highs : Dict [int , Set [int ]] = defaultdict (set )
591+
592+ for face_index , node_pairs in self ._face_and_node_pair_iter ():
593+ for pair in node_pairs :
594+ low , high = sorted (pair )
595+ low_highs [low ].add (high )
596+ return np .array ([
597+ [low , high ]
598+ for low , highs in low_highs .items ()
599+ for high in highs
600+ ], dtype = self .sensible_dtype )
602601
603602 @cached_property
604603 def has_valid_edge_face_connectivity (self ) -> bool :
@@ -650,26 +649,22 @@ def edge_face_array(self) -> np.ndarray:
650649 return self ._to_index_array (
651650 self .edge_face_connectivity , self .edge_dimension )
652651
653- # Access these outside of the timer below
654- fill_value = self .sensible_fill_value
655- face_edge = self .face_edge_array
652+ return self .make_edge_face_array ()
656653
657- # Build an edge_face_connectivity matrix
658- logger .info ("Building edge_face_array" )
659- with utils .PerfTimer () as timer :
660- # The edge_face connectivity matrix
661- shape = (self .edge_count , 2 )
662- filled = np .full (shape , fill_value , dtype = self .sensible_dtype )
663- edge_face : np .ndarray = np .ma .masked_array (filled , mask = True )
654+ @utils .timed_func
655+ def make_edge_face_array (self ) -> np .ndarray :
656+ # The edge_face connectivity matrix
657+ shape = (self .edge_count , 2 )
658+ filled = np .full (shape , self .sensible_fill_value , dtype = self .sensible_dtype )
659+ edge_face : np .ndarray = np .ma .masked_array (filled , mask = True )
664660
665- # The number of faces already seen for this edge
666- edge_face_count = np .zeros (self .edge_count , dtype = self .sensible_dtype )
661+ # The number of faces already seen for this edge
662+ edge_face_count = np .zeros (self .edge_count , dtype = self .sensible_dtype )
667663
668- for face_index , edge_indices in enumerate (face_edge ):
669- for edge_index in edge_indices .compressed ():
670- edge_face [edge_index , edge_face_count [edge_index ]] = face_index
671- edge_face_count [edge_index ] += 1
672- logger .debug ("Built edge_face_array in %f seconds" , timer .elapsed )
664+ for face_index , edge_indices in enumerate (self .face_edge_array ):
665+ for edge_index in edge_indices .compressed ():
666+ edge_face [edge_index , edge_face_count [edge_index ]] = face_index
667+ edge_face_count [edge_index ] += 1
673668
674669 return edge_face
675670
@@ -763,27 +758,24 @@ def face_edge_array(self) -> np.ndarray:
763758 return self ._to_index_array (
764759 self .face_edge_connectivity , self .face_dimension )
765760
766- # Access these outside of the timer below
767- fill_value = self .sensible_fill_value
768- edge_node = self .edge_node_array
761+ return self .make_face_edge_array ()
769762
763+ @utils .timed_func
764+ def make_face_edge_array (self ) -> np .ndarray :
770765 # Build a face_edge_connectivity matrix
771- logger .info ("Building face_edge_array" )
772- with utils .PerfTimer () as timer :
773- shape = (self .face_count , self .max_node_count )
774- filled = np .full (shape , fill_value , dtype = self .sensible_dtype )
775- face_edge : np .ndarray = np .ma .masked_array (filled , mask = True )
776-
777- node_pair_to_edge_index = {
778- frozenset (edge ): edge_index
779- for edge_index , edge in enumerate (edge_node )
780- }
781-
782- for face_index , node_pairs in self ._face_and_node_pair_iter ():
783- for column , node_pair in enumerate (node_pairs ):
784- edge_index = node_pair_to_edge_index [frozenset (node_pair )]
785- face_edge [face_index , column ] = edge_index
786- logger .debug ("Built face_edge_array in %f seconds" , timer .elapsed )
766+ shape = (self .face_count , self .max_node_count )
767+ filled = np .full (shape , self .sensible_fill_value , dtype = self .sensible_dtype )
768+ face_edge : np .ndarray = np .ma .masked_array (filled , mask = True )
769+
770+ node_pair_to_edge_index = {
771+ frozenset (edge ): edge_index
772+ for edge_index , edge in enumerate (self .edge_node_array )
773+ }
774+
775+ for face_index , node_pairs in self ._face_and_node_pair_iter ():
776+ for column , node_pair in enumerate (node_pairs ):
777+ edge_index = node_pair_to_edge_index [frozenset (node_pair )]
778+ face_edge [face_index , column ] = edge_index
787779
788780 return face_edge
789781
@@ -834,27 +826,23 @@ def face_face_array(self) -> np.ndarray:
834826 return self ._to_index_array (
835827 self .face_face_connectivity , self .face_dimension )
836828
837- # Access these outside of the timer below
838- fill_value = self .sensible_fill_value
839- edge_face = self .edge_face_array
829+ return self .make_face_face_array ()
840830
831+ def make_face_face_array (self ) -> np .ndarray :
841832 # Build a face_face_connectivity matrix
842- logger .info ("Building face_face_array" )
843- with utils .PerfTimer () as timer :
844- face_count = np .zeros (self .face_count , dtype = self .sensible_dtype )
845- shape = (self .face_count , self .max_node_count )
846- filled = np .full (shape , fill_value , dtype = self .sensible_dtype )
847- face_face : np .ndarray = np .ma .masked_array (filled , mask = True )
848-
849- for edge_index , face_indices in enumerate (edge_face ):
850- if np .any (np .ma .getmask (face_indices )):
851- continue
852- left , right = face_indices
853- face_face [left , face_count [left ]] = right
854- face_face [right , face_count [right ]] = left
855- face_count [left ] += 1
856- face_count [right ] += 1
857- logger .debug ("Built face_face_array in %f seconds" , timer .elapsed )
833+ face_count = np .zeros (self .face_count , dtype = self .sensible_dtype )
834+ shape = (self .face_count , self .max_node_count )
835+ filled = np .full (shape , self .sensible_fill_value , dtype = self .sensible_dtype )
836+ face_face : np .ndarray = np .ma .masked_array (filled , mask = True )
837+
838+ for edge_index , face_indices in enumerate (self .edge_face_array ):
839+ if np .any (np .ma .getmask (face_indices )):
840+ continue
841+ left , right = face_indices
842+ face_face [left , face_count [left ]] = right
843+ face_face [right , face_count [right ]] = left
844+ face_count [left ] += 1
845+ face_count [right ] += 1
858846
859847 return face_face
860848
@@ -1083,6 +1071,7 @@ def get_grid_kind_and_size(
10831071 raise ValueError ("Data array did not have any face, edge, or node dimension" )
10841072
10851073 @cached_property
1074+ @utils .timed_func
10861075 def polygons (self ) -> np .ndarray :
10871076 """Generate list of Polygons"""
10881077 # X,Y coords of each node
0 commit comments