def fromVolumeFile(filename, options): img = VolumeImage(filename) morse = VectorField(img, threshold = options.threshold, filename = options.field) dim = lambda v: img.cellDimension(v) val = lambda v: img.scalarForCell(v) if v else infinity weights = dict((tuple(v), x) for v, x in morse.weights()) return tuple((val(v), val(w), dim(v), v, w, weights.get(tuple(v), 0)) for v, w in morse.birthsAndDeaths())
def fromVolumeFile(filename, options): img = VolumeImage(filename) morse = VectorField(img, threshold=options.threshold, filename=options.field) dim = lambda v: img.cellDimension(v) val = lambda v: img.scalarForCell(v) if v else infinity weights = dict((tuple(v), x) for v, x in morse.weights()) return tuple((val(v), val(w), dim(v), v, w, weights.get(tuple(v), 0)) for v, w in morse.birthsAndDeaths())
def getProcessedMorseData(infile, threshold): if infile.endswith('.nc'): img = VolumeImage(infile) morse = VectorField(img, threshold) critical = list(morse.criticalCells()) data = { 'scalars': img.data(), 'basins': morse.basinMap(), 'watersheds': morse.watersheds(), 'skeleton': morse.skeleton(), 'paths': morse.paths(), 'critical': critical, 'critval': map(img.scalarForCell, critical), 'critdim': map(img.cellDimension, critical) } outfile = "%s.npz" % os.path.splitext(os.path.basename(infile))[0] np.savez(outfile, **data) else: data = np.load(infile) return data
def getProcessedMorseData(infile, threshold): if infile.endswith('.nc'): img = VolumeImage(infile) morse = VectorField(img, threshold) critical = list(morse.criticalCells()) data = { 'scalars' : img.data(), 'basins' : morse.basinMap(), 'watersheds': morse.watersheds(), 'skeleton' : morse.skeleton(), 'paths' : morse.paths(), 'critical' : critical, 'critval' : map(img.scalarForCell, critical), 'critdim' : map(img.cellDimension, critical) } outfile = "%s.npz" % os.path.splitext(os.path.basename(infile))[0] np.savez(outfile, **data) else: data = np.load(infile) return data
parser.error("at least one argument needed; -h shows list of options") return options, args if __name__ == '__main__': import sys, os.path from MorseAnalysis import VolumeImage, VectorField (options, args) = parse_options() infile = args[0] if infile.endswith('.nc'): img = VolumeImage(infile) morse = VectorField(img, threshold=options.threshold, filename=options.field) critical = list(morse.criticalCells()) data = { 'scalars': img.data(), 'directions': morse.data(), 'basins': morse.basinMap(), 'watersheds': morse.watersheds(), 'skeleton': morse.skeleton(), 'paths': morse.paths(), 'critical': critical, 'critval': map(img.scalarForCell, critical), 'critdim': map(img.cellDimension, critical) } else:
parser.error("at least one argument needed; -h shows list of options") return options, args if __name__ == '__main__': import sys, os.path from MorseAnalysis import VolumeImage, VectorField (options, args) = parse_options() infile = args[0] if infile.endswith('.nc'): img = VolumeImage(infile) morse = VectorField(img, threshold = options.threshold, filename = options.field) critical = list(morse.criticalCells()) data = { 'scalars' : img.data(), 'directions': morse.data(), 'basins' : morse.basinMap(), 'watersheds': morse.watersheds(), 'skeleton' : morse.skeleton(), 'paths' : morse.paths(), 'critical' : critical, 'critval' : map(img.scalarForCell, critical), 'critdim' : map(img.cellDimension, critical) } else: