def DoReadIn(filenames, pattern, fn_measure): #read in lots of stuff files = [h5files.open(fn, 'r') for fn in filenames] output_f = h5py.File(fn_measure) for afile in files: #edges index_of_circulated = np.bitwise_and( np.asarray(afile[pattern + '/edges/flags']), ku.CIRCULATED) > 0 index_of_arteries = np.bitwise_and( np.asarray(afile[pattern + '/edges/flags']), ku.ARTERY) > 0 index_of_veins = np.bitwise_and( np.asarray(afile[pattern + '/edges/flags']), ku.VEIN) > 0 index_of_capillaries = np.bitwise_and( np.asarray(afile[pattern + '/edges/flags']), ku.CAPILLARY) > 0 index_of_boundary = np.bitwise_and( np.asarray(afile[pattern + '/edges/flags']), ku.BOUNDARY) > 0 indeces_of_circulated_arteries = np.bitwise_and( index_of_circulated, index_of_arteries) indeces_of_circulated_veins = np.bitwise_and(index_of_circulated, index_of_veins) indeces_of_circulated_capillaries = np.bitwise_and( index_of_circulated, index_of_capillaries) radii_of_capillaries = np.asarray( afile[pattern + '/edges/radius'])[indeces_of_circulated_capillaries] #nodes index_of_circulated_nodes = np.bitwise_and( np.asarray(afile[pattern + '/nodes/nodeflags']), ku.CIRCULATED) > 0 indeces_of_roots = np.asarray(afile[pattern + '/nodes/roots']) artery_roots = [] artery_roots_radii = [] artery_roots_pressure = [] venous_roots = [] venous_roots_radii = [] venous_roots_pressure = [] nodeflags = np.asarray(afile[pattern + '/nodes/nodeflags']) for aIndex in indeces_of_roots: if index_of_circulated_nodes[aIndex] and np.bitwise_and( nodeflags[aIndex], ku.ARTERY): artery_roots.append(aIndex) artery_roots_pressure.append( np.asarray(afile[pattern + '/nodes/pressure'])[aIndex]) if index_of_circulated_nodes[aIndex] and np.bitwise_and( nodeflags[aIndex], ku.VEIN): venous_roots.append(aIndex) venous_roots_pressure.append( np.asarray(afile[pattern + '/nodes/pressure'])[aIndex]) NodeAIndex = np.asarray( afile[pattern + '/edges/node_a_index'])[index_of_boundary] NodeBIndex = np.asarray( afile[pattern + '/edges/node_b_index'])[index_of_boundary] radii_of_boundary = np.asarray( afile[pattern + '/edges/radius'])[index_of_boundary] for (i, aNodeAIndex) in enumerate(NodeAIndex): if (aNodeAIndex in artery_roots) and not (aNodeAIndex in NodeBIndex): artery_roots_radii.append(radii_of_boundary[i]) for (i, aNodeBIndex) in enumerate(NodeBIndex): if aNodeBIndex in artery_roots: artery_roots_radii.append(radii_of_boundary[i]) for (i, aNodeAIndex) in enumerate(NodeAIndex): if aNodeAIndex in venous_roots and not (aNodeAIndex in NodeBIndex): venous_roots_radii.append(radii_of_boundary[i]) for (i, aNodeBIndex) in enumerate(NodeBIndex): if aNodeBIndex in venous_roots: venous_roots_radii.append(radii_of_boundary[i]) if 1: print("Circulated: %i " % np.sum(index_of_circulated)) print("Circulated Arteries: %i " % np.sum(indeces_of_circulated_arteries)) print("Circulated Veins: %i " % np.sum(indeces_of_circulated_veins)) print("Circulated Capillaries: %i " % np.sum(indeces_of_circulated_capillaries)) if 1: print("# Circulated Nodes: %i " % np.sum(index_of_circulated_nodes)) print("# Arterious roots: %i " % len(artery_roots)) print("# Venous roots: %i " % len(venous_roots)) #print("Circulated Veins: %i " % np.sum(indeces_of_circulated_veins)) #print("Circulated Capillaries: %i " % np.sum(indeces_of_circulated_capillaries)) #write to file if 1: print("Working on file: %s" % afile.filename) output_grp = output_f.create_group(os.path.basename( afile.filename)) #output_grp.attrs.create("#circulated") output_grp.attrs['#circulated'] = np.sum(index_of_circulated) N = np.sum(index_of_circulated) output_grp.attrs['#artery'] = np.sum( indeces_of_circulated_arteries) output_grp.attrs['#veins'] = np.sum(indeces_of_circulated_veins) output_grp.attrs['#capillary'] = np.sum( indeces_of_circulated_capillaries) l = afile[pattern + '/lattice'].attrs['SCALE'] output_grp.attrs['length'] = l if (np.var(radii_of_capillaries)) > 0.0001: break r_0 = np.mean(radii_of_capillaries) output_grp.attrs['c_radius'] = r_0 output_grp.create_dataset('a_roots', data=artery_roots) output_grp.create_dataset('a_roots_radius', data=artery_roots_radii) output_grp.create_dataset('a_roots_pressure', data=artery_roots_pressure) output_grp.create_dataset('v_roots', data=venous_roots) output_grp.create_dataset('v_roots_radius', data=venous_roots) output_grp.create_dataset('v_roots_pressure', data=venous_roots_pressure) dataman = myutils.DataManager(100, [DataBasicVessel()]) vessels = dataman.obtain_data( 'vessel_graph', afile['/' + pattern + '/'], ['flow', 'pressure', 'flags', 'radius', 'nodeflags']) conductivities, avgVenousPressure, avgArterialPressure, totalFlow = ComputeVascularTreeBloodFlowResistances( vessels) output_grp.attrs['avgVenousPressure'] = avgVenousPressure output_grp.attrs['avgArterialPressure'] = avgArterialPressure output_grp.attrs['totalFlow_from_BloodFlowResistance'] = totalFlow
ax.set(xlabel=r'distance from rim [$\mu m$]', ylabel=r'mvd [1/mm$^2$]') ax.legend() pdfpages.savefig(fig) if __name__ == '__main__': filenames = sys.argv[1:] files = [h5files.open(fn, 'r') for fn in filenames] fmeasure = h5files.open('analyzeBloodVolumeMeasurements.h5', 'a') dataman = myutils.DataManager(10, [ DataTumorTissueSingle(), DataVesselRadial(), DataVesselSamples(), DataBasicVessel(), DataDistanceFromCenter() ]) #allgroups = sorted(filter(lambda k: k.startswith('out'), files[0].keys())) allgroups = defaultdict(list) for f in files: keys = filter(lambda k: k.startswith('out'), f.keys()) for k in keys: allgroups[k].append(f[k]) allgroups = [(k, allgroups[k]) for k in sorted(allgroups.keys())] groupslist = [allgroups[-1], allgroups[len(allgroups) / 2]] outfn = 'bloodVolume-%s.pdf' % splitext(basename(filenames[0]))[0] pprint(groupslist) print '-> %s' % (outfn) with mpl_utils.PdfWriter(outfn) as pdfpages:
dest="force_flow_recompute", help="recompute blood flow", default=False, action="store_true") parser.add_option( "--write-flow", dest="write_flow", help= "writes the recomputed flow; note: hematocrit is completely ignored!", default=False, action="store_true") options, args = parser.parse_args() if options.write_flow: options.force_flow_recompute = True dataman = myutils.DataManager(100, [DataBasicVessel()]) filenames, pattern = args[:-1], args[-1] files = [ h5files.open(fn, 'a' if options.add_resistor_bc else 'r+') for fn in filenames ] groups = list( itertools.chain.from_iterable( myutils.walkh5(f, pattern, return_h5objects=True) for f in files)) for vesselgroup in groups: if options.force_flow_recompute and not options.add_resistor_bc: (pressure, flow, shearforce) = krebsutils.calc_vessel_hydrodynamics(vesselgroup) vessels = dataman.obtain_data('vessel_graph', vesselgroup,