Repository navigation
Expand file tree
/
Copy pathplot_demos.py
More file actions
116 lines (88 loc) · 3.16 KB
/
Copy pathplot_demos.py
File metadata and controls
116 lines (88 loc) · 3.16 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
# -*- coding: utf-8 -*-
r"""
Plot all demos
"""
import glob
import locale
import os
import shutil
import subprocess
import matplotlib.pyplot as plt
import microstructpy as msp
locale.setlocale(locale.LC_NUMERIC, "C")
# Digest of the example inputs and of the library that meshes them.
#
# Sphinx-Gallery skips this script when its hash matches the .md5 beside
# the output of an earlier build, which is what lets a cached build skip
# the examples. The examples are found by glob below and none of them are
# named here, so without this line the hash would not move when one of
# them is edited, and the build would serve stale figures.
#
# Managed by docs/example_digest.py. Do not edit by hand.
EXAMPLES_DIGEST = '1cc876c00916b073'
example_dir = '../../../src/microstructpy/examples'
welcome_fnames = ['intro_2_quality/trimesh.png',
'minimal/polymesh.png',
'basalt_circle/trimesh.png',
'foam/trimesh.png',
'two_phase_3D/trimesh.png',
'colormap/trimesh.png']
def main():
# Copy Supporting Files
supporting_files = ['aphanitic_cdf.csv', 'olivine_cdf.csv']
for fname in supporting_files:
filename = os.path.join(example_dir, fname)
shutil.copy(filename, '.')
# Run XML files
xml_pattern = os.path.join(example_dir, '*.xml')
for filename in glob.glob(xml_pattern):
msp.cli.run_file(filename)
# Run Python Scripts
py_pattern = os.path.join(example_dir, '*.py')
for filename in glob.glob(py_pattern):
subprocess.call(['python', filename])
# Remove Supporting Files
for fname in supporting_files:
os.remove(fname)
# Create welcome figure
create_welcome()
# Create example subfigures
seed_poly_tri('.')
def create_welcome():
fig, axes = plt.subplots(2, 3, figsize=(21, 15))
plt.subplots_adjust(wspace=0.05, hspace=0)
for i, fname in enumerate(welcome_fnames):
filename = os.path.join(example_dir, fname)
im = plt.imread(filename)
row_num = int(i / 3)
col_num = i % 3
ax = axes[row_num, col_num]
ax.imshow(im)
ax.set_axis_off()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
sub_fname = 'welcome_examples.png'
sub_filename = os.path.join(example_dir, sub_fname)
plt.tight_layout()
plt.savefig(sub_filename, pad_inches=0, dpi=200)
plt.close('all')
def seed_poly_tri(filepath):
basenames = ['seeds.png', 'polymesh.png', 'trimesh.png']
ex_path = os.path.join(example_dir, filepath)
fig, axes = plt.subplots(1, 3, figsize=(20, 10))
plt.subplots_adjust(wspace=0.05, hspace=0)
for i, fname in enumerate(basenames):
filename = os.path.join(ex_path, fname)
im = plt.imread(filename)
ax = axes[i]
ax.imshow(im)
ax.set_axis_off()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
sub_fname = 'joined.png'
sub_filename = os.path.join(ex_path, sub_fname)
plt.tight_layout()
plt.savefig(sub_filename, pad_inches=0, dpi=300)
plt.close('all')
if __name__ == '__main__':
main()