In [23]:
%run evaltools.ipynb


Populating the interactive namespace from numpy and matplotlib
0/4277

In [ ]:


In [24]:
sns.set_style("whitegrid")
context = "talk"
sns.set_context(context)
sns.axes_style()
sns.set_style("whitegrid", {"axes.edgecolor": "0.0", "grid.linestyle": ":"})
# sns.set_context("paper")

In [25]:
datapath
df = read_data(datapath)

output_fn_prefix = "../graphics/paper/"
# this is going to remove unwanted data from the dataset

# df = select_df(df, older_than="2017-10-03 23:00", note="mix 2 cylinder surface + sphere error", remove=True, print_log=True)
df = select_df(df, older_than="2017-10-05 12:00", note_contains="mix 2", remove=True, print_log=True)
df = select_df(df, older_than="2017-10-05 17:00", note_contains="mix 4", remove=True, print_log=True)


3880/4277
3880/3880

In [26]:
df_error = show_violin_separated(df)



In [ ]:


In [27]:
# for k in df.keys():
#     print(k)

In [28]:
list_filter(df.keys(), contain="note")


Out[28]:
['config output note']

Wilcox a Spearman

docela dobře vychází třeba experiment mix 4 cylinder surface a mix 4 cylinder volume

Nově se testuje velikost erroru, což je absolutní hodnota z difference. Pomocí Mann–Whitney–Wilcoxon (Wilcoxon rank-sum test) ověřujeme, že je medián erroru menší než 0.001.


In [29]:
mw_surf_key = "Wilcoxon Mann Whitney surface error < 0.1 %"
mw_vol_key = "Wilcoxon Mann Whitney vol error < 0.1 %"

maximal_error = 0.001
data = {
    "config output note": [],
    "wilcoxon volume": [],
    "spearman volume": [],
    "wilcoxon surface" : [],
    "spearman surface" : [],
    mw_surf_key: [],
    mw_vol_key: [],
    "number of samples": [],
    "surface mean err": [],
    "volume mean err": [],
#     "surface mean err test": [],
#     "volume mean err test": [],
#     "mannwhitneyu volume test": [],
#     "mannwhitneyu surface test": [],
}
for note in np.unique(df["config output note"]):
    dfs = df[df["config output note"] == note]
#     vw, vs, sw, ss = statistic_tests(dfs)
    sw, vw = wilcoxon_from_df(dfs)
    sm, vm = mannthitneyu_from_df(dfs, maximal_error)
    ss, vs = spearman_from_df(dfs)
    data["config output note"].append(note)
    data["wilcoxon volume"].append(vw.pvalue)
    data["spearman volume"].append(vs.pvalue)
    data["wilcoxon surface"].append(sw.pvalue)
    data["spearman surface"].append(ss.pvalue)
    data["number of samples"].append(len(dfs))
    
#     if len(dfs) > 3:
#         serrt = np.abs((dfs["surface [mm^2]"] - dfs["numeric surface [mm^2]"]) / dfs["surface [mm^2]"] )
#         verrt = np.abs((dfs["volume [mm^3]"] - dfs["numeric volume [mm^3]"]) / dfs["volume [mm^3]"] )
#         surf_sh = scipy.stats.mannwhitneyu(serrt, np.ones_like(serrt)*maximal_error, alternative="less")[1]
#         vol_sh = scipy.stats.mannwhitneyu(verrt, np.ones_like(verrt)*maximal_error, alternative="less")[1]
# #         surf_sh = np.mean(err)
# #         surf_sh = scipy.stats.shapiro(dfs["surface [mm^2]"] - dfs["numeric surface [mm^2]"])
#     else:
#         surf_sh = NaN
#         vol_sh = NaN
#         serrt = NaN
#         verrt = NaN
#     Wilcoxon–Mann–Whitney test
    data[mw_surf_key].append(sm)
    data[mw_vol_key].append(vm)
#     data["mannwhitneyu surface test"].append(surf_sh)
#     data["mannwhitneyu volume test"].append(vol_sh)
    data["surface mean err"].append(np.mean(dfs["surface error [-]"]))
    data["volume mean err"].append(np.mean(dfs["volume error [-]"]))
#     data["surface mean err test"].append(np.mean(serrt))
#     data["volume mean err test"].append(np.mean(verrt))
    
#     show_error(dfs, radius_method=note)
pd.set_option("display.max_rows",101)
pd.DataFrame(data)
pd.DataFrame(data)


