Skip to content

Commit 4f92ca4

Browse files
authored
fix: experiment notebook (#155)
2 parents 9746551 + 976fbe1 commit 4f92ca4

1 file changed

Lines changed: 149 additions & 18 deletions

File tree

notebooks/experiment.ipynb

Lines changed: 149 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "4f3e3089",
6+
"metadata": {},
7+
"source": [
8+
"Load in modules"
9+
]
10+
},
311
{
412
"cell_type": "code",
513
"execution_count": null,
@@ -19,6 +27,33 @@
1927
"%matplotlib inline"
2028
]
2129
},
30+
{
31+
"cell_type": "markdown",
32+
"id": "1bc3fec6",
33+
"metadata": {},
34+
"source": [
35+
"Change a default setting within defdap"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "a3d943f6",
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"from defdap import defaults\n",
46+
"defaults['hrdic_grain_finding_method'] = 'warp'"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"id": "b99a3fe7",
52+
"metadata": {},
53+
"source": [
54+
"Define an empty experiment to load data into"
55+
]
56+
},
2257
{
2358
"cell_type": "code",
2459
"execution_count": null,
@@ -29,14 +64,33 @@
2964
"exp = experiment.Experiment()"
3065
]
3166
},
67+
{
68+
"cell_type": "markdown",
69+
"id": "f619dcd6",
70+
"metadata": {},
71+
"source": [
72+
"Define paths to data. HRDIC path now has a wildcard '*' to use all matched files."
73+
]
74+
},
3275
{
3376
"cell_type": "code",
3477
"execution_count": null,
3578
"id": "2ae42113-e960-4c0c-b800-62604bfefc9f",
3679
"metadata": {},
3780
"outputs": [],
3881
"source": [
39-
"data_dir = Path('/Users/user/Downloads/small_DIC_data_set/')"
82+
"data_dir = Path('./')\n",
83+
"hrdic_dir = data_dir / 'DIC_DaVis_Export'\n",
84+
"hrdic_file_pattern = 'B*.txt'\n",
85+
"ebsd_file = data_dir / 'EBSD/Sample 2.cpr'"
86+
]
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"id": "579fa880",
91+
"metadata": {},
92+
"source": [
93+
"Load HRDIC maps and place them in a new increment (default) in the experiment, but define a single frame they share to make registration easier."
4094
]
4195
},
4296
{
@@ -47,10 +101,18 @@
47101
"outputs": [],
48102
"source": [
49103
"dic_frame = experiment.Frame()\n",
50-
"for dic_file in sorted(data_dir.glob('B*.txt')):\n",
104+
"for dic_file in sorted(hrdic_dir.glob(hrdic_file_pattern)):\n",
51105
" hrdic.Map(dic_file, experiment=exp, frame=dic_frame)"
52106
]
53107
},
108+
{
109+
"cell_type": "markdown",
110+
"id": "7a37a8c4",
111+
"metadata": {},
112+
"source": [
113+
"Load the EBSD and place it in the first incremnet but in a different frame."
114+
]
115+
},
54116
{
55117
"cell_type": "code",
56118
"execution_count": null,
@@ -60,11 +122,19 @@
60122
"source": [
61123
"ebsd_frame = experiment.Frame()\n",
62124
"ebsd.Map(\n",
63-
" data_dir / 'A3_zone1.cpr',\n",
125+
" ebsd_file,\n",
64126
" increment=exp.increments[0], frame=experiment.Frame()\n",
65127
")"
66128
]
67129
},
130+
{
131+
"cell_type": "markdown",
132+
"id": "34382ce4",
133+
"metadata": {},
134+
"source": [
135+
"Define homologous points. This only needs to be done for once for all of the HRDIC maps as they share a reference frame."
136+
]
137+
},
68138
{
69139
"cell_type": "code",
70140
"execution_count": null,
@@ -74,58 +144,119 @@
74144
"source": [
75145
"dic_map = exp.increments[0].maps['hrdic']\n",
76146
"dic_map.frame.homog_points = [\n",
77-
" (259, 225), \n",
78-
" (322, 376), \n",
79-
" (91, 21), \n",
80-
" (365, 97)\n",
147+
" ( 806, 239), (1198, 147), (1445, 376), (1769, 790), (1622, 1341),\n",
148+
" (1782, 1814), (1215, 1473), ( 563, 1617), ( 728, 1295), ( 758, 1102),\n",
149+
" ( 483, 1161), ( 231, 1032), ( 212, 659), (1169, 1066)\n",
81150
"]\n",
151+
"\n",
82152
"ebsd_map = exp.increments[0].maps['ebsd']\n",
83153
"ebsd_map.frame.homog_points = [\n",
84-
" (90, 84), \n",
85-
" (110, 141), \n",
86-
" (31, 10), \n",
87-
" (128, 40)\n",
154+
" (238, 120), (324, 102), (375, 147), (440, 230), (400, 344), \n",
155+
" (429, 440), (310, 371), (166, 399), (207, 334), (216, 295), \n",
156+
" (155, 308), (102, 282), (104, 206), (306, 288)\n",
88157
"]"
89158
]
90159
},
160+
{
161+
"cell_type": "markdown",
162+
"id": "b5284775",
163+
"metadata": {},
164+
"source": [
165+
"Loop over all the HRIDC maps stored in the experiment to set some parameters."
166+
]
167+
},
91168
{
92169
"cell_type": "code",
93170
"execution_count": null,
94-
"id": "2fd94bd2-5485-485a-812a-33628c575a29",
171+
"id": "d663f030",
95172
"metadata": {},
96173
"outputs": [],
97174
"source": [
175+
"field_width = 30 # microns\n",
176+
"num_pixels = 2048\n",
177+
"pixel_size = field_width / num_pixels\n",
178+
"\n",
98179
"for inc, dic_map in exp.iter_over_maps('hrdic'):\n",
180+
" dic_map.set_crop(left=100, right=100, bottom=100, top=100)\n",
99181
" dic_map.link_ebsd_map(ebsd_map, transform_type=\"affine\")\n",
100-
" dic_map.plot_map(\n",
182+
" dic_map.set_scale(pixel_size)"
183+
]
184+
},
185+
{
186+
"cell_type": "markdown",
187+
"id": "74a998de",
188+
"metadata": {},
189+
"source": [
190+
"Loop over the maps and plot a subregion of each map."
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"execution_count": null,
196+
"id": "2fd94bd2-5485-485a-812a-33628c575a29",
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"for inc, dic_map in exp.iter_over_maps('hrdic'):\n",
201+
" plot = dic_map.plot_map(\n",
101202
" 'max_shear', vmin=0, vmax=0.10, \n",
102203
" plot_scale_bar=False, plot_gbs='line'\n",
103204
" )\n",
205+
" plot.ax.set_xlim([800, 1200])\n",
206+
" plot.ax.set_ylim([800, 1200])\n",
104207
" plt.tight_layout()"
105208
]
106209
},
210+
{
211+
"cell_type": "markdown",
212+
"id": "677435e4",
213+
"metadata": {},
214+
"source": [
215+
"As the grain segmentation is done using the same EBSD data, the grain ids for all of the HRDIC should be consistent. So pick the same grain from each time step and plot deformation data over each step."
216+
]
217+
},
107218
{
108219
"cell_type": "code",
109220
"execution_count": null,
110221
"id": "7fef2016-c924-41a4-8036-8240f46cc1fc",
111222
"metadata": {},
112223
"outputs": [],
113-
"source": []
224+
"source": [
225+
"dic_grain_id = 400\n",
226+
"\n",
227+
"num_incs = len(exp.increments)\n",
228+
"fig, axes = plt.subplots(2, int(np.ceil(num_incs / 2)))\n",
229+
"\n",
230+
"for inc, dic_map in exp.iter_over_maps('hrdic'):\n",
231+
" dic_grain = dic_map[dic_grain_id]\n",
232+
" plot = dic_grain.plot_map(\n",
233+
" 'max_shear', vmin=0, vmax=0.10, \n",
234+
" plot_scale_bar=(inc == 0), plot_colour_bar=False,\n",
235+
" fig=fig, ax=axes.flat[inc]\n",
236+
" )\n",
237+
"\n",
238+
"for ax in axes.flat:\n",
239+
" ax.axis('off')\n",
240+
"\n",
241+
"fig.subplots_adjust(right=0.8)\n",
242+
"cbar_ax = fig.add_axes([0.85, 0.15, 0.03, 0.7])\n",
243+
"fig.colorbar(plot.img_layers[0], cax=cbar_ax, label=\"Effective shear strain\")\n"
244+
]
114245
},
115246
{
116247
"cell_type": "code",
117248
"execution_count": null,
118-
"id": "457eba02-2eda-4fe3-b70a-40f73aae3bf1",
249+
"id": "f4392ca6",
119250
"metadata": {},
120251
"outputs": [],
121252
"source": []
122253
}
123254
],
124255
"metadata": {
125256
"kernelspec": {
126-
"display_name": "Python [conda env:defdap]",
257+
"display_name": "workshop_test",
127258
"language": "python",
128-
"name": "conda-env-defdap-py"
259+
"name": "python3"
129260
},
130261
"language_info": {
131262
"codemirror_mode": {
@@ -137,7 +268,7 @@
137268
"name": "python",
138269
"nbconvert_exporter": "python",
139270
"pygments_lexer": "ipython3",
140-
"version": "3.11.0"
271+
"version": "3.13.13"
141272
}
142273
},
143274
"nbformat": 4,

0 commit comments

Comments
 (0)