Skip to content

Commit 37baf23

Browse files
author
Verweijen
committed
Improve documentation
1 parent ba4a6f9 commit 37baf23

File tree

8 files changed

+143
-44
lines changed

8 files changed

+143
-44
lines changed

docs/source/conf.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
'sphinx.ext.githubpages',
2020
'sphinx.ext.viewcode',
2121
'myst_parser',
22+
'sphinxcontrib.mermaid',
2223
]
2324

2425
templates_path = ['_templates']
2526
exclude_patterns = []
2627

27-
28+
# Make sure __init__ is always documented.
29+
autodoc_default_options = {
30+
# 'members': True,
31+
'member-order': 'bysource',
32+
'special-members': '__init__',
33+
# 'undoc-members': True,
34+
# 'exclude-members': '__weakref__'
35+
}
2836

2937
# -- Options for HTML output -------------------------------------------------
3038
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

docs/source/hierarchies.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Hierarchies #
2+
3+
For explanatory variables, it is recommended to supply a hierarchy.
4+
There are 3 kinds of hierarchy supported by PiArgus.
5+
6+
## FlatHierarchy ##
7+
8+
This is the default if no hierarchy is supplied.
9+
All labels are of the same level with a single total.
10+
11+
```python
12+
import piargus as pa
13+
14+
datacol = ["A", "B", "C", "B", "A"]
15+
hierarchy = pa.FlatHierarchy(total_code="Total")
16+
```
17+
18+
```{mermaid}
19+
graph LR;
20+
Total --> A;
21+
Total --> B;
22+
Total --> C;
23+
```
24+
25+
## LevelHierarchy ##
26+
27+
A level hierarchy is useful when the hierarchy is encoded within the code itself.
28+
29+
```python
30+
import piargus as pa
31+
32+
datacol = ["11123", "11234", "23456"]
33+
hierarchy = pa.LevelHierarchy(levels=[2, 3], total_code="Total")
34+
```
35+
36+
```{mermaid}
37+
graph LR;
38+
Total --> 11;
39+
Total --> 23;
40+
11 --> 123;
41+
11 --> 234;
42+
23 --> 456;
43+
```
44+
45+
## TreeHierarchy ##
46+
47+
For complex hierarchies, a TreeHierarchy can be used.
48+
These are typically stored in a hrc-file.
49+
50+
```python
51+
import piargus as pa
52+
53+
datacol = ["PV20", "PV21", "PV22"]
54+
hierarchy = pa.TreeHierarchy.from_hrc("provinces.hrc", total_code="NL01")
55+
```
56+
57+
```{mermaid}
58+
graph LR;
59+
NL01 --> LD01;
60+
NL01 --> LD02;
61+
LD01 --> PV20;
62+
LD01 --> PV21;
63+
LD02 --> PV22;
64+
```
65+
66+
The file provinces.hrc may look like this:
67+
```hrc
68+
LD01
69+
@PV20
70+
@PV21
71+
LD02
72+
@PV22
73+
```
74+
75+
It can also be created programmatically:
76+
```python
77+
import piargus as pa
78+
79+
hierarchy = pa.TreeHierarchy(total_code="NL01")
80+
hierarchy.create_node(["NL01", "LD01", "PV20"])
81+
hierarchy.create_node(["NL01", "LD01", "PV21"])
82+
hierarchy.create_node(["NL01", "LD02", "PV22"])
83+
hierarchy.to_hrc('provinces.hrc')
84+
```

docs/source/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ It's also recommended to read the `TauArgus manual <https://research.cbs.nl/casc
1616
:maxdepth: 2
1717
:caption: Contents:
1818

19-
installation
20-
tutorial
19+
userguide
2120
api
2221
changes
2322

docs/source/userguide.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
User guide
2+
----------
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
:caption: Contents:
7+
8+
installation
9+
tutorial
10+
hierarchies