Out[29]:
Wilcoxon Mann Whitney surface error < 0.1 % Wilcoxon Mann Whitney vol error < 0.1 % config output note number of samples spearman surface spearman volume surface mean err volume mean err wilcoxon surface wilcoxon volume
0 NaN NaN NaN 0 NaN NaN NaN NaN NaN NaN
1 2.439090e-02 1.000000e+00 compensation method 1 sphere cylinder surface 176 4.495098e-102 1.631674e-83 0.006397 0.019545 1.808256e-30 1.808256e-30
2 9.182861e-40 9.932706e-01 compensation method 1 sphere cylinder surface ... 175 6.914812e-123 4.234327e-101 0.000693 0.009893 5.558936e-23 1.939335e-29
3 9.309709e-01 6.224406e-14 compensation method 1 sphere cylinder volume 175 4.208930e-103 1.388799e-121 0.008033 0.002022 1.808256e-30 3.187138e-20
4 7.556557e-01 1.943776e-44 compensation method 1 sphere cylinder volume +... 175 9.630842e-99 6.914812e-123 0.008317 0.000953 1.808256e-30 8.655532e-13
5 1.000000e+00 1.000000e+00 compensation method 1 sphere inscribed 175 1.056327e-74 2.615000e-60 0.019180 0.037037 1.808256e-30 1.808256e-30
6 1.456177e-02 1.000000e+00 element number cylinder surface 70 2.371909e-08 2.371909e-08 0.001889 0.008411 3.418554e-13 3.418554e-13
7 5.768393e-28 9.999863e-01 element number cylinder surface + sphere error 119 2.592102e-13 2.592102e-13 0.000507 0.006029 2.876874e-05 2.813429e-21
8 2.011486e-01 7.994165e-01 element number cylinder surface + sphere error... 119 2.592102e-13 2.592102e-13 0.002746 0.002868 2.813429e-21 2.813429e-21
9 9.999938e-01 6.331498e-06 element number cylinder volume 70 2.371909e-08 2.371909e-08 0.004268 0.000959 3.418554e-13 3.418554e-13
10 9.980039e-01 3.059528e-18 element number cylinder volume + sphere error 91 1.134014e-10 1.134014e-10 0.004385 0.000614 1.057584e-16 2.675441e-16
11 9.999938e-01 1.229905e-18 element number cylinder volume + sphere error ... 70 2.371909e-08 2.371909e-08 0.004053 0.000429 3.418554e-13 1.565658e-04
12 1.000000e+00 1.000000e+00 element number inscribed 91 1.134014e-10 1.134014e-10 0.008141 0.018099 1.057584e-16 1.057584e-16
13 1.000000e+00 1.000000e+00 generated volume element_number anisotropic in... 20 0.000000e+00 0.000000e+00 0.001734 0.005635 8.732638e-05 8.732638e-05
14 1.000000e+00 1.000000e+00 generated volume isotropy inscribed 20 0.000000e+00 0.000000e+00 0.001707 0.005611 8.732638e-05 8.732638e-05
15 1.000000e+00 1.000000e+00 generated volume length inscribed 20 0.000000e+00 0.000000e+00 0.002463 0.006225 8.732638e-05 8.732638e-05
16 1.000000e+00 1.000000e+00 generated volume noise inscribed 20 NaN NaN 0.001734 0.005622 7.744216e-06 7.744216e-06
17 1.000000e+00 1.000000e+00 generated volume radius inscribed 21 0.000000e+00 0.000000e+00 0.002164 0.005919 5.858101e-05 5.858101e-05
18 1.000000e+00 1.000000e+00 generated volume resolution_mm inscribed 20 NaN NaN 0.001734 0.005622 7.744216e-06 7.744216e-06
19 9.363226e-05 1.000000e+00 mix 10 cylinder surface 27 5.162163e-26 5.162163e-26 0.000593 0.003193 5.606117e-06 5.606117e-06
20 7.758394e-01 9.605278e-01 mix 10 cylinder surface + sphere error 27 2.953924e-22 5.162163e-26 0.002151 0.001393 4.421944e-05 1.301337e-01
21 2.297338e-01 4.107451e-02 mix 10 cylinder surface + sphere error + join ... 27 5.162163e-26 5.162163e-26 0.000841 0.000981 4.421944e-05 5.606117e-06
22 1.000000e+00 8.396949e-12 mix 10 cylinder volume 27 5.162163e-26 5.162163e-26 0.001569 0.000295 5.606117e-06 5.606117e-06
23 9.999999e-01 8.396949e-12 mix 10 cylinder volume + sphere error 27 5.162163e-26 5.162163e-26 0.001413 0.000079 5.606117e-06 7.366070e-01
24 9.999999e-01 8.396949e-12 mix 10 cylinder volume + sphere error + join e... 27 5.162163e-26 5.162163e-26 0.001413 0.000081 5.606117e-06 7.366070e-01
25 1.000000e+00 1.000000e+00 mix 10 inscribed 27 5.162163e-26 5.162163e-26 0.002745 0.006661 5.606117e-06 5.606117e-06
26 3.649495e-01 9.997556e-01 mix 2 cylinder surface + sphere error 56 9.485780e-51 1.456168e-39 0.002893 0.006095 5.783869e-05 1.345073e-02
27 5.156943e-22 5.156943e-22 mix 2 cylinder surface + sphere error + join e... 54 2.767976e-68 2.767976e-68 0.000465 0.000572 1.625698e-10 1.625698e-10
28 5.156943e-22 5.156943e-22 mix 2 cylinder volume + sphere error 54 4.899073e-65 2.767976e-68 0.000683 0.000015 1.625698e-10 4.455037e-08
29 5.156943e-22 1.499357e-20 mix 2 cylinder volume + sphere error + join error 54 4.899073e-65 2.767976e-68 0.000679 0.000024 1.625698e-10 1.492427e-01
30 9.999999e-01 6.021451e-01 mix 3 cylinder surface + sphere error 27 2.007613e-30 2.455915e-14 0.006514 0.085505 7.658295e-03 7.731171e-01
31 1.000000e+00 3.493207e-12 mix 3 cylinder surface + sphere error + join e... 28 0.000000e+00 7.487600e-48 0.001192 0.000398 3.786883e-06 1.860323e-05
32 1.000000e+00 3.493207e-12 mix 3 cylinder volume + sphere error 28 7.487600e-48 7.487600e-48 0.001393 0.000083 3.789619e-06 2.523212e-05
33 1.000000e+00 8.396949e-12 mix 3 cylinder volume + sphere error + join error 27 3.381669e-197 3.381669e-197 0.001395 0.000071 5.606117e-06 2.910610e-05
34 1.000000e+00 1.000000e+00 mix 3 inscribed 27 3.381669e-197 3.381669e-197 0.002142 0.005905 5.606117e-06 5.606117e-06
35 8.396949e-12 1.000000e+00 mix 4 cylinder surface 27 3.381669e-197 3.381669e-197 0.000461 0.002965 5.606117e-06 5.606117e-06
36 9.879696e-01 9.994326e-01 mix 4 cylinder surface + sphere error 27 3.169521e-28 1.031750e-17 0.010543 0.093029 1.085403e-03 4.564078e-01
37 1.000000e+00 2.165778e-07 mix 4 cylinder surface + sphere error + join e... 29 2.941917e-50 2.941917e-50 0.001148 0.000570 2.561358e-06 4.797795e-06
38 1.000000e+00 8.396949e-12 mix 4 cylinder volume 27 3.381669e-197 3.381669e-197 0.001467 0.000194 5.606117e-06 5.606117e-06
39 1.000000e+00 8.396949e-12 mix 4 cylinder volume + sphere error 27 3.381669e-197 3.381669e-197 0.001411 0.000110 5.606117e-06 4.129368e-04
40 1.000000e+00 8.396949e-12 mix 4 cylinder volume + sphere error + join error 27 3.381669e-197 3.381669e-197 0.001410 0.000114 5.606117e-06 4.129368e-04
41 1.000000e+00 1.000000e+00 mix 4 inscribed 27 3.381669e-197 3.381669e-197 0.002382 0.006108 5.606117e-06 5.606117e-06
42 5.156943e-22 1.000000e+00 mix 44 cylinder surface 54 2.326033e-79 2.326033e-79 0.000341 0.002357 1.625698e-10 1.625698e-10
43 1.000000e+00 7.619815e-01 mix 44 cylinder surface + sphere error 54 3.523365e-72 1.980588e-76 0.003712 0.005779 4.181287e-06 1.696499e-01
44 5.013102e-01 5.156943e-22 mix 44 cylinder volume 54 2.326033e-79 2.326033e-79 0.001171 0.000145 1.625698e-10 1.625698e-10
45 5.013102e-01 5.156943e-22 mix 44 cylinder volume + sphere error 54 2.326033e-79 2.326033e-79 0.001131 0.000021 1.625698e-10 1.503020e-08
46 1.000000e+00 1.000000e+00 mix 44 inscribed 54 1.980588e-76 2.326033e-79 0.001849 0.004849 1.625698e-10 1.625698e-10
47 2.007812e-03 1.000000e+00 mix 5 cylinder surface 20 0.000000e+00 0.000000e+00 0.000702 0.003157 8.857458e-05 8.857458e-05
48 1.076230e-02 9.999757e-01 mix 5 cylinder surface + sphere error 20 3.713628e-24 0.000000e+00 0.001487 0.001728 8.857458e-05 1.162429e-03
49 5.057673e-01 7.233206e-01 mix 5 cylinder surface + sphere error + join e... 20 0.000000e+00 0.000000e+00 0.000806 0.001133 8.857458e-05 8.857458e-05
50 1.000000e+00 4.003273e-09 mix 5 cylinder volume 20 0.000000e+00 0.000000e+00 0.001530 0.000330 8.857458e-05 8.857458e-05
51 1.000000e+00 4.003273e-09 mix 5 cylinder volume + sphere error 20 0.000000e+00 0.000000e+00 0.001382 0.000015 8.857458e-05 8.857458e-05
52 1.000000e+00 4.003273e-09 mix 5 cylinder volume + sphere error + join error 20 0.000000e+00 0.000000e+00 0.001381 0.000013 8.857458e-05 8.857458e-05
53 1.000000e+00 1.000000e+00 mix 5 inscribed 20 0.000000e+00 0.000000e+00 0.002926 0.006626 8.857458e-05 8.857458e-05
54 8.396949e-12 1.000000e+00 mix 6 cylinder surface 27 3.381669e-197 3.381669e-197 0.000468 0.002969 5.606117e-06 5.606117e-06
55 9.879696e-01 9.999130e-01 mix 6 cylinder surface + sphere error 27 3.381669e-197 3.381669e-197 0.003293 0.001586 5.606117e-06 9.043841e-01
56 9.999990e-01 6.054686e-04 mix 6 cylinder surface + sphere error + join e... 27 3.381669e-197 3.381669e-197 0.001140 0.000798 5.606117e-06 5.606117e-06
57 1.000000e+00 8.396949e-12 mix 6 cylinder volume 27 3.381669e-197 3.381669e-197 0.001468 0.000197 5.606117e-06 5.606117e-06
58 1.000000e+00 2.300053e-10 mix 6 cylinder volume + sphere error 27 3.381669e-197 3.381669e-197 0.001411 0.000229 5.606117e-06 4.140142e-01
59 1.000000e+00 2.300053e-10 mix 6 cylinder volume + sphere error + join error 27 3.381669e-197 3.381669e-197 0.001410 0.000239 5.606117e-06 4.564078e-01
60 1.000000e+00 1.000000e+00 mix 6 inscribed 27 3.381669e-197 3.381669e-197 0.002397 0.006119 5.606117e-06 5.606117e-06
61 2.124039e-12 1.000000e+00 mix 7 cylinder surface 36 2.167498e-46 2.167498e-46 0.000515 0.003463 1.680296e-07 1.680296e-07
62 9.851140e-01 9.999532e-01 mix 7 cylinder surface + sphere error 36 2.167498e-46 2.167498e-46 0.003186 0.001756 1.680296e-07 3.666216e-02
63 1.000000e+00 2.687603e-04 mix 7 cylinder surface + sphere error + join e... 36 2.167498e-46 2.167498e-46 0.001369 0.000796 1.680296e-07 1.680296e-07
64 1.000000e+00 3.207465e-15 mix 7 cylinder volume 36 2.167498e-46 2.167498e-46 0.001747 0.000251 1.680296e-07 1.680296e-07
65 1.000000e+00 2.124039e-12 mix 7 cylinder volume + sphere error 36 2.167498e-46 2.167498e-46 0.001680 0.000311 1.680296e-07 2.843639e-04
66 1.000000e+00 2.124039e-12 mix 7 cylinder volume + sphere error + join error 36 2.167498e-46 2.167498e-46 0.001681 0.000333 1.680296e-07 2.366648e-04
67 1.000000e+00 1.000000e+00 mix 7 inscribed 36 2.167498e-46 2.167498e-46 0.002767 0.007155 1.680296e-07 1.680296e-07
68 8.396949e-12 1.000000e+00 mix 8 cylinder surface 27 3.381669e-197 3.381669e-197 0.000512 0.002995 5.606117e-06 5.606117e-06
69 7.758394e-01 9.999990e-01 mix 8 cylinder surface + sphere error 27 3.381669e-197 6.041819e-38 0.003194 0.001958 5.606117e-06 1.634838e-01
70 9.999999e-01 2.297338e-01 mix 8 cylinder surface + sphere error + join e... 27 3.381669e-197 6.041819e-38 0.001128 0.001299 5.606117e-06 2.910610e-05
71 1.000000e+00 8.396949e-12 mix 8 cylinder volume 27 3.381669e-197 3.381669e-197 0.001480 0.000216 5.606117e-06 5.606117e-06
72 1.000000e+00 1.099431e-06 mix 8 cylinder volume + sphere error 27 3.381669e-197 6.041819e-38 0.001418 0.000550 5.606117e-06 2.204716e-01
73 1.000000e+00 1.099431e-06 mix 8 cylinder volume + sphere error + join error 27 3.381669e-197 6.041819e-38 0.001418 0.000553 5.606117e-06 2.488283e-01
74 1.000000e+00 1.000000e+00 mix 8 inscribed 27 3.381669e-197 3.381669e-197 0.002496 0.006189 5.606117e-06 5.606117e-06
75 3.100324e-03 1.000000e+00 mix 9 cylinder surface 27 3.381669e-197 3.381669e-197 0.000572 0.003069 5.606117e-06 5.606117e-06
76 7.758394e-01 9.994326e-01 mix 9 cylinder surface + sphere error 27 3.381669e-197 3.381669e-197 0.002281 0.001395 2.618048e-05 3.246118e-01
77 9.970696e-01 1.262148e-02 mix 9 cylinder surface + sphere error + join e... 27 3.381669e-197 3.381669e-197 0.000906 0.000944 2.618048e-05 6.281085e-06
78 1.000000e+00 8.396949e-12 mix 9 cylinder volume 27 3.381669e-197 3.381669e-197 0.001496 0.000267 5.606117e-06 5.606117e-06
79 1.000000e+00 8.396949e-12 mix 9 cylinder volume + sphere error 27 3.381669e-197 3.381669e-197 0.001379 0.000170 5.606117e-06 1.708665e-01
80 1.000000e+00 8.396949e-12 mix 9 cylinder volume + sphere error + join error 27 3.381669e-197 3.381669e-197 0.001379 0.000174 5.606117e-06 1.784961e-01
81 1.000000e+00 1.000000e+00 mix 9 inscribed 27 3.381669e-197 3.381669e-197 0.002631 0.006388 5.606117e-06 5.606117e-06
82 3.207465e-15 1.000000e+00 proof mix cylinder surface 36 0.000000e+00 0.000000e+00 0.000453 0.002958 1.680296e-07 1.680296e-07
83 9.954268e-01 9.590435e-01 proof mix cylinder surface + sphere error 36 0.000000e+00 0.000000e+00 0.002761 0.001367 1.680296e-07 6.604218e-02
84 9.999999e-01 7.517910e-06 proof mix cylinder surface + sphere error + jo... 36 0.000000e+00 0.000000e+00 0.001129 0.000730 1.680296e-07 3.857629e-06
85 1.000000e+00 3.207465e-15 proof mix cylinder volume 36 0.000000e+00 0.000000e+00 0.001464 0.000190 1.680296e-07 1.680296e-07
86 1.000000e+00 9.052584e-14 proof mix cylinder volume + sphere error 36 0.000000e+00 0.000000e+00 0.001410 0.000150 1.680296e-07 1.210568e-03
87 1.000000e+00 9.052584e-14 proof mix cylinder volume + sphere error + joi... 36 0.000000e+00 0.000000e+00 0.001409 0.000153 1.680296e-07 9.695364e-04
88 1.000000e+00 1.000000e+00 proof mix inscribed 36 0.000000e+00 0.000000e+00 0.002362 0.006092 1.680296e-07 1.680296e-07
89 9.999581e-01 9.999581e-01 volume fraction overlap 4 inscribed 8 NaN NaN 0.555472 0.357924 4.677735e-03 4.677735e-03
90 NaN NaN volume fraction overlap inscribed 1 NaN NaN 0.789146 0.556912 3.173105e-01 3.173105e-01
91 9.992170e-01 9.992170e-01 volume fraction unconnected 4 inscribed 6 0.000000e+00 0.000000e+00 0.008106 0.019611 2.770785e-02 2.770785e-02

