In [1]:
%run ./msgc_experiments_ct_init.ipynb
In [2]:
im_ext = "eps"
# im_ext = "png"
In [3]:
import imma
In [4]:
img, true_segmentation, seeds, voxelsize_mm, orig_vs_mm = prepare_data(1, "left_kidney")
# plt.figure(figsize=(10,15))
plt.figure()
import copy
imgview = copy.copy(img)
imgview[:,:,-1] = 0
imgview[:,-1,:] = 0
imgview[-1,:,:] = 0
# sed3.show_slices(imgview, contour=seg, seeds=seeds, show=False, slice_step=16.9, first_slice_offset_to_see_seed_with_label=2)
sed3.show_slices(imgview,
contour=(true_segmentation > 0).astype(np.int) * 3,
show=False, shape=[3,3],
# first_slice_offset_to_see_seed_with_label=2
)
plt.axis("off")
# plt.savefig("../graphics/msgc-ct-imgsample_separated.png")
plt.savefig(
latex_dir / "ircadb01_slices_uncropped.png",
dpi=dpi, bbox_inches='tight')
plt.savefig(
latex_dir / "ircadb01_slices_uncropped.eps",
dpi=dpi, bbox_inches='tight')
In [5]:
df = pd.read_csv(fnamenew)
df.rename(columns={"msgc time": "MSGC time"})
# dfs = df[(df["data seedsz"]==3) & (df["data offset"] == 3) & (df["data radius"] == 10)]
# dfs_plus = dfs[dfs['data size'] > 160]
import seaborn as sns
sns.set_context("paper")
sns.set_style("white")
In [6]:
# temp fixutre
if "data orig voxesize mm 0" in df.keys():
print("je to tam")
df = df.rename(columns={
"data orig voxesize mm 0": "data orig voxelsize mm 0",
"data orig voxesize mm 1": "data orig voxelsize mm 1",
"data orig voxesize mm 2": "data orig voxelsize mm 2",
"data voxesize mm 0": "data voxelsize mm 0",
"data voxesize mm 1": "data voxelsize mm 1",
"data voxesize mm 2": "data voxelsize mm 2",
"data voxesize mm^3": "data voxelsize mm^3",
})
In [7]:
df["relative object size"] = df["data target size px"] / df["data size px"]
df["relative object size [%]"] = 100 * df["data target size px"] / df["data size px"]
df["data orig size 0"] = df["data size 0"] * df["data voxelsize mm 0"]/df["data orig voxelsize mm 0"]
df["VOE [%]"] = df["error"] / df["data target size px"]
In [8]:
dfs = df
dfs.keys()
Out[8]:
In [9]:
pd.set_option('display.max_columns', 500)
dfs
Out[9]:
In [10]:
sns.boxplot(data=df, y="time", x="method")
Out[10]:
In [11]:
mfmc_label = "Min-Cut"
rename_bp = {"gc time": mfmc_label, "time": "total"}
uu = pd.melt(df.rename(columns=rename_bp), value_vars=[mfmc_label, "total"], id_vars=["method"], var_name="Time type", value_name="Time [s]")
bp = sns.boxplot(data=uu, hue="Time type",y="Time [s]", x="method",
# showfliers=False,
hue_order=["total", mfmc_label],
)
# bp.set(xaxis="log")
bp.set(yscale="log")
plt.savefig(op.join(latex_dir, "msgc_time_boxplot_ct.pdf"), dpi=1000)
plt.savefig(op.join(latex_dir, "msgc_time_boxplot_ct.eps"), dpi=800)
In [12]:
# uu["method"] == "msgc_lo2hi"
uu[uu["method"] == "msgc_lo2hi "]
Out[12]:
In [20]:
dfsp = dfs.rename(columns=rename_bp)
table = pd.pivot_table(
dfsp, values=['Min-Cut', 'total', "VOE [%]", "jaccard", "dice"], index=['method'],
# aggfunc=[min, np.mean, max],
aggfunc={'Min-Cut': [min, np.mean, max] , 'total': [min, np.mean, max] }
)
text = dtt.save(table, "pivot_table_time_ct", index=True)
print(text)
table
Out[20]:
In [25]:
dfsp = dfs.rename(columns=rename_bp)
table = pd.pivot_table(
dfsp, values=["VOE [%]", "jaccard", "dice", "rmsd", "maxd"], index=['method'],
aggfunc=np.mean
# aggfunc=[np.mean, max],
# aggfunc={'Min-Cut': [min, np.mean, max] , 'total': [min, np.mean, max], "VOE [%]":[min, max], "jaccard": max, "dice":max }
)
dtt.save(table, "pivot_table_error_ct", index=True)
table
Out[25]:
In [23]:
dfsp = dfs.rename(columns=rename_bp)
table = pd.pivot_table(
dfsp, values=['Min-Cut', 'total', "VOE [%]", "jaccard", "dice"], index=['method'],
# aggfunc=[min, np.mean, max],
aggfunc={'Min-Cut': [min, np.mean, max] , 'total': [min, np.mean, max], "VOE [%]": np.mean , "jaccard": np.mean}
# aggfunc={'Min-Cut': [min, np.mean, max] , 'total': [min, np.mean, max], "VOE [%]":[min, max], "jaccard": max, "dice":max }
)
# dtt.save(table, "pivot_table_combination_ct")
table
In [76]:
table = pd.pivot_table(
dfs, values=['gc time', 'time', "t3", "t4", "t5", "t6", "t7", "t8"], index=['method'],
aggfunc={'gc time': np.mean, 'time': [np.mean, min, max], "t3": np.mean,"t4": np.mean, "t5": np.mean, "t6": np.mean, "t7": np.mean, "t8": np.mean}
)
table
Out[76]:
In [77]:
table = pd.pivot_table(
dfs, values=['gc time', 'time', "t2", "t3", "t3.1", "t3.2", "t3.3", "t4", "t5", "t6", "t7", "t8", "low level image voxels", "low level object voxels"], index=['method'],
aggfunc=np.min
)
table
Out[77]:
In [78]:
table = pd.pivot_table(
dfs, values=['gc time', 'time', "t graph 01", "t graph 10", "t graph 11", "t graph 13", "t graph 14", "low level image voxels", "low level object voxels"], index=['method'],
aggfunc=np.mean
)
table
Out[78]:
In [79]:
table = pd.pivot_table(
dfs, values=[
'gc time', 'time',
"t graph low",
"t graph high",
"t split 01",
"t split 02",
"t split 03",
"t split 04",
"t split 05",
"t split 06",
"t split 07",
"t split 08",
"t split 081",
"t split 082",
"t split 09",
"t split 10",
"low level image voxels", "low level object voxels"], index=['method'],
aggfunc=np.mean
)
table
Out[79]:
In [80]:
dfs.keys()
Out[80]:
In [81]:
dfsu = dfs[["data id", "data orig voxelsize mm 0", "data orig voxelsize mm 1", "relative object size [%]", 'data size px', 'data target size px', "data orig size 0"]].drop_duplicates().describe()
dfsu
Out[81]:
In [82]:
# pivot_table(dfsu, values='D', index=[''],
# ... columns=['C'], aggfunc=np.sum)
In [83]:
help(dtt.save)
In [84]:
df[["data orig size 0", "data size 0", "data orig voxelsize mm 0", "data voxelsize mm 0"]]
Out[84]:
In [85]:
dtt.save(dfs["data orig voxelsize mm 0"].min(), "data_ct_vxmm0_min")
dtt.save(dfs["data orig voxelsize mm 0"].max(), "data_ct_vxmm0_max")
dtt.save(dfs["data orig voxelsize mm 1"].min(), "data_ct_vxmm1_min")
dtt.save(dfs["data orig voxelsize mm 1"].max(), "data_ct_vxmm1_max")
dtt.save(dfs["data orig voxelsize mm 1"].count(), "data_ct_count")
dtt.save(dfs["relative object size [%]"].min(), "data_ct_relative_object_size_min")
dtt.save(dfs["relative object size [%]"].max(), "data_ct_relative_object_size_max")
dtt.save(int(dfs["data orig size 0"].min()), "data_ct_orig_sz0_min")
dtt.save(int(dfs["data orig size 0"].max()), "data_ct_orig_sz0_max")
dtt.save(working_voxelsize_mm[0], "data_ct_wvs_mm")
Out[85]:
In [86]:
dfs["data orig size 0"].min()
Out[86]:
In [ ]:
In [104]:
rename_data = {
"data orig voxelsize mm 0": "slice thickness [mm]",
"data orig voxelsize mm 1": "pixel spacing [mm]",
"gc time": mfmc_label + " [s]",
"time" : "time [s]",
"maxd" : "maxd [mm]",
"rmsd": "RMSD"
#"error": "error"
# "voxelsize mm 0": "slice thickness [mm]",
# "data voxelsize mm 1": "pixel spacing [mm]",
}
df_tex = df.rename(columns=rename_data)[[
"data id", "slice thickness [mm]", "pixel spacing [mm]", mfmc_label + " [s]", "time [s]", "method",
# "error",
"VOE [%]", "jaccard", "dice", "maxd [mm]", "RMSD"
]]
# df_tex
dtt.save(df_tex, "data_ct_table")
df_tex
Out[104]:
In [88]:
import os, platform, subprocess, re
def get_processor_name():
if platform.system() == "Windows":
return platform.processor()
elif platform.system() == "Darwin":
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin'
command ="sysctl -n machdep.cpu.brand_string"
return subprocess.check_output(command).strip()
elif platform.system() == "Linux":
command = "cat /proc/cpuinfo"
all_info = subprocess.check_output(command, shell=True).strip()
for line in all_info.split("\n"):
if "model name" in line:
return re.sub( ".*model name.*:", "", line,1)
return ""
In [89]:
get_processor_name()
Out[89]:
In [90]:
# from psutil import virtual_memory
# virtual_memory()
In [91]:
dfs.keys()
Out[91]:
In [92]:
from scipy import stats
dfs_plus = dfs
ssgc_rows = dfs_plus[dfs_plus["method"].str.contains(labels[0])]
ssgc_hi2lo_rows = dfs_plus[dfs_plus["method"].str.contains(labels[1])]
ssgc_lo2hi_rows = dfs_plus[dfs_plus["method"].str.contains(labels[2])]
pp0 = stats.ttest_rel(ssgc_rows["time"], ssgc_hi2lo_rows["time"])
pp1 = stats.ttest_rel(ssgc_rows["time"], ssgc_lo2hi_rows["time"])
pp2 = stats.ttest_rel(ssgc_hi2lo_rows["time"], ssgc_lo2hi_rows["time"])
print("pokud je pvalue mensi nez zvolena hladina vyznamnosti (0.01=1%), je vsechno ok")
#mozna staci i dvojnasobek hladiny vyzamnosi
print("statistic musi byt vetsi nez 0, pokud jde o jednostranný test. V tomto případě lze jen prohodit pořadí proměnných")
display(pp0)
display(pp1)
display(pp2)
float_to_latex_file(pp0.pvalue, op.join(latex_dir, "ttest_pvalue_ct_ssgc_msgc_hi2lo.tex"))
float_to_latex_file(pp1.pvalue, op.join(latex_dir, "ttest_pvalue_ct_ssgc_msgc_lo2hi.tex"))
float_to_latex_file(pp2.pvalue, op.join(latex_dir, "ttest_pvalue_ct_msgc_hi2lo_msgc_lo2hi.tex"))
In [93]:
ssgc_rows
Out[93]:
In [116]:
# pp0 = stats.ttest_rel(ssgc_hi2lo_rows["time"], ssgc_rows["time"])
# pp1 = stats.ttest_rel(ssgc_lo2hi_rows["time"], ssgc_rows["time"])
# pp2 = stats.ttest_rel(ssgc_lo2hi_rows["time"], ssgc_hi2lo_rows["time"])
# pp_err0 = stats.ttest_rel(ssgc_lo2hi_rows["VOE [%]"], ssgc_rows["VOE [%]"])
# pp_err2 = stats.ttest_rel(ssgc_lo2hi_rows["VOE [%]"], ssgc_hi2lo_rows["VOE [%]"])
# stats.ttest_rel
# display(pp0)
# display(pp1)
# display(pp2)
# display(pp_err0)
# display(pp_err2)