src/piargus/inputspec/microdata.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def __init__(
3030
:param weight: Column that contains the sampling weight of this record.
3131
:param request: Column that indicates if a respondent asks for protection.
3232
:param request_values: Parameters that indicate if request is asked.
33-
Two different request values can be specified for two different levels in the request_rule.
33+
Two different request values can be specified for two different levels in the request_rule.
3434
:param holding: Column containing the group identifier.
3535
:param args: See InputData.
3636
:param kwargs: See InputData.
37+
3738
See the Tau-Argus documentation for more details on these parameters.
3839
"""
3940
super().__init__(dataset, **kwargs)

src/piargus/inputspec/tabledata.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def __init__(
5858
:param total_codes: Codes within explanatory that are used for the totals.
5959
:param frequency: Column containing number of contributors to this cell.
6060
:param top_contributors: The columns containing top contributions for dominance rule.
61-
The columns should be in the same order as they appear in the dataset.
62-
The first of the these columns should describe the highest contribution,
63-
the second column the second-highest contribution.
61+
The columns should be in the same order as they appear in the dataset.
62+
The first of the these columns should describe the highest contribution,
63+
the second column the second-highest contribution.
6464
:param lower_protection_level: Column that denotes the level below which values are unsafe.
6565
:param upper_protection_level: Column that denotes the level above which values are unsafe.
6666
:param status_indicator: Column indicating the status of cells.
6767
:param status_markers: The meaning of each status.
68-
Should be dictionary mapping "SAFE", "UNSAFE" and "STATUS" to a code indicating status.
68+
Should be dictionary mapping "SAFE", "UNSAFE" and "STATUS" to a code indicating status.
6969
:param kwargs: See InputData
7070
"""
7171

src/piargus/job.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ def __init__(
3939
the existing file is used. If modifications are made to the metadata, then the user
4040
should call metadata.to_rda() first.
4141
42-
:param input_data: The source from which to generate tables. Needs to be either
43-
MicroData or TableData.
42+
:param input_data: The source from which to generate tables.
43+
Needs to be either MicroData or TableData.
4444
:param tables: The tables to be generated. Can be omitted if input_data is TableData.
4545
:param metadata: The metadata of input_data. If omitted, it will be derived from input_data.
4646
:param linked_suppress_method: Method to use for linked suppression.
47-
Options are:
48-
- `GHMITER` ("GH"): Hypercube
49-
- `MODULAR` ("MOD"): Modular
50-
Warning: The Tau-Argus manual doesn't document this. Therefore, usage is not recommended.
47+
Options are:
48+
* `GHMITER` ("GH"): Hypercube
49+
* `MODULAR` ("MOD"): Modular
5150
:param linked_suppress_method_args: Parameters to pass to suppress_method.
5251
:param directory: Where to write tau-argus files.
5352
:param name: Name from which to derive the name of some temporary files.

src/piargus/outputspec/table.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,40 @@ def __init__(
3131
"""
3232
Create a new Table
3333
34-
Parameters:
3534
:param explanatory: List of background variables that explain the response.
36-
Will be set as a Dataframe-index.
35+
Will be set as a Dataframe-index.
3736
:param response: The column that needs to be explained.
3837
:param shadow: The column that is used for the safety rules. Default: response.
3938
:param cost: The column that contains the cost of suppressing a cell.
40-
Set to 1 to minimise the number of cells suppressed (although this might suppress totals).
41-
Default: response.
42-
:param labda: If set to a value > 0, a box-cox transformation is applied on the cost
43-
variable.
44-
If set to 0, a log transformation is applied on the cost.
45-
Default: 1.
39+
Set to 1 to minimise the number of cells suppressed (although this might suppress totals).
40+
Default: response.
41+
:param labda: If set to a value > 0, a box-cox transformation is applied on the cost variable.
42+
If set to 0, a log transformation is applied on the cost.
43+
Default: 1.
4644
:param safety_rule: A set of safety rules on individual level.
47-
Can be supplied as:
48-
- str where parts are separated by |
49-
- A sequence of parts
50-
- A dict with keys {"individual": x "holding": y} with separate rules on individual and
51-
holding level .
52-
Each part can be:
53-
- "P(p, n=1)": p% rule
54-
- "NK(n, k)": (n, k)-dominance rule
55-
- "ZERO(safety_range)": Zero rule
56-
- "FREQ(minfreq, safety_range)": Frequency rule
57-
- "REQ(percentage_1, percentage_2, safety_margin)": Request rule
58-
See the Tau-Argus manual for details on those rules.
59-
:param apriori: Apriori file to change parameters
45+
Can be supplied as:
46+
* str where parts are separated by |
47+
* A sequence of parts
48+
* A dict with keys {"individual": x "holding": y} with separate rules on individual and
49+
holding level.
50+
Each part can be:
51+
* "P(p, n=1)": p% rule
52+
* "NK(n, k)": (n, k)-dominance rule
53+
* "ZERO(safety_range)": Zero rule
54+
* "FREQ(minfreq, safety_range)": Frequency rule
55+
* "REQ(percentage_1, percentage_2, safety_margin)": Request rule
56+
See the Tau-Argus manual for details on those rules.
57+
:param apriori: Apriori file to change parameters.
6058
:param suppress_method: Method to use for secondary suppression.
61-
Options are:
62-
- `GHMITER` ("GH"): Hypercube
63-
- `MODULAR` ("MOD"): Modular
64-
- `OPTIMAL` ("OPT"): Optimal [default]
65-
- `NETWORK` ("NET"): Network
66-
- `ROUNDING` ("RND"): Controlled rounding
67-
- `TABULAR_ADJUSTMENT` ("CTA"): Controlled Tabular Adjustment
68-
- None: No secondary suppression is applied
69-
See the Tau-Argus manual for details on those rules.
59+
Options are:
60+
* `GHMITER` ("GH"): Hypercube
61+
* `MODULAR` ("MOD"): Modular
62+
* `OPTIMAL` ("OPT"): Optimal [default]
63+
* `NETWORK` ("NET"): Network
64+
* `ROUNDING` ("RND"): Controlled rounding
65+
* `TABULAR_ADJUSTMENT` ("CTA"): Controlled Tabular Adjustment
66+
* None: No secondary suppression is applied
67+
See the Tau-Argus manual for details on those rules.
7068
:param suppress_method_args: Parameters to pass to suppress_method.
7169
"""
7270

0 commit comments

Comments
 (0)