Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.1.2 #20

Merged
merged 40 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f73a42f
Add BlockOverlap handling for febus format.
atrabattoni Jun 7, 2024
14898da
add comment
ClaudioStrumia Jul 3, 2024
6d2feea
docs: add dim="..." everywhere for those who copy paste.
atrabattoni Aug 5, 2024
f92ec6e
code-coverage
atrabattoni Aug 6, 2024
4645c31
Improve code coverage accuracy + badge.
atrabattoni Aug 6, 2024
009edab
Add Terra15 support.
atrabattoni Sep 4, 2024
d888a0c
Fix UTC datetime import for python 3.10 compatibility.
atrabattoni Sep 4, 2024
d4baa8d
Add ZMQ streaming capabilities for ASN.
atrabattoni Sep 6, 2024
573fc9e
Add example.
atrabattoni Sep 6, 2024
2804cf6
Ensure reproducibility.
atrabattoni Sep 6, 2024
1aaa490
Add ZeroMQ pub/sub reader/loader.
atrabattoni Sep 6, 2024
e296048
Add examples.
atrabattoni Sep 6, 2024
359bf91
Add zmq dependency.
atrabattoni Sep 17, 2024
69e80e5
Rename ZMQSubscriber
atrabattoni Sep 17, 2024
2bde9ee
fix bug for timezone
chauvetige Sep 17, 2024
db4aae3
Add ZMQPublisher with tests.
atrabattoni Sep 17, 2024
2bd651a
Add transpose for safety.
atrabattoni Sep 17, 2024
c5bbdd1
test int16.
atrabattoni Sep 17, 2024
a40ce24
Refactor Publisher and add tests
atrabattoni Sep 17, 2024
fb8b135
Add test change header for ASN subscriber
atrabattoni Sep 17, 2024
2e25680
test iter for xdas.io.asn.ZMQPublisher.
atrabattoni Sep 17, 2024
ea6bb0c
Add get_free_port and refactor/update docstring.
atrabattoni Sep 17, 2024
0445bb0
Add example to ASN ZMQSubscriber.
atrabattoni Sep 17, 2024
6bf2a1f
Add dummy fast sythetics and fix doc examples of zmq.
atrabattoni Sep 17, 2024
a08b46c
Add tests for ZMQPublisher/Subscriber
atrabattoni Sep 17, 2024
c7b3102
Add streaming documentation + encoding is given at init.
atrabattoni Sep 17, 2024
3705ac4
Add note about ASN protocol and fix references.
atrabattoni Sep 17, 2024
c67c2aa
Merge pull request #17 from xdas-dev/feature/zeromq
atrabattoni Sep 17, 2024
9421361
Format code.
atrabattoni Sep 17, 2024
c93db0d
Merge branch 'dev' into feature/terra15
atrabattoni Sep 17, 2024
0249f19
Merge pull request #16 from xdas-dev/feature/terra15
atrabattoni Sep 17, 2024
f71fb3a
Merge remote-tracking branch 'origin/dev' into fix/febus-overlap
atrabattoni Sep 18, 2024
c770334
Allow to manually specify ovelaps in Febus engine.
atrabattoni Sep 18, 2024
3941c76
open_* functions redirect **kwargs to the read function.
atrabattoni Sep 18, 2024
76cf8e5
Add some doc.
atrabattoni Sep 18, 2024
3f5b71d
typo.
atrabattoni Sep 18, 2024
02ff886
Fix Febus overlap and time offset
ClaudioStrumia Sep 18, 2024
c6b0f35
Formatting.
atrabattoni Sep 18, 2024
88fe71c
Merge pull request #19 from xdas-dev/fix/febus-overlap
atrabattoni Sep 18, 2024
8306384
Version 0.1.2
atrabattoni Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Code Coverage

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install '.[tests]'

- name: Run tests with coverage
run: coverage run --source=xdas -m pytest

- name: Generate coverage report
run: coverage xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

