Skip to content

Commit 656e3f3

Browse files
authored
Merge pull request #45 from cadenmyers13/example-ci
test: Run tutorials in tests
2 parents 6167dd9 + b8822b2 commit 656e3f3

File tree

12 files changed

+74
-64
lines changed

12 files changed

+74
-64
lines changed

docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# 1: Import relevant system packages that we will need...
1010
from pathlib import Path
1111

12-
import matplotlib as mpl
1312
import matplotlib.pyplot as plt
1413
import numpy as np
14+
from bg_mpl_stylesheets.styles import all_styles
1515
from scipy.optimize import least_squares
1616

1717
# ... and the relevant CMI packages
@@ -25,6 +25,7 @@
2525
from diffpy.srfit.structure import constrainAsSpaceGroup
2626
from diffpy.structure.parsers import getParser
2727

28+
plt.style.use(all_styles["bg-style"])
2829
# Config
2930
# 2: Give a file path to where your PDF (.gr) and
3031
# structure (.cif) files are located.
@@ -33,7 +34,7 @@
3334
# First we store the absolute directory of this script,
3435
# then two directories above this,with the directory
3536
# 'data' appended
36-
PWD = Path(__file__).parent.absolute()
37+
PWD = Path(__file__).parent.resolve()
3738
DPATH = PWD.parent.parent / "data"
3839

3940
# 3: Give an identifying name for the refinement, similar
@@ -264,13 +265,6 @@ def plot_results(recipe, fig_name):
264265
# Calculate the residual (difference) array and offset it vertically.
265266
diff = g - gcalc + diffzero
266267

267-
# Change some style details of the plot
268-
mpl.rcParams.update(mpl.rcParamsDefault)
269-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
270-
plt.style.use(
271-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
272-
)
273-
274268
# Create a figure and an axis on which to plot
275269
fig, ax1 = plt.subplots(1, 1)
276270

docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitNPPt.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# 1: Import relevant system packages that we will need...
1414
from pathlib import Path
1515

16-
import matplotlib as mpl
1716
import matplotlib.pyplot as plt
1817
import numpy as np
18+
from bg_mpl_stylesheets.styles import all_styles
1919
from scipy.optimize import least_squares
2020

2121
# ... and the relevant CMI packages
@@ -30,6 +30,7 @@
3030
from diffpy.srfit.structure import constrainAsSpaceGroup
3131
from diffpy.structure.parsers import getParser
3232

33+
plt.style.use(all_styles["bg-style"])
3334
# Config ##############################
3435
# 2: Give a file path to where your PDF (.gr) and structure (.cif) files
3536
# are located.
@@ -241,13 +242,6 @@ def plot_results(recipe, fig_name):
241242
# Calculate the residual (difference) array and offset it vertically.
242243
diff = g - gcalc + diffzero
243244

244-
# Change some style details of the plot
245-
mpl.rcParams.update(mpl.rcParamsDefault)
246-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
247-
plt.style.use(
248-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
249-
)
250-
251245
# Create a figure and an axis on which to plot
252246
fig, ax1 = plt.subplots(1, 1)
253247

docs/examples/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# 1: Import relevant system packages that we will need...
1111
from pathlib import Path
1212

13-
import matplotlib as mpl
1413
import matplotlib.pyplot as plt
1514
import numpy as np
15+
from bg_mpl_stylesheets.styles import all_styles
1616
from scipy.optimize import least_squares
1717

1818
# ... and the relevant CMI packages
@@ -26,6 +26,7 @@
2626
from diffpy.srfit.structure import constrainAsSpaceGroup
2727
from diffpy.structure.parsers import getParser
2828

29+
plt.style.use(all_styles["bg-style"])
2930
# Config ##############################
3031
# 2: Give a file path to where your pdf (.gr) and (.cif) files are located.
3132
PWD = Path(__file__).parent.absolute()
@@ -271,13 +272,6 @@ def plot_results(recipe, fig_name):
271272
ni_signal = ni_scale * recipe.crystal.G_Ni.profile.ycalc
272273
ni_signal += min(si_signal) - np.abs(max(ni_signal))
273274

274-
# Change some style details of the plot
275-
mpl.rcParams.update(mpl.rcParamsDefault)
276-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
277-
plt.style.use(
278-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
279-
)
280-
281275
# Create a figure and an axis on which to plot
282276
fig, ax1 = plt.subplots(1, 1)
283277

docs/examples/ch06RefineCrystalStructureGen/solutions/diffpy-cmi/fitCrystalGen.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# 1: Import relevant system packages that we will need...
1111
from pathlib import Path
1212

