def getVesselTypes(vessel_groups): veins = [] arteries = [] capillaries = [] if ('edges' in vessel_groups.keys()): # in fact it is only one group! g = vessel_groups flags = np.array(_ku.read_vessels_from_hdf(g, ['flags'])[1]) circulated = np.bitwise_and(flags, _ku.CIRCULATED) circulated_indeces = np.nonzero(circulated) veins = np.bitwise_and(flags, _ku.VEIN) veins = veins[circulated_indeces] arteries = np.bitwise_and(flags, _ku.ARTERY) arteries = arteries[circulated_indeces] capillaries = np.bitwise_and(flags, _ku.CAPILLARY) capillaries = capillaries[circulated_indeces] veins = np.nonzero(veins) arteries = np.nonzero(arteries) capillaries = np.nonzero(capillaries) else: for g in vessel_groups: flags = _ku.read_vessels_from_hdf(g, ['flags']) goods = np.sum(np.bitwise_and(flags[1], _ku.VEIN)) veins.append(goods) goods = np.sum(np.bitwise_and(flags[1], _ku.ARTERY)) arteries.append(goods) goods = np.sum(np.bitwise_and(flags[1], _ku.CAPILLARY)) capillaries.append(goods) return veins, arteries, capillaries
def renderSliceWithDistribution(vesselgroup, imagefn, options): vessel_ld = krebsutils.read_lattice_data_from_hdf( vesselgroup['vessels/lattice']) vessel_graph = krebsutils.read_vessels_from_hdf( vesselgroup['vessels'], ['position', 'flags', 'radius', 'pressure', 'shearforce', 'nodeflags'], return_graph=True) vessel_graph.edges['radius'] *= 4. #kwargs = deepcopy(kwargs) wbbox = vessel_ld.worldBox trafo = calc_centering_normalization_trafo(wbbox) height = (wbbox[5] - wbbox[4]) * trafo.w print('Vessel BBox:' + str(vessel_ld.worldBox)) print(vessel_ld) print('Post Trafo Ld BBox:' + str(transform_ld(trafo, vessel_ld).worldBox)) hasGfField = 'field_ld' in vesselgroup and vessel_ld.shape[2] == 1 #hasGfField = False if hasGfField: volume_ld = krebsutils.read_lattice_data_from_hdf( vesselgroup['field_ld']) print('Volume BBox:' + str(volume_ld.worldBox)) print(volume_ld) volumedata = np.asarray(vesselgroup['gf']) #print volumedata.shape, volumedata.min(), volumedata.max() volume_ld = transform_ld(trafo, volume_ld) print('Post Trafo Volume BBox:' + str(volume_ld.worldBox)) print('volume data bounds:' + str(volumedata.min()), str(volumedata.max())) colorfactory(vessel_graph) with EasyPovRayRender(**options) as epv: epv.setBackground(options.pop('background', 0.0)) cam_fov = 60. cam_distance_factor = ComputeCameraDistanceFactor( cam_fov, options['res'], wbbox) epv.setCamera((0, 0, cam_distance_factor * 1.05), lookat=(0, 0, 0), fov=cam_fov, up='y') epv.addLight(10. * Vec3(1, 0.5, 2), 1.2) cm = matplotlib.cm.ScalarMappable(cmap=cm_gf) cm.set_clim(-0.01, 1.01) pvcm = matplotlibColormapToPovray('DATACOLORMAP', cm) epv.declareColorMap(pvcm) if hasGfField: volumedata = epv.declareVolumeData(volumedata, volume_ld.worldBox, volume_ld) epv.addVolumeDataSlice(volumedata, (0, 0, 0), (0, 0, 1.), pvcm) addVesselTree(epv, vessel_graph, trafo=trafo, **options) imagefn = epv.render(imagefn)
def render_different_data_types(vesselgroup, options): filenamepostfix = '' labels = { 'flow': '$log_{10}$ Flow Rate', 'shearforce': '$log_{10}$ Shear Force', 'hematocrit': 'Hematocrit', 'pressure': 'Blood Pressure $kPa$', 'S_tot': 'Adaption Signal', 'conductivitySignal': 'Conductivity Signal', 'metabolicSignal': 'Metabolic Signal', 'radius': 'Vesselradius $\mu$m', } graph = krebsutils.read_vessels_from_hdf( vesselgroup, ['position', 'flags', 'radius', 'nodeflags'] + options.datalist, return_graph=True) #nodeflags not good for apj.h5 #numpy int64 bug! #graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'flags', 'radius' ] + options.datalist, return_graph=True) #if vesselgroup.attrs.get('CLASS') == 'GRAPH': # vessel_ld = krebsutils.read_lattice_data_from_hdf(vesselgroup['lattice']) # options.wbbox = vessel_ld.GetWorldBox() #if vesselgroup.attrs.get('CLASS') == 'REALWORLD': # options.wbbox = np.max(np.asarray(vesselgroup['nodes/world_pos']),0) options.wbbox = ComputeBoundingBox(vesselgroup, graph) if options.filteruncirculated: graph = graph.get_filtered(edge_indices=myutils.bbitwise_and( graph['flags'], krebsutils.CIRCULATED)) if options.filterradiushighpass > 0: graph = graph.get_filtered( edge_indices=graph['radius'] > filterradiushighpass) filenamepostfix = '_rhp' if options.filterradiuslowpass > 0: print("lowpass filter activated:") graph = graph.get_filtered( edge_indices=graph['radius'] < filterradiuslowpass) filenamepostfix = '_rlp' for data_name in options.datalist: if 'colorfactory' in options: colors_factory = options.colorfactory colors_factory(graph) cm, (datamin, datamax) = make_any_color_arrays(graph, data_name, options) fn = vesselgroup.file.filename options.imageFileName = splitext( basename(fn) )[0] + '_' + myutils.sanitize_posixpath(vesselgroup.name).replace( '/', '-') + '_' + data_name + filenamepostfix + '.' + options.format print(options.imageFileName) with EasyPovRayRender(options) as epv: CreateScene2(vesselgroup, epv, graph, options) if options.noOverlay: epv.render(imagefn) else: RenderImageWithOverlay(epv, cm, labels[data_name], options)
def CalcPhiVessels(dataman, vesselgroup, ld, scaling, samples_per_cell = 5): '''samples per cell mean the lattice grid cell, the total number of samples for a vessel is determined by the ratio of its volume to the volume of a grid cell times the samples_per_cell''' graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'radius', 'flags'] , return_graph=True) mask=myutils.bbitwise_and(graph['flags'], krebsutils.CIRCULATED) print(mask.shape) graph = graph.get_filtered(edge_indices = mask) print('vessels filtered before fraction calculation!') theRadii = np.asarray(graph['radius'])*scaling if(theRadii.ndim>1): theRadii = theRadii[:,0] if theRadii.dtype == np.float32: thePositions = np.asarray(graph['position'],dtype=np.float32)*scaling else: thePositions = np.asarray(graph['position'])*scaling theEdgeList = np.asarray(graph.edgelist) if sys.flags.debug: print(thePositions) print(thePositions.shape) print(type(thePositions)) print("thepos: %s" % thePositions.dtype) print(theEdgeList) print(theEdgeList.shape) print(type(theEdgeList)) print("theEd: %s" % theEdgeList.dtype) print(theRadii) print(theRadii.shape) print(type(theRadii)) print('theRadii: %s' % theRadii.dtype) print(ld) print(type(ld)) print(ld.GetScale()) print(type(samples_per_cell)) vessel_fraction = krebsutils.make_vessel_volume_fraction_field(thePositions,theEdgeList,theRadii,ld,samples_per_cell) return vessel_fraction
def obtain_data(self, dataman, dataname, *args): if dataname == 'vessel_graph': vesselgroup, properties = args graph = krebsutils.read_vessels_from_hdf(vesselgroup, properties, return_graph=True) for prop in properties: data, association = self.get_property(dataman, vesselgroup, 'auto', prop) getattr(graph, association)[prop] = data return graph elif dataname == 'vessel_graph_property': res, a = self.get_property(dataman, *args) return res, a elif dataname == 'vessel_system_length': group, = args def read(gmeasure, groupname): return np.asscalar(gmeasure[groupname][...]) def write(gmeasure, groupname): l = np.sum(dataman.obtain_data('vessel_graph_property', group, 'edges', 'length')[0]) gmeasure.create_dataset(groupname, data = l) return myutils.hdf_data_caching(read, write, group, ('vessel_system_length',), (1,))
def renderScene(vesselgroup, imagefn, **kwargs): vess_ldgroup = vesselgroup['lattice'] graph = krebsutils.read_vessels_from_hdf( vesselgroup, ['position', 'flags', 'radius', 'pressure'], return_graph=True) colorfactory = kwargs.pop('colorfactory', make_pressure_color_arrays) colorfactory(graph) wbbox = ComputeBoundingBox(vesselgroup, graph) trafo = calc_centering_normalization_trafo(wbbox) zsize = (wbbox[5] - wbbox[4]) with EasyPovRayRender(**kwargs) as epv: epv.setBackground(kwargs.pop('background', 0.0)) cam = kwargs.pop( 'cam', 'topdown' ) # this stuff is copy pasted everywhere, should be refactored in a extra function if cam in ('topdown', 'topdown_slice'): cam_fov = 60. cam_distance_factor = ComputeCameraDistanceFactor( cam_fov, kwargs['res'], wbbox) epv.addLight(10 * Vec3(1.7, 1.2, 2), 1., area=(4, 4, 3, 3), jitter=True) if cam == 'topdown_slice': kwargs.update(vessel_clip=('zslice', -201 * trafo.w, 201 * trafo.w), tumor_clip=('zslice', -100 * trafo.w, 100 * trafo.w)) epv.setCamera( (0, 0, cam_distance_factor * 0.5 * (200. * trafo.w + 2.)), (0, 0, 0), cam_fov, up='y') else: epv.setCamera( (0, 0, cam_distance_factor * 0.5 * (zsize * trafo.w + 2.)), (0, 0, 0), cam_fov, up='y') else: basepos = np.asarray((0.6, 0.7, 0.7)) * (1. / 1.4) epv.setCamera(basepos, (0, 0, 0), 90, up=(0, 0, 1)) num_samples_large_light = 10 num_samples_small_light = 3 epv.addLight(10 * Vec3(0.7, 1., 0.9), 0.8, area=(1., 1., num_samples_small_light, num_samples_small_light), jitter=True) epv.addLight(10 * Vec3(0.5, 0.5, 0.5), 0.6, area=(5., 5., num_samples_large_light, num_samples_large_light), jitter=True) kwargs.update(vessel_clip=('pie', 0.), tumor_clip=('pie', -20 * trafo.w)) addVesselTree(epv, graph, trafo=trafo, **kwargs) epv.render(imagefn)
for fn in filenames: fn, _ = myutils.splitH5PathsFromFilename(fn) f = h5py.File(fn, 'r') dirs = myutils.walkh5(f['/'], pattern) if goodArguments.outfn: print("you chose: %s as outfilename" % goodArguments.outfn) goodArguments.outfn = goodArguments.outfn + '_%s.vtk' else: goodArguments.outfn = outfn = "%s-%%s.vtk" % (os.path.splitext(os.path.basename(fn))[0]) for d in dirs: if 'vessels' in d and 'po2' not in d: vesselgroup = f[join('/',d)]['.'] new = False if new: graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'radius', 'hematocrit', 'pressure', 'flow', 'flags','shearforce','nodeflags','edge_boundary'] + datalist, return_graph=True) else: graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'radius', 'hematocrit', 'pressure', 'flow', 'flags','shearforce'] + datalist, return_graph=True) if goodArguments.filteruncirculated: graph = graph.get_filtered(edge_indices = myutils.bbitwise_and(graph['flags'], krebsutils.CIRCULATED)) writeVessels_(graph, goodArguments) elif 'out' in d: vesselgroup = f[join('/',d+'/vessels')]['.'] new = False if new: graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'radius', 'hematocrit', 'pressure', 'flow', 'flags','shearforce','nodeflags','edge_boundary'] + datalist, return_graph=True) else: graph = krebsutils.read_vessels_from_hdf(vesselgroup, ['position', 'radius', 'hematocrit', 'pressure', 'flow', 'flags','shearforce'] + datalist, return_graph=True) if goodArguments.filteruncirculated: graph = graph.get_filtered(edge_indices = myutils.bbitwise_and(graph['flags'], krebsutils.CIRCULATED))
def plot_cells(goodArguments): with h5py.File(goodArguments.vbl_simulation_output_filename, 'r') as f: h5_cells_grp = f[goodArguments.output_grp_name + "/cells"] pos = h5_cells_grp['cell_center_pos'] pos = np.asarray(pos) rad = h5_cells_grp['cell_radii'] rad = np.asarray(rad) o2 = h5_cells_grp['o2'] o2 = np.asarray(o2) x = pos[:,0] y = pos[:,1] z = pos[:,2] s = rad[:,0] pts = mlab.quiver3d(x,y,z, s,s,s, scalars=o2, colormap="blue-red", scale_factor=2, mode='sphere') pts.glyph.color_mode = 'color_by_scalar' pts.glyph.glyph_source.glyph_source.center = [0,0,0] ''' CELLS READY ''' #this ready the graph info from hdf with h5py.File(goodArguments.vbl_simulation_output_filename, 'r') as f: h5_vessel_grp = f[goodArguments.output_grp_name + "/vessels"] graph = ku.read_vessels_from_hdf(h5_vessel_grp, ['position', 'flags', 'radius', 'nodeflags'], return_graph=True) node_pos=np.asarray(graph['position']) myEdges = graph.edgelist ''' create radii at the vertices ''' num_verts = len(node_pos) node_rad = np.zeros(num_verts) node_n = np.zeros(num_verts) for r,(a,b) in itertools.izip(np.asarray(graph['radius']),np.asarray(myEdges)): # itertools, or it will blow up in yr face cuz ultra slow python lists and shit will be created node_rad[a] += r node_rad[b] += r node_n[a] += 1. node_n[b] += 1. node_rad /= np.maximum(1, node_n) ''' create points data set, similar to vtk points data set we take the radius as associated scalar ''' pts = mlab.points3d(np.asarray(node_pos[:,0]), np.asarray(node_pos[:,1]), np.asarray(node_pos[:,2]), node_rad, scale_factor=1.0) #create lines pts.mlab_source.dataset.lines = np.array(graph.edgelist) #same as in the constructor! could be changed here pts.mlab_source.scalars = node_rad #set up a tube pipeline tube = mlab.pipeline.tube(pts) #I use this construction to the the possible options if 0: alloptions = dir(tube.filter) for option in alloptions: print(option) #tube.filter.set_input_data=node_rad #tube.filter.radius= 42 #tube.filter.radius_factor = 1. tube.filter.vary_radius = 'vary_radius_by_absolute_scalar' ''' colors ''' #mlab.pipeline.surface(tube, color=(0.8, 0.8, 0)) mlab.pipeline.surface(tube, colormap="blue-red") mlab.colorbar()
def sample_line_general(quantity_name, group_name, starting_point, end_point): print('sample_line_general for points:') print('starting point:') print(starting_point) print('end_point:') print(end_point) print('quantity_name: %s \t group_name: %s' % (quantity_name, group_name)) print(goodArguments) with h5py.File(goodArguments.vbl_simulation_file_name, 'r') as f: datalist = map(lambda s: s, map(str.strip, goodArguments.datalist.split(','))) vesselgroup = f[os.path.join(group_name, 'vessels')] graph = krebsutils.read_vessels_from_hdf( vesselgroup, [ 'position', 'radius', 'hematocrit', 'pressure', 'flow', 'flags', 'shearforce' ] + datalist, return_graph=True) cell_center_pos = np.asarray(f[os.path.join(group_name, 'cells/cell_center_pos')]) cell_o2_mass = np.asarray(f[os.path.join(group_name, 'cells/o2')]) cell_radii = np.asarray(f[os.path.join(group_name, 'cells/cell_radii')]) cell_pH = np.asarray(f[os.path.join(group_name, 'cells/pH_ex')]) index_of_nearest_vessel = np.asarray(f[os.path.join( group_name, 'cells/index_of_nearest_vessel')]) index_of_nearest_vessel = index_of_nearest_vessel[:, 0] distance_to_nearest_vessel = np.asarray(f[os.path.join( group_name, 'cells/distance_to_nearest_vessel')]) distance_to_nearest_vessel = distance_to_nearest_vessel[:, 0] print('****** important points *************') a = graph.edgelist[521] print('a: %s pos_a: %s pos_b: %s' % (a, graph['position'][a[0]], graph['position'][a[1]])) b = graph.edgelist[1244] print('b: %s pos_a: %s pos_b: %s' % (b, graph['position'][b[0]], graph['position'][b[1]])) print('cell_o2_mass shape:') cell_o2_mass = cell_o2_mass[:, 0] print(cell_o2_mass.shape) print('cell_radii_shape:') cell_radii = cell_radii[:, 0] print(cell_radii.shape) # pg/ mum^3 cell_o2_concentration = cell_o2_mass / (4 / float(3) * np.pi * np.power(cell_radii, 3)) #cell_o2_concentration = cell_o2_mass volume_o2_ml = cell_o2_concentration / (1.429 * 1e9) #volume_o2_ml = cell_o2_mass/1.429 ''' o2 density 1.429 g/L --> 1.429*10^9 pg/ml 1cm^3 = 10^12 (mum^3) ''' solubility = 3.1e-3 #ml O2/cm^3 mmHg #solubility = 2.8e-3 #ml O2/cm^3 mmHg #solubility = 1.1e-4 #ml O2/cm^3 mmHg solubility = solubility * 1e-12 #ml O2/mum^3 mmHg #volume_density = 1.429e9 #pg/ml #x = cell_o2_concentration/volume_density # ml / mum^3 #cell_po2 = x/solubility if quantity_name == 'o2': quantity_to_average = volume_o2_ml / solubility if quantity_name == 'pH_ex': quantity_to_average = cell_pH #quantity_to_average = cell_o2_mass/solubility #quantity_to_average = cell_po2 #quantity_to_average = cell_o2_concentration #quantity_to_average = cell_o2_mass print('cell_center_pos') if scoop.IS_RUNNING: if not np.asarray(scoop.shared.getConst('cell_center_pos_')).any(): scoop.shared.setConst(cell_center_pos_=cell_center_pos) print(goodArguments.vbl_simulation_file_name) print(goodArguments.grp_pattern) print("sample along line from:") print("%s to %s" % (starting_point, end_point)) sample_pos, distances = get_sample_points_along_line( starting_point, end_point, metadata_dict['number_of_sampling_points']) box_length_of_max_norm = distances[1] * 0.5 print(distances) if scoop.IS_RUNNING: if not scoop.shared.getConst('box_length_of_max_norm'): scoop.shared.setConst( box_length_of_max_norm=box_length_of_max_norm) print('box_length_of_max_norm %f' % box_length_of_max_norm) #cell_center_pos = np.asarray(f[os.path.join(goodArguments.grp_pattern, 'cells/cell_center_pos')]) #print('cell_center_pos') #scoop.shared.setConst(cell_center_pos_=cell_center_pos) lists = list(scoop.futures.map(is_index_good, sample_pos)) for (aList, aSamplePos) in zip(lists, sample_pos): print('for pos: %s found %i points in eps range' % (aSamplePos, len(aList))) ''' average ''' average_value = [] errors = [] for (aList, aSamplePos) in zip(lists, sample_pos): this_avg = np.average(quantity_to_average[aList]) average_value.append(this_avg) #errors.append(np.sqrt(1/float(len(aList)))*this_avg) errors.append(np.std(quantity_to_average[aList])) print('finished sample_line_general') return (np.asarray(average_value), np.asarray(errors), np.asarray(distances))
def process(grp): veins, arteries, capillaries = getVesselTypes(grp) edges, radii = krebsutils.read_vessels_from_hdf(grp,['radius']) return radii[capillaries]
def read_vessels_data(vesselgroup, datanames): return krebsutils.read_vessels_from_hdf(vesselgroup, datanames, return_graph = True, return_not_found = False)
def process(grp): veins, arteries, capillaries = getVesselTypes(grp) edges, flows = krebsutils.read_vessels_from_hdf(grp,['flow']) return flows[capillaries]
def renderScene(vesselgroup, tumorgroup, imagefn, options): if vesselgroup is not None: vgrp = vesselgroup['lattice'] wbbox = krebsutils.read_lattice_data_from_hdf_by_filename( str(vgrp.file.filename), str(vgrp.name)).worldBox else: wbbox = krebsutils.read_lattice_data_from_hdf( tumorgroup.file['field_ld']).worldBox trafo = calc_centering_normalization_trafo(wbbox) zsize = (wbbox[5] - wbbox[4]) vessel_ld = krebsutils.read_lattice_data_from_hdf_by_filename( str(vesselgroup.file.filename), str(vesselgroup.name) + '/lattice') options.wbbox = vessel_ld.GetWorldBox() with EasyPovRayRender(options) as epv: epv.setBackground(options.background) cam = options.cam if cam in ('topdown', 'topdown_slice'): cam_fov = 60. cam_distance_factor = options.cam_distance_multiplier * ComputeCameraDistanceFactor( cam_fov, options.res, wbbox) epv.addLight(10 * Vec3(1.7, 1.2, 2), 1., area=(4, 4, 3, 3), jitter=True) if cam == 'topdown_slice': imagefn += '_slice' options.vessel_clip = ('zslice', -201 * trafo.w, 201 * trafo.w) options.tumor_clip = ('zslice', -100 * trafo.w, 100 * trafo.w) epv.setCamera( (0, 0, cam_distance_factor * 0.5 * (200. * trafo.w + 2.)), (0, 0, 0), cam_fov, up='y') else: imagefn += '_top' epv.setCamera( (0, 0, cam_distance_factor * 0.5 * (zsize * trafo.w + 2.)), (0, 0, 0), cam_fov, up='y') else: imagefn += '_pie' cam_fov = 60. basepos = options.cam_distance_multiplier * np.asarray( (0.6, 0.7, 0.55)) * (1. / 1.4) * math.tan( math.pi * 0.25) / math.tan(math.pi / 180. / 2. * cam_fov) epv.setCamera(basepos, (0, 0, 0), cam_fov, up=(0, 0, 1)) num_samples_large_light = 4 num_samples_small_light = 2 epv.addLight(10 * Vec3(0.7, 1., 0.9), 0.8, area=(1., 1., num_samples_small_light, num_samples_small_light), jitter=True) epv.addLight(10 * Vec3(0.5, 0.5, 0.5), 0.6, area=(5., 5., num_samples_large_light, num_samples_large_light), jitter=True) options.vessel_clip = ('pie', 0.) options.tumor_clip = ('pie', -50 * trafo.w) if vesselgroup is not None: graph = krebsutils.read_vessels_from_hdf( vesselgroup, ['position', 'flags', 'radius', 'pressure'], return_graph=True) if options.filteruncirculated: graph = graph.get_filtered(edge_indices=myutils.bbitwise_and( graph['flags'], krebsutils.CIRCULATED)) if 'colorfactory' in options: print('colorfactory is in options') colorfactory = options.colorfactory else: print('colorfactory not in options') colorfactory = make_pressure_color_arrays colorfactory(graph) #addVesselTree(epv, graph, trafo, vesselgroup = vesselgroup, options) epv.addVesselTree2(epv, graph, trafo, options) if tumorgroup is not None and 'conc' in tumorgroup: addBulkTissueTumor(epv, tumorgroup, trafo, options) if (tumorgroup is not None and tumorgroup.attrs['TYPE'] == 'faketumor'): print('nix') if options.noOverlay: epv.render(imagefn + '.png') else: povrayEasy.RenderImageWithOverlay(epv, imagefn + '.png', None, 'tumor', options)
def render_different_data_types(vesselgroup, tumorgroup, imagefn, options, cell_group=None): filenamepostfix = '' labels = { 'flow': '$log_{10}$ Flow Rate', 'shearforce': '$log_{10}$ Shear Force', 'hematocrit': 'Hematocrit', 'pressure': 'Blood Pressure $kPa$', 'S_tot': 'Adaption Signal', 'conductivitySignal': 'Conductivity Signal', 'metabolicSignal': 'Metabolic Signal', 'radius': 'Vesselradius $\mu$m', } graph = krebsutils.read_vessels_from_hdf( vesselgroup, ['position', 'flags', 'radius', 'nodeflags'] + options.datalist, return_graph=True) options.wbbox = povrayRenderVessels.ComputeBoundingBox(vesselgroup, graph) if options.filteruncirculated: graph = graph.get_filtered(edge_indices=myutils.bbitwise_and( graph['flags'], krebsutils.CIRCULATED)) if options.filterradiushighpass > 0: graph = graph.get_filtered( edge_indices=graph['radius'] > filterradiushighpass) filenamepostfix = '_rhp' if options.filterradiuslowpass > 0: print("lowpass filter activated:") graph = graph.get_filtered( edge_indices=graph['radius'] < filterradiuslowpass) filenamepostfix = '_rlp' for data_name in options.datalist: if 'colorfactory' in options: print('colorfactory in options') colors_factory = options.colorfactory colors_factory(graph) cm, (datamin, datamax) = povrayRenderVessels.make_any_color_arrays( graph, data_name, options) fn = vesselgroup.file.filename if cell_group is not None and options.cells: options.imageFileName = splitext( basename(fn) )[0] + '_' + myutils.sanitize_posixpath(vesselgroup.name).replace( '/', '-' ) + '_' + data_name + '_cell_' + options.cellsProperty + '_' + filenamepostfix #+'.'+ options.format else: options.imageFileName = splitext( basename(fn) )[0] + '_' + myutils.sanitize_posixpath(vesselgroup.name).replace( '/', '-') + '_' + data_name + filenamepostfix #+'.'+ options.format with povrayEasy.EasyPovRayRender(options) as epv: povrayEasy.CreateScene2(vesselgroup, epv, graph, options) if options.noOverlay: epv.render(options.imageFileName) else: if cell_group and options.cells: cells_cm = povrayRenderCells.addVBLCells( epv, options.cellsProperty, cell_group, options) povrayEasy.RenderImageWithOverlay(epv, cm, labels[data_name], options, colormap_cells=cells_cm) else: povrayEasy.RenderImageWithOverlay(epv, cm, labels[data_name], options)
def process(grp): #veins, arteries, capillaries = getVesselTypes(grp) edges, flows = krebsutils.read_vessels_from_hdf(grp,['flow']) #capillaries = np.asarray(capillaries) return flows
fn = sys.argv[1] group = sys.argv[2] fout = open('Network.dat', 'w+') ''' the single capillary case was used to test the software ''' single_capillary_case = fn == 'vessel-single-all.h5' with h5py.File(fn, 'r') as f: if single_capillary_case: node_grp = f['thierry_case2/vessels/nodes'] vessel_grp = f['thierry_case2/vessels/'] else: node_grp = f[group + '/nodes'] vessel_grp = f[group] roots_list = np.asarray(node_grp['roots']) segment_list, real_world_positions, pressure_at_node, radius_data, flow_data, hematocrit_data, flag_data_edges, a, b = krebsutils.read_vessels_from_hdf( vessel_grp, [ 'position', 'pressure', 'radius', 'flow', 'hematocrit', 'flags', 'node_a_index', 'node_b_index' ]) pressure_at_node = pressure_at_node[:, 0] radius_data = radius_data[:, 0] flow_data = flow_data[:, 0] hematocrit_data = hematocrit_data[:, 0] flag_data_edges = flag_data_edges[:, 0] a = a[:, 0] b = b[:, 0] ''' *************** Unit change **********************''' ''' secomb uses flow measured in nl as input see flowfac in his implementation ''' flow_data = flow_data * 60 / 1e6
if (vesselgroup.attrs['CLASS'] == 'GRAPH'): worldbox = krebsutils.read_lattice_data_from_hdf( vesselgroup['lattice']).GetWorldBox() if (vesselgroup.attrs['CLASS'] == 'REALWORLD'): pos = vesselgroup['nodes/world_pos'] x_min = np.min(pos[:, 0]) x_max = np.max(pos[:, 0]) y_min = np.min(pos[:, 1]) y_max = np.max(pos[:, 1]) z_min = np.min(pos[:, 2]) z_max = np.max(pos[:, 2]) worldbox = np.asarray( [x_min, x_max, y_min, y_max, z_min, z_max]) graph = krebsutils.read_vessels_from_hdf( vesselgroup, ['position', 'flags', 'radius'] + datalist, return_graph=True) if options.filteruncirculated: graph = graph.get_filtered(edge_indices=myutils.bbitwise_and( graph['flags'], krebsutils.CIRCULATED)) if options.filterradiushighpass > 0: graph = graph.get_filtered( edge_indices=graph['radius'] > options.filterradiushighpass ) filenamepostfix = '_rhp' for data_name in datalist: cm, (datamin, datamax) = make_any_color_arrays(graph, data_name) imagefn = splitext( basename(fn))[0] + myutils.sanitize_posixpath( vesselgroup.name).replace(