def MakePolygonNetworkFromWaterSeg(waterArr,minSplit=30,allValsByFrame=None,cVLS=None): '''Go all the way from raw 2d+t array to an pointList,indexes format''' if allValsByFrame==None: allValsByFrame = [ list(set(w.flat)) for w in waterArr ] if cVLS==None: cVLS = GetContourValuesLengthsAndSubContoursByFrame(waterArr,allValsByFrame) allPtsList = [] allSegsList = [] for t in range(len(cVLS)): contours = [i[2] for i in cVLS[t]] nc = len(contours) lc = [len(i) for i in contours] div = [i//30 for i in lc] sep = [ (lc[i] if div[i]==0 else lc[i]//div[i]) for i in range(nc)] #subPtsOld = [ ([] if div[i]==0 else contours[i][ ::(len(contours[i])//div[i]) ] ) # for i in range(nc) ] inds = [ ( [0,lc[i]-1] if (lc[i]-1 < 2*minSplit) else range(0,lc[i]-2,sep[i])+[lc[i]-1] ) for i in range(nc) ] subPts = [[ tuple(contours[i][j]) for j in inds[i] ] for i in range(nc) ] allPts = sorted(list(set(flatten( subPts )))) subPtsInds = [[ allPts.index(j) for j in i ] for i in subPts ] allSegsInds = flatten([ zip(i[:-1],i[1:]) for i in subPtsInds ]) allPtsList.append(allPts) allSegsList.append(allSegsInds) return allPtsList,allSegsList
def GetCVLSWithLimitedPointsBetweenNodes(cVLS,allValsByFrame,splitLength=1,fixedNumInteriorPoints=None,interpolate=True): '''Return a copy of the cVLS, but trim some points between triple junctions using one of several approaches.''' allValues = list(set(tuple(flatten(allValsByFrame)))) allPairs = sorted(list(set([tuple(c[0]) for cVLSByFrame in cVLS for c in cVLSByFrame]))) # Value pairs... if fixedNumInteriorPoints: numInteriorPoints = {p:fixedNumInteriorPoints for p in allPairs} else: minLength = {} for p in allPairs: #minLength is the number of points of the shortest subcountour between cells p[0] and p[1] from all frames minLength[p] = min([ len(c[2]) for cVLSByFrame in cVLS for c in cVLSByFrame if tuple(c[0])==p ]) # length of subcontour numInteriorPoints = {} for p in allPairs: numInteriorPoints[p] = minLength[p]//splitLength cVLS2 = deepcopy(cVLS) # otherwise, we'd also change the input argument cVLS in the outside world! limIntPtsFunc = limitInteriorPointsInterpolating if interpolate else limitInteriorPoints for cvlsByFrame in cVLS2: for c in cvlsByFrame: c[2] = limIntPtsFunc(c[2],numInteriorPoints[tuple(c[0])]) return cVLS2
def _nonefy_lines(line_list): '''Take a list of lines in [[[x1, y1], [x2, y2]], ...] format and convert them to a format suitable for fast plotting with dplot by placing all points in a single flattened list with None's separating disconnected values, aka: [ [x1,y1],[x2,y2], None ,... ]''' return flatten(intersperse(line_list, [[None, None]]))
def GetSubContoursByFrameWithLimitedPointsBetweenNodes(scListByFrame,allValsByFrame,splitLength=1,fixedNumInteriorPoints=None,interpolate=True): # IN PROGRESS... allValues = list(set(tuple(flatten(allValsByFrame)))) allPairs = sorted(list(set([tuple(sc.values) for scList in scListByFrame for sc in scList]))) # Value pairs... # Build the numInteriorPointsDict: if fixedNumInteriorPoints: numInteriorPointsDict = {p:fixedNumInteriorPoints for p in allPairs} else: minLength = {} for p in allPairs: #minLength is the number of points of the shortest subcountour between cells p[0] and p[1] from all frames minLength[p] = min([ len(sc.adjusted_length) for scList in scListByFrame for sc in scList if tuple(sc.points)==p ]) # length of subcontour numInteriorPointsDict = { p:(minLength[p]//splitLength) for p in allPairs } scListByFrameNew = deepcopy(scListByFrame) # otherwise, we'd also change the input argument scListByFrame in the outside world! for scList in scListByFrameNew: LimitPointsBetweenSubContourNodes(scList,numInteriorPointsDict,interpolate=interpolate) return scListByFrameNew