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 runs_on_client(filename): import krebs.plotIff import myutils import h5py dataman = myutils.DataManager(100, krebs.plotIff.GetDataManDataInstances()) with h5py.File(filename, 'r+') as iff_file: krebs.plotIff.ComputeIfpVsIffCorrelationDataLocal(dataman, iff_file)
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 ProduceData(fitParameters, filename): from krebs.analyzeGeneral import DataBasicVessel, DataVesselSamples, DataVesselGlobal from krebs.detailedo2Analysis import DataDetailedPO2 import krebs.detailedo2Analysis.singleVesselCases as singleVesselCases paramspo2Override = dict( massTransferCoefficientModelNumber=1, conductivity_coeff1=fitParameters[0], conductivity_coeff2=fitParameters[1], conductivity_coeff3=fitParameters[2], ) f = h5files.open(filename, 'a') krebsutils.set_num_threads(2) dataman = myutils.DataManager(20, [ DataDetailedPO2(), DataBasicVessel(), DataVesselSamples(), DataVesselGlobal() ]) for k, params in fitCases: params = deepcopy(params) params.paramspo2.update(paramspo2Override) singleVesselCases.GenerateSingleCapillaryWPo2(dataman, f, k, 16, params) return f
def printBloodFlowSimple(filenames, group): files = [h5py.File(fn, 'r') for fn in filenames] fnmeasure = 'analyzeBloodVolumeMeasurements.h5' dataman = myutils.DataManager(100, [ DataBloodVolume(fnmeasure), DataTumorTissueSingle(), DataTumorBloodFlow() ]) bv = obtain_averaged_blood_flow(dataman, files, group) # unit is 1/s, converted to 1/min -> x60 def printit(id, label, unit): s = r'%s = %s +/- %s [%s]' % (label, myutils.f2s( bv[id][0] * 60.), myutils.f2s(bv[id][1] * 60.), unit) print s if 'tumor_flow' in bv: printit('tumor_flow', 'BF_{tumor}', 'um^3 Blood / min'), printit('tumor_flow_p_volume', 'rBF_{tumor}', 'ml Blood / (ml Tissue min)'), print 'tumor_volume %e' % bv['tumor_volume'][0] printit('total_flow', 'BF_{total}', 'um^3 Blood / min'), printit('total_flow_p_volume', 'rBF_{total}', 'ml Blood / (ml Tissue min)') print 'total_volume %e' % bv['total_volume'][0]
def plotComparison(): postfixes1 = [ '-st0', '-st100', '-st1000', '-st10000', ] labels1 = ['$0$', '$10^{0}$', '$10^{2}$', '$10^{3}$', '$10^{4}$'] postfixes2 = [ '-MOtcx1ncx1', '-MOtcx10ncx1', ] labels2 = ['$5k\,/\,5k$', '$50k\,/\,5k$'] filename_matrix = np.asarray( [['prez2d-stf-test' + p1 + p2 + '.h5' for p2 in postfixes2] for p1 in postfixes1]) outfn = 'prez2d-stf-test' dataman = myutils.DataManager(100, [ DataTumorTissueSingle(), DataTumorMeasureCurvature(), DataTumor3dRendering() ]) file_matrix = np.asarray([ ResultFile(h5py.File(fn, 'r+'), dataman) for fn in filename_matrix.ravel() ], dtype=np.object).reshape(filename_matrix.shape) with mpl_utils.SinglePageWriter(outfn + ".pdf") as pdfpages: plotSnapshotMatrix(file_matrix, pdfpages, xlabels=labels2, ylabels=labels1)
def estimate_ratio_hypoxic(oxy_grp,threshold): dataman = myutils.DataManager(2, [DataDetailedPO2(), DataBasicVessel()]) gvessels, gtumor = OpenVesselAndTumorGroups(oxy_grp) po2vessels, po2field_ld, po2field, parameters = dataman('detailedPO2', oxy_grp) po2vessels = np.average(po2vessels, axis=0) print 'po2vessels:', po2vessels.min(), po2vessels.max() print 'po2field:', np.amin(po2field), np.amax(po2field) #tissueOxygen = np.asarray(oxy_grp['po2field']) #print(tissueOxygen) #I neglect 5 entries from the boarder oxy_np_field= np.asarray(po2field) border=15 cropped_oxy = oxy_np_field[border:-border,border:-border,border:-border] hypoxic_Tissue = cropped_oxy<threshold hypoxic_counts = np.sum(hypoxic_Tissue[:]) number_of_boxes = cropped_oxy.shape[0]*cropped_oxy.shape[1]*cropped_oxy.shape[2] #times volume of each box cropped_volume = number_of_boxes*np.power(po2field_ld.scale,3) print('considerd volume of: %f mum^3' % cropped_volume) print('considerd volume of: %f mm^3' % (cropped_volume/1e9)) hypoxic_fraction = float(hypoxic_counts)/float(number_of_boxes) print('hypoxic fraction: %s ' % hypoxic_fraction) hypoxic_volume = hypoxic_counts*np.power(po2field_ld.scale,3) #to mm hypoxic_volume = hypoxic_volume/1e9 return hypoxic_fraction,hypoxic_volume
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')
def renderScene(drug_grp, imagefn, options): imagefn, ext = splitext(imagefn) ext = '.' + options.format options.imageFileName = imagefn+'_iff_drug'+ext max_conc = getMaxConcentration(drug_grp.file) dataman = myutils.DataManager(2, [DataBasicVessel()]) timepoint = drug_grp.attrs['time'] #comes in seconds timepoint = timepoint/3600. #gvessels = drug_grp.parent['iff/vessels'] gvessels = drug_grp.parent['vessels'] iff_pressure_field = drug_grp.parent['iff/iff_pressure'] drug_conc_field = drug_grp['conc'] cell_drug_conc_field = drug_grp['conc_cell'] ex_drug_conc_field = drug_grp['conc_ex'] #ex_drug_auc_field = drug_grp.parent['measurements/drug_local_integral']['auc_ex'] #in_drug_auc_field = drug_grp.parent['measurements/drug_local_integral']['auc_in'] #iff_ld = krebsutils.read_lattice_data_from_hdf_by_filename(drug_grp.parent['field_ld']) iff_ld = krebsutils.read_lattice_data_from_hdf_by_filename(str(drug_grp.file.filename),str(drug_grp.parent.name)+'field_ld') #ld = iffgroup['lattice'] #po2vessels, po2field_ld, po2field, parameters = dataman('detailedPO2', po2group) #po2vessels = np.average(po2vessels, axis=0) #print 'po2vessels:', po2vessels.min(), po2vessels.max() print 'ifpfield:', np.amin(iff_pressure_field), np.amax(iff_pressure_field) print 'drug_conc_field:', np.amin(drug_conc_field), np.amax(drug_conc_field) #vessel_ld = krebsutils.read_lattice_data_from_hdf(gvessels['lattice']) vessel_ld = krebsutils.read_lattice_data_from_hdf_by_filename(str(gvessels.file.filename),str(gvessels.name)+'/lattice') vessel_graph = dataman('vessel_graph', gvessels, ['position', 'flags', 'radius']) #vessel_graph.edges['po2vessels'] = po2vessels #vessel_graph.edges['saturation'] = PO2ToSaturation(po2vessels, parameters) #vessel_graph.edges['hboconc'] = vessel_graph.edges['saturation']*vessel_graph.edges['hematocrit']*chb_of_rbcs*1.0e3 vessel_graph = vessel_graph.get_filtered(edge_indices = myutils.bbitwise_and(vessel_graph['flags'], krebsutils.CIRCULATED)) if options.filterradiuslowpass>0.0: print("lowpass filter activated:") vessel_graph = vessel_graph.get_filtered(edge_indices = vessel_graph['radius']< kwargs['filterradiuslowpass']) imagefn, ext = splitext(imagefn) ext = '.' + options.format if 1: if timepoint==0: renderSliceWithDistribution((vessel_ld, vessel_graph, 'iff_pressure'), (iff_ld, iff_pressure_field), (imagefn+'_iff_pressure_t%0.1fh'%timepoint )+ext, 'IF pressure t=%.1f h'%timepoint, options, max_conc=max_conc) renderSliceWithDistribution((vessel_ld, vessel_graph, 'drug_conc'), (iff_ld, drug_conc_field), (imagefn+'_iff_drug_t%0.1fh'%timepoint )+ext, '%s t=%.1f h'%(drug_grp.file.attrs.get('MESSAGE'),timepoint), options, max_conc=max_conc) #renderSliceWithDistribution((vessel_ld, vessel_graph, 'drug_conc'), (iff_ld, cell_drug_conc_field), (imagefn+'_iff_drug_incell_t%0.1fh'%timepoint)+ext, 'Tr. intr. t=%.1f h'%timepoint, kwargs) #renderSliceWithDistribution((vessel_ld, vessel_graph, 'drug_conc'), (iff_ld, ex_drug_conc_field), (imagefn+'_iff_drug_excell_t%0.1fh'%timepoint)+ext, 'Tr. extr. t=%.1f h'%timepoint, kwargs) if options.plot_auc: renderSliceWithDistribution((vessel_ld, vessel_graph, 'auc'), (iff_ld, ex_drug_auc_field), imagefn+'_iff_ex_drug_auc'+ext, 'Tr. extr. t=%.1f h'%timepoint, options, max_conc=max_conc) #renderSliceWithDistribution((vessel_ld, vessel_graph, 'auc'), (iff_ld, in_drug_auc_field), imagefn+'_iff_in_drug_auc'+ext, 'Tr. intr. t=%.1f h'%timepoint, kwargs) if 0: renderSlice((vessel_ld, vessel_graph, 'radius'), (iff_ld, iff_pressure_field), imagefn+'_iff_pressure'+ext, '', options) renderSlice((vessel_ld, vessel_graph, 'radius'), (iff_ld, drug_conc_field), imagefn+'_iff_drug'+ext, '', options) renderSlice((vessel_ld, vessel_graph, 'radius'), (iff_ld, cell_drug_conc_field), imagefn+'_iff_drug_incell'+ext, '', options) renderSlice((vessel_ld, vessel_graph, 'radius'), (iff_ld, ex_drug_conc_field), imagefn+'_iff_drug_excell'+ext, '', options)
def ObtainDataOfVesselFile(f): dataman = myutils.DataManager(20, [ krebs.analyzeGeneral.DataTumorTissueSingle(), krebs.analyzeGeneral.DataVesselRadial(), krebs.analyzeGeneral.DataDistanceFromCenter(), krebs.analyzeBloodFlow.DataTumorBloodFlow(), krebs.analyzeGeneral.DataBasicVessel(), krebs.analyzeGeneral.DataVesselSamples(), ]) vesselgroup = f['vessels'] ld = krebsutils.read_lattice_data_from_hdf(f['field_ld']) #print 'field_box = ', ld.worldBox #bins_spec = krebs.analyzeGeneral.BinsSpecRange(100., 1000., 100.) bins_spec = krebs.analyzeGeneral.BinsSpecRange(100., 1000., 100.) mvd, mvd_bins = dataman.obtain_data('sphere_vessel_density', vesselgroup, None, bins_spec, 'radial', ld, (f, 'data')) rbf, rbf_bins = dataman.obtain_data('cum_rbf_radial', vesselgroup, None, bins_spec, 'radial', ld, (f, 'data')) rbv = dataman.obtain_data('basic_vessel_radial', 'phi_vessels', vesselgroup, None, 50., bins_spec, 'radial', ld, (f, 'data')) # rbv returns myutils.MeanValueArray scale = f['vessels/lattice'].attrs['SCALE'] message = f['parameters'].attrs['MESSAGE'] return dict(mvd=np.asarray(mvd), rbf=np.asarray(rbf), rbv=rbv.avg, bins=bins_spec.arange(), scale=scale, message=message)
def from_vessel_file(filenames, grp_pattern): dirs = set() dataman = myutils.DataManager(20, [ krebs.plotIff.DataTissue(), krebs.plotIff.DataGlobalIff(), krebs.plotIff.DataRadialIff(), krebs.analyzeGeneral.DataDistanceFromCenter(), krebs.analyzeGeneral.DataVesselSamples(), krebs.analyzeGeneral.DataBasicVessel(), o2analysis.DataDetailedPO2() ]) f_measure = h5files.open('chache.h5', 'a', search=False) def cachelocation(g): path = posixpath.join( 'FileCS_' + myutils.checksum(basename(g.file.filename)), g.name.strip(posixpath.sep)) return (f_measure, path) #run with grp_pattern: iff/vessels for fn in filenames: with h5py.File(fn, 'r+') as f: d = myutils.walkh5(f, grp_pattern) assert len(d), 'you f****d up, pattern "%s" not found in "%s"!' % ( grp_pattern, fn) dirs = set.union(dirs, d) for group_path in dirs: if 'vessel' in grp_pattern and not 'o2' in grp_pattern: vesselgroup = f[group_path] ldvessels = ku.read_lattice_data_from_hdf( vesselgroup['lattice']) fieldld = ku.SetupFieldLattice(ldvessels.worldBox, 3, 10, 0.) phi_vessels = krebs.analyzeGeneral.CalcPhiVessels( dataman, vesselgroup, fieldld, scaling=1., samples_per_cell=5) print('bla') import nibabel as nib new_image = nib.Nifti1Image(phi_vessels, affine=np.eye(4)) common_filename = os.path.splitext(os.path.basename(fn))[0] new_image.to_filename(common_filename + '_vessels' + '.nii') if 'o2' in grp_pattern: po2group = f[group_path] #sample_length = 500. #data = dataman.obtain_data('detailedPO2_global', 'po2_tissue', po2group, sample_length, cachelocation(po2group)) data = np.asarray(po2group['po2field']) print('bla') import nibabel as nib new_image = nib.Nifti1Image(data, affine=np.eye(4)) common_filename = os.path.splitext(os.path.basename(fn))[0] new_image.to_filename(common_filename + '_po2' + '.nii')
def estimate_annoxic_hypoxic_normoxic(oxy_grp, tumorradius,threshold1,threshold2): dataman = myutils.DataManager(2, [DataDetailedPO2(), DataBasicVessel()]) gvessels, gtumor = OpenVesselAndTumorGroups(oxy_grp) po2vessels, po2field_ld, po2field, parameters = dataman('detailedPO2', oxy_grp) po2vessels = np.average(po2vessels, axis=0) print 'po2vessels:', po2vessels.min(), po2vessels.max() print 'po2field:', np.amin(po2field), np.amax(po2field) #tissueOxygen = np.asarray(oxy_grp['po2field']) #print(tissueOxygen) #I neglect 5 entries from the boarder oxy_np_field= np.asarray(po2field) #find minimal dimension min_dim = np.min(oxy_np_field.shape) print("tumorradius: %f, ld: %f" %(tumorradius,po2field_ld.scale)) border0=int(np.floor(oxy_np_field.shape[0]/2)-np.ceil(tumorradius/po2field_ld.scale)) border1=int(np.floor(oxy_np_field.shape[1]/2)-np.ceil(tumorradius/po2field_ld.scale)) border2=int(np.floor(oxy_np_field.shape[2]/2)-np.ceil(tumorradius/po2field_ld.scale)) print("border0: %i" %border0) print("border1: %i" %border1) print("border2: %i" %border2) cropped_oxy = oxy_np_field[border0:-border0,border1:-border1,border2:-border2] annoxic_Tissue = cropped_oxy<threshold1 annoxic_counts = np.sum(annoxic_Tissue[:]) hypoxic_Tissue = np.logical_and(cropped_oxy<threshold2, cropped_oxy>threshold1) #hypoxic_Tissue = hypoxic_Tissue>threshold1 hypoxic_counts = np.sum(hypoxic_Tissue[:]) normoxic_Tissue = cropped_oxy>threshold2 normoxic_counts = np.sum(normoxic_Tissue[:]) number_of_boxes = cropped_oxy.shape[0]*cropped_oxy.shape[1]*cropped_oxy.shape[2] ''' volume correction for not sampling a sphere, but a cube \frac{volume(sphere)}{volume(cube of 2 times radius)} = \pi/6 ''' volume_correction_factor = np.pi/6. #volume_correction_factor = 1. #times volume of each box cropped_volume = number_of_boxes*np.power(po2field_ld.scale,3) print('considerd volume of: %f mum^3' % cropped_volume) print('considerd volume of: %f mm^3' % (cropped_volume/1e9)) hypoxic_fraction = float(hypoxic_counts)/float(number_of_boxes) print('hypoxic fraction: %s ' % hypoxic_fraction) annoxic_volume = annoxic_counts*np.power(po2field_ld.scale,3) * volume_correction_factor #to mm annoxic_volume = annoxic_volume/1e9 normoxic_volume = normoxic_counts*np.power(po2field_ld.scale,3) * volume_correction_factor #to mm normoxic_volume = normoxic_volume/1e9 hypoxic_volume = hypoxic_counts*np.power(po2field_ld.scale,3) * volume_correction_factor #to mm hypoxic_volume = hypoxic_volume/1e9 #return hypoxic_fraction,hypoxic_volume return annoxic_volume,hypoxic_volume,normoxic_volume
def AddAverageConductivity(vesselgroup, parameters): dataman = myutils.DataManager(100, [DataBasicVessel()]) vessels = dataman.obtain_data('vessel_graph', vesselgroup, ['flow', 'pressure', 'flags', 'radius','nodeflags']) def DoBC(): conductivities, avgVenousPressure, avgArterialPressure, totalFlow = ComputeVascularTreeBloodFlowResistances(vessels) avgConductivity = (totalFlow/(avgArterialPressure-avgVenousPressure)) print 'avgVenousPressure', avgVenousPressure print 'avgArterialPressure', avgArterialPressure print 'totalFlow', totalFlow print 'avgConductivity', avgConductivity return avgConductivity avgConductivity = DoBC() parameters['adaption']['avgRootNodeConductivity'] = avgConductivity return parameters
def from_vessel_file(filenames, grp_pattern): dirs = set() dataman = myutils.DataManager(20, [ krebs.plotIff.DataTissue(), krebs.plotIff.DataGlobalIff(), krebs.plotIff.DataRadialIff(), krebs.analyzeGeneral.DataDistanceFromCenter(), krebs.analyzeGeneral.DataBasicVessel() ]) #run with grp_pattern: iff/vessels for fn in filenames: with h5py.File(fn, 'r') as f: d = myutils.walkh5(f, grp_pattern) assert len(d), 'you f****d up, pattern "%s" not found in "%s"!' % ( grp_pattern, fn) dirs = set.union(dirs, d) for group_path in dirs: vesselgroup = f[group_path] ldvessels = ku.read_lattice_data_from_hdf( vesselgroup['lattice']) fieldld = ku.SetupFieldLattice(ldvessels.worldBox, 3, 10, 0.) #fieldldFine = ku.SetupFieldLattice(fieldld.worldBox, 3, 50 / 10, 0.) phi_vessels = krebs.analyzeGeneral.CalcPhiVessels( dataman, f['iff/vessels'], fieldld, scaling=1., samples_per_cell=5) #a_abs = np.fabs(phi_vessels) #a_max = np.amax(a_abs) #n_phi = phi_vessels/a_max #visual = (phi_vessels-phi_vessels.min()) #inner1 = matplotlib.cm.gist_earth(n_phi) #inner2 = np.uint8(inner1*255) #result = Image.fromarray(inner2[:,:,:,0:2],mode='RGB') #result.save('out.tiff') print('bla') import nibabel as nib new_image = nib.Nifti1Image(phi_vessels, affine=np.eye(4)) new_image.to_filename('myni') #for i in np.arange(0,phi_vessels.shape[2]): # plt.imsave('img/%03i.png' % i,phi_vessels[:,:,i]) #scipy.io.savemat('test.mat', phi_vessels) #np.save('mydata.tiff',phi_vessels) #pydicom. #pydicom.write_file('mydata.dcm', phi_vessels) plt.imshow(phi_vessels[:, :, 20]) plt.show()
def renderScene(po2group, imagefn, options): dataman = myutils.DataManager(2, [DataDetailedPO2(), DataBasicVessel()]) gvessels, gtumor = OpenVesselAndTumorGroups(po2group) po2vessels, po2field_ld, po2field, parameters = dataman( 'detailedPO2', po2group) po2vessels = np.average(po2vessels, axis=0) print 'po2vessels:', po2vessels.min(), po2vessels.max() print 'po2field:', np.amin(po2field), np.amax(po2field) #vessel_ld = krebsutils.read_lattice_data_from_hdf(gvessels['lattice']) vessel_graph = dataman('vessel_graph', gvessels, ['position', 'flags', 'radius', 'hematocrit']) vessel_graph.edges['po2_vessels'] = po2vessels print(parameters) vessel_graph.edges['saturation'] = PO2ToSaturation(po2vessels, parameters) vessel_graph.edges['hboconc'] = vessel_graph.edges[ 'saturation'] * vessel_graph.edges['hematocrit'] * chb_of_rbcs * 1.0e3 vessel_graph = vessel_graph.get_filtered(edge_indices=myutils.bbitwise_and( vessel_graph['flags'], krebsutils.CIRCULATED)) if options.filterradiuslowpass > 0: print("lowpass filter activated:") vessel_graph = vessel_graph.get_filtered( edge_indices=vessel_graph['radius'] < options.filterradiuslowpass) imagefn, ext = splitext(imagefn) ext = '.' + options.format #renderSliceWithDistribution((vessel_ld, vessel_graph, 'po2vessels'), (po2field_ld, po2field), imagefn+'_po2vessels'+ext, '', options) #renderSlice((vessel_ld, vessel_graph, 'saturation'), (None, None), imagefn+'_saturation'+ext, '', options) #renderSlice((vessel_ld, vessel_graph, 'hboconc'), (None, None), imagefn+'_hboconc'+ext, 'HbO [mmol/l blood]', options) #try world options.imageFileName = imagefn + '_po2vessels' + ext renderSliceWithDistribution((po2field_ld, vessel_graph, 'po2_vessels'), (po2field_ld, po2field), '', options) options.imageFileName = imagefn + '_saturation' + ext renderSlice((po2field_ld, vessel_graph, 'saturation'), (None, None), '', options) options.imageFileName = imagefn + '_hboconc' + ext renderSlice((po2field_ld, vessel_graph, 'hboconc'), (None, None), 'HbO [mmol/l blood]', options)
def plotSingleRun(fn): out = splitext(basename(fn))[0] f = h5files.open(fn, 'r') rc = matplotlib.rc rc('figure', figsize=(7, 7), dpi=100) rc('font', size=8.) rc('axes', titlesize=10., labelsize=10.) rc('pdf', compression=6, fonttype=42) rc( 'figure', **{ 'subplot.left': 0.02, 'subplot.right': 1. - 0.05, 'subplot.bottom': 0.01, 'subplot.top': 1. - 0.05, 'subplot.wspace': 0.1, 'subplot.hspace': 0.1 }) #rc('savefig', facecolor='none', edgecolor='none', dpi=100) rc('savefig', dpi=100) rc('font', **{'family': 'sans-serif'}) #,'sans-serif':['Helvetica']}) rc('path', simplify_threshold=0.01) #rc('text', usetex=True, **{ 'latex.unicode' : True }) with mpl_utils.PdfWriter(out + ".pdf") as pdfpages: dataman = myutils.DataManager(100, [ DataTumorTissueSingle(), DataTumorMeasureCurvature(), DataTumor3dRendering(), DataTissueRadial(), DataTissueRadialAveraged() ]) resultfile = ResultFile(f, dataman) is3d = resultfile.obtain_data('ld').shape[2] > 1 if is3d: plot3dRendering(resultfile, pdfpages, showVessels=True, showTumor=False) plot3dRendering(resultfile, pdfpages) plot3dRendering(resultfile, pdfpages, showVessels=True) plotSnapshots(resultfile, pdfpages)
def printVolumina(filenames, group): data = [] dataman = myutils.DataManager(100, [DataTumorTissueSingle()]) for fn in filenames: with h5py.File(fn, 'r') as f: d = obtain_volumes(f, group, dataman) data.append(d) data = np.asarray(data).transpose() v_tot = data[0] vr_tumor = data[1] vr_viable = data[2] def printavg(name, data): avg, std = np.average(data), np.std(data) print '%s = %s +/- %s' % (name, f2s(avg), f2s(std)) printavg('V_Sys', v_tot) printavg('V_trum', vr_tumor * v_tot) printavg('V_viable', vr_viable * v_tot) printavg('rV_trum', vr_tumor) printavg('rV_viable', vr_viable)
def create_nice_file_containing_all_the_data(): filenames = sys.argv[1:] files = [h5files.open(fn, 'r') for fn in filenames] fmeasure = h5files.open('analyzeVesselTumor.h5', 'a') dataman = myutils.DataManager(10, [DataVesselLength(), DataVesselTumor()]) 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]] outfn = 'Length-%s.pdf' % splitext(basename(filenames[0]))[0] pprint(groupslist) print '-> %s' % (outfn) for key, groups in groupslist: for group in groups: cachelocation = (fmeasure, '%s_file_%s_FILEID%s' % (group.name, group.file.filename, myutils.checksum(group.file.filename))) data = dataman.obtain_data('length_dist', 'length_dist', group['vessels'], group['tumor'], cachelocation) data = dataman.obtain_data('within_fake_tumor', 'radii_within_tumor', group['vessels'], group['tumor'], cachelocation) data = dataman.obtain_data('within_fake_tumor', 'pressures_within_tumor', group['vessels'], group['tumor'], cachelocation) data = dataman.obtain_data('within_fake_tumor', 'flows_within_tumor', group['vessels'], group['tumor'], cachelocation) print('you just created a big nice file')
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
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,
path = myutils.splitPath( 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,
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)
from os.path import basename import mpl_utils from plotIff import DataTissue, DataGlobalIff, DataRadialIff, DataTumorBloodFlow, averaged if __name__ == '__main__': if 0: #this is read in filenames = sys.argv[1:] files = [h5py.File(fn, 'r') for fn in filenames] fmeasure = h5files.open('analyzeIFF.h5', 'a') dataman = myutils.DataManager(100, [ DataTissue(), DataGlobalIff(), DataRadialIff(), DataTumorBloodFlow() ]) #data = dataman('iff_radial', files[0], 'vs_dr', 'iff_pressure') xlim = -1.5, 1.0 array_of_plateau = [] array_of_v_max = [] for f in files: print('Running file: %s' % f.filename) iff_pressure = dataman('iff_radial', f, 'vs_dr', 'iff_pressure') iff_velocity_mag = dataman('iff_radial', f, 'vs_dr', 'iff_velocity_mag') bins = (1. / 1000.) * dataman('iff_radial', f, 'vs_dr', 'bins') mask = np.logical_and(bins < xlim[1], bins >= xlim[0])
with h5py.File(goodArguments.vbl_simulation_file_name, 'r') as f: d = myutils.walkh5(f, goodArguments.grp_pattern) if not len(d) > 0: raise AssertionError('pattern "%s" not found in "%s"!' % (goodArguments.grp_pattern, goodArguments.vbl_simulation_file_name)) else: dirs = set.union(dirs, d) except Exception, e: print(e.message) sys.exit(-1) ''' begin of code ''' '''register a clases at data manager''' f_cache = h5py.File('cache_' + goodArguments.vbl_simulation_file_name, 'a') dataman = myutils.DataManager( 20, [DataArterialBifurcation(), DataVenousBifurcation()]) ''' pdf output ''' meta_data_fig = plt.figure(figsize=(11.69, 8.27)) meta_data_fig.clf() result_string = '' infos = False addpH = True if goodArguments.type == 'a': with PdfPages('3d_arterial_%s_%s.pdf' % (goodArguments.vbl_simulation_file_name, goodArguments.grp_pattern)) as pp: '''creates data for all time points''' plot_averages_at_arterial_bifurcation_for_all_times(pp) with PdfPages('out0350_arterial_%s_%s.pdf' %
) for k, v in d.iteritems(): d[k] = np.asarray(v) return d def write(gmeasure, name): press, flow, force, hema = krebsutils.calc_vessel_hydrodynamics( vesselgroup, True) grp = gmeasure.create_group(name) egrp = grp.create_group('edges') ngrp = grp.create_group('nodes') ngrp.create_dataset('h_press', data=press, compression=9) egrp.create_dataset('h_flow', data=flow, compression=9) egrp.create_dataset('h_hema', data=hema, compression=9) egrp.create_dataset('h_force', data=force, compression=9) fm = myutils.MeasurementFile(f, h5files, prefix='hematocrit_') ret = myutils.hdf_data_caching(read, write, fm, args[0].split(posixpath.pathsep), (1, )) return ret if __name__ == '__main__': fn = sys.argv[1] pattern = sys.argv[2] with myutils.H5Files() as h5files: dataman = myutils.DataManager(2, [DataHematocritSolver(h5files)]) f = h5files.open(fn, 'r') data = dataman('flow_w_hematocrit', f, pattern)
# specific naming scheme for paper from detailedo2Analysis.plotsForPaper import RewriteVesselLabel return RewriteVesselLabel(m) ## ---------------- ------- ----------------------- ## ---------------- ------- ----------------------- if __name__ == '__main__': filenames = sys.argv[1:-1] pattern = sys.argv[-1] files = [h5py.File(fn, 'r') for fn in filenames] dataman = myutils.DataManager(100, [ krebs.analyzeGeneral.DataTumorTissueSingle(), krebs.analyzeGeneral.DataBasicVessel(), krebs.analyzeGeneral.DataDistanceFromCenter(), DataTumorBloodFlow() ]) groupnames = myutils.walkh5(files[0], pattern, return_h5objects=False) allgroups = list( itertools.chain.from_iterable( (f[g] for g in groupnames) for f in files)) # determination of storage file, copied from analyzeVesselsBulkTumor prefix, suffix = myutils.splitcommonpresuffix( map(lambda s: basename(s), filenames)) outputbasename, _ = splitext(prefix + suffix) fn_measure = 'common-radial-cache.h5' f_measure = h5files.open(fn_measure, 'a')
plotAnalyzeConvergence(dataman, pdfwriter, plotties) plotties[0].AddStatsPage(pdfwriter) plotAnalyzeIterativeConvergence(dataman, pdfwriter, plotties) pyplot.close('all') if __name__ == '__main__': krebsutils.set_num_threads(2) dataman = myutils.DataManager(20, [DataDetailedPO2(),DataBasicVessel(), DataVesselSamples(), DataVesselGlobal()]) fn = 'vessel-single-all.h5' #os.unlink(fn) f = h5files.open(fn,'a') GenerateSingleCapillaryWPo2(dataman, f, 'nair_uptake', 14, singleVesselParameterSets.nair_uptake) plot_single_capillary(dataman, f['nair_uptake'], useInsets = True) GenerateSingleCapillaryWPo2(dataman, f, 'nair_release', 14, singleVesselParameterSets.nair_release) plot_single_capillary(dataman, f['nair_release'], useInsets = True) grouplist = [] for name in [ 'moschandreou_case%02i' % i for i in xrange(6) ]: params = getattr(singleVesselParameterSets, name) r = params.paramsTube['r']
def WriteSamplesToDisk(po2group): dataman = myutils.DataManager(5, [DataDetailedPO2()]) cachelocation = MakeSampleLocation(po2group) dataman.obtain_data('detailedPO2_total_fluxes', None, po2group, 30., None, cachelocation)
#ax.set(ylim = lim, xlim = (ax.get_xlim()[0], 1000)) 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)
def doit(filenames, pattern): dataman = myutils.DataManager(20, [ DataTumorTissueSingle(), DataDistanceFromCenter(), DataBasicVessel(), DataVesselSamples(), DataVesselRadial(), DataVesselGlobal(), DataTumorBloodFlow() ]) ensemble = EnsembleFiles(dataman, filenames, pattern) if ensemble.has_tumor: print 'paths: ', map(lambda (_t0, path, _t1): path, ensemble.tumor_snapshots) else: print 'paths: ', set(map(lambda e: e.path, ensemble.items)) prefix, suffix = myutils.splitcommonpresuffix( map(lambda s: basename(s), filenames)) outputbasename, _ = splitext(prefix + suffix) fn_measure = outputbasename + '-radial-cache.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) #name = ensemble.items[0].path.split('/')[-1] measurementinfo = dict(sample_length=30., cachelocation_callback=cachelocation, distancemap_spec='radial') print 'getting radial curves' stuff = [] stuff2 = [] for items, path, time in ensemble.tumor_snapshots: bins_spec, curves = CollectAllRadialData(dataman, items, measurementinfo) tumorradius = GetAverageApproximateTumorRadius(dataman, ensemble, items) stuff.append((time, tumorradius, curves)) stuff2.append((time, tumorradius, curves, path)) #output_filename+= '_'+name with mpl_utils.PdfWriter(outputbasename + '-radial.pdf') as pdfwriter: PlotRadialCurves(pdfwriter, bins_spec, stuff, measurementinfo, ensemble.world_size) with h5py.File(outputbasename + '-radial.h5', 'w') as f: f.attrs['COMMONPREFIX'] = os.path.commonprefix( map(lambda s: basename(s), filenames)) f.create_dataset('files', data=filenames) f.create_dataset('groups', data=np.asarray(set( map(lambda item: item.path, ensemble.items)), dtype=np.str)) for i, (time, tumorradius, curves, path) in enumerate(stuff2): g = f.create_group(path.strip('/').replace('/', '-')) g.attrs['TUMORRADIUS'] = tumorradius g.attrs['TIME'] = time for name, curve in curves.iteritems(): curve = myutils.MeanValueArray.fromSummation( map(lambda x: x.avg, curve)) g.create_dataset(name + '/avg', data=np.asarray(curve.avg)) g.create_dataset(name + '/std', data=np.asarray(curve.std)) g.create_dataset(name + '/mask', data=~curve.avg.mask) g.create_dataset(name + '/std_mean', data=np.asarray(curve.std_mean)) g.create_dataset('bins', data=bins_spec.arange())