Vybrané experimenty

Následující experimenty vypadají obstojně. mix 4 testuje vždy jen jeden objekt. Navíc to má dobrá čísla objemu při kompenzaci povrchu.


In [30]:
df_graph = show_box(select_df(df, "mix 2 cylinder surface + sphere error"))
df_graph = show_box(select_df(df, "mix 4 cylinder surface + sphere error"))
df_graph = show_box(select_df(df, "mix 6 cylinder surface + sphere error"))



In [ ]:


In [31]:
current_palette = sns.color_palette("deep")
sns.palplot(current_palette)
sns.set_palette(current_palette)



In [32]:
df_graph = show_violin_separated(select_df(df, "mix 4 cylinder surface"))
plt.figure()
df_graph = show_violin_separated(select_df(df, "mix 4 cylinder volume"))
plt.figure()
df_graph = show_violin_separated(select_df(df, "mix 4 cylinder surface + sphere error"))



In [ ]:

Object number


In [33]:
# radius_method.find("surface")

In [34]:
dpi = paper_dpi
date = "2017-10-05 21:00"
# for radius_method in available_radius_methods:
for radius_method in [
    "inscribed",
    "cylinder volume + sphere error",
    "cylinder surface + sphere error",
    "cylinder surface",
]:
    dfs = df[
        df[note_key] == "element number " + radius_method
        # df["generators Unconnected cylinders radius_distribution_mean"] == 5 
    ]
    dfs = dfs[dfs["measurement resolution"] > 10]
    dfs = dfs[dfs["element number"] > 10]
    dfs = dfs[dfs["measurement resolution"] != 15]
    dfs = dfs[dfs["measurement resolution"] != 25]
    l1 = len(dfs)
    dfs = newer_data(dfs, date)
    print("{}/{}".format(len(dfs), l1))
    if len(dfs) < 1:
        continue
    sns.set_context(context)

    # surface
    if radius_method.find("volume") < 0:
        ykey="surface error [mm^2]"
        ykey="surface error [%]"
        dfs_group = dfs[["element number", "measurement_resolution", ykey]].sort_values(by="element number").groupby(by="measurement_resolution")
        # .plot(x="element_number")
        fig, ax = plt.subplots(
    #         figsize=(5,3)
        )
        # dfs_group.plot(x="element_number", y="surface error [%]", ax=ax)
        for label, dfi in dfs_group:
            #dfi.plot(x="element number", y=ykey, ax=ax, label="resolution={}".format(label))
            dfi.groupby(by="element number").mean().reset_index().plot(x="element number", y=ykey, ax=ax, label="resolution={}".format(label))
        #    df.vals.plot(x="element_number", ax=ax, label=label)
        #plt.legend()
        plt.ylabel(ykey)
        plt.suptitle(radius_method)
        fn = output_fn_prefix + "sensitivity_element_number_surface_" + radius_method 
        savefig(fn, dataframe=dfs)
    #     plt.savefig(fn + ".pdf", bbox_inches='tight')
    #     plt.savefig(fn + ".png", bbox_inches='tight', dpi=dpi)

    # volume
    if radius_method.find("surface") < 0:
        ykey="volume error [mm^3]"
        ykey="volume error [%]"
        dfs_group = dfs[["element number", "measurement_resolution", ykey]].sort_values(by="element number").groupby(by="measurement_resolution")
        # .plot(x="element_number")

        fig, ax = plt.subplots(
    #         figsize=(5,3)
        )
        # dfs_group.plot(x="element_number", y="surface error [%]", ax=ax)
        for label, dfi in dfs_group:
            dfi.groupby(by="element number").mean().reset_index().plot(x="element number", y=ykey, ax=ax, label="resolution={}".format(label))
        #    df.vals.plot(x="element_number", ax=ax, label=label)
        #plt.legend()
        plt.ylabel(ykey)
        plt.suptitle(radius_method)
        fn = output_fn_prefix + "sensitivity_element_number_volume_" + radius_method 
        savefig(fn, dataframe=dfs)
    #     plt.savefig(fn + ".pdf", bbox_inches='tight')
    #     plt.savefig(fn + ".png", bbox_inches='tight', dpi=dpi)


