Skip to content

Commit e14d9fa

Browse files
authored
Merge pull request #530 from scipp/example-data-instead-of-paths
Make functions in `data.examples` return loaded DataArrays instead of paths
2 parents 49477dc + 15902b2 commit e14d9fa

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

docs/gallery/nyc-taxi.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"from scipp.scipy.ndimage import gaussian_filter\n",
3636
"import ipywidgets as ipw\n",
3737
"\n",
38-
"data = sc.io.load_hdf5(examples.nyc_taxi())\n",
38+
"data = examples.nyc_taxi()\n",
3939
"data"
4040
]
4141
},

docs/plotting/inspector-plot.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,9 @@
225225
"metadata": {},
226226
"outputs": [],
227227
"source": [
228-
"import scipp as sc\n",
229228
"from plopp.data.examples import air_temperature\n",
230229
"\n",
231-
"air = sc.io.load_hdf5(air_temperature())\n",
230+
"air = air_temperature()\n",
232231
"air"
233232
]
234233
},

docs/plotting/mesh3d-plot.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"metadata": {},
5050
"outputs": [],
5151
"source": [
52-
"dg = sc.io.load_hdf5(examples.teapot())\n",
52+
"dg = examples.teapot()\n",
5353
"dg"
5454
]
5555
},

src/plopp/data/examples.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_path(name: str) -> str:
3939
return _pooch.fetch(name)
4040

4141

42-
def nyc_taxi() -> str:
42+
def nyc_taxi() -> sc.DataArray:
4343
"""
4444
Return the path to the NYC taxi dataset from 2015 histogrammed in latitude,
4545
longitude, and hour-of-the-dat, stored in scipp's HDF5 format.
@@ -50,10 +50,10 @@ def nyc_taxi() -> str:
5050
---------
5151
This data has been manipulated!
5252
"""
53-
return get_path('nyc_taxi_data.h5')
53+
return sc.io.load_hdf5(get_path('nyc_taxi_data.h5'))
5454

5555

56-
def teapot() -> str:
56+
def teapot() -> sc.DataArray:
5757
"""
5858
Values extracted from the Utah teapot:
5959
https://graphics.cs.utah.edu/courses/cs6620/fall2013/?prj=5
@@ -63,15 +63,15 @@ def teapot() -> str:
6363
>> vertices = scene.vertices
6464
>> faces = scene.meshes[None].faces
6565
"""
66-
return get_path('teapot.h5')
66+
return sc.io.load_hdf5(get_path('teapot.h5'))
6767

6868

69-
def air_temperature() -> str:
69+
def air_temperature() -> sc.DataArray:
7070
"""
7171
North American air temperature dataset from Xarray.
7272
See https://docs.xarray.dev/en/latest/user-guide/plotting.html
7373
"""
74-
return get_path('air_temperature.h5')
74+
return sc.io.load_hdf5(get_path('air_temperature.h5'))
7575

7676

7777
def three_bands(

tests/graphics/artists_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from functools import partial
55

66
import pytest
7-
import scipp as sc
87

98
import plopp as pp
109
from plopp.data import examples
@@ -71,12 +70,12 @@
7170
"mesh3d-pythreejs": (
7271
('3d', 'pythreejs'),
7372
pp.mesh3d,
74-
dict(sc.io.load_hdf5(examples.teapot())),
73+
dict(examples.teapot()),
7574
),
7675
"mesh3d-pythreejs-edges": (
7776
('3d', 'pythreejs'),
7877
partial(pp.mesh3d, edgecolor='blue'),
79-
dict(sc.io.load_hdf5(examples.teapot())),
78+
dict(examples.teapot()),
8079
),
8180
}
8281

tests/plotting/mesh3d_test.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,30 @@
22
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
33

44
import numpy as np
5-
import pytest
6-
import scipp as sc
75

86
import plopp as pp
97
from plopp.data import examples
108

119

12-
@pytest.fixture
13-
def teapot_data():
14-
return sc.io.load_hdf5(examples.teapot())
15-
16-
17-
def test_mesh3d_default(teapot_data):
10+
def test_mesh3d_default():
11+
teapot_data = examples.teapot()
1812
pp.mesh3d(
1913
vertices=teapot_data["vertices"],
2014
faces=teapot_data["faces"],
2115
)
2216

2317

24-
def test_mesh3d_solid_color(teapot_data):
18+
def test_mesh3d_solid_color():
19+
teapot_data = examples.teapot()
2520
fig = pp.mesh3d(
2621
vertices=teapot_data["vertices"], faces=teapot_data["faces"], color='red'
2722
)
2823
(mesh,) = fig.artists.values()
2924
assert np.array_equal(mesh.geometry.attributes["color"].array[0, :], (1, 0, 0))
3025

3126

32-
def test_mesh3d_vertexcolors(teapot_data):
27+
def test_mesh3d_vertexcolors():
28+
teapot_data = examples.teapot()
3329
z = teapot_data["vertices"].fields.z
3430
fig = pp.mesh3d(
3531
vertices=teapot_data["vertices"],
@@ -44,7 +40,8 @@ def test_mesh3d_vertexcolors(teapot_data):
4440
assert not np.array_equal(colors[imin, :], colors[imax, :])
4541

4642

47-
def test_mesh3d_edgecolor(teapot_data):
43+
def test_mesh3d_edgecolor():
44+
teapot_data = examples.teapot()
4845
fig = pp.mesh3d(
4946
vertices=teapot_data["vertices"],
5047
faces=teapot_data["faces"],
@@ -55,7 +52,8 @@ def test_mesh3d_edgecolor(teapot_data):
5552
assert mesh.edges.material.color == 'blue'
5653

5754

58-
def test_mesh3d_cmap(teapot_data):
55+
def test_mesh3d_cmap():
56+
teapot_data = examples.teapot()
5957
fig = pp.mesh3d(
6058
vertices=teapot_data["vertices"],
6159
faces=teapot_data["faces"],

0 commit comments

Comments
 (0)