Metadata-Version: 2.5
Name: apstrim
Version: 4.3.0
Summary: Logger and extractor of time-series data (e.g. EPICS PVs or liteServer LDOs).
Project-URL: Homepage, https://github.com/ASukhanov/apstrim
Project-URL: Bug Tracker, https://github.com/ASukhanov/apstrim/issues
Author-email: Andrey Sukhanov <cyxandr@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: liteaccess
Requires-Dist: msgpack
Description-Content-Type: text/markdown

# apstrim

Logger and extractor of time-series data (e.g. EPICS PVs).

- Data are objects indexed in time order.
- Supported control infrastructures: EPICS Channel Access + PV Access, ADO, and LITE. Easily extendable.
- Wide range of data objects: strings, lists, maps, NumPy arrays, and custom types.
- Data objects can be inhomogeneous and have arbitrary frequencies.
- Self-describing data format; no schema is required.
- Data objects are binary serialized using MessagePack.
- Fast online compression.
- Fast random-access retrieval of data objects for a selected time interval.
- Simultaneous writing and reading.
- Typical speed of compressed serialization to a logbook file is 80 MB/s.
- Deserialization speed is up to 1200 MB/s when the logbook is cached in memory.
- Basic plotting of logged data.

<img src="/docs/apstrim_file_format.png" width="400">

## Installation

Main dependency: **msgpack,numpy**

Additional dependencies:
- **lz4framed**, if compression is enabled
- EPICS PV Access requires **p4p**.
- EPICS Channel Access requires **caproto**.
- The program for deserialization and plotting, **apstrim.view**, requires **pyqtgraph**.


```console
pip3 install apstrim
```

## API reference

[apstrim](https://htmlpreview.github.io/?https://github.com/ASukhanov/apstrim/blob/main/docs/apstrim.html)

[scan](https://htmlpreview.github.io/?https://github.com/ASukhanov/apstrim/blob/main/docs/scan.html)

## Examples

### Serialization

```console
# Serialization of one float64 parameter from an EPICS simulated scope IOC:
python -m apstrim -nEPICS -T59 testAPD:scope1:MeanValue_RBV
Logging finished for 1 section, 1 parList, 7.263 KB.
...

# The same with compression:
python -m apstrim -nEPICS -T59 testAPD:scope1:MeanValue_RBV --compress
Logging finished for 1 section, 1 parList, 6.101 KB. Compression ratio: 1.19
...

# Serialization of a 1000-element array and a scalar of floats:
python -m apstrim -nEPICS -T59 testAPD:scope1:MeanValue_RBV,Waveform_RBV --compress
Logging finished for 1 section, 2 parLists, 2405.354 KB. Compression ratio: 1.0
...
# Compression is poor for floating-point arrays with high entropy.

# Serialization of an incrementing integer parameter:
python -m apstrim -nLITE --compress liteHost:dev1:cycle
Logging finished for 1 section, 1 parList, 56.526 KB. Compression ratio: 1.25
...
# In this case, the normalized compressed volume is 9.3 bytes per entry.
# Each entry consists of an int64 timestamp and an int64 value, which would
# occupy 16 bytes per entry when written using the standard format.
```

### Deserialization

Example of deserializing and plotting all parameters from several logbooks:

```console
python -m apstrim.view -i all -p '*.aps'
```

Python code snippet for extracting items 1, 2, and 3 from a logbook
for a 20-second interval starting on 2021-08-12 at 23:31:31:

```python
from apstrim.scan import APScan

apscan = APScan("aLogbook.aps")
headers = apscan.get_headers()
print(headers["Index"])
extracted = apscan.extract_objects(
    span=20,
    items=[1, 2, 3],
    startTime="210812_233131",
)
print(extracted[3])  # Print the extracted data for item [3]
# Returned:
{
    "par": "liteBridge.peakSimulator:rps",  # object (PV) name of item [3]
    "times": [1628825500.8938403, 1628825510.898658],  # timestamps for item [3]
    "values": [95.675125, 95.55396],  # values for item [3]
}
```

