In [3]:
%run ./msgc_experiments_ct_init.ipynb
In [4]:
import imma
In [5]:
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')
In [6]:
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 [7]:
# 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 [8]:
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 [9]:
dfs = df
dfs.keys()
Out[9]:
In [10]:
dfs
Out[10]:
In [11]:
sns.boxplot(data=df, y="time", x="method")
Out[11]:
In [12]:
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)
In [13]:
# uu["method"] == "msgc_lo2hi"
uu[uu["method"] == "msgc_lo2hi "]
Out[13]:
In [14]:
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[14]:
In [15]:
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[15]:
In [16]:
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[16]:
In [17]:
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[17]:
In [18]:
dfs.keys()
Out[18]:
In [19]:
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[19]:
In [20]:
# pivot_table(dfsu, values='D', index=[''],
# ... columns=['C'], aggfunc=np.sum)
In [21]:
help(dtt.save)
In [22]:
df[["data orig size 0", "data size 0", "data orig voxelsize mm 0", "data voxelsize mm 0"]]
Out[22]:
In [30]:
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")
In [24]:
dfs["data orig size 0"].min()
Out[24]:
In [25]:
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]"
# "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",
# "VOE [%]"
]]
# df_tex
dtt.save(df_tex, "data_ct_table")
df_tex
Out[25]:
In [26]:
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 [27]:
get_processor_name()
Out[27]:
In [28]:
# from psutil import virtual_memory
# virtual_memory()
In [32]:
dfs.keys()
Out[32]:
In [34]:
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")
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 [35]:
ssgc_rows
Out[35]: