Skip to content

Commit 3180db4

Browse files
committed
DOC: small rewrite of gettingstarted
Refer to coordinate systems doc. Minor rewrites.
1 parent c54080f commit 3180db4

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

doc/source/gettingstarted.rst

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,46 @@ file format format has its own features and pecularities that need to be taken
1818
care of to get the most out of it. To this end, NiBabel offers both high-level
1919
format-independent access to neuroimages, as well as an API with various levels
2020
of format-specific access to all available information in a particular file
21-
format. The following demonstrations show some of NiBabel's capabilities and
22-
familiarize oneself with the basic design of the API.
21+
format. The following examples show some of NiBabel's capabilities and give
22+
you an idea of the API.
2323

24-
When loading an image, NiBabel aims to figure out the image format from the
24+
For more detail on the API, see :doc:`nibabel_images`.
25+
26+
When loading an image, NiBabel tries to figure out the image format from the
2527
filename. An image in a known format can easily be loaded by simply passing its
26-
name to the ``load`` function.
28+
filename to the ``load`` function.
2729

28-
We load some useful libraries:
30+
To start the code examples, we load some useful libraries:
2931

3032
>>> import os
3133
>>> import numpy as np
3234

33-
Then we get the nibabel example data directory:
35+
Then we fine the nibabel directory containing the example data:
3436

3537
>>> from nibabel.testing import data_path
3638

37-
Now we can load an image:
39+
There is a NIfTI file in this directory called ``example4d.nii.gz``:
40+
41+
>>> example_filename = os.path.join(data_path, 'example4d.nii.gz')
42+
43+
Now we can import nibabel and load the image:
3844

3945
>>> import nibabel as nib
40-
>>> img = nib.load(os.path.join(data_path, 'example4d.nii.gz'))
46+
>>> img = nib.load(example_filename)
4147

4248
A NiBabel image knows about its shape:
4349

4450
>>> img.shape
4551
(128, 96, 24, 2)
4652

47-
and the data type of the data as stored on disk. In this case the data on disk
48-
are 16 bit signed integers:
53+
It also records the data type of the data as stored on disk. In this case the
54+
data on disk are 16 bit signed integers:
4955

5056
>>> img.get_data_dtype() == np.dtype(np.int16)
5157
True
5258

53-
The image also has an affine transformation that determines the
54-
world-coordinates of the image elements.
59+
The image has an affine transformation that determines the world-coordinates of
60+
the image elements (see :doc:`coordinate_systems`):
5561

5662
>>> img.affine.shape
5763
(4, 4)
@@ -80,18 +86,18 @@ e.g.
8086
Corresponding "setter" methods allow modifying a header, while ensuring its
8187
compliance with the file format specifications.
8288

83-
In some situations even more flexibility is required and for ultimate experts
89+
In some situations we need even more flexibility, and for with great courage,
8490
NiBabel also offers access to the raw header information
8591

8692
>>> raw = hdr.structarr
8793
>>> raw['xyzt_units']
8894
array(10, dtype=uint8)
8995

90-
This lowest level of the API is only for people that know what they are doing
91-
and comes without any safety-net.
96+
This lowest level of the API is designed for people who know the file format
97+
well enough to work with its internal data, and comes without any safety-net.
9298

9399
Creating a new image in some file format is also easy. At a minimum it only
94-
needs some image data and an image coordinate transformation.
100+
needs some image data and an image coordinate transformation (affine):
95101

96102
>>> import numpy as np
97103
>>> data = np.ones((32, 32, 15, 100), dtype=np.int16)
@@ -101,15 +107,19 @@ True
101107
>>> img.header.get_xyzt_units()
102108
('unknown', 'unknown')
103109

104-
In this case, identity is used as the affine transformation. The image header
105-
is initialized from the provided data array (i.e. shape, dtype) and all other
106-
values are set to resonable defaults.
110+
In this case, we used the identity matrix as the affine transformation. The
111+
image header is initialized from the provided data array (i.e. shape, dtype)
112+
and all other values are set to resonable defaults.
107113

108114
Saving this new image to a file is trivial. We won't do it here, but it looks
109115
like::
110116

111117
img.to_filename(os.path.join('build','test4d.nii.gz'))
112118

119+
or::
120+
121+
nib.save(img, os.path.join('build','test4d.nii.gz'))
122+
113123
This short introduction only gave a quick overview of NiBabel's capabilities.
114124
Please have a look at the :ref:`api` for more details about supported file
115125
formats and their features.

0 commit comments

Comments
 (0)