-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample.py
More file actions
51 lines (43 loc) · 1.46 KB
/
example.py
File metadata and controls
51 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import larray as la
__all__ = ['EXAMPLE_FILES_DIR', 'load_example_data']
EXAMPLE_FILES_DIR = os.path.dirname(__file__) + '/tests/data/'
AVAILABLE_EXAMPLE_DATA = {
'demography' : os.path.join(EXAMPLE_FILES_DIR, 'demography.h5')
}
def load_example_data(name):
"""Load arrays used in the tutorial so that all examples in it can be reproduced.
Parameters
----------
name : str
Example data to load. Available example datasets are:
- demography
Returns
-------
Session
Session containing one or several arrays
Examples
--------
>>> demo = load_example_data('demography')
>>> demo.pop.info # doctest: +SKIP
26 x 3 x 121 x 2 x 2
time [26]: 1991 1992 1993 ... 2014 2015 2016
geo [3]: 'BruCap' 'Fla' 'Wal'
age [121]: 0 1 2 ... 118 119 120
sex [2]: 'M' 'F'
nat [2]: 'BE' 'FO'
>>> demo.qx.info # doctest: +SKIP
26 x 3 x 121 x 2 x 2
time [26]: 1991 1992 1993 ... 2014 2015 2016
geo [3]: 'BruCap' 'Fla' 'Wal'
age [121]: 0 1 2 ... 118 119 120
sex [2]: 'M' 'F'
nat [2]: 'BE' 'FO'
"""
if name is None:
name = 'demography'
if not isinstance(name, str):
raise TypeError("Expected string for argument example_data")
if name not in AVAILABLE_EXAMPLE_DATA.keys():
raise ValueError("example_data must be chosen from list {}".format(list(AVAILABLE_EXAMPLE_DATA.keys())))
return la.Session(AVAILABLE_EXAMPLE_DATA[name])