def doit(filenames): dataman = myutils.DataManager(50, map(lambda x: x(), detailedo2Analysis.O2DataHandlers) + [ analyzeGeneral.DataTumorTissueSingle(), analyzeGeneral.DataDistanceFromCenter(), analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), analyzeGeneral.DataVesselRadial(), analyzeGeneral.DataVesselGlobal(), analyzeBloodFlow.DataTumorBloodFlow()]) ensemble = EnsembleFiles(dataman, filenames,'po2/adaption/' ) out_prefix, out_suffix = myutils.splitcommonpresuffix(map(lambda s: basename(s), filenames)) output_base_filename = splitext(out_prefix+out_suffix)[0] if ensemble.o2ConfigName: fn_measure = 'detailedo2_%s_common.h5' % ensemble.o2ConfigName else: fn_measure = 'detailedo2_common.h5' f_measure = h5files.open(fn_measure, 'a') def cachelocation(g): path = posixpath.join('FileCS_'+myutils.checksum(basename(g.file.filename)), g.name.strip(posixpath.sep)) return (f_measure, path) measurementinfo = MeasurementInfo(sample_length = 30., cachelocation_callback = cachelocation, distancemap_spec = 'radial') with mpl_utils.PageWriter(output_base_filename+'.pdf', fileformats = ['pdf']) as pdfwriter: if 0: compare_tissue_saturation(dataman, ensemble, pdfwriter) if 0: #try: # histogramGroupFinal = f_measure['combinedHistogramsFinal'] # histogramGroupInitial = f_measure['combinedHistogramsInitial'] #except KeyError: #histogramGroupFinal = f_measure.recreate_group('combinedHistogramsFinal') histogramGroupInitial = f_measure.recreate_group('combinedHistogramsInitial') #ComputeHistogramsOfPo2Items(dataman, ensemble.items, measurementinfo, histogramGroupFinal) ComputeHistogramsOfPo2Items(dataman, ensemble.items, measurementinfo, histogramGroupInitial) #PlotHistograms(pdfwriter, histogramGroupFinal, 'tum', 'Tumor') PlotHistograms(pdfwriter, histogramGroupInitial, 'all', 'Initial')
analyzeGeneral.DataDistanceFromCenter(), analyzeGeneral.DataBasicVessel(), analyzeGeneral.DataVesselSamples(), DataPressureMvdCorrelation(200., 5, 30., cachelocation, cachelocationEnsemble) ]) if not options.picz: print '-----------computing sammples------------' localSamples = dataman.obtain_data('intervascular_map_correlations', thegroups) globalSamples = dataman.obtain_data( 'intervascular_global_correlations', thegroups) print '--------------plotting ---------------' with mpl_utils.PageWriter(outputbasename + '_mvd-grad.pdf', fileformats=['svg']) as pdfwriter: fig, axes = pyplot.subplots(1, 2, figsize=mpl_utils.a4size * np.asarray( (0.8, 0.2))) ax = axes[0] dataPage = [] samples = localSamples mask = np.asarray(samples['mask']) maski = ~mask maski[np.random.rand(len(mask)) < 0.95] = False r = np.random.rand(len(mask)) dilution = float(options.num_samples) / len(mask) mask[r > dilution] = False
def AnalyzeScaleVariation(filenames): import matplotlib.pyplot as pyplot import mpl_utils import krebs.quantities as Q import collections data = [] for fn in filenames: with h5py.File(fn, 'r+') as f: sample = ObtainDataOfVesselFile(f) del sample['message'] data.append(sample) byScale = collections.defaultdict(list) for d in data: scale = d['scale'] byScale[scale].append(d) for k, v in byScale.items(): byScale[k] = myutils.zipListOfDicts(v) curves = collections.defaultdict(list) for k, v in byScale.items(): res = ComputeSingleNumberAvgStd(v) for name, (std, avg) in res.items(): curves[name].append((std, avg)) order = np.argsort(np.asarray(curves['scale'])[:, 0]) for k, v in curves.items(): curves[k] = np.asarray(v).transpose()[:, order] scales = { 'mvd': (Q.um**-2).asNumber(Q.mm**-2), 'rbv': 100., 'rbf': 60., } with mpl_utils.PageWriter('vessel-calibration-analysis', fileformats=['pdf']) as pdfwriter: fig, axes = pyplot.subplots(3, 1, figsize=mpl_utils.a4size * np.asarray([0.4, 0.5])) for scale, data in byScale.items(): bins = np.average( data['bins'], axis=0 ) # sanity check, all bins arrays have equal size, so just try to average the bin boundaries, even if it makes no real sense x = bins x_rbv = 0.5 * (x[1:] + x[:-1]) # bin center for rBV # plot things ax = axes[0] ya = data['mvd'] ax.errorbar(x, scales['mvd'] * np.average(ya, axis=0), yerr=scales['mvd'] * np.std(ya, axis=0), label=('h = %0.f' % scale)) legend = ax.legend(loc=4, fontsize='xx-small') ax = axes[1] scale = scales['rbv'] ya = data['rbv'] ax.errorbar(x_rbv, scale * np.average(ya, axis=0), yerr=scale * np.std(ya, axis=0)) ax = axes[2] ya = data['rbf'] scale = scales['rbf'] ax.errorbar(x, scale * np.average(ya, axis=0), yerr=scale * np.std(ya, axis=0)) axes[0].set(ylabel='mvd [$mm^{-1}$]') axes[1].set(ylabel='rbv [$\%$]') axes[2].set(ylabel='rbf [$min^{-1}$]', xlabel='$|x| [\mu m]$') pyplot.tight_layout() pyplot.legend() pdfwriter.savefig(fig) fig, axes = pyplot.subplots(3, 1, figsize=mpl_utils.a4size * np.asarray([0.4, 0.5])) for ax in axes: ax.grid(linestyle=':', linewidth=0.5, color='#aaaaaa') x = curves['scale'][0, :] ax = axes[0] y, yerr = scales['mvd'] * curves['mvd'] ax.errorbar(x, y, yerr=yerr) ax = axes[1] y, yerr = scales['rbv'] * curves['rbv'] ax.errorbar(x, y, yerr=yerr) ax = axes[2] y, yerr = scales['rbf'] * curves['rbf'] ax.errorbar(x, y, yerr=yerr) axes[0].set(ylabel='mvd [$mm^{-1}$]') axes[1].set(ylabel='rbv [$\%$]') axes[2].set(ylabel='rbf [$min^{-1}$]', xlabel='$h [\mu m]$') pyplot.tight_layout() pdfwriter.savefig(fig)
if __name__ == "__main__": filenames = sys.argv[1:-1] pattern = sys.argv[-1] if 0: plotSingleRun(sys.argv[1]) else: dataman = myutils.DataManager(100, [ DataTumorTissueSingle(), DataVesselRadial(), DataVesselSamples(), DataBasicVessel(), DataDistanceFromCenter() ]) files = [ ResultFile(h5files.open(fn, 'r+'), dataman, pattern) for fn in filenames ] for f in files: fix_time(f.f) common_filename = myutils.sanitize_posixpath( splitext(commonprefix(filenames))[0]) with mpl_utils.PageWriter(common_filename + '.pdf', formats=['pdf']) as pdfwriter: PlotRadial(pdfwriter, dataman, files, 'radial') #vesselgroups = [ f.f[f.groupnames[-1]]['vessels'] for f in files ] #fig, ax = pyplot.subplots(1,1, figsize = (mpl_utils.a4size[0]*0.8, mpl_utils.a4size[0]*0.4)) #PlotRadiusHistogram(ax, dataman, vesselgroups, krebsutils.WITHIN_TUMOR) #pdfwriter.savefig(fig, postfix='_radiushisto') if 0: printVolumina(sys.argv[2:], sys.argv[1])