50/66
51/66
78/78
42/42

In [35]:
# dfs["volume error [%]"]

In [ ]:


In [ ]:


In [ ]:


In [36]:
radius_method = "inscribed"
dfs = df[
    df[note_key] == "element number " + radius_method
        # df["generators Unconnected cylinders radius_distribution_mean"] == 5 
]
k1 = "volume error [%]"
k2 = "measurement_resolution"

k2 in dfs.keys()
sns.lmplot(y=k1, x=k2, data=dfs, order=4, 
           truncate=True
           
#            logx=True
          )


Out[36]:
<seaborn.axisgrid.FacetGrid at 0x7f3a29433390>

Analytic vs numeric


In [37]:
op.dirname(fn)


Out[37]:
'../graphics/paper'

In [38]:
notec = "proof mix"
def create_dir_if_necessary(fn):
    if not op.exists(op.dirname(fn)):
        import os
        os.makedirs(op.dirname(fn))
# notec = "element number"
# notec = "mix 4"

def manwh(dfs, x, y, maximal_error):
        serr = np.abs((dfs[x] - dfs[y]) / dfs[x] )
        mw = scipy.stats.mannwhitneyu(serr, np.ones_like(serr)*maximal_error, alternative="less")[1]
        return mw


def show_anal_vs_num(dfs, x, y, fn, maximal_error=None, save_xls=False, save_subset=True, fn1_fmt=[], fn2_fmt=[]):
    create_dir_if_necessary(fn)
    
    sns.lmplot(data=dfs, x=x, y=y, ci=None, line_kws={"c":sns.color_palette()[1], "alpha":0.1})
    # sns.lmplot(data=dfs, x="volume [mm^3]", y="numeric volume [mm^3]")
    fn1 = fn.format(*fn1_fmt)
    fn2 = fn.format(*fn2_fmt) + "_bland_altman"
    if save_xls:
        if save_subset:
            dfs[[x,y]].to_excel(fn1 + ".xls")
        else:
            dfs.to_excel(fn1 + ".xls")
    savefig(fn1)

    plt.figure()
    mean, diff = bland_altman_plot(dfs[x], dfs[y], c=sns.color_palette()[0])
#     plt.suptitle("Bland-Altman plot")
    savefig(fn2)
    if save_xls:
        if save_subset:
            dfsav = dfs[[x,y]]
            dfsav["Average of two measures"] = mean
            dfsav["Difference between two measures"] = mean
            dfsav.to_excel(fn2 + ".xls")
    if maximal_error is not None:
        print(x)
        print(manwh(dfs, x, y, maximal_error))
    
fn = output_fn_prefix + "Figure2/Fig2{}_num_volume_to_anal_volume"
x = "volume [mm^3]"
y = "numeric volume [mm^3]"
dfs = select_df(df, note=notec + " cylinder volume + sphere error")
dfs = dfs[dfs["measurement resolution"] > 20]
show_anal_vs_num(dfs, x, y, fn, maximal_error=maximal_error, fn1_fmt=["B"], fn2_fmt=["D"], save_xls=True)
# dfs1 = [dfs[note]]


volume [mm^3]
9.0525839414e-14
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:37: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [39]:
x="surface [mm^2]"
y="numeric surface [mm^2]"
fn = output_fn_prefix + "Figure2/Fig2{}_num_surface_to_anal_surface"
# dfs_surface = select_df(df, note=notec + " cylinder surface + sphere error")
dfs_surface = select_df(df, note=notec + " cylinder surface")
show_anal_vs_num(dfs_surface, x, y, fn, maximal_error=maximal_error, fn1_fmt=["A"], fn2_fmt=["C"], save_xls=True)

# sns.lmplot(data=dfs, x="surface [mm^2]", y="numeric surface [mm^2]", line_kws={"c":sns.color_palette()[1], "alpha":0.1})
# # sns.lmplot(data=dfs, x="volume [mm^3]", y="numeric volume [mm^3]")
# savefig("../graphics/num_surface_to_anal_surface")


Not enough space under red line
('text offset', 0.015288000000000003)
surface [mm^2]
3.20746530942e-15
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:37: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Compare manual vs analytic measurement


In [40]:
dfmanual = pd.read_excel("/home/mjirik/Dropbox/science/clanky/2017-tonar/output_rows_modified_newnoise_MB_4-9-2017_errors.xls", skip_footer=1)

In [41]:
for key in dfmanual.keys():
    print(key)


