def DoIt(filenames, options): fn_measure = basename(commonprefix(filenames)) fn_measure = myutils.strip_from_end(fn_measure, '.h5') fn_measure = myutils.strip_from_end(fn_measure, '-type') f_measure = h5files.open('adaption_common.h5', 'a', search = False) files = [h5files.open(fn, 'r') for fn in filenames] groups_without_adaption = [f['/adaption/recomputed'] for f in files] groups_with_adaption = [f['/adaption/vessels_after_adaption'] for f in files] with mpl_utils.PdfWriter(fn_measure+'caps.pdf') as pdfpages: import analyzeGeneral dataman = myutils.DataManager(20, [ analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselGlobal()]) # vesselgroups_without = groups_without_adaption # vesselgroups_with = groups_with_adaption # geometric_data_before = getGeometricData(groups_without_adaption) # perfusion_data_before = getTotalPerfusion(groups_without_adaption)*60 # geometric_data_after = getGeometricData(groups_with_adaption) # perfusion_data_after = getTotalPerfusion(groups_with_adaption)*60 if 1: plotFlowHistogram(dataman, f_measure, filenames, options, pdfpages) if 1: plotRadiusHistogram(dataman, f_measure, filenames, options, pdfpages) if 1: plotCapillaryFlowHistogram(dataman, f_measure, filenames, options, pdfpages) if 1: plotCapillaryRadiusHistogram(dataman, f_measure, filenames, options, pdfpages)
def DoIt_single(filenames, options): fn_measure = basename(commonprefix(filenames)) fn_measure = myutils.strip_from_end(fn_measure, '.h5') fn_measure = myutils.strip_from_end(fn_measure, '-type') f_measure = h5files.open('adaption_common.h5', 'a', search = False) files = [h5files.open(fn, 'r') for fn in filenames] groups_without_adaption = [f['/adaption/recomputed'] for f in files] groups_with_adaption = [f['/adaption/vessels_after_adaption'] for f in files] import analyzeGeneral dataman = myutils.DataManager(20, [ analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselGlobal()]) with mpl_utils.PdfWriter(fn_measure+'flow_hist.pdf') as pdfpages: if 1: plotFlowHistogram(dataman, f_measure, filenames, options, pdfpages) with mpl_utils.PdfWriter(fn_measure+'radius_hist.pdf') as pdfpages: if 1: plotRadiusHistogram(dataman, f_measure, filenames, options, pdfpages) with mpl_utils.PdfWriter(fn_measure+'cap_flow_hist.pdf') as pdfpages: if 1: plotCapillaryFlowHistogram(dataman, f_measure, filenames, options, pdfpages) with mpl_utils.PdfWriter(fn_measure+'cap_radius_hist.pdf') as pdfpages: if 1: plotCapillaryRadiusHistogram(dataman, f_measure, filenames, options, pdfpages)
def enlarge_vessels(factor, gv_filename, bloodflowparams): '''gvdst = group where the data is placed in, does not create a 'vesse' folder in it but writes nodes, edges directly; gv = source vessel group ''' inFile = h5files.open(gv_filename, 'r') gv = inFile['vessels'] fac_as_percent = int(np.ceil(float(factor) * 100 - 100)) dest_file = h5files.open( myutils.strip_from_end(gv_filename, '.h5') + '_growth_by_%02i.h5' % fac_as_percent, 'a') dest_file.attrs.create('enlargeFactor', data=fac_as_percent) gvdst = dest_file.create_group('vessels') gvdst.attrs['CLASS'] = 'GRAPH' myutils.buildLink(gvdst, 'SOURCE', gv) # first we need to copy some of the vessel data gvedst = gvdst.create_group('edges') gvndst = gvdst.create_group('nodes') gvedst.attrs['COUNT'] = gv['edges'].attrs['COUNT'] gvndst.attrs['COUNT'] = gv['nodes'].attrs['COUNT'] gv.copy('lattice', gvdst) for name in [ 'lattice_pos', 'roots', 'nodeflags', 'gf', 'bc_conductivity_value', 'bc_node_index', 'bc_type', 'bc_value' ]: gv['nodes'].copy(name, gvndst) for name in ['radius', 'node_a_index', 'node_b_index', 'flags']: if name == 'radius': radii = gv['edges/' + name] radii = factor * np.asarray(radii) gvedst.create_dataset(name, data=radii) else: gv['edges'].copy(name, gvedst) # then we recompute blood flow because the alorithm has changed and we may or may not want hematocrit (pressure, flow, shearforce, hematocrit, flags) = krebsutils.calc_vessel_hydrodynamics( gvdst, return_flags=True, bloodflowparams=bloodflowparams) # then we save the new data to complete the network copy gvedst.create_dataset('flow', data=flow, compression=9) gvedst.create_dataset('shearforce', data=shearforce, compression=9) gvedst.create_dataset('hematocrit', data=hematocrit, compression=9) gvndst.create_dataset('pressure', data=pressure, compression=9)
def DoIt(filenames, pattern, with_o2): fn_measure = basename(commonprefix(filenames)) fn_measure = myutils.strip_from_end(fn_measure, '.h5') fn_measure = myutils.strip_from_end(fn_measure, '-type') def cachelocation(g): path = posixpath.join( 'FileCS_' + myutils.checksum(basename(g.file.filename)), g.name.strip(posixpath.sep)) return (f_measure, path) if with_o2: fn_measure = myutils.strip_from_end(fn_measure, '_detailedpo2') files = [h5files.open(fn, 'a') for fn in filenames] f_measure = h5files.open('plotVessels_chache.h5', 'a', search=False) groups = list( itertools.chain.from_iterable( myutils.walkh5(f, pattern, return_h5objects=True) for f in files)) if len(groups) <= 0: print 'no matching groups in hdf file(s)' sys.exit(0) if with_o2: name = posixpath.commonprefix(map(lambda g: g.name, groups)) name = myutils.strip_from_start(name, '/po2/vessels').replace('/', '-') fn_measure += name with mpl_utils.PdfWriter(fn_measure + '.pdf') as pdfpages: rc = matplotlib.rc rc('font', size=8.) rc('axes', titlesize=10., labelsize=8.) if with_o2: import detailedo2Analysis as o2analysis import detailedo2Analysis.plotsForPaper import detailedo2 dataman = myutils.DataManager(20, [ o2analysis.DataDetailedPO2(), analyzeGeneral.DataTumorTissueSingle(), analyzeGeneral.DataDistanceFromCenter(), analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeBloodFlow.DataTumorBloodFlow(), analyzeGeneral.DataVesselRadial(), analyzeGeneral.DataVesselGlobal() ]) vesselgroups = list( detailedo2.OpenVesselAndTumorGroups(g)[0] for g in groups) #original_vesselgroups = list(h5files.openLink(g, 'SOURCE') for g in vesselgroups) if 1: PrintGlobalDataWithOxygen(pdfpages, groups, vesselgroups, f_measure, dataman) '''FormatParameters makes the network creation parameters that does not work, if we have an o2 file''' #text = FormatParameters(original_vesselgroups[0].file) text = [' '] text += detailedo2Analysis.plotsForPaper.FormatParameters( groups[0]) fig, _ = mpl_utils.MakeTextPage(text, figsize=(mpl_utils.a4size[0], mpl_utils.a4size[0])) pdfpages.savefig(fig, postfix='_vesselsparams') if 1: res = getMultiScatter(300. * len(filenames), vesselgroups) plotMultiScatterBeauty(res, pdfpages) else: dataman = myutils.DataManager(20, [ analyzeGeneral.DataTumorTissueSingle(), analyzeGeneral.DataVesselRadial(), analyzeGeneral.DataDistanceFromCenter(), analyzeBloodFlow.DataTumorBloodFlow(), analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselGlobal() ]) #dataman = myutils.DataManager(20, [ analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselGlobal()]) vesselgroups = groups if 0: res = getMultiScatter(300. * len(filenames), vesselgroups) plotMultiScatterBeauty(res, pdfpages) if 0: PlotRadiusHistogram2(dataman, vesselgroups, pdfpages) if 0 and all(map(lambda g: 'data' in g.parent, vesselgroups)): data = VesselData() for g in vesselgroups: data.add(g.parent['data']) plot_topological_stats_avg(data, pdfpages) if 0: #reproduce swine plot_geometric_stuff_on_RC(dataman, f_measure, filenames, options, pdfpages) if 1: PrintGlobalData(pdfpages, vesselgroups, f_measure, dataman)
def DoIt(filenames, options): fn_measure = basename(commonprefix(filenames)) fn_measure = myutils.strip_from_end(fn_measure, '.h5') fn_measure = myutils.strip_from_end(fn_measure, '-type') f_measure = h5files.open('adaption_common.h5', 'a', search = False) files = [h5files.open(fn, 'r') for fn in filenames] groups_with_adaption = [f['/vessels_after_adaption'] for f in files] #this data is stored with the adaption files_without_adaption = [] for afile in files: completeFilename=str(afile['/vessels_after_adaption/parameters'].attrs['cwd'])+'/'+str(afile['/vessels_after_adaption/parameters'].attrs['vesselFileName']) files_without_adaption.append( h5files.open(completeFilename)) groups_without_adaption = [f['vessels'] for f in files_without_adaption] with mpl_utils.PdfWriter('adaption_' + fn_measure+'.pdf') as pdfpages: import analyzeGeneral dataman = myutils.DataManager(20, [ analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselGlobal()]) # vesselgroups_without = groups_without_adaption # vesselgroups_with = groups_with_adaption geometric_data_before = getGeometricData(groups_without_adaption) perfusion_data_before = getTotalPerfusion(groups_without_adaption)*60 geometric_data_after = getGeometricData(groups_with_adaption) perfusion_data_after = getTotalPerfusion(groups_with_adaption)*60 if 1: res_without = getMultiScatter(300. * len(filenames), groups_without_adaption) plotMultiScatterBeauty(res_without, pdfpages) res_with = getMultiScatter(300. * len(filenames), groups_with_adaption) plotMultiScatterBeauty(res_with, pdfpages, withRadiusPressureRelation=False) # if 0: # PlotRadiusHistogram2(dataman, groups_without_adaption, pdfpages) # PlotRadiusHistogram2(dataman, groups_with_adaption, pdfpages) # if 0: #printBarPlot_rBV(filenames, pdfpages) -->alt printBarPlot_rBV(dataman, f_measure, filenames, options, pdfpages) #-->mw enginered if 0: printBarPlot_rBF(dataman, f_measure, filenames, options, pdfpages) if 0: PlotRadiusHistogram_with_cache_by_RC(dataman, f_measure, filenames, options, pdfpages) #PlotRadiusHistogram_with_cache(dataman, f_measure, filenames, options, pdfpages) if 0: printBarPlot_vesseltype_on_root_node_configuration(filenames, pdfpages) ## is it worth to update this ??? if 1: #importing the murray thing #DoGetMurray(filenames, pdfpages) printMurray(dataman, f_measure, filenames, options, pdfpages) if 1: printMurray_alphas_effective(dataman, f_measure, filenames, options, pdfpages) if 1: text = ["Before adaption"] text2 = FormatGeometricAndPerfusionData(geometric_data_before, perfusion_data_before) text = text+text2 def cachelocation(g): path = posixpath.join('FileCS_'+myutils.checksum(basename(g.file.filename)), g.name.strip(posixpath.sep)) return (f_measure, path) prop_list2 = ['shearforce', 'velocity'] for name in prop_list2: data = [] for gvessels in groups_without_adaption: data.append(dataman.obtain_data('basic_vessel_global', name, gvessels, cachelocation(gvessels))) text.append(r'$<%s>$ = $%s$%s' % (Prettyfier.get_sym(name), Format(name, data), Prettyfier.get_munit(name))) fig, _ = mpl_utils.MakeTextPage(text,figsize = (mpl_utils.a4size[0]*0.8, mpl_utils.a4size[0]*0.8)) pdfpages.savefig(fig, postfix='_vesselsglobal') text = FormatParameters(groups_without_adaption[0].file) fig, _ = mpl_utils.MakeTextPage(text,figsize = (mpl_utils.a4size[0]*0.8, mpl_utils.a4size[0]*0.8)) pdfpages.savefig(fig, postfix='_vesselsparams') text = ["After adaption"] text2 = FormatGeometricAndPerfusionData(geometric_data_after, perfusion_data_after) text = text+text2 def cachelocation(g): path = posixpath.join('FileCS_'+myutils.checksum(basename(g.file.filename)), g.name.strip(posixpath.sep)) return (f_measure, path) prop_list2 = ['shearforce', 'velocity'] for name in prop_list2: data = [] for gvessels in groups_with_adaption: data.append(dataman.obtain_data('basic_vessel_global', name, gvessels, cachelocation(gvessels))) text.append(r'$<%s>$ = $%s$%s' % (Prettyfier.get_sym(name), Format(name, data), Prettyfier.get_munit(name))) fig, _ = mpl_utils.MakeTextPage(text,figsize = (mpl_utils.a4size[0]*0.8, mpl_utils.a4size[0]*0.8)) pdfpages.savefig(fig, postfix='_vesselsglobal') text = FormatParameters(groups_without_adaption[0].file) fig, _ = mpl_utils.MakeTextPage(text,figsize = (mpl_utils.a4size[0]*0.8, mpl_utils.a4size[0]*0.8)) pdfpages.savefig(fig, postfix='_vesselsparams') if 0 and all(map(lambda g: 'data' in g.parent, groups_without_adaption)): data = VesselData() for g in groups_without_adaption: data.add(g.parent['data']) plot_topological_stats_avg(data, pdfpages) if 1: #PlotQdevs_unnormalized(filenames, pdfpages) PlotQdevs_normalized(filenames, options, pdfpages)