Skip to content

Commit 21b6450

Browse files
committed
Add tutorial and doctest.
1 parent ee108e0 commit 21b6450

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

README.rst

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,77 @@ Scientific Data Format for Python
44
=================================
55

66
SDF is a Python package to read, write and interpolate multi-dimensional data.
7-
The Scientific Data Format is an open file format based on HDF5 to store
8-
multi-dimensional data such as parameters, simulations results or measurements.
7+
The Scientific Data Format is an open file format based on HDF5_ to store
8+
multi-dimensional data such as parameters, simulation results or measurements.
99
It supports...
1010

1111
- very large files
1212
- up to 32 dimensions
1313
- hierarchical structure
1414
- units, comments and custom meta-information
1515

16-
For detailed information see the SDF specification.
16+
For detailed information see the `SDF specification`_.
1717

1818

1919
Installation
2020
------------
2121

22-
Install the latest release from PyPI
22+
Install the latest release from PyPI::
2323

24-
::
24+
$ pip install sdf
2525

26-
$ sudo pip install sdf
27-
28-
or install the latest development version from source
29-
30-
::
26+
or install the latest development version from source::
3127

3228
$ git clone --branch develop --recursive https://github.com/ScientificDataFormat/SDF-Python.git
3329
$ cd SDF-Python
34-
$ sudo pip install .
30+
$ pip install .
31+
32+
33+
Tutorial
34+
--------
35+
36+
Import the ``SDF`` and ``NumPy`` packages:
37+
38+
>>> import sdf
39+
>>> import numpy as np
40+
41+
Create the data arrays:
42+
43+
>>> t = np.linspace(0, 10, 51)
44+
>>> v = np.sin(t)
45+
46+
Create the datasets:
47+
48+
>>> ds_t = sdf.Dataset('t', data=t, unit='s', is_scale=True, display_name='Time')
49+
>>> ds_v = sdf.Dataset('v', data=v, unit='V', scales=[ds_t])
50+
51+
Create the root group and write the file:
52+
53+
>>> g = sdf.Group('/', comment='A sine voltage', datasets=[ds_t, ds_v])
54+
>>> sdf.save('sine.sdf', g)
55+
56+
Read the dataset from the SDF file asserting the correct unit of the dataset and scale:
57+
58+
>>> ds_v2 = sdf.load('sine.sdf', '/v', unit='V', scale_units=['s'])
59+
60+
Get the meta info and data array from the dataset:
61+
62+
>>> ds_v2.unit
63+
'V'
64+
>>> ds_v2.data.shape
65+
(51,)
66+
67+
Get the scale for the first dimension:
68+
69+
>>> ds_t2 = ds_v2.scales[0]
70+
>>> ds_t2.unit
71+
's'
3572

3673

3774
-----------------------------
3875

3976
|copy| 2017 Dassault Systèmes
4077

78+
.. _SDF specification: https://github.com/ScientificDataFormat/SDF-Specification
79+
.. _HDF5: https://www.hdfgroup.org/hdf5/
4180
.. |copy| unicode:: U+000A9

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ init:
1313
- "echo %PYTHON_VERSION% %MINICONDA%"
1414

1515
install:
16-
- cmd: git submodule update --init --recursive
16+
- git submodule update --init --recursive
1717
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
1818
- conda config --set always_yes yes --set changeps1 no
1919
- conda update -q conda
@@ -23,6 +23,7 @@ install:
2323
- pip install dymat
2424

2525
test_script:
26+
- python -m doctest README.rst
2627
- build_windows
2728
- pip install .
2829
- cd tests

0 commit comments

Comments
 (0)