Skip to content

Commit 3a8a271

Browse files
committed
modified tutorial 5
1 parent ce3bf46 commit 3a8a271

File tree

2 files changed

+240
-65
lines changed

2 files changed

+240
-65
lines changed

tutorials/tutorial5/tutorial-5-file.ipynb

Lines changed: 196 additions & 56 deletions
Large diffs are not rendered by default.

tutorials/tutorial5/tutorial-5-file.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,36 @@
1313
# As usually, at the beginning we import all the modules we need.
1414

1515
# In[1]:
16+
import sys
17+
import platform
18+
print(f"Python Version: {sys.version}")
19+
print(f"Platform: {sys.platform}")
20+
print(f"System: {platform.system()} {platform.release()}")
21+
import subprocess
22+
try:
23+
import pygem
24+
print(f"PyGeM version: {pygem.__version__}")
25+
except ImportError:
26+
print(f"PyGeM not found. Installing...")
27+
# Installing from local source. It can be replaced with github installation once pushed and merged.
28+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", ".[tut]"])
29+
import pygem
30+
31+
print(f"PyGeM version: {pygem.__version__}")
32+
33+
try:
34+
from smithers import io
35+
except ImportError:
36+
print("smithers not found. Installing from GitHub...")
37+
subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/mathLab/Smithers.git"])
38+
from smithers import io
1639

17-
18-
get_ipython().run_line_magic("matplotlib", "inline")
1940
import numpy as np
41+
np.random.seed(42)
42+
43+
2044

45+
import matplotlib.pyplot as plt
2146
from pygem import FFD
2247
from smithers import io
2348

@@ -28,7 +53,6 @@
2853

2954

3055
def plot(data, color=None):
31-
3256
from mpl_toolkits.mplot3d import Axes3D
3357
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
3458
import matplotlib.pyplot as plt
@@ -57,11 +81,17 @@ def plot(data, color=None):
5781

5882
# In[3]:
5983

84+
import os
85+
import urllib.request
86+
87+
if os.path.exists("cube.vtp"):
88+
os.remove("cube.vtp")
6089

61-
get_ipython().system("rm -rf cube.vtp")
62-
get_ipython().system(
63-
"wget https://raw.githubusercontent.com/mathLab/Smithers/master/tests/test_datasets/cube.vtp"
90+
urllib.request.urlretrieve(
91+
"https://raw.githubusercontent.com/mathLab/Smithers/master/tests/test_datasets/cube.vtp",
92+
"cube.vtp"
6493
)
94+
6595
vtp_filename = "cube.vtp"
6696

6797
vtp_content = io.VTPHandler.read(vtp_filename)
@@ -112,10 +142,15 @@ def plot(data, color=None):
112142
# In[8]:
113143

114144

115-
get_ipython().system("rm -rf cube.stl")
116-
get_ipython().system(
117-
"wget https://raw.githubusercontent.com/mathLab/Smithers/master/tests/test_datasets/cube.stl"
145+
if os.path.exists("cube.stl"):
146+
os.remove("cube.stl")
147+
148+
urllib.request.urlretrieve(
149+
"https://raw.githubusercontent.com/mathLab/Smithers/master/tests/test_datasets/cube.stl",
150+
"cube.stl"
118151
)
152+
153+
119154
stl_filename = "cube.stl"
120155

121156
stl_content = io.STLHandler.read(stl_filename)

0 commit comments

Comments
 (0)