config filepattern
uct measurement count [] (počet samostatých nedotýkajících se objektů)
uct measurement length [mm]  (průměrná délka objektů ve stacku)
uct  element length std (směrodatná odchylka délek)
uct measurement total length  [mm](celková délka objektů ve stacku)
uct length density [mm^-2] (objemový podíl celkové délky objektů na objem  stacku)
uct measurement volume mean [mm^3] (průměrný objem objektů ve stacku)
uct  element volume std (směrodatná odchylka objemu)
uct measurement total volume  [mm^3] (celkový objem objektů ve stacku)
uct volume fraction [] (objemový podíl objektů ve stacku)
uct measurement surface mean [mm^2] (průměrný povrch objektů ve stacku) 
uct  element surface std (směrodatná odchylka povrchu)
uct measurement total volume  [mm^2] (celkový povrch objektů ve stacku)
uct surface density [mm^-1] (povrchová hustota objektů ve stacku, tj. celkový povrch dělený objemem stacku)
uct measurement diameter mean [mm] (průměrný průměr objektů ve stacku)
uct radius std (směrodatná odchylka poloměru)
micro-CT measurement area volume [mm^3]
measurement area volume [mm^3]
measurement count []
measurement length [mm]
measurement length d. [mm^-2]
measurement numeric surface [mm^2]
measurement numeric volume [mm^3]
measurement surface [mm^2]
measurement surface d. [mm^-1]
measurement volume [mm^3]
measurement volume d. []
config appearance noise_preview
config appearance show_aposteriori_surface
config appearance skip_volume_generation
config areasampling areasize_mm
config areasampling areasize_px
config areasampling voxelsize_mm
config filepattern.1
config filepattern_series_number
config generator_id
config generators Continuous tubes element_number
config generators Continuous tubes radius_distribution_fixed
config generators Continuous tubes radius_distribution_maximum
config generators Continuous tubes radius_distribution_mean
config generators Continuous tubes radius_distribution_minimum
config generators Continuous tubes radius_distribution_normal
config generators Continuous tubes radius_distribution_standard_deviation
config generators Continuous tubes radius_distribution_uniform
config generators Continuous tubes random_generator_seed
config generators Gensei n_objects
config generators Unconnected tubes allow_overlap
config generators Unconnected tubes element_number
config generators Unconnected tubes last_element_can_be_smaller
config generators Unconnected tubes length_distribution_mean
config generators Unconnected tubes length_distribution_standard_deviation
config generators Unconnected tubes maximum_1000_iteration_number
config generators Unconnected tubes orientation_alpha_rad
config generators Unconnected tubes orientation_anisotropic
config generators Unconnected tubes orientation_beta_rad
config generators Unconnected tubes orientation_variance_rad
config generators Unconnected tubes radius_distribution_fixed
config generators Unconnected tubes radius_distribution_maximum
config generators Unconnected tubes radius_distribution_mean
config generators Unconnected tubes radius_distribution_minimum
config generators Unconnected tubes radius_distribution_normal
config generators Unconnected tubes radius_distribution_standard_deviation
config generators Unconnected tubes radius_distribution_uniform
config generators Unconnected tubes random_generator_seed
config generators Unconnected tubes tube_shape
config generators Unconnected tubes volume_fraction
config generators Voronoi tubes element_number
config generators Voronoi tubes radius_distribution_fixed
config generators Voronoi tubes radius_distribution_maximum
config generators Voronoi tubes radius_distribution_mean
config generators Voronoi tubes radius_distribution_minimum
config generators Voronoi tubes radius_distribution_normal
config generators Voronoi tubes radius_distribution_standard_deviation
config generators Voronoi tubes radius_distribution_uniform
config generators Voronoi tubes random_generator_seed
config measurement polygon_radius_selection_method
config measurement tube_shape
config output aposteriori_measurement
config output aposteriori_measurement_multiplier
config output note
config output one_row_filename
config postprocessing add_noise
config postprocessing background_intensity
config postprocessing gaussian_blur
config postprocessing gaussian_filter_sigma_mm
config postprocessing intensity_profile_intensity
config postprocessing intensity_profile_radius
config postprocessing limit_negative_intensities
config postprocessing measurement_resolution
config postprocessing negative
config postprocessing noise_exponent
config postprocessing noise_lambda0
config postprocessing noise_lambda1
config postprocessing noise_mean
config postprocessing noise_rng_seed
config postprocessing noise_std
config postprocessing output_dtype
config output note.1
Unnamed: 98
Unnamed: 99
Unnamed: 100
Unnamed: 101
Unnamed: 102
Unnamed: 103
Unnamed: 104
Unnamed: 105
Unnamed: 106
processing_info datetime
processing_info step1_finished
processing_info step1_generate_time_s
processing_info step1_generate_vtk_time_s
processing_info step1_init_datetime
processing_info step1_total_time_s
processing_info step2_finish_datetime
processing_info step2_finished
processing_info step2_generate_volume_time_s
processing_info step2_init_datetime
processing_info step2_numeric_measurement_time_s
processing_info step2_save_volume_time_s
processing_info step2_total_time_s

In [42]:
maximal_uct_error = 0.20
ren = {
    u"uct surface density [mm^-1] (povrchová hustota objektů ve stacku, tj. celkový povrch dělený objemem stacku)": "Micro-CT surface density [mm^-1]",
    "measurement surface d. [mm^-1]": "analytic surface density [mm^-1]",
    u"uct volume fraction [] (objemový podíl objektů ve stacku)": "Micro-CT volume fraction []",
    "measurement volume d. []": "analytic volume fraction []"
}
dfmanualr = dfmanual.rename(columns=ren)
fn = output_fn_prefix + "Figure7/Fig7{}_uct_surface_to_anal_surface"
# dfmanualr["uct surface density [mm^-1]"]
show_anal_vs_num(dfmanualr, "analytic surface density [mm^-1]", "Micro-CT surface density [mm^-1]", fn, maximal_error=maximal_uct_error, save_xls=True, fn1_fmt=["A"], fn2_fmt=["C"])
fn = output_fn_prefix + "Figure7/Fig7{}_uct_volume_to_anal_volume"
show_anal_vs_num(dfmanualr, "analytic volume fraction []", "Micro-CT volume fraction []", fn, maximal_error=maximal_uct_error, fn1_fmt=["B"], fn2_fmt=["D"], save_xls=True)


/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:37: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
analytic surface density [mm^-1]
6.62407856396e-14
analytic volume fraction []
1.0

Boxplot

fousy jsou 1.5 násobkem IQR interquartile range

Box represents two quartile Q1 to quartile Q3 separated by the median. Whiskers are Q1 - 1.5 (Q3 - Q1) and Q3 + 1.5 (Q3-Q1).


In [43]:
# notec = "element number"
# == puvodni definice datasetu
dfs = select_df(df, note_contains=notec)
dfs = select_df(dfs, note_contains="surface", remove=True)
dfs = select_df(dfs, note_contains="join", remove=True)
dfs = dfs[dfs["measurement resolution"] > 20]
# ==

# dfs = select_df(dfs, note_contains="mix 4", remove)
save_subset = True
save_all_data = False
xl = "radius method"
yl = "volume error [%]"
anall = "volume [mm^3]"
numerl = "numeric volume [mm^3]"
fn = output_fn_prefix + "Figure2/Fig2F_boxplot_volume"

# def error_boxplot(dfs, yl, xl, fn=None, anall=None, numerl=None, save_all_data=False, save_subset=True)
g = sns.boxplot(data=dfs, y=yl, x=xl, showfliers=False)
labels = [mtext.get_text() for mtext in g.get_xticklabels()]

# pn = labels[2].find("+") 
labels[2] = "cylinder volume +\n sphere error"
g.set_xticklabels(labels, rotation=5)
# g.set_xlabel = "compensation method"
# g.set_xlabel("measurement compensation method")
plt.xlabel("")

if save_subset:
    savefig(fn)
    dfs[[xl, yl, anall, numerl]].to_excel(fn + ".xls")
if save_all_data:
# save all whole data table
    savefig(fn, dataframe=dfs)



In [ ]:


In [44]:
dfs = select_df(df, note_contains=notec)
dfs = select_df(dfs, note_contains="volume", remove=True)
dfs = select_df(dfs, note_contains="join", remove=True)
dfs = dfs[dfs["measurement resolution"] > 20]

xl = "radius method"
yl = "surface error [%]"
anall = "surface [mm^2]"
numerl = "numeric surface [mm^2]"
fn = output_fn_prefix + "Figure2/Fig2E_boxplot_surface"


# dfs = select_df(dfs, note_contains="mix 4", remove)
g = sns.boxplot(data=dfs, y=yl, x=xl, showfliers=False)
labels = [mtext.get_text() for mtext in g.get_xticklabels()]
# labels[2] = "cylinder volume +\n sphere error"
g.set_xticklabels(labels, rotation=5)
plt.xlabel("")

if save_subset:
    savefig(fn)
    dfs[[xl, yl, anall, numerl]].to_excel(fn + ".xls")
if save_all_data:
# save all whole data table
    savefig(fn, dataframe=dfs)



In [ ]:


