@@ -2726,7 +2726,7 @@ def renumber_cells_ordering(self):
27262726 Nactive = sum (~ self .cells ['deleted' ])
27272727 return np .argsort ( self .cells ['deleted' ],kind = 'mergesort' )[:Nactive ]
27282728
2729- def renumber_cells (self ,order = None ):
2729+ def renumber_cells (self ,order = None , min_edge_mark = - 2000 ):
27302730 """
27312731 Renumber cell indices, dropping deleted cells.
27322732 Update edges['cells'], preserving negative values (e.g.
@@ -2735,12 +2735,16 @@ def renumber_cells(self,order=None):
27352735 to get new cell indices. Cell map is actually slightly
27362736 larger than the number of old cells, to accomodate negative
27372737 indexing. For example, cell_map[-2]=-2
2738+ min_edge_mark: limits negative indexing, in case int.minValue
2739+ or something absurd comes in.
27382740 """
27392741 if order is None :
27402742 csort = self .renumber_cells_ordering ()
27412743 else :
2742- csort = order
2743- Nneg = - min (- 1 ,self .edges ['cells' ].min ())
2744+ csort = order
2745+
2746+ min_mark = self .edges ['cells' ].min ().clip (min_edge_mark ,- 1 )
2747+ Nneg = - min_mark
27442748 cell_map = np .zeros (self .Ncells ()+ Nneg ,np .int32 ) # do this before truncating cells
27452749 self .cells = self .cells [csort ]
27462750
@@ -2751,14 +2755,14 @@ def renumber_cells(self,order=None):
27512755 # or cell_map[csort[a]] = a
27522756 # for all a, so
27532757 # cell_map[csort[arange(Ncells)]] = arange(Ncells)
2754- cell_map [:] = - 999 # these should only remain for deleted cells, and never show up in the output
2758+ cell_map [:] = min_edge_mark # these should only remain for deleted cells, and never show up in the output
27552759 cell_map [:- Nneg ][csort ] = np .arange (self .Ncells ())
27562760 # cell_map[-1] = -1 # land edges map cell -1 to -1
27572761 # allow broader range of negatives:
27582762 # map cell -1 to -1, -2 to -2, etc.
27592763 cell_map [- Nneg :] = np .arange (- Nneg ,0 )
27602764
2761- self .edges ['cells' ] = cell_map [self .edges ['cells' ]]
2765+ self .edges ['cells' ] = cell_map [self .edges ['cells' ]. clip ( min_mark , None ) ]
27622766 self ._cell_center_index = None
27632767 return cell_map
27642768
@@ -3566,7 +3570,7 @@ def cells_centroid_shapely(self,ids=None):
35663570
35673571 for ci ,c in enumerate (ids ):
35683572 if not self .cells ['deleted' ][c ]:
3569- centroids [ci ]= np .array (self .cell_polygon (c ).centroid )
3573+ centroids [ci ]= np .array (self .cell_polygon (c ).centroid . coords )
35703574 return centroids
35713575
35723576 def cells_centroid_py (self ,ids = None ):
0 commit comments