Skip to content

Commit 57c806c

Browse files
committed
- added references to API Reference page + other sections of the tutorial in the tutorial_presenting_larray_objects notebook
- updated the subsection Session of the tutorial_presenting_larray_objects notebook
1 parent 281e51f commit 57c806c

File tree

2 files changed

+128
-113
lines changed

2 files changed

+128
-113
lines changed

doc/source/tutorial/tutorial_presenting_larray_objects.ipyml

Lines changed: 57 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ cells:
99
import warnings
1010
warnings.filterwarnings("ignore", message=r'.*numpy.dtype size changed*')
1111

12-
id: 0
1312
metadata:
1413
nbsphinx: hidden
1514

@@ -20,7 +19,6 @@ cells:
2019
- code: |
2120
from larray import *
2221

23-
id: 1
2422

2523
- markdown: |
2624
Check the version of LArray:
@@ -30,7 +28,6 @@ cells:
3028
from larray import __version__
3129
__version__
3230

33-
id: 2
3431

3532
- markdown: |
3633
## Axis
@@ -53,7 +50,10 @@ cells:
5350

5451
age, sex, time, other
5552

56-
id: 3
53+
54+
- markdown: |
55+
See the [Axis](../api.rst#axis) section of the API Reference to explore all methods of Axis objects.
56+
5757

5858
- markdown: |
5959
## Groups
@@ -75,7 +75,6 @@ cells:
7575

7676
teens
7777

78-
id: 4
7978

8079
- markdown: |
8180
It is possible to set a name or to rename a group after its declaration:
@@ -90,12 +89,19 @@ cells:
9089

9190
teens
9291

93-
id: 5
92+
93+
- markdown: |
94+
See the [Group](../api.rst#group) section of the API Reference to explore all methods of Group objects.
95+
9496

9597
- markdown: |
9698
## LArray
9799

98-
A ``LArray`` object represents a multidimensional array with labeled axes (#ref needed).
100+
A ``LArray`` object represents a multidimensional array with labeled axes.
101+
102+
See the [LArray](../api.rst#larray) section of the API Reference to explore all methods of LArray objects.
103+
104+
To know how to save and load arrays in CSV, Excel or HDF format, please refer to the [Loading and Dumping Arrays](tutorial_IO.ipynb#Loading-and-Dumping-Arrays) section of the tutorial.
99105

100106
### Create an array from scratch
101107

@@ -116,7 +122,6 @@ cells:
116122
arr = LArray(data, axes, meta=meta)
117123
arr
118124

119-
id: 6
120125

121126
- markdown: |
122127
Metadata can be added to an array at any time using:
@@ -127,7 +132,6 @@ cells:
127132

128133
arr.meta
129134

130-
id: 7
131135

132136
- markdown: |
133137
<div class="alert alert-warning">
@@ -172,14 +176,12 @@ cells:
172176
# start defines the starting value of data
173177
ndtest(['age=0..2', 'sex=M,F', 'time=2007..2009'], start=-1)
174178

175-
id: 8
176179

177180
- code: |
178181
# start defines the starting value of data
179182
# label_start defines the starting index of labels
180183
ndtest((3, 3), start=-1, label_start=2)
181184

182-
id: 9
183185

184186
- code: |
185187
# empty generates uninitialised array with correct axes
@@ -190,24 +192,20 @@ cells:
190192
# will be overridden.
191193
empty(['age=0..2', 'sex=M,F', 'time=2007..2009'])
192194

193-
id: 10
194195

195196
- code: |
196197
# example with anonymous axes
197198
zeros(['0..2', 'M,F', '2007..2009'])
198199

199-
id: 11
200200

201201
- code: |
202202
# dtype=int forces to store int data instead of default float
203203
ones(['age=0..2', 'sex=M,F', 'time=2007..2009'], dtype=int)
204204

205-
id: 12
206205

207206
- code: |
208207
full(['age=0..2', 'sex=M,F', 'time=2007..2009'], 1.23)
209208

210-
id: 13
211209

212210
- markdown: |
213211
All the above functions exist in *(func)_like* variants which take axes from another array
@@ -216,7 +214,6 @@ cells:
216214
- code: |
217215
ones_like(arr)
218216

219-
id: 14
220217

221218
- markdown: |
222219
Create an array using the special ``sequence`` function (see link to documention of ``sequence`` in API reference for more examples):
@@ -226,7 +223,6 @@ cells:
226223
# With initial=1.0 and inc=0.5, we generate the sequence 1.0, 1.5, 2.0, 2.5, 3.0, ...
227224
sequence('sex=M,F', initial=1.0, inc=0.5)
228225

229-
id: 15
230226

231227
- markdown: |
232228
### Inspecting LArray objects
@@ -236,7 +232,6 @@ cells:
236232
# create a test array
237233
arr = ndtest([age, sex, time, other])
238234

239-
id: 16
240235

241236
- markdown: |
242237
Get array summary : dimensions + description of axes
@@ -245,7 +240,6 @@ cells:
245240
- code: |
246241
arr.info
247242

248-
id: 17
249243

250244
- markdown: |
251245
Get axes
@@ -254,7 +248,6 @@ cells:
254248
- code: |
255249
arr.axes
256250

257-
id: 18
258251

259252
- markdown: |
260253
Get array dimensions
@@ -263,7 +256,6 @@ cells:
263256
- code: |
264257
arr.shape
265258

266-
id: 19
267259

268260
- markdown: |
269261
Get number of elements
@@ -272,7 +264,6 @@ cells:
272264
- code: |
273265
arr.size
274266

275-
id: 20
276267

277268
- markdown: |
278269
Get size in memory
@@ -281,7 +272,6 @@ cells:
281272
- code: |
282273
arr.memory_used
283274

284-
id: 21
285275

286276
- markdown: |
287277
Display the array in the viewer (graphical user interface) in read-only mode.
@@ -306,39 +296,63 @@ cells:
306296
A ``Session`` object is a dictionary-like object used to gather several arrays, axes and groups.
307297
A session is particularly adapted to gather all input objects of a model or to gather the output arrays from different scenarios. Like with arrays, it is possible to associate metadata to sessions.
308298

309-
In addition to act like dictionaries, sessions offer several specific methods, like:
310-
- ``save`` and ``load`` to save and load all arrays of a session at once in/from CSV or Excel or HDF5 file(s),
311-
- ``equals`` and ``array_equals`` to compare arrays between two sessions (scenarios) one by one,
312-
- ``apply`` to apply a function to all arrays of a session.
299+
See the [Session](../api.rst#session) section of the API Reference to explore all methods of Session objects.
300+
301+
To know how to save and load sessions in CSV, Excel or HDF format, please refer to the [Loading and Dumping Sessions](tutorial_IO.ipynb#Loading-and-Dumping-Sessions) section of the tutorial.
313302

314-
See the API Reference section to explore all methods of Session objects.
303+
To see how to work with sessions, please read the [Working With Sessions](tutorial_sessions.ipynb#Working-With-Sessions) section of the tutorial.
315304

316305

317306
- markdown: |
318-
### Create a Session
307+
### Creating Sessions
319308

320-
Create an empty session and populate it:
309+
To create a session, you can first create an empty session and then populate it with arrays, axes and groups:
321310

322311

323312
- code: |
324313
# create an empty session
325-
s = Session()
314+
s_pop = Session()
326315

327-
# populate the session (with arrays, axes or groups) using 2 ways:
328-
# 1) with syntax: session.object_name = object
329-
s.axisa = Axis('a=a0..a2')
330-
s.arr1 = ndtest(s.axisa)
331-
# 2) like a dictionary: session['object_name'] = object
332-
s['axisb'] = Axis('b=b0..b3')
333-
s['arr2'] = ndtest((s['axisa'], s['axisb']))
316+
# add axes to the session
317+
gender = Axis("gender=Male,Female")
318+
s_pop.gender = gender
319+
time = Axis("time=2013,2014,2015")
320+
s_pop.time = time
321+
322+
# add arrays to the session
323+
s_pop.pop = zeros((gender, time))
324+
s_pop.births = zeros((gender, time))
325+
s_pop.deaths = zeros((gender, time))
334326

335327
# add metadata after creation
336-
s.meta.title = 'Input objects'
337-
s.meta.description = 'Input axes and arrays for the model X'
328+
s_pop.meta.title = 'Demographic Model of Belgium'
329+
s_pop.meta.description = 'Modelize the demography of Belgium'
330+
331+
# print content of the session
332+
print(s_pop.summary())
333+
334+
335+
- markdown: |
336+
or you can create and populate a session in one step:
337+
338+
339+
- code: |
340+
gender = Axis("gender=Male,Female")
341+
time = Axis("time=2013,2014,2015")
342+
343+
# create and populate a new session in one step
344+
# Python <= 3.5
345+
s_pop = Session([('gender', gender), ('time', time), ('pop', zeros((gender, time))),
346+
('births', zeros((gender, time))), ('deaths', zeros((gender, time)))],
347+
meta=[('title', 'Demographic Model of Belgium'),('description', 'Modelize the demography of Belgium')])
348+
# Python 3.6+
349+
s_pop = Session(gender=gender, time=time, pop=zeros((gender, time)),
350+
births=zeros((gender, time)), deaths=zeros((gender, time)),
351+
meta=Metadata(title='Demographic Model of Belgium', description='Modelize the demography of Belgium'))
338352

339-
s
353+
# print content of the session
354+
print(s_pop.summary())
340355

341-
id: 22
342356

343357
- markdown: |
344358
<div class="alert alert-warning">
@@ -348,29 +362,14 @@ cells:
348362
<li>Contrary to array metadata, saving and loading session metadata is supported for
349363
all current session file formats: Excel, CSV and HDF (.h5).</li>
350364
<li>Metadata is not kept when actions or methods are applied on a session
351-
except for operations modifying a session in-place, such as: `s['arr1'] = 0`.
365+
except for operations modifying a session in-place, such as: `s.arr1 = 0`.
352366
Do not add metadata to a session if you know you will apply actions or methods
353367
on it before dumping it.</li>
354368
</ul>
355369

356370
</div>
357371

358372

359-
- markdown: |
360-
Load a session from a file:
361-
362-
363-
- code: |
364-
# get the filepath of the example file to be read
365-
filepath = get_example_filepath('demography.h5')
366-
367-
# load session
368-
s2 = Session(filepath)
369-
370-
s2
371-
372-
id: 23
373-
374373
# The lines below here may be deleted if you do not need them.
375374
# ---------------------------------------------------------------------------
376375
metadata:
@@ -395,16 +394,3 @@ metadata:
395394
nbformat: 4
396395
nbformat_minor: 2
397396

398-
# ---------------------------------------------------------------------------
399-
data:
400-
[{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
401-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
402-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
403-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
404-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
405-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
406-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
407-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
408-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
409-
outputs: []}, {execution_count: null, outputs: []}]
410-

0 commit comments

Comments
 (0)