In [45]:
dfs = select_df(df, note_contains=notec)
# dfs = select_df(dfs, note_contains="volume", remove=True)
dfs = select_df(dfs, note_contains="join", remove=True)
dfs = dfs[dfs["measurement resolution"] > 20]

mw_surf_key = "Wilcoxon Mann Whitney surface error < 0.1 %"
mw_vol_key = "Wilcoxon Mann Whitney vol error < 0.1 %"

maximal_error = 0.001
data = {
    "config output note": [],
#     "wilcoxon volume": [],
    "spearman volume": [],
#     "wilcoxon surface" : [],
    "spearman surface" : [],
    mw_surf_key: [],
    mw_vol_key: [],
    "number of samples": [],
    "surface mean err": [],
    "volume mean err": [],
#     "surface mean err test": [],
#     "volume mean err test": [],
#     "mannwhitneyu volume test": [],
#     "mannwhitneyu surface test": [],
}
for note in np.unique(dfs["config output note"]):
    dfsi = dfs[dfs["config output note"] == note]
#     vw, vs, sw, ss = statistic_tests(dfs)
    sw, vw = wilcoxon_from_df(dfsi)
    sm, vm = mannthitneyu_from_df(dfsi, maximal_error)
    ss, vs = spearman_from_df(dfsi)
    data["config output note"].append(note)
#     data["wilcoxon volume"].append(vw.pvalue)
    data["spearman volume"].append(vs.pvalue)
#     data["wilcoxon surface"].append(sw.pvalue)
    data["spearman surface"].append(ss.pvalue)
    data["number of samples"].append(len(dfsi))
    
#     if len(dfs) > 3:
#         serrt = np.abs((dfs["surface [mm^2]"] - dfs["numeric surface [mm^2]"]) / dfs["surface [mm^2]"] )
#         verrt = np.abs((dfs["volume [mm^3]"] - dfs["numeric volume [mm^3]"]) / dfs["volume [mm^3]"] )
#         surf_sh = scipy.stats.mannwhitneyu(serrt, np.ones_like(serrt)*maximal_error, alternative="less")[1]
#         vol_sh = scipy.stats.mannwhitneyu(verrt, np.ones_like(verrt)*maximal_error, alternative="less")[1]
# #         surf_sh = np.mean(err)
# #         surf_sh = scipy.stats.shapiro(dfs["surface [mm^2]"] - dfs["numeric surface [mm^2]"])
#     else:
#         surf_sh = NaN
#         vol_sh = NaN
#         serrt = NaN
#         verrt = NaN
#     Wilcoxon–Mann–Whitney test
    data[mw_surf_key].append(sm)
    data[mw_vol_key].append(vm)
#     data["mannwhitneyu surface test"].append(surf_sh)
#     data["mannwhitneyu volume test"].append(vol_sh)
    data["surface mean err"].append(np.mean(dfsi["surface error [-]"]))
    data["volume mean err"].append(np.mean(dfsi["volume error [-]"]))
#     data["surface mean err test"].append(np.mean(serrt))
#     data["volume mean err test"].append(np.mean(verrt))
    
#     show_error(dfs, radius_method=note)
# pd.set_option("display.max_rows",101)
pd.DataFrame(data)
pd.DataFrame(data)

# mann-whitney by měl vycházet pod 0.05


Out[45]:
Wilcoxon Mann Whitney surface error < 0.1 % Wilcoxon Mann Whitney vol error < 0.1 % config output note number of samples spearman surface spearman volume surface mean err volume mean err
0 3.207465e-15 1.000000e+00 proof mix cylinder surface 36 0.0 0.0 0.000453 0.002958
1 9.954268e-01 9.590435e-01 proof mix cylinder surface + sphere error 36 0.0 0.0 0.002761 0.001367
2 1.000000e+00 3.207465e-15 proof mix cylinder volume 36 0.0 0.0 0.001464 0.000190
3 1.000000e+00 9.052584e-14 proof mix cylinder volume + sphere error 36 0.0 0.0 0.001410 0.000150
4 1.000000e+00 1.000000e+00 proof mix inscribed 36 0.0 0.0 0.002362 0.006092

In [46]:
uu = g.get_xticklabels()
mtext = uu[0]
mtext.get_text()


Out[46]:
u'inscribed'

Bland-Altman plot


In [47]:
# bland_altman_plot

In [48]:
sns.color_palette()[1]


Out[48]:
(0.3333333333333333, 0.6588235294117647, 0.40784313725490196)

Error and measurement resolution


In [49]:
# zip(list(dfs_group))

# for radius_method in available_radius_methods:
# radius_method = "inscribed"
# dfs = df[
#     df[note_key] == "element number " + radius_method
#     # df["generators Unconnected cylinders radius_distribution_mean"] == 5 
# ]
dfs = select_df(df, note_contains="element number ")
dfs = select_df(dfs, note_contains="join", remove=True)
dfs = select_df(dfs, note_contains="volume", remove=True)
l1 = len(dfs)
dfs = newer_data(dfs, date)
print("{}/{}".format(len(dfs), l1))
if len(dfs) < 1:
    print "blbe"
#     continue
xkey="measurement resolution"
ykey="surface error [%]"
# .plot(x="element_number")
sns.set_context("talk")

dfs_group = dfs[[ykey, xkey, note_key]].sort_values(by=xkey).groupby(by=note_key)
fig, ax = plt.subplots(
#         figsize=(5,3)
)
    # dfs_group.plot(x="element_number", y="surface error [%]", ax=ax)
for label, dfi in dfs_group:
    dfi.groupby(by=xkey).mean().abs().reset_index().plot(x=xkey, y=ykey, ax=ax, label="{}".format(label[15:]))
plt.ylabel(ykey)
plt.xlabel(xkey)
fn = output_fn_prefix + "sensitivity_surface_error_to_measurement_resolution"

savefig(fn, dataframe=dfs)


# dfs_group.plot(x=xkey, y=ykey)
xkey="measurement resolution"
ykey="volume error [%]"
# .plot(x="element_number")
sns.set_context("talk")

dfs = select_df(df, note_contains="element number ")
dfs = select_df(dfs, note_contains="join", remove=True)
dfs = select_df(dfs, note_contains="surface", remove=True)
dfs_group = dfs[[ykey, xkey, note_key]].sort_values(by=xkey).groupby(by=note_key)
fig, ax = plt.subplots(
#         figsize=(5,3)
)
    # dfs_group.plot(x="element_number", y="surface error [%]", ax=ax)
for label, dfi in dfs_group:
    dfi.groupby(by=xkey).mean().abs().reset_index().plot(x=xkey, y=ykey, ax=ax, label="{}".format(label[15:]))
plt.ylabel(ykey)
plt.xlabel(xkey)
fn = output_fn_prefix + "sensitivity_volume_error_to_measurement_resolution"
savefig(fn, dataframe=dfs)


253/280

In [50]:
sns.lmplot(data=dfs, x="measurement resolution", y="volume error [%]", hue=note_key, order=1, logx=True)
# dfs


/home/mjirik/miniconda2/lib/python2.7/site-packages/seaborn/regression.py:277: RuntimeWarning: divide by zero encountered in log
  grid = np.c_[np.ones(len(grid)), np.log(grid)]
Out[50]:
<seaborn.axisgrid.FacetGrid at 0x7f3a2c41bdd0>

In [51]:
# dfi.groupby(by="measurement_resolution").mean().abs().reset_index().plot(x=xkey, y=ykey, ax=ax, label="resolution={}".format(label))
# dfi

In [52]:
# dfs_group = dfs[["surface error [%]", "measurement_resolution" ]].sort_values(by="measurement_resolution")#.groupby(by="surface error")
# dfs_group
# label
# dfi

Volume fraction data


In [53]:
dfs = select_df(df, note_contains= "volume fraction")
# dfs = df[
#     df[note_key] == "volume fraction overlap inscribed"
# ]
# np.unique(df[note_key])
dfs["numeric volume [mm^3]"]
print(list_filter(dfs.keys(), contain="area"))

