Skip to content

Commit 71b6a38

Browse files
committed
fix #829 : made some changes in the Tutorial (see list below)
- replaced the pop variable by population everywhere in the tutorial and in examples data. - replaced the s_population variable by demography_session everywhere in the tutorial. - replaced the demo_eurostat variable by demography_eurostat everywhere in the tutorial. - replaced sex by gender in the 'Getting Started' and 'Presenting LArray Objects' sections. - moved set_labels(dict) example before set_labels(func) in the tutorial. - added a warning about set_labels(list) in the api doc because this is a big source of mistake. - added an example of Array.clip() with arrays as minval and maxval. - added many examples in the Plotting section of the tutorial. - split the 'Arithmetic Operations And Aggregations' section into two sections 'Arithmetic Operations' and 'Aggregations'. - rewritten the 'Extra Or Missing Axes (Broadcasting)' subsection of the 'Arithmetic Operations' section. - added small subsection 'Iterating over an Axis' in the 'Indexing, Selecting and Assigning' section. - moved subsection 'Loading and Dumping Sessions' from tutorial_IO notebook to tutorial_sessions notebook. - moved subsection 'Combine Arrays' from the tutorial_transforming notebook to a new tutorial_combine_arrays notebook. - added new array 'population_5_countries' in the 'demography_eurostat' dataset. - replaced use of sum() by mean() in the 'Pythonic VS String Syntax' section.
1 parent 4ca9961 commit 71b6a38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3523
-2463
lines changed

doc/source/tutorial.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ It is mainly dedicated to help new users to familiarize with it and others to re
1616
./tutorial/tutorial_presenting_larray_objects.ipynb
1717
./tutorial/tutorial_IO.ipynb
1818
./tutorial/tutorial_transforming.ipynb
19+
./tutorial/tutorial_combine_arrays.ipynb
1920
./tutorial/tutorial_indexing.ipynb
20-
./tutorial/tutorial_arithmetic_op_and_aggregation.ipynb
21+
./tutorial/tutorial_arithmetic_operations.ipynb
22+
./tutorial/tutorial_aggregations.ipynb
2123
./tutorial/tutorial_string_syntax.ipynb
2224
./tutorial/tutorial_plotting.ipynb
2325
./tutorial/tutorial_miscellaneous.ipynb

doc/source/tutorial/getting_started.ipyml

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ cells:
6464
[756, 775, 793]]]
6565

6666
# create an Array object
67-
pop = Array(data, axes=[age, gender, time])
68-
pop
67+
population = Array(data, axes=[age, gender, time])
68+
population
6969

7070

7171
- markdown: |
7272
You can optionally attach some metadata to an array:
7373

7474

7575
- code: |
76-
# attach some metadata to the pop array
77-
pop.meta.title = 'population by age, sex and year'
78-
pop.meta.source = 'Eurostat'
76+
# attach some metadata to the population array
77+
population.meta.title = 'population by age, gender and year'
78+
population.meta.source = 'Eurostat'
7979

8080
# display metadata
81-
pop.meta
81+
population.meta
8282

8383

8484
- markdown: |
@@ -87,7 +87,7 @@ cells:
8787

8888
- code: |
8989
# Array summary: metadata + dimensions + description of axes
90-
pop.info
90+
population.info
9191

9292

9393
- markdown: |
@@ -134,8 +134,8 @@ cells:
134134

135135

136136
- code: |
137-
# save our pop array to a CSV file
138-
pop.to_csv('belgium_pop.csv')
137+
# save our population array to a CSV file
138+
population.to_csv('population_belgium.csv')
139139

140140

141141
- markdown: |
@@ -164,8 +164,8 @@ cells:
164164

165165

166166
- code: |
167-
pop = read_csv('belgium_pop.csv')
168-
pop
167+
population = read_csv('population_belgium.csv')
168+
population
169169

170170

171171
- markdown: |
@@ -184,31 +184,31 @@ cells:
184184

185185

186186
- code: |
187-
pop['67+', 'female', 2017]
187+
population['67+', 'female', 2017]
188188

189189

190190
- markdown: |
191191
Labels can be given in arbitrary order:
192192

193193

194194
- code: |
195-
pop[2017, 'female', '67+']
195+
population[2017, 'female', '67+']
196196

197197

198198
- markdown: |
199199
When selecting a larger subset the result is an array:
200200

201201

202202
- code: |
203-
pop['female']
203+
population['female']
204204

205205

206206
- markdown: |
207207
When selecting several labels for the same axis, they must be given as a list (enclosed by ``[ ]``)
208208

209209

210210
- code: |
211-
pop['female', ['0-9', '10-17']]
211+
population['female', ['0-9', '10-17']]
212212

213213

214214
- markdown: |
@@ -219,13 +219,13 @@ cells:
219219

220220
- code: |
221221
# in this case '10-17':'67+' is equivalent to ['10-17', '18-66', '67+']
222-
pop['female', '10-17':'67+']
222+
population['female', '10-17':'67+']
223223

224224

