-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate_word_document.py
More file actions
557 lines (479 loc) · 28.4 KB
/
Create_word_document.py
File metadata and controls
557 lines (479 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# Load routines for working with word
from docx import Document
from docx.shared import Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
from PIL import Image # Import some tools for image resizing, so the word report will not become too large.
# Other routines
import os # Miscellaneous operating system interfaces - https://docs.python.org/2.7/library/os.html
import datetime #https://docs.python.org/2/library/datetime.html
import pickle # Python object serialization - https://docs.python.org/2/library/pickle.html
import re #Regular expression matching operations similar to those found in Perl - https://docs.python.org/2.7/library/re.html
import win32com.client # Load module for Automation of Windows Applications with Python
# Load routines for math and plotting
import matplotlib.pyplot as plt # Matplotlib is a Python 2D plotting library - https://matplotlib.org/
import numpy as np # NumPy is the fundamental package for scientific computing with Python - https://docs.scipy.org/doc/
from pathlib import Path
def ImgResizewithfeedback(path,ImgRefRatio):
'''
This routine will resize the microscopy pictures automatically, so the
word document will not become too large
'''
# setup the width of the resized images
basewidth = 800
# open the image
img = Image.open(path)
# calculate scale factor
imgRatio = float(img.size[0])/float(img.size[1])
if ImgRefRatio>imgRatio:
dimensionFeedback = 'height'
else:
dimensionFeedback = 'width'
wpercent = (basewidth / float(img.size[0]))
# calculate the horizontal width
hsize = int((float(img.size[1]) * float(wpercent)))
# do the rescaling
img = img.resize((basewidth, hsize), Image.Resampling.LANCZOS)
# save a temporary picture in working directory
img.save('resized_image.jpg')
return dimensionFeedback
#Generates a TableCaption below a table in a word report
def TableCaption(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Table \* ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
def TableCaption2(n):
n = n + 1
return n
def FigureCaption2(m):
m = m + 1
return m
#Generates a figure caption for a figure in the word report.
def FigureCaption(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Figure \* ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
#routing for saving picture in accordance with different modes (pickle format or .png format).
def SaveFigAsPickleAndPngOrInteractive(name, figobject, PicturesDumped, mode):
'''Function which generat figures as pickle objects + as pictures.
pictures can be loaded using the below command line
with open('D:\\ABS_R27_Post\\Specimen4_100mm_min\\Secant_modulus_as_function_of_strain' + '.pickle', 'rb') as handle:
Picture= pickle.load(handle)'''
if mode == 'save':
with open(name[0] + '\\PicturePickles\\' + name[1] + '.pickle', 'wb') as handle:
pickle.dump(figobject, handle)
handle.close()
plt.savefig(name[0] + '\\Pictures\\' + name[1] + '.png')
PicturesDumped.append(name)
if mode == 'png':
plt.savefig(name[0] + '\\Pictures\\' + name[1] + '.png')
PicturesDumped.append(name)
return PicturesDumped
def find_file(search_path, filename):
for root, dirs, files in os.walk(search_path):
for f in files:
if filename in f:
return os.path.join(root, f)
#this routine writes the word document (DIC auto-report)
def GenerateWordDocument(FileName, ImageInformation, Mainfolder, Testplaninfo, PicturesDumped, Timeseries, name, Force, Picmode, Origin):
document = Document('\\\\dkafil-msc\\DIC-DATA\\06_Scripts\\New---DIC-Tensile-Test---py3\\Templates\\DICTemplate2.docx')
#generate and add the document title
TestplanId = Timeseries[name]['Post']['TestPlan']['TestplanId']
DocumentTitle = 'DIC Report: '+Testplaninfo.TestID+", Specimen: "+TestplanId
document.add_heading(DocumentTitle, 0)
SampleID = int(Mainfolder.split("pecimen")[-1][0])
n = 0
m = 0
#Get the current stamp
Time = datetime.datetime.now()
document.add_paragraph('Autoreport generated by user: ' + os.getenv('username'))
document.add_paragraph('Report auto-generated: ' + Time.strftime("%Y-%m-%d %H:%M"))
# -----------------------------------------------------------------------------------------------------------
# Generate word document table for batch information
# -----------------------------------------------------------------------------------------------------------
document.add_heading('Test Plan: Batch Information', level=1)
batch_info_list = {"Test ID": Testplaninfo.TestID,
"Granta ID, if applicable": str(Testplaninfo.GrantaID),
"Test Engineer": Testplaninfo.TestEngineer,
"Test Date and Time": Testplaninfo.TestDateAndTime,
"Specimen Fabrication Date": Testplaninfo.SpecimenFabricationDate,
"Material Designation": Testplaninfo.MaterialDesignation,
"Nonstandard Material Designation": Testplaninfo.NonstandardMaterialDesignation,
"Material Grade / Trade Name": Testplaninfo.MaterialGradeTradeName,
"Manufacturing process": Testplaninfo.ManufacturingProcess,
"Material Color": Testplaninfo.MaterialColor,
"Total Number of Test Specimens": str(Testplaninfo.TotalNumberOfTestSpecimens),
'Tensile Tester Programme': Testplaninfo.TensileTesterProgramme,
"Test Type": Testplaninfo.TestType,
"Pattern Method": Testplaninfo.PatternMethod}
table = document.add_table(rows=15, cols=2)
table.style = 'Table Grid'
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Information').bold = True
hdr_cells[1].paragraphs[0].add_run('Value').bold = True
for i in range(1, len(batch_info_list) + 1):
row_cells = table.rows[i].cells
row_cells[0].paragraphs[0].add_run(list(batch_info_list.keys())[i-1])
row_cells[1].paragraphs[0].add_run(str(batch_info_list[list(batch_info_list.keys())[i-1]]))
#caption
paragraph = document.add_paragraph('Table ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
n = TableCaption2(n)
paragraph.add_run(str(n) + ': Standard test batch information.')
# -----------------------------------------------------------------------------------------------------------
# Generate word document table for sample information
# -----------------------------------------------------------------------------------------------------------
document.add_heading('Test Plan: Specimen Information', level=1)
table = document.add_table(rows=6, cols=2)
table.style = 'Table Grid'
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Information').bold = True
hdr_cells[1].paragraphs[0].add_run('Value').bold = True
for counter in range(0,len(Testplaninfo.Specimendata)):
if str(SampleID) == str(Testplaninfo.Specimendata[counter]['Number']):
i = 1
row_cells = table.rows[i].cells
i = i + 1
row_cells[0].paragraphs[0].add_run('Number')
row_cells[1].paragraphs[0].add_run(Testplaninfo.Specimendata[counter]['Number'])
row_cells = table.rows[i].cells
i = i + 1
row_cells[0].paragraphs[0].add_run('Specimen Type')
row_cells[1].paragraphs[0].add_run(Testplaninfo.Specimendata[counter]['Specimen Type'])
row_cells = table.rows[i].cells
i = i + 1
row_cells[0].paragraphs[0].add_run('Test Speed mm/min')
row_cells[1].paragraphs[0].add_run(Testplaninfo.Specimendata[counter]['TestSpeed'])
row_cells = table.rows[i].cells
i = i + 1
row_cells[0].paragraphs[0].add_run('Specimen Orientation')
row_cells[1].paragraphs[0].add_run(Testplaninfo.Specimendata[counter]['Orientation'])
row_cells = table.rows[i].cells
i = i + 1
row_cells[0].paragraphs[0].add_run('Experimental Observations')
row_cells[1].paragraphs[0].add_run(Testplaninfo.Specimendata[counter]['Experimental Observations'])
break
#Caption
paragraph = document.add_paragraph('Table ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
n = TableCaption2(n)
paragraph.add_run(str(n) + ': Standard test Specimen information.')
# -----------------------------------------------------------------------------------------------------------
# Creating the Table of Contents
# -----------------------------------------------------------------------------------------------------------
document.add_page_break()
document.add_heading('Table of Contents', level=1)
paragraph = document.add_paragraph()
run = paragraph.add_run()
fldChar = OxmlElement('w:fldChar') # creates a new element
fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element
instrText = OxmlElement('w:instrText')
instrText.set(qn('xml:space'), 'preserve') # sets attribute on element
instrText.text = 'TOC \\o "1-3" \\h \\z \\u' # change 1-3 depending on heading levels you need
fldChar2 = OxmlElement('w:fldChar')
fldChar2.set(qn('w:fldCharType'), 'separate')
fldChar3 = OxmlElement('w:t')
fldChar3.text = "Right-click to update field."
fldChar2.append(fldChar3)
fldChar4 = OxmlElement('w:fldChar')
fldChar4.set(qn('w:fldCharType'), 'end')
r_element = run._r
r_element.append(fldChar)
r_element.append(instrText)
r_element.append(fldChar2)
r_element.append(fldChar4)
r_element = paragraph._p
epsilon = '\u03B5'
# -----------------------------------------------------------------------------------------------------------
# Adding images and figures to the document
# -----------------------------------------------------------------------------------------------------------
# Strain Preload compensation
document.add_page_break()
Picturenames = [i[1] for i in PicturesDumped]
document.add_heading('Strain Preload compensation', level=1)
paragraph = document.add_paragraph()
paragraph.add_run('Specimen stress strain response is outlined in this section.')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if 'Strain_Force_Preload_correction' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + f': Strain correction, {epsilon}_corr., identified by means of preload strain compensation calculator.')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Eng_and_true_stress_strain_curve_5%' in x][0]
run.add_picture(Mainfolder.rstrip('\\')+'\\Pictures\\'+Picname+'.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Specimen stress-strain response for 0 to 5% strain range. Stress in [MPa], Strain in [-].')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Stress_strain_curve' in x][0]
run.add_picture(Mainfolder.rstrip('\\')+'\\Pictures\\'+Picname+'.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Specimen stress-strain response for full strain range. Stress in [MPa], Strain in [-].')
# Secant Modulus Estimate
document.add_page_break()
document.add_heading('E-Modulus Estimate', level=1)
paragraph = document.add_paragraph()
paragraph.add_run("The secant Modulus is estimated in this section.")
# Add table with Secant Modulii estimates
table = document.add_table(rows=4, cols=3)
table.style = 'Table Grid'
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Reference strain[-]').bold = True
hdr_cells[1].paragraphs[0].add_run('Eng.').bold = True
hdr_cells[2].paragraphs[0].add_run('Vol. Constant').bold = True
column_cells = table.columns[0].cells
column_cells[1].paragraphs[0].add_run('0.005')
column_cells[2].paragraphs[0].add_run('0.01')
column_cells[3].paragraphs[0].add_run('0.02')
column_cells = table.columns[1].cells
Strings =re.sub(r"[\[\].]", "",str(np.round(np.poly1d(Timeseries[name]['Post']['Eng']['Sec_Modulus_poly_Eng'].Data)([0.005, 0.01, 0.02]), 0)),flags=re.I).split()
column_cells[1].paragraphs[0].add_run(Strings[0])
column_cells[2].paragraphs[0].add_run(Strings[1])
column_cells[3].paragraphs[0].add_run(Strings[2])
column_cells = table.columns[2].cells
Strings = re.sub(r"[\[\].]", "", str(np.round(np.poly1d(Timeseries[name]['Post']['Volkst']['Sec_Modulus_poly_VolConstant'].Data)([0.005, 0.01, 0.02]),0)),flags=re.I).split()
column_cells[1].paragraphs[0].add_run(Strings[0])
column_cells[2].paragraphs[0].add_run(Strings[1])
column_cells[3].paragraphs[0].add_run(Strings[2])
#caption
paragraph = document.add_paragraph('Table ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
n=TableCaption2(n)
paragraph.add_run(str(n) + ': Specimen Secant Modulus response for 0.5%, 1% and 2% strain ranges. Strain in [-], Modulus in [MPa].')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Secant_modulus_as_function_of_strain_5%_max' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Specimen Secant Modulus response for 0 to 5% strain range. Modulus in [MPa], Strain in [-].')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Secant_modulus_as_function_of_strain' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Specimen Secant Modulus response for full strain range. Modulus in [MPa], Strain in [-].')
# Poisson's Ratio Estimate
document.add_page_break()
document.add_heading(r"Poisson's Ratio Estimate", level=1)
document.add_heading(r'Small strains', level=2)
paragraph = document.add_paragraph()
run = paragraph.add_run(r"The small strain Poisson's ratio has been calculated to be " + str(np.round(Timeseries[name]['Post']['Gen']['Poisson'].Data, 2)[0])+'. ')
run = paragraph.add_run(r"The reference strain level for the calculated Poisson's ratio is: " + str(np.round(Timeseries[name]['Post']['Gen']['PoissonRefStrain'].Data, 3)[0])+'.')
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Poissons_ratio_estimated_strains_vs_org_strains' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ": Specimen Poisson's ratio-strain estimate for 4% strain regime. Longitudinal strain in [-], Transverse Strain in [-]. Calculated Poisson's ratio is: " + str(np.round(Timeseries[name]['Post']['Gen']['Poisson'].Data,2)[0])+'.')
paragraph = document.add_paragraph()
document.add_heading('Large strains', level=2)
paragraph = document.add_paragraph()
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_nu_yx_as_function_of_principal_strain' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ": Specimen Poisson's ratio-strain estimate for full strain regime. Longitudinal strain in [-], Transverse Poisson's ratio in [-].")
# Tensile tester response history
document.add_page_break()
document.add_heading('Force-Displacement history', level=1)
document.add_heading('Tensile tester', level=2)
paragraph = document.add_paragraph()
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Force_displacement' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Force-Displacement response. Force in [N], displacement in [mm].')
paragraph = document.add_paragraph()
run = paragraph.add_run('Note: In the case of large deviations, you might want to review the setup of Analog input in DIC software.')
paragraph = document.add_paragraph()
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Force_Time' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': Force-Time response. Force in [N], Time in [s].')
paragraph = document.add_paragraph()
document.add_heading('True specimen elongation (measured on the sample)', level=2)
paragraph = document.add_paragraph()
run = paragraph.add_run('True elongation is taken as a difference of longitudinal displacements between first and last point of "Line-0".')
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Elongation_vs_time' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': True specimen elongation over time')
paragraph = document.add_paragraph()
run = paragraph.add_run('True elongation is taken as a difference of longitudinal displacements between first '
'and last point of "Line-0".')
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Elongation_vs_Force' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': True specimen elongation over time')
# Specimen neck width, thickness and area estimates
document.add_page_break()
document.add_heading('Specimen neck width, thickness, area and thickness correction response', level=1)
paragraph = document.add_paragraph()
run = paragraph.add_run('The estimated dimensions of the specimen through-out the experiment are outlined in this chapter.')
paragraph = document.add_paragraph()
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Necking_width_vs_strain_approximation' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': The estimated necking width approximation as function of longitudinal neck strain. Neck strain in [-], Neck width in [mm].')
paragraph = document.add_paragraph()
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Necking_Thickness_vs_strain_approximation' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': The estimated necking thickness approximation as function of longitudinal strain. Necking strain in [-], Neck thickness in [mm].')
paragraph = document.add_paragraph()
run = paragraph.add_run()
Picname = [x for x in Picturenames if '_Necking_area_vs_strain_approximation' in x][0]
run.add_picture(Mainfolder.rstrip('\\') + '\\Pictures\\' + Picname + '.png', width=Cm(17))
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': The estimated necking area approximation as function of longitudinal strain. Strain in [-], Neck area in [mm')
run=paragraph.add_run('2')
run.font.superscript = True
paragraph.add_run('].')
# Image information found - inserting images.
if ImageInformation is not None:
document.add_page_break()
paragraph = document.add_paragraph()
document.add_heading('Images From DIC.',level=1)
paragraph = document.add_paragraph()
ImageInformationLen = len(ImageInformation)
for counter in range(ImageInformationLen):
try:
print(' Images From DIC: '+str(counter+1)+' of '+str(ImageInformationLen))
PicPath = find_file(Mainfolder, ImageInformation[counter]['image'].split("peci")[-1])
PicDimString = ImgResizewithfeedback(PicPath, 7.0/17.5)
table = document.add_table(rows=11, cols=2)
table.style = 'Style1'
column_cells = table.columns[0].cells
column_cells[0].paragraphs[0].add_run('DIC summary image: '+str(counter+1)).bold = True
column_cells[0].add_paragraph()
column_cells[1].paragraphs[0].add_run('Index:').bold = True
column_cells[1].add_paragraph()
column_cells[1].paragraphs[1].add_run(str(ImageInformation[counter]['index']))
column_cells[1].add_paragraph()
column_cells[2].paragraphs[0].add_run('Original Index:').bold = True
column_cells[2].add_paragraph()
column_cells[2].paragraphs[1].add_run(ImageInformation[counter]['OrgIndex'])
column_cells[2].add_paragraph()
column_cells[3].paragraphs[0].add_run('Tensile Tester Displacement [mm]: ').bold = True
column_cells[3].add_paragraph()
column_cells[3].paragraphs[1].add_run(ImageInformation[counter]['dispTester'])
column_cells[3].add_paragraph()
column_cells[4].paragraphs[0].add_run('DIC Longitudinal neck strain [-]').bold = True
column_cells[4].add_paragraph()
column_cells[4].paragraphs[1].add_run(ImageInformation[counter]['Neckstrain'])
column_cells[4].add_paragraph()
column_cells[5].paragraphs[0].add_run('Tensile Tester force [N]:').bold = True
column_cells[5].add_paragraph()
column_cells[5].paragraphs[1].add_run(ImageInformation[counter]['Force'])
column_cells[5].add_paragraph()
column_cells[6].paragraphs[0].add_run('DIC original camera image: ').bold = True
column_cells[6].add_paragraph()
column_cells[6].paragraphs[1].add_run(ImageInformation[counter]['OrgCamera'])
column_cells[6].add_paragraph()
if ImageInformation[counter]['index']!='N.A.':
figobject = plt.figure(100000+counter, figsize=(16, 8))
titlestr = "Index-Force"
plt.title(titlestr, fontdict={'family': 'serif', 'color': 'black', 'weight': 'bold', 'size': 18})
plt.xlabel('Index [-]', fontdict={'family': 'serif', 'color': 'black', 'weight': 'normal', 'size': 30})
plt.ylabel('Force [N]', fontdict={'family': 'serif', 'color': 'black', 'weight': 'normal', 'size': 30})
plt.rc('xtick', labelsize=20) # fontsize of the tick labels
plt.rc('ytick', labelsize=20) # fontsize of the tick labels
plt.plot(Force, label='Raw Force',linewidth=4.0)
plt.plot(ImageInformation[counter]['index'],Force[ImageInformation[counter]['index']],'*',markersize=20, label='Image')
Picname = [os.path.join(Origin, Mainfolder), str(100000+counter) + '_' + "ForcePoint"]
SaveFigAsPickleAndPngOrInteractive(Picname, figobject, PicturesDumped, Picmode)
plt.close()
run = column_cells[10].paragraphs[0].add_run('')
run.add_picture(Mainfolder +'\\Pictures\\'+str(100000+counter) + '_' + "ForcePoint"+'.png', width=Cm(7))
OrgDir=os.getcwd()
os.remove(Mainfolder +'\\Pictures\\'+str(100000+counter) + '_' + "ForcePoint"+'.png')
os.chdir(OrgDir)
column_cells = table.columns[1].cells
column_cells[0].merge(column_cells[10])
run = column_cells[0].paragraphs[0].add_run('')
if PicDimString=='height':
run.add_picture('resized_image.jpg', height=Cm(17.5))
else:
if PicDimString == 'width':
run.add_picture('resized_image.jpg', width=Cm(7))
os.remove('resized_image.jpg')
paragraph = document.add_paragraph('Figure ', style='Caption')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
m=FigureCaption2(m)
paragraph.add_run(str(m) + ': DIC image: '+ImageInformation[counter]['OrgIndex']+', Camera; '+ImageInformation[counter]['OrgCamera'])
document.add_page_break()
except Exception as e:
print(' Could not add image '+str(counter+1)+' to report. Error: '+str(e))
continue
document.core_properties.category = u'DIC Report'
document.core_properties.comments = u'Autoreport'
document.core_properties.language = u'English'
document.core_properties.title = FileName + "_Specimen" + TestplanId
document.save(Mainfolder + r'\\PostOut\\' + FileName+"_Specimen" + TestplanId + "_Report.docx")
word = win32com.client.DispatchEx("Word.Application")
doc = word.Documents.Open(Mainfolder + '\\PostOut\\' + FileName + "_Specimen" + TestplanId + "_Report.docx")
doc.TablesOfContents(1).Update()
print('Starting Win32com Client - updated')
doc.Close(SaveChanges=True)
print('Starting Win32com Client - Closed ')
word.Quit()
print('Starting Win32com Client - quit')