# print(list_filter(dfs.keys(), contain="frac"))
volume_fraction = dfs["numeric volume [mm^3]"] / dfs["measurement area volume [mm^3]"]
dfs["volume fraction"] = volume_fraction
print(volume_fraction)
dfs[[note_key, "volume fraction"]]


['config areasampling areasize_mm', 'config areasampling areasize_px', 'config areasampling voxelsize_mm', 'measurement area volume [mm^3]']
3951     0.795136
5591     0.480873
5592     0.480873
5593     0.480873
5594     0.480873
5595     0.480873
5596     0.480873
5597     0.480873
5598     0.480873
13275    0.105338
13276    0.166921
13277    0.207468
13279    0.216790
13281    0.026190
13283    0.104759
dtype: float64
/home/mjirik/miniconda2/lib/python2.7/site-packages/ipykernel/__main__.py:11: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
Out[53]:
config output note volume fraction
3951 volume fraction overlap inscribed 0.795136
5591 volume fraction overlap 4 inscribed 0.480873
5592 volume fraction overlap 4 inscribed 0.480873
5593 volume fraction overlap 4 inscribed 0.480873
5594 volume fraction overlap 4 inscribed 0.480873
5595 volume fraction overlap 4 inscribed 0.480873
5596 volume fraction overlap 4 inscribed 0.480873
5597 volume fraction overlap 4 inscribed 0.480873
5598 volume fraction overlap 4 inscribed 0.480873
13275 volume fraction unconnected 4 inscribed 0.105338
13276 volume fraction unconnected 4 inscribed 0.166921
13277 volume fraction unconnected 4 inscribed 0.207468
13279 volume fraction unconnected 4 inscribed 0.216790
13281 volume fraction unconnected 4 inscribed 0.026190
13283 volume fraction unconnected 4 inscribed 0.104759

volume fraction 34%

ke stažení zde Tenhle má cca 1000 objektů a výpočet zabere kolem 5ti hodin. Ještě se snažím vytvořit větší zaplnění. Až se dostanu přes 50% vygeneruju i obrázky.

Computation info


In [54]:
id_of_requested_table = 0
dfcinfo = pd.read_html("hardinfo_report.html")[id_of_requested_table]
# df
dfcinfo[(dfcinfo[0] == "Operating System") | (dfcinfo[0] == "Memory") | (dfcinfo[0] == "Processor")]
# memory_str = df[df[0] == "Memory" ].iloc[0][1]
# memory_str[0:memory_str.find(" (")]


Out[54]:
0 1
2 Processor 4x Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz
3 Memory 8129MB (4283MB used)
4 Operating System Ubuntu 16.04.3 LTS

In [55]:
import imtools
import imtools.dili as dili
dfs = select_df(df, note_contains="generated")
req_keys = list(dili.list_contains(dfs.keys(), "time [s]"))
req_keys.append(note_key)
dfsm = dfs[req_keys].groupby(by=note_key).agg(["min", "max", "mean", "std"])
display(dfsm)


step 1 time [s] step 2 time [s] total time [s]
min max mean std min max mean std min max mean std
config output note
generated volume element_number anisotropic inscribed 38.067334 943.498296 399.942898 301.944696 18.566351 77.062346 46.914479 19.266408 56.633685 1020.560642 446.857378 320.514139
generated volume isotropy inscribed 80.243249 93.768053 90.037884 4.094332 24.964832 517.954692 63.729704 107.140593 105.208081 608.299338 153.767588 107.532475
generated volume length inscribed 78.629314 99.982460 87.964211 6.884682 13.760947 189.663245 34.923465 41.636544 92.397705 268.292559 122.887676 42.837337
generated volume noise inscribed 96.139334 97.079383 96.663124 0.285720 92.011967 160.093097 154.491107 14.768321 188.151301 257.172480 251.154231 14.880327
generated volume radius inscribed 9.242478 140.440047 78.798792 34.741947 27.609752 277.606368 123.353067 98.997194 123.314850 359.767343 199.069796 76.759503
generated volume resolution_mm inscribed 96.829405 102.029161 97.574106 1.538118 0.289337 517.954692 34.890713 118.328807 97.181585 615.050720 132.230342 118.253473

In [56]:
dfsm.describe()


Out[56]:
step 1 time [s] step 2 time [s] total time [s]
min max mean std min max mean std min max mean std
count 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000 6.000000
mean 66.525186 246.132900 141.830169 58.248249 29.533864 290.055740 76.383756 66.689644 110.481201 521.523847 217.661168 113.462876
std 35.273777 342.066459 126.631575 120.072529 32.101107 187.811597 50.549117 46.731371 43.883027 291.714889 121.951759 108.611204
min 9.242478 93.768053 78.798792 0.285720 0.289337 77.062346 34.890713 14.768321 56.633685 257.172480 122.887676 14.880327
25% 48.207829 97.805152 88.482629 2.177171 14.962298 167.485634 37.921219 24.858942 93.593675 291.161255 137.614653 51.317878
50% 79.436282 101.005810 93.350504 5.489507 21.765591 233.634807 55.322091 70.316869 101.194833 484.033341 176.418692 92.145989
75% 92.165313 130.837325 97.346360 27.777631 26.948522 457.867611 108.447226 105.104743 118.788158 613.362875 238.133122 115.573224
max 96.829405 943.498296 399.942898 301.944696 92.011967 517.954692 154.491107 118.328807 188.151301 1020.560642 446.857378 320.514139

measurement resolution dependency


In [57]:
# element number inscribed
dfs = select_df(df, newer_than="2017-10-05", note="element number inscribed")
req_keys = list(dili.list_contains(dfs.keys(), "time [s]"))
req_keys.append(note_key)
dfsm = dfs[req_keys].groupby(by=note_key).agg(["min", "max", "mean", "std"])
display(dfsm)
# display(sns.lmplot(data=dfs, x="element number", y="processing_info step1_total_time_s"))
# display(sns.lmplot(data=dfs[dfs["element number"] == 50], x="measurement_resolution", y="processing_info step1_total_time_s", order=3))
display(sns.lmplot(data=dfs[dfs["element number"] >= 40], x="measurement resolution", y="step 1 time [s]", order=3))
display(sns.lmplot(data=dfs[dfs["measurement resolution"] >= 60], x="element number", y="step 1 time [s]", order=3))
# dili.list_contains(dfs.keys(), "resolution")


step 1 time [s] step 2 time [s] total time [s]
min max mean std min max mean std min max mean std
config output note
element number inscribed 0.761139 185.648213 59.91961 48.360153 0.021872 0.509206 0.197092 0.134437 0.817495 186.053428 60.116702 48.43324
<seaborn.axisgrid.FacetGrid at 0x7f3a29110450>
<seaborn.axisgrid.FacetGrid at 0x7f3a291103d0>

Dataset configuration


In [58]:
import collections

def ordered_dict_to_dict(config):
    """
    Use dict instead of ordered dict in structure. 
    """
    
    if type(config) == collections.OrderedDict:
        config = dict(config)
    if type(config) == list:
        for i in range(0, len(config)):
            config[i] = ordered_dict_to_dict(config[i])
    elif type(config) == dict:
        for key in config:
            config[key] = ordered_dict_to_dict(config[key])

    return config
# run_lists

Datasets

Generated Dataset 1


In [59]:
# Save measured
notec = "generated"
dfs = select_df(df, note_contains=notec)
dfs.to_excel(output_fn_prefix + "Dataset1.xls")
dfs.to_csv(output_fn_prefix + "Dataset1.csv")

In [60]:
%run paper_experiments_params.ipynb
config = get_paper_config()


Populating the interactive namespace from numpy and matplotlib
Populating the interactive namespace from numpy and matplotlib
0/4277
/home/mjirik/projects/teigen
Using QVariant and QString version 1
['/home/mjirik/projects/teigen/teigen']
INFO:teigen.tgmain:Starting Teigen
INFO:teigen.tgmain:Starting Teigen