13-
import matplotlib as mpl
1413
import matplotlib.pyplot as plt
1514
import numpy as np
15+
from bg_mpl_stylesheets.styles import all_styles
1616
from scipy.optimize import least_squares
1717

1818
# ... and the relevant CMI packages
@@ -27,12 +27,7 @@
2727
from diffpy.structure.atom import Atom
2828
from diffpy.structure.parsers import getParser
2929

30-
try:
31-
from bg_mpl_stylesheets.bg_mpl_stylesheet import bg_mpl_style
32-
33-
plt.style.use(bg_mpl_style)
34-
except ImportError:
35-
pass
30+
plt.style.use(all_styles["bg-style"])
3631

3732
# Config ##############################
3833
# 2: Give a file path to where your pdf (.gr) and (.cif) files are located.
@@ -246,13 +241,6 @@ def plot_results(recipe, fig_name):
246241
# Calculate the residual (difference) array and offset it vertically.
247242
diff = g - gcalc + diffzero
248243

249-
# Change some style details of the plot
250-
mpl.rcParams.update(mpl.rcParamsDefault)
251-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
252-
plt.style.use(
253-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
254-
)
255-
256244
# Create a figure and an axis on which to plot
257245
fig, ax1 = plt.subplots(1, 1)
258246

docs/examples/ch07StructuralPhaseTransitions/solutions/diffpy-cmi/fitTSeries.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# 1: Import relevant system packages that we will need...
1010
from pathlib import Path
1111

12-
import matplotlib as mpl
1312
import matplotlib.pyplot as plt
1413
import numpy as np
14+
from bg_mpl_stylesheets.styles import all_styles
1515
from scipy.optimize import least_squares
1616

1717
# ... and the relevant CMI packages
@@ -25,12 +25,7 @@
2525
from diffpy.srfit.structure import constrainAsSpaceGroup
2626
from diffpy.structure.parsers import getParser
2727

28-
try:
29-
from bg_mpl_stylesheets.bg_mpl_stylesheet import bg_mpl_style
30-
31-
plt.style.use(bg_mpl_style)
32-
except ImportError:
33-
pass
28+
plt.style.use(all_styles["bg-style"])
3429

3530
# Config ##############################
3631
# 2: Give a file path to where your pdf (.gr) and (.cif) files are located.
@@ -221,13 +216,6 @@ def plot_results(recipe, fig_name):
221216
# Calculate the residual (difference) array and offset it vertically.
222217
diff = g - gcalc + diffzero
223218

224-
# Change some style details of the plot
225-
mpl.rcParams.update(mpl.rcParamsDefault)
226-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
227-
plt.style.use(
228-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
229-
)
230-
231219
# Create a figure and an axis on which to plot
232220
fig, ax1 = plt.subplots(1, 1)
233221

docs/examples/ch08NPRefinement/solutions/diffpy-cmi/fitCdSeNP.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# 1: Import relevant system packages that we will need...
1111
from pathlib import Path
1212

13-
import matplotlib as mpl
1413
import matplotlib.pyplot as plt
1514
import numpy as np
1615
from scipy.optimize import least_squares
@@ -445,13 +444,6 @@ def plot_results(recipe, fig_name):
445444
# Calculate the residual (difference) array and offset it vertically.
446445
diff = g - gcalc + diffzero
447446

448-
# Change some style details of the plot
449-
mpl.rcParams.update(mpl.rcParamsDefault)
450-
if (PWD.parent.parent.parent / "utils" / "billinge.mplstyle").exists():
451-
plt.style.use(
452-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
453-
)
454-
455447
# Create a figure and an axis on which to plot
456448
fig, ax1 = plt.subplots(1, 1)
457449

docs/examples/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ def plot_results(recipe, figname):
199199
diff = g - gcalc + diffzero
200200

201201
mpl.rcParams.update(mpl.rcParamsDefault)
202-
plt.style.use(
203-
str(PWD.parent.parent.parent / "utils" / "billinge.mplstyle")
204-
)
205202

206203
fig, ax1 = plt.subplots(1, 1)
207204

news/example-ci.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Add tests that run PDF example scripts
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

requirements/packs/plotting.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ipywidgets
22
matplotlib
33
ipympl
4+
bg-mpl-stylesheets
45
py3dmol>=2.0.1

requirements/tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ pytest-env
88
pytest-mock
99
freezegun
1010
DeepDiff
11+
psutil
12+
bg-mpl-stylesheets

0 commit comments

Comments
 (0)