225225
- code: |
226226
# :'18-66' selects all labels between the first one and '18-66'
227227
# 2017: selects all labels between 2017 and the last one
228-
pop[:'18-66', 2017:]
228+
population[:'18-66', 2017:]
229229

230230

231231
- markdown: |
@@ -287,34 +287,45 @@ cells:
287287
immigration[country['Netherlands'], citizenship['Belgium'], 2017]
288288

289289

290+
- markdown: |
291+
## Iterating over an axis
292+
293+
To iterate over an axis, use the following syntax:
294+
295+
296+
- code: |
297+
for year in time:
298+
print(year)
299+
300+
290301
- markdown: |
291302
## Aggregation
292303

293304

294305
- markdown: |
295306
The LArray library includes many [aggregations methods](../api.rst#aggregation-functions): sum, mean, min, max, std, var, ...
296307

297-
For example, assuming we still have an array in the ``pop`` variable:
308+
For example, assuming we still have an array in the ``population`` variable:
298309

299310

300311
- code: |
301-
pop
312+
population
302313

303314

304315
- markdown: |
305-
We can sum along the 'sex' axis using:
316+
We can sum along the 'gender' axis using:
306317

307318

308319
- code: |
309-
pop.sum(gender)
320+
population.sum(gender)
310321

311322

312323
- markdown: |
313-
Or sum along both 'age' and 'sex':
324+
Or sum along both 'age' and 'gender':
314325

315326

316327
- code: |
317-
pop.sum(age, gender)
328+
population.sum(age, gender)
318329

319330

320331
- markdown: |
@@ -323,7 +334,7 @@ cells:
323334

324335

325336
- code: |
326-
pop.sum_by(time)
337+
population.sum_by(time)
327338

328339

329340
- markdown: |
@@ -354,31 +365,31 @@ cells:
354365

355366

356367
- markdown: |
357-
Still using the same ``pop`` array:
368+
Still using the same ``population`` array:
358369

359370

360371
- code: |
361-
pop
372+
population
362373

363374

364375
- markdown: |
365376
Groups can be used in selections:
366377

367378

368379
- code: |
369-
pop[working]
380+
population[working]
370381

371382

372383
- code: |
373-
pop[nonworking]
384+
population[nonworking]
374385

375386

376387
- markdown: |
377388
or aggregations:
378389

379390

380391
- code: |
381-
pop.sum(nonworking)
392+
population.sum(nonworking)
382393

383394

384395
- markdown: |
@@ -387,7 +398,7 @@ cells:
387398

388399

389400
- code: |
390-
pop.sum((children, working, nonworking))
401+
population.sum((children, working, nonworking))
391402

392403

393404
- markdown: |
@@ -401,19 +412,21 @@ cells:
401412

402413

403414
- code: |
404-
pop = zeros([age, gender, time])
415+
population = zeros([age, gender, time])
405416
births = zeros([age, gender, time])
406417
deaths = zeros([age, gender, time])
407418

408-
# create a session containing the three arrays 'pop', 'births' and 'deaths'
409-
demo = Session(pop=pop, births=births, deaths=deaths)
419+
# create a session containing the three arrays 'population', 'births' and 'deaths'
420+
demography_session = Session(population=population, births=births, deaths=deaths)
410421

411422
# displays names of arrays contained in the session
412-
demo.names
413-
# get an array
414-
demo['pop']
423+
demography_session.names
424+
# get an array (option 1)
425+
demography_session['population']
426+
# get an array (option 2)
427+
demography_session.births
415428
# add/modify an array
416-
demo['foreigners'] = zeros([age, gender, time])
429+
demography_session['foreigners'] = zeros([age, gender, time])
417430

418431

419432
- markdown: |
@@ -422,7 +435,7 @@ cells:
422435
to the Session constructor otherwise the arrays will be stored in an arbitrary order in
423436
the new session. For example, the session above must be created using the syntax:
424437

425-
`demo=Session([('pop', pop), ('births', births), ('deaths', deaths)])`.
438+
`demography_session=Session([('population', population), ('births', births), ('deaths', deaths)])`.
426439
</div>
427440

428441

@@ -431,10 +444,10 @@ cells:
431444

432445

433446
- code: |
434-
# dump all arrays contained in the session 'demo' in one HDF5 file
435-
demo.save('demo.h5')
436-
# load all arrays saved in the HDF5 file 'demo.h5' and store them in the session 'demo'
437-
demo = Session('demo.h5')
447+
# dump all arrays contained in demography_session in one HDF5 file
448+
demography_session.save('demography.h5')
449+
# load all arrays saved in the HDF5 file 'demography.h5' and store them in the 'demography_session' variable
450+
demography_session = Session('demography.h5')
438451

439452

440453
- markdown: |
@@ -452,10 +465,10 @@ cells:
452465
- markdown: |
453466
```python
454467
# shows the arrays of a given session in a graphical user interface
455-
view(demo)
468+
view(demography_session)
456469

457470
# the session may be directly loaded from a file
458-
view('demo.h5')
471+
view('demography.h5')
459472

460473
# creates a session with all existing arrays from the current namespace
461474
# and shows its content

0 commit comments

Comments
 (0)