Skip to content

Commit 515f669

Browse files
committed
Add reference documentation for public API
1 parent 9f15bfb commit 515f669

3 files changed

Lines changed: 70 additions & 17 deletions

File tree

harp/io.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import numpy as np
77
import pandas as pd
88

9-
"""The reference epoch for UTC harp time."""
109
REFERENCE_EPOCH = datetime(1904, 1, 1)
10+
"""The reference epoch for UTC harp time."""
1111

1212

1313
class MessageType(IntEnum):
14+
"""Specifies the type of a Harp message."""
15+
1416
NA = 0
1517
READ = 1
1618
WRITE = 2
@@ -41,22 +43,33 @@ def read(
4143
epoch: Optional[datetime] = None,
4244
keep_type: bool = False,
4345
):
44-
"""
45-
Read single-register Harp data from the specified file.
46-
47-
:param file: Open file object or filename containing binary data from
48-
a single device register.
49-
:param address: Expected register address. If specified, the address of
50-
the first message in the file is used for validation.
51-
:param dtype: Expected data type of the register payload. If specified, the
52-
payload type of the first message in the file is used for validation.
53-
:param length: Expected number of elements in register payload. If specified,
54-
the payload length of the first message in the file is used for validation.
55-
:param columns: The optional column labels to use for the data values.
56-
:param epoch: Reference datetime at which time zero begins. If specified,
57-
the result data frame will have a datetime index.
58-
:param keep_type: Specifies whether to include a column with the message type.
59-
:return: A pandas data frame containing message data, sorted by time.
46+
"""Read single-register Harp data from the specified file.
47+
48+
Parameters
49+
----------
50+
file
51+
Open file object or filename containing binary data from
52+
a single device register.
53+
address
54+
Expected register address. If specified, the address of
55+
the first message in the file is used for validation.
56+
dtype
57+
Expected data type of the register payload. If specified, the
58+
payload type of the first message in the file is used for validation.
59+
length
60+
Expected number of elements in register payload. If specified, the
61+
payload length of the first message in the file is used for validation.
62+
columns
63+
The optional column labels to use for the data values.
64+
epoch
65+
Reference datetime at which time zero begins. If specified,
66+
the result data frame will have a datetime index.
67+
keep_type
68+
Specifies whether to include a column with the message type.
69+
70+
Returns
71+
-------
72+
A pandas data frame containing message data, sorted by time.
6073
"""
6174
data = np.fromfile(file, dtype=np.uint8)
6275
if len(data) == 0:

harp/reader.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ def create_reader(
213213
epoch: Optional[datetime] = None,
214214
keep_type: bool = False,
215215
):
216+
"""Creates a device reader object from the specified dataset or schema.
217+
218+
Parameters
219+
----------
220+
device
221+
A path to the device schema, dataset folder, or parsed device schema object
222+
describing the device.
223+
include_common_registers
224+
Specifies whether to include the set of Harp common registers in the
225+
parsed device schema object. If a parsed device schema object is provided,
226+
this parameter is ignored.
227+
epoch
228+
The default reference datetime at which time zero begins. If specified,
229+
the data frames returned by each register reader will have a datetime index.
230+
keep_type
231+
Specifies whether to include a column with the message type by default.
232+
233+
Returns
234+
-------
235+
A device reader object which can be used to read binary data for each
236+
register or to access metadata about each register. Individual registers
237+
can be accessed using dot notation using the name of the register as the
238+
key.
239+
"""
216240
if isinstance(device, Model):
217241
base_path = Path(device.device)
218242
else:

harp/schema.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ def _read_common_registers() -> Registers:
1414
def read_schema(
1515
file: Union[str, PathLike, TextIO], include_common_registers: bool = True
1616
) -> Model:
17+
"""Read and parse a device schema from the specified file.
18+
19+
Parameters
20+
----------
21+
file
22+
Open file object or filename containing a YAML text stream describing
23+
a device schema.
24+
include_common_registers
25+
Specifies whether to include the set of Harp common registers in the
26+
returned device schema object.
27+
28+
Returns
29+
-------
30+
A Pydantic model object representing the Harp device schema.
31+
"""
32+
1733
if isinstance(file, (str, PathLike)):
1834
with open(file) as fileIO:
1935
return read_schema(fileIO)

0 commit comments

Comments
 (0)