3
3
Design of data packages for the nipy suite
4
4
==========================================
5
5
6
- See :ref: `data-package-discuss ` for a more general discussion of design issues.
6
+ See :ref: `data-package-discuss ` for a more general discussion of design
7
+ issues.
7
8
8
- When developing or using nipy, many data files can be useful. We divide
9
- the data files nipy uses into at least 3 categories
9
+ When developing or using nipy, many data files can be useful. We divide the
10
+ data files nipy uses into at least 3 categories
10
11
11
12
#. *test data * - data files required for routine code testing
12
13
#. *template data * - data files required for algorithms to function,
13
14
such as templates or atlases
14
15
#. *example data * - data files for running examples, or optional tests
15
16
16
17
Files used for routine testing are typically very small data files. They are
17
- shipped with the software, and live in the code repository. For example, in the
18
- case of ``nipy `` itself, there are some test files that live in the module path
19
- ``nipy.testing.data ``.
18
+ shipped with the software, and live in the code repository. For example, in
19
+ the case of ``nipy `` itself, there are some test files that live in the module
20
+ path ``nipy.testing.data ``.
20
21
21
22
*template data * and *example data * are example of *data packages *. What
22
23
follows is a discussion of the design and use of data packages.
23
24
25
+ .. testsetup ::
26
+
27
+ # Make fake data and template directories
28
+ import os
29
+ from os.path import join as pjoin
30
+ import tempfile
31
+ tmpdir = tempfile.mkdtemp()
32
+ os.environ['NIPY_USER_DIR'] = tmpdir
33
+ for subdir in ('data', 'templates'):
34
+ files_dir = pjoin(tmpdir, 'nipy', subdir)
35
+ os.makedirs(files_dir)
36
+ with open(pjoin(files_dir, 'config.ini'), 'wt') as fobj:
37
+ fobj.write(
38
+ """[DEFAULT]
39
+ version = 0.2
40
+ """)
41
+
24
42
Use cases for data packages
25
43
+++++++++++++++++++++++++++
26
44
@@ -33,28 +51,29 @@ The programmer will want to use the data something like this:
33
51
34
52
from nibabel.data import make_datasource
35
53
36
- templates = make_datasource('nipy', ' templates')
54
+ templates = make_datasource(dict(relpath= 'nipy/ templates') )
37
55
fname = templates.get_filename('ICBM152', '2mm', 'T1.nii.gz')
38
-
56
+
39
57
where ``fname `` will be the absolute path to the template image
40
- ``ICBM152/2mm/T1.nii.gz ``.
58
+ ``ICBM152/2mm/T1.nii.gz ``.
41
59
42
60
The programmer can insist on a particular version of a ``datasource ``:
43
61
44
- .. testcode ::
45
-
46
- if templates.version < '0.4':
47
- raise ValueError('Need datasource version at least 0.4')
62
+ >>> if templates.version < ' 0.4' :
63
+ ... raise ValueError (' Need datasource version at least 0.4' )
64
+ Traceback (most recent call last):
65
+ ...
66
+ ValueError: Need datasource version at least 0.4
48
67
49
68
If the repository cannot find the data, then:
50
69
51
- >>> make_datasource(' nipy' , ' implausible' )
52
- Traceback
70
+ >>> make_datasource(dict ( relpath = ' nipy/ implausible' ) )
71
+ Traceback (most recent call last):
53
72
...
54
- nibabel.data.DataError
73
+ nibabel.data.DataError: ...
55
74
56
75
where ``DataError `` gives a helpful warning about why the data was not
57
- found, and how it should be installed.
76
+ found, and how it should be installed.
58
77
59
78
Warnings during installation
60
79
````````````````````````````
@@ -68,8 +87,8 @@ data when installing the package. Thus::
68
87
will import nipy after installation to check whether these raise an error:
69
88
70
89
>>> from nibabel.data import make_datasource
71
- >>> template = make_datasource(' nipy' , ' templates' )
72
- >>> example_data = make_datasource(' nipy' , ' data' )
90
+ >>> templates = make_datasource(dict ( relpath = ' nipy/ templates' ) )
91
+ >>> example_data = make_datasource(dict ( relpath = ' nipy/ data' ) )
73
92
74
93
and warn the user accordingly, with some basic instructions for how to
75
94
install the data.
@@ -82,7 +101,7 @@ Finding the data
82
101
The routine ``make_datasource `` will need to be able to find the data
83
102
that has been installed. For the following call:
84
103
85
- >>> templates = make_datasource(' nipy' , ' templates' )
104
+ >>> templates = make_datasource(dict ( relpath = ' nipy/ templates' ) )
86
105
87
106
We propose to:
88
107
@@ -130,8 +149,8 @@ umbrella of neuroimaging in python - and the NIPY package - the main
130
149
code package in the NIPY project. Thus, if you want to install data
131
150
under the NIPY *package * umbrella, your data might go to
132
151
``/usr/share/nipy/nipy/packagename `` (on Unix). Note ``nipy `` twice -
133
- once for the project, once for the pacakge . If you want to install data
134
- under - say - the ``` pbrain `` package umbrella, that would go in
152
+ once for the project, once for the package . If you want to install data
153
+ under - say - the ``pbrain `` package umbrella, that would go in
135
154
``/usr/share/nipy/pbrain/packagename ``.
136
155
137
156
Data package format
@@ -141,7 +160,7 @@ The following tree is an example of the kind of pattern we would expect
141
160
in a data directory, where the ``nipy-data `` and ``nipy-templates ``
142
161
packages have been installed::
143
162
144
- <ROOT>
163
+ <ROOT>
145
164
`-- nipy
146
165
|-- data
147
166
| |-- config.ini
@@ -191,8 +210,9 @@ For the example above this will result in these subdirectories::
191
210
because ``nipy `` is both the project, and the package to which the data
192
211
relates.
193
212
194
- If you install to a particular location, you will need to add that
195
- location to the output of ``nipy.data.get_data_path() `` using one of the mechanisms above, for example, in your system configuration::
213
+ If you install to a particular location, you will need to add that location to
214
+ the output of ``nipy.data.get_data_path() `` using one of the mechanisms above,
215
+ for example, in your system configuration::
196
216
197
217
export NIPY_DATA_PATH=/my/prefix/share/nipy
198
218
@@ -202,13 +222,13 @@ Packaging for distributions
202
222
For a particular data package - say ``nipy-templates `` - distributions
203
223
will want to:
204
224
205
- #. Install the data in set location. The default from ``python setup.py install `` for the data packages will be ``/usr/share/nipy `` on Unix.
206
- #. Point a system installation of NIPY to these data.
225
+ #. Install the data in set location. The default from ``python setup.py
226
+ install `` for the data packages will be ``/usr/share/nipy `` on Unix.
227
+ #. Point a system installation of NIPY to these data.
207
228
208
- For the latter, the most obvious route is to copy an ``.ini `` file named
209
- for the data package into the NIPY ``etc_dir ``. In this case, on Unix,
210
- we will want a file called ``/etc/nipy/nipy_templates.ini `` with
211
- contents::
229
+ For the latter, the most obvious route is to copy an ``.ini `` file named for
230
+ the data package into the NIPY ``etc_dir ``. In this case, on Unix, we will
231
+ want a file called ``/etc/nipy/nipy_templates.ini `` with contents::
212
232
213
233
[DATA]
214
234
path = /usr/share/nipy
@@ -219,16 +239,17 @@ Current implementation
219
239
This section describes how we (the nipy community) implement data packages at
220
240
the moment.
221
241
222
- The data in the data packages will not usually be under source control. This is
223
- because images don't compress very well, and any change in the data will result
224
- in a large extra storage cost in the repository. If you're pretty clear that
225
- the data files aren't going to change, then a repository could work OK.
242
+ The data in the data packages will not usually be under source control. This
243
+ is because images don't compress very well, and any change in the data will
244
+ result in a large extra storage cost in the repository. If you're pretty
245
+ clear that the data files aren't going to change, then a repository could work
246
+ OK.
226
247
227
- The data packages will be available at a central release location. For
228
- now this will be: http://nipy.org/data-packages/ .
248
+ The data packages will be available at a central release location. For now
249
+ this will be: http://nipy.org/data-packages/ .
229
250
230
- A package, such as ``nipy-templates-0.2.tar.gz `` will have the following
231
- sort of structure::
251
+ A package, such as ``nipy-templates-0.2.tar.gz `` will have the following sort
252
+ of structure::
232
253
233
254
234
255
<ROOT>
@@ -248,26 +269,31 @@ sort of structure::
248
269
249
270
250
271
There should be only one ``nipy/packagename `` directory delivered by a
251
- particular package. For example, this package installs
252
- `` nipy/templates ``, but does not contain ``nipy/data ``.
272
+ particular package. For example, this package installs `` nipy/templates ``,
273
+ but does not contain ``nipy/data ``.
253
274
254
275
Making a new package tarball is simply:
255
276
256
- #. Downloading and unpacking e.g ``nipy-templates-0.1.tar.gz `` to form
257
- the directory structure above.
258
- #. Making any changes to the directory
277
+ #. Downloading and unpacking e.g. ``nipy-templates-0.1.tar.gz `` to form the
278
+ directory structure above;
279
+ #. Making any changes to the directory;
259
280
#. Running ``setup.py sdist `` to recreate the package.
260
281
261
282
The process of making a release should be:
262
283
263
- #. Increment the major or minor version number in the ``config.ini `` file
264
- #. Make a package tarball as above
265
- #. Upload to distribution site
284
+ #. Increment the major or minor version number in the ``config.ini `` file;
285
+ #. Make a package tarball as above;
286
+ #. Upload to distribution site.
266
287
267
288
There is an example nipy data package ``nipy-examplepkg `` in the
268
289
``examples `` directory of the NIPY repository.
269
290
270
291
The machinery for creating and maintaining data packages is available at
271
- http://github.com/nipy/data-packaging
292
+ http://github.com/nipy/data-packaging.
272
293
273
294
See the ``README.txt `` file there for more information.
295
+
296
+ .. testcleanup ::
297
+
298
+ import shutil
299
+ shutil.rmtree(tmpdir)
0 commit comments