[![Documentation Status](https://readthedocs.org/projects/xdas/badge/?version=latest)](https://xdas.readthedocs.io/en/latest/?badge=latest)
[![Tests Status](https://github.com/xdas-dev/xdas/actions/workflows/tests.yaml/badge.svg)](https://github.com/xdas-dev/xdas/actions/workflows/tests.yaml)
[![codecov](https://codecov.io/gh/xdas-dev/xdas/graph/badge.svg?token=00MD52JRA3)](https://codecov.io/gh/xdas-dev/xdas)
[![PyPI](https://img.shields.io/pypi/v/xdas)](https://pypi.org/project/xdas/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![DOI](https://zenodo.org/badge/560867006.svg)](https://zenodo.org/badge/latestdoi/560867006)
Expand Down
7 changes: 4 additions & 3 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
:maxdepth: 1

xdas
atoms
io
fft
signal
processing
parallel
processing
signal
synthetics
virtual
atoms
```
27 changes: 27 additions & 0 deletions docs/api/io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```{eval-rst}
.. currentmodule:: xdas.io
```

# xdas.io

```{eval-rst}
.. autosummary::
:toctree: ../_autosummary

get_free_port
```

```{eval-rst}
.. currentmodule:: xdas.io.asn
```


## ASN

```{eval-rst}
.. autosummary::
:toctree: ../_autosummary

ZMQPublisher
ZMQSubscriber
```
2 changes: 2 additions & 0 deletions docs/api/processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
DataArrayLoader
RealTimeLoader
DataArrayWriter
ZMQPublisher
ZMQSubscriber
```
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
author = "Alister Trabattoni"

# The full version, including alpha/beta/rc tags
release = "0.1"
release = "0.1.2"


# -- General configuration ---------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release notes

## 0.1.2

- Add ZeroMQ streaming capabilities (@atrabattoni)
- Add support of Terra15 format (@chauvetige).
- Fix Febus engine (@ClaudioStrumia)

## 0.1.1

- Add support for `hdf5plugin` compression schemes.
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/convert-displacement.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import xdas.signal as xp

strain = xp.integrate(strain_rate, dim="time")
deformation = xp.integrate(strain, dim="distance")
displacement = xp.sliding_mean_removal(deformation, wlen=2000.0)
displacement = xp.sliding_mean_removal(deformation, wlen=2000.0, dim="distance")
displacement.plot(yincrease=False, vmin=-0.5, vmax=0.5);
```

Expand Down
8 changes: 7 additions & 1 deletion docs/user-guide/data-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ os.chdir("../_data")

## Implemented file formats

The formats that are currently implemented are: ASN, FEBUS, OPTASENSE and SINTELA. To read them you have to specifiy which one you want in the `engine` argument in {py:func}`xdas.open_dataarray` for a single file or {py:func}`xdas.open_mfdataarray` for multiple files:
The formats that are currently implemented are: ASN, FEBUS, OPTASENSE, SINTELA and TERRA15. To read them you have to specifiy which one you want in the `engine` argument in {py:func}`xdas.open_dataarray` for a single file or {py:func}`xdas.open_mfdataarray` for multiple files:

| DAS constructor | `engine` argument |
|:-----------------:|:-----------------:|
| ASN | `"asn"` |
| FEBUS | `"febus"` |
| OPTASENSE | `"optasense"` |
| SINTELA | `"sintela"` |
| TERRA15 | `"terra15"` |

```{warning}
Due to poor documentation of the various version of the Febus format, it is recommended to manually provide the required trimming and the position of the timestamps within each block. For example to trim 100 samples on both side of each block and to set the timestamp location at the center of the block for a block of 2000 samples:
`xdas.open_dataarray("path.h5", engine="febus", overlaps=(100, 100), offset=1000)`
```

## Extending *xdas* with your file format

Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ interpolated-coordinates
convert-displacement
atoms
processing
streaming
```
91 changes: 91 additions & 0 deletions docs/user-guide/streaming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
file_format: mystnb
kernelspec:
name: python3
---

# Streaming data

Xdas allows to stream data over any network using [ZeroMQ](https://zeromq.org). Xdas use the Publisher and Subscriber patterns meaning that on one node the data is published and that any number of subscribers can receive the data stream.

Streaming data with Xdas is done by simply dumping each chunk to NetCDF binaries and to send those as packets. This ensure that each packet is self described and that feature such as compression are available (which can be very helpful to minimize the used bandwidth).

Xdas implements the {py:class}`~xdas.processing.ZMQPublisher` and {py:class}`~xdas.processing.ZMQSubscriber`.Those object can respectively be used as a Writer and a Loader as described in the [](processing) section. Both are initialized by giving an network address. The publisher use the `submit` method to send packets while the subscriber is an infinite iterator that yields packets.

In this section, we will mimic the use of several machine by using multithreading, where each thread is supposed to be a different machine. In real-life application, the publisher and subscriber are generally called in different machine or software.

## Simple use case

```{code-cell}
import threading
import time

import xdas as xd
from xdas.processing import ZMQPublisher, ZMQSubscriber
```

First we generate some data and split it into packets

```{code-cell}
da = xd.synthetics.dummy()
packets = xd.split(da, 5)
```

We then publish the packets on machine 1.

```{code-cell}
address = f"tcp://localhost:{xd.io.get_free_port()}"
publisher = ZMQPublisher(address)

def publish():
for packet in packets:
publisher.submit(packet)
# give a chance to the subscriber to connect in time and to get the last packet
time.sleep(0.1)

machine1 = threading.Thread(target=publish)
machine1.start()
```

Let's receive the packets on machine 2.

```{code-cell}
subscriber = ZMQSubscriber(address)

packets = []

def subscribe():
for packet in subscriber:
packets.append(packet)

machine2 = threading.Thread(target=subscribe)
machine2.start()
```

Now we wait for machine 1 to finish sending its packet and see if everything went well.

```{code-cell}
machine1.join()
print(f"We received {len(packets)} packets!")
assert xd.concatenate(packets).equals(da)
```

## Using encoding

To reduce the volume of the transmitted data, compression is often useful. Xdas enable the use of the ZFP algorithm when storing data but also when streaming it. Encoding is declared the same way.

```{code-cell}
:tags: [remove-output]

import hdf5plugin

address = f"tcp://localhost:{xd.io.get_free_port()}"
encoding = {"chunks": (10, 10), **hdf5plugin.Zfp(accuracy=1e-6)}
publisher = ZMQPublisher(address, encoding) # Add encoding here, the rest is the same
```

{py:class}`~xdas.io.asn.ZMQSubscriber`

```{note}
Xdas also implements the ZeroMQ protocol used by the OptoDAS interrogators by ASN. Equivalent {py:class}`~xdas.io.asn.ZMQPublisher` and {py:class}`~xdas.io.asn.ZMQSubscriber` can be found in {py:mod}`xdas.io.asn`. This can be useful get data in real-time from one instrument of that kind. Note that compression is not available with that protocol yet.
```
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "xdas"
version = "0.1.1"
version = "0.1.2"
requires-python = ">= 3.10"
authors = [
{ name = "Alister Trabattoni", email = "alister.trabattoni@gmail.com" },
Expand All @@ -23,6 +23,7 @@ dependencies = [
"watchdog",
"xarray",
"xinterp",
"pyzmq",
]

[project.optional-dependencies]
Expand Down
Loading