Skip to content

Commit 37bb5c4

Browse files
committed
docs: from Numpy to reStructuredText
1 parent 412523e commit 37bb5c4

14 files changed

Lines changed: 312 additions & 395 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pip install -e .[dev]
2828
When pushing commits, please use the project naming conventions, which are available in [this guide](https://www.conventionalcommits.org/en/v1.0.0/).
2929
If you haven't respected these conventions, do a rebase before making the pull request.
3030

31-
The documentation style used in the project is **NumPy**. Please, if you add or modify documentation, use this style. If you need more information or examples, look in the code, or in [this guide](https://numpydoc.readthedocs.io/en/latest/format.html).
31+
The documentation style used in the project is **reStructuredText**. Please, if you add or modify documentation, use this style. If you need more information or examples, look in the code, in [this guide](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html), or in [this PEP](https://peps.python.org/pep-0287/).
3232

3333
Before creating your pull request, when you have made all your commits, you need to run this:
3434
```shell

aztec_tool/__init__.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""A fast, pure-Python Aztec Code reader with auto-orientation and Reed-Solomon correction."""
2+
13
from __future__ import annotations
24

35
from importlib.metadata import PackageNotFoundError
@@ -64,39 +66,35 @@ def decode(
6466
"""Decode an Aztec Code image in **one line**.
6567
6668
This convenience wrapper instantiates :class:`~aztec_tool.decoder.AztecDecoder`
67-
and returns its :pyattr:`~aztec_tool.decoder.AztecDecoder.message`
68-
property. All keyword arguments are forwarded unchanged.
69-
70-
Parameters
71-
----------
72-
image_path : Union[str, pathlib.Path]
73-
Path to the cropped image containing the Aztec symbol.
74-
auto_orient : Optional[bool], default ``True``
75-
Auto-rotate the matrix to the canonical orientation.
76-
auto_correct : Optional[bool], default ``True``
77-
Apply Reed-Solomon correction on the *data* code-words.
78-
mode_auto_correct : Optional[bool], default ``True``
79-
Apply Reed-Solomon correction on the *mode* message.
80-
**kwargs
81-
Reserved for future options, currently ignored.
82-
83-
Returns
84-
-------
85-
str
86-
The decoded user message.
87-
88-
Raises
89-
------
90-
InvalidParameterError
91-
The image path is invalid or the file cannot be opened.
92-
BullseyeDetectionError, OrientationError, ReedSolomonError, …
93-
Any exception propagated by the underlying decoder phases.
94-
95-
Examples
96-
--------
97-
>>> from aztec_tool import decode
98-
>>> decode("ticket.png")
99-
'EVENT: Concert\\nROW 12 SEAT 34'
69+
and returns its :attr:`~aztec_tool.decoder.AztecDecoder.message`
70+
property. All keyword arguments are forwarded unchanged.
71+
72+
:param image_path: Path to the cropped image containing the Aztec symbol.
73+
:type image_path: Union[str, pathlib.Path]
74+
:param auto_orient: Auto-rotate the matrix to the canonical orientation, defaults to ``True``
75+
:type auto_orient: Optional[bool]
76+
:param auto_correct: Apply Reed-Solomon correction on the *data* code-words, defaults to ``True``
77+
:type auto_correct: Optional[bool]
78+
:param mode_auto_correct: Apply Reed-Solomon correction on the *mode* message, defaults to ``True``
79+
:type mode_auto_correct: Optional[bool]
80+
:param kwargs: Reserved for future options, currently ignored.
81+
:type kwargs: Any
82+
83+
:return: The decoded user message.
84+
:rtype: str
85+
86+
:raises InvalidParameterError: The image path is invalid or the file cannot be opened.
87+
:raises BullseyeDetectionError: Error during bullseye detection.
88+
:raises OrientationError: Error during orientation detection.
89+
:raises ReedSolomonError: Error during Reed-Solomon correction.
90+
91+
**Example:**
92+
93+
.. code-block:: python
94+
95+
>>> from aztec_tool import decode
96+
>>> decode("ticket.png")
97+
'EVENT: Concert\\\\nROW 12 SEAT 34'
10098
"""
10199
return AztecDecoder(
102100
image_path,

aztec_tool/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""aztec-tool command line interface."""
2+
13
import argparse
24
import sys
35
from pathlib import Path

aztec_tool/codewords.py

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Aztec Code code-word reader with Reed-Solomon error correction and high-level decoding."""
2+
13
from __future__ import annotations
24

35
from functools import cached_property
@@ -23,42 +25,23 @@
2325
class CodewordReader:
2426
"""Read the data spiral, apply Reed-Solomon correction and decode code-words.
2527
26-
Parameters
27-
----------
28-
matrix : numpy.ndarray
29-
Square binary matrix (0/1) representing the Aztec symbol.
30-
layers : int
31-
Number of data layers (excluding the bull's-eye).
32-
data_words : int
33-
Expected count of data code-words (script does *not* include ECC words).
34-
aztec_type : AztecType
35-
``AztecType.COMPACT`` or ``AztecType.FULL`` according to the spec.
36-
auto_correct : Optional[bool], default ``True``
37-
If *True*, a Reed-Solomon pass is executed before high-level decoding.
38-
39-
Attributes
40-
----------
41-
bitmap : numpy.ndarray
42-
Raw bit-stream extracted from the symbol (before ECC correction).
43-
corrected_bits : List[int]
44-
Bit-stream after Reed-Solomon decoding and bit-stuff removal.
45-
decoded_string : str
46-
Final user message built with the Aztec shift/latch tables.
47-
48-
Raises
49-
------
50-
InvalidParameterError
51-
One of the constructor arguments is incoherent (e.g. *layers* < 1).
52-
BitReadError
53-
Data spiral extraction failed (index out of matrix or empty result).
54-
ReedSolomonError
55-
The Reed-Solomon decoder could not correct the symbol.
56-
BitStuffingError
57-
Stuffed/padding bits do not follow the spec rules.
58-
SymbolDecodeError
59-
An index maps to no entry in the current character table.
60-
StreamTerminationError
61-
Premature end of bit-stream (e.g. incomplete Byte-shift segment).
28+
:param matrix: Square binary matrix (0/1) representing the Aztec symbol.
29+
:type matrix: numpy.ndarray
30+
:param layers: Number of data layers (excluding the bull's-eye).
31+
:type layers: int
32+
:param data_words: Expected count of data code-words (script does *not* include ECC words).
33+
:type data_words: int
34+
:param aztec_type: ``AztecType.COMPACT`` or ``AztecType.FULL`` according to the spec.
35+
:type aztec_type: AztecType
36+
:param auto_correct: If *True*, a Reed-Solomon pass is executed before high-level decoding, defaults to ``True``
37+
:type auto_correct: Optional[bool]
38+
39+
:raises InvalidParameterError: One of the constructor arguments is incoherent (e.g. *layers* < 1).
40+
:raises BitReadError: Data spiral extraction failed (index out of matrix or empty result).
41+
:raises ReedSolomonError: The Reed-Solomon decoder could not correct the symbol.
42+
:raises BitStuffingError: Stuffed/padding bits do not follow the spec rules.
43+
:raises SymbolDecodeError: An index maps to no entry in the current character table.
44+
:raises StreamTerminationError: Premature end of bit-stream (e.g. incomplete Byte-shift segment).
6245
"""
6346

6447
PRIM_POLY = {
@@ -67,6 +50,7 @@ class CodewordReader:
6750
10: 0x409, # x^10 + x^3 + 1
6851
12: 0x1069, # x^12 + x^6 + x^5 + x^3 + 1
6952
}
53+
"""Primitive polynomials for Galois Field generation, keyed by code-word size."""
7054

7155
def __init__(
7256
self,
@@ -93,21 +77,18 @@ def __init__(
9377

9478
def _is_reference(self, r: int, c: int) -> bool:
9579
"""Check if the given coordinates are part of the reference grid.
80+
9681
A coordinate is part of the reference grid if it is a multiple of 16
9782
from the center of the matrix. The center is defined as the middle of the
9883
matrix (i.e. the middle row and column).
9984
100-
Parameters
101-
----------
102-
r : int
103-
Row index of the coordinate.
104-
c : int
105-
Column index of the coordinate.
106-
107-
Returns
108-
-------
109-
bool
110-
True if the coordinate is part of the reference grid, False otherwise.
85+
:param r: Row index of the coordinate.
86+
:type r: int
87+
:param c: Column index of the coordinate.
88+
:type c: int
89+
90+
:return: True if the coordinate is part of the reference grid, False otherwise.
91+
:rtype: bool
11192
"""
11293
centre = self.matrix.shape[0] // 2
11394
return bool((r - centre) % 16 == 0 or (c - centre) % 16 == 0)
@@ -221,6 +202,7 @@ def _read_bits(self) -> np.ndarray:
221202

222203
@cached_property
223204
def bitmap(self) -> np.ndarray:
205+
"""Raw bit-stream extracted from the symbol (before ECC correction)."""
224206
return self._read_bits()
225207

226208
def _correct(self) -> List[int]:
@@ -275,6 +257,7 @@ def _correct(self) -> List[int]:
275257

276258
@cached_property
277259
def corrected_bits(self) -> List[int]:
260+
"""Bit-stream after Reed-Solomon decoding and bit-stuff removal."""
278261
return self._correct()
279262

280263
@classmethod
@@ -289,24 +272,21 @@ def _remove_stuff_bits(
289272
self, bits: List[int], cw_size: int, data_words: int
290273
) -> List[int]:
291274
"""Remove the stuffing bits from the bit-stream.
275+
292276
A stuffed bit is a bit that is added to the bit-stream when there are cw_size-1
293277
consecutive bits of the same value. The stuffed bit is the opposite of the last bit.
294278
We need to remove the stuffed bits from the bit-stream before decoding it.
295279
Remove also the padding bits at the beginning of the stream.
296280
297-
Parameters
298-
----------
299-
bits : List[int]
300-
The bit-stream to clean.
301-
cw_size : int
302-
The size of the code-words (6, 8, 10 or 12).
303-
data_words : int
304-
The number of data code-words in the symbol.
305-
306-
Returns
307-
-------
308-
List[int]
309-
The cleaned bit-stream without the stuffed bits and the padding bits.
281+
:param bits: The bit-stream to clean.
282+
:type bits: List[int]
283+
:param cw_size: The size of the code-words (6, 8, 10 or 12).
284+
:type cw_size: int
285+
:param data_words: The number of data code-words in the symbol.
286+
:type data_words: int
287+
288+
:return: The cleaned bit-stream without the stuffed bits and the padding bits.
289+
:rtype: List[int]
310290
"""
311291
cleaned = []
312292
i = 0
@@ -443,4 +423,5 @@ def _decode(self) -> str:
443423

444424
@cached_property
445425
def decoded_string(self) -> str:
426+
"""Final user message built with the Aztec shift/latch tables."""
446427
return self._decode()

0 commit comments

Comments
 (0)