コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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')
コード例 #4
0
            posixpath.join(
                splitext(basename(vesselgroup.file.filename))[0],
                vesselgroup.name.strip(posixpath.sep))) + (dataname, )
        return (f_measure, path)

    def cachelocationEnsemble(dataname, groups):
        groupchecksum = myutils.checksum(*map(
            lambda g: str(g.file.filename + '/' + g.name), sum(groups, [])))
        path = ('%s_%s' % (dataname, groupchecksum), )
        return (f_measure, path)

    dataman = myutils.DataManager(20, [
        analyzeGeneral.DataTumorTissueSingle(),
        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,
コード例 #5
0
ファイル: plotVessels.py プロジェクト: Amenhotep19/tumorcode
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)
コード例 #6
0
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)