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 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 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 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)
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']
pyplot.tight_layout() pdfwriter.savefig(fig, postfix='_curves') 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)