In [61]:
import pprint
pp = pprint.PrettyPrinter(indent=2)
# pp.pprint(config)

config


isinstance(1, collections.Iterable)
    
        
        
new_config = ordered_dict_to_dict(config)
# pp.pprint(new_config)
import yaml
print(yaml.dump(new_config, default_flow_style=False))

# dict(config)

# def sprint(structure, indent=):
#     for item in structure


appearance:
  force_rewrite: false
  noise_preview: false
  show_aposteriori_surface: true
  skip_volume_generation: false
  surface_3d_preview: false
areasampling:
  areasize_mm:
  - 10.0
  - 10.0
  - 10.0
  areasize_px:
  - 500.0
  - 500.0
  - 500.0
  voxelsize_mm:
  - 0.02
  - 0.02
  - 0.02
filepattern: ~/teigen_data/{seriesn:03d}/data{:06d}.jpg
filepattern_abspath: null
generator_id: 3
generators:
  Connected tubes:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Porosity:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Unconnected tubes:
    allow_overlap: false
    element_number: 30
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 0.1
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: false
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: false
    radius_distribution_maximum: 3.0
    radius_distribution_mean: 0.2
    radius_distribution_minimum: 0.02
    radius_distribution_normal: true
    radius_distribution_standard_deviation: 0.1
    radius_distribution_uniform: false
    random_generator_seed: 100
    tube_shape: true
    volume_fraction: 0.5
measurement:
  polygon_radius_selection_method: inscribed
  tube_shape: true
output:
  aposteriori_measurement: false
  aposteriori_measurement_multiplier: 1.0
  note: ''
  one_row_filename: ~/teigen_data/output_rows.csv
postprocessing:
  add_noise: false
  background_intensity: 20
  gaussian_blur: true
  gaussian_filter_sigma_mm: 0.04
  intensity_profile_intensity:
  - 195
  - 190
  - 200
  - 30
  intensity_profile_radius:
  - 0.4
  - 0.7
  - 1.0
  - 1.3
  limit_negative_intensities: true
  measurement_resolution: 35
  negative: false
  noise_exponent: 0.0
  noise_lambda0: 0.02
  noise_lambda1: 1.0
  noise_mean: 30.0
  noise_rng_seed: 0
  noise_std: 40.0
  output_dtype: uint8

Dataset 2


In [62]:
# Analytic to numeric 
notec = "proof mix"
dfs = select_df(df, note_contains=notec)
dfs.to_excel(output_fn_prefix + "Dataset2.xls")
dfs.to_csv(output_fn_prefix + "Dataset2.csv")

config_select = select_configs(configs, [notec])
        
config = config_select[0]
new_config = ordered_dict_to_dict(config)
# pp.pprint(new_config)
print(yaml.dump(new_config, default_flow_style=False))


appearance:
  force_rewrite: false
  noise_preview: false
  show_aposteriori_surface: true
  skip_volume_generation: true
  surface_3d_preview: false
areasampling:
  areasize_mm:
  - 100.0
  - 100.0
  - 100.0
  areasize_px:
  - 100
  - 100
  - 100
  voxelsize_mm:
  - 1.0
  - 1.0
  - 1.0
filepattern: ~/teigen_data/mix4_000__{seriesn:03d}/data{:06d}.jpg
filepattern_abspath: null
generator_id: Unconnected tubes
generators:
  Connected tubes:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Porosity:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Unconnected tubes:
    allow_overlap: false
    element_number: 3
    last_element_can_be_smaller: false
    length_distribution_mean: 1.0
    length_distribution_standard_deviation: 0.1
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: false
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: false
    radius_distribution_maximum: 5.0
    radius_distribution_mean: 0.5
    radius_distribution_minimum: 0.1
    radius_distribution_normal: true
    radius_distribution_standard_deviation: 0.1
    radius_distribution_uniform: false
    random_generator_seed: 111
    tube_shape: true
    volume_fraction: 0.5
measurement:
  polygon_radius_selection_method: inscribed
  tube_shape: true
output:
  aposteriori_measurement: false
  aposteriori_measurement_multiplier: 1.0
  note: proof mix inscribed
  one_row_filename: ~/teigen_data/output_rows.csv
  run_label: proof mix
postprocessing:
  add_noise: false
  background_intensity: 20
  gaussian_blur: true
  gaussian_filter_sigma_mm: 0.04
  intensity_profile_intensity:
  - 195
  - 190
  - 200
  - 30
  intensity_profile_radius:
  - 0.4
  - 0.7
  - 1.0
  - 1.3
  limit_negative_intensities: true
  measurement_resolution: 35
  negative: false
  noise_exponent: 0.0
  noise_lambda0: 0.02
  noise_lambda1: 1.0
  noise_mean: 30.0
  noise_rng_seed: 0
  noise_std: 40.0
  output_dtype: uint8

Dataset 3


In [63]:
# Sensitivity
notec = "element number"
dfs = select_df(df, note_contains=notec)
dfs.to_excel(output_fn_prefix + "Dataset3.xls")
dfs.to_csv(output_fn_prefix + "Dataset3.csv")
config_select = select_configs(configs, [notec])
        
config = config_select[0]
new_config = ordered_dict_to_dict(config)
# pp.pprint(new_config)
print(yaml.dump(new_config, default_flow_style=False))


appearance:
  force_rewrite: false
  noise_preview: false
  show_aposteriori_surface: true
  skip_volume_generation: true
  surface_3d_preview: false
areasampling:
  areasize_mm:
  - 200.0
  - 200.0
  - 200.0
  areasize_px:
  - 200.0
  - 200.0
  - 200.0
  voxelsize_mm:
  - 0.2
  - 0.2
  - 0.2
filepattern: ~/teigen_data/{seriesn:03d}/data{:06d}.jpg
filepattern_abspath: null
generator_id: 3
generators:
  Connected tubes:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Porosity:
    allow_overlap: false
    element_number: -1
    last_element_can_be_smaller: false
    length_distribution_mean: 3.0
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: true
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: null
    radius_distribution_maximum: 10.0
    radius_distribution_mean: 1.0
    radius_distribution_minimum: 0.1
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 1.0
    radius_distribution_uniform: null
    random_generator_seed: 0
    tube_shape: true
    volume_fraction: 0.1
  Unconnected tubes:
    allow_overlap: false
    element_number: 10
    last_element_can_be_smaller: false
    length_distribution_mean: 10
    length_distribution_standard_deviation: 1.0
    maximum_1000_iteration_number: 10
    orientation_alpha_rad: 0.0
    orientation_anisotropic: false
    orientation_beta_rad: 0.0
    orientation_variance_rad: 0.1
    radius_distribution: normal
    radius_distribution_fixed: false
    radius_distribution_maximum: 30.0
    radius_distribution_mean: 5.0
    radius_distribution_minimum: 3.0
    radius_distribution_normal: null
    radius_distribution_standard_deviation: 0.1
    radius_distribution_uniform: true
    random_generator_seed: 110
    tube_shape: true
    volume_fraction: 0.5
measurement:
  polygon_radius_selection_method: cylinder surface
  tube_shape: true
output:
  aposteriori_measurement: false
  aposteriori_measurement_multiplier: 1.0
  note: element number cylinder surface
  one_row_filename: ~/teigen_data/output_rows.csv
  run_label: element number
postprocessing:
  add_noise: true
  background_intensity: 20
  gaussian_blur: true
  gaussian_filter_sigma_mm: 1.0
  intensity_profile_intensity:
  - 195
  - 190
  - 200
  - 30
  intensity_profile_radius:
  - 0.4
  - 0.7
  - 1.0
  - 1.3
  limit_negative_intensities: true
  measurement_resolution: 10
  negative: false
  noise_exponent: 0.0
  noise_lambda0: 0.02
  noise_lambda1: 1.0
  noise_mean: 30.0
  noise_rng_seed: 0
  noise_std: 40.0
  output_dtype: uint8