From 0146fb4db2c9345c77b958c7688e73b2aa0f3710 Mon Sep 17 00:00:00 2001 From: Christos Falas Date: Sun, 26 Jan 2025 18:06:23 +0000 Subject: [PATCH] add CSI recording to hdf5 file --- pyproject.toml | 5 +++-- src/cli/__init__.py | 3 +++ src/cli/file.py | 40 ++++++++++++++++++++++++++++++++++++++++ uv.lock | 30 +++++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/cli/file.py diff --git a/pyproject.toml b/pyproject.toml index b3a71aa..b2a2636 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,13 +5,14 @@ description = "Use Wi-Fi Channel State Information to locate human presence" requires-python = ">=3.11" dependencies = [ "flask", - "numpy", + "numpy>=2.0.0", "flask-sock", "pytest", "matplotlib", "scipy", "scipy-stubs", - "typer" + "typer", + "h5py>=3.12.1", ] diff --git a/src/cli/__init__.py b/src/cli/__init__.py index 3350f18..57a2e9c 100644 --- a/src/cli/__init__.py +++ b/src/cli/__init__.py @@ -48,3 +48,6 @@ def heatmap() -> None: webapp_queue.put(aoa) ingest.start_processing(callback) + + +app.add_typer(file.app, name="file", help="Commands for working with CSI files") diff --git a/src/cli/file.py b/src/cli/file.py new file mode 100644 index 0000000..f72277e --- /dev/null +++ b/src/cli/file.py @@ -0,0 +1,40 @@ +import logging +from datetime import datetime +from pathlib import Path + +import h5py +import numpy as np +import numpy.typing as npt +import typer + +from ..collection import ingest + +app = typer.Typer() +logger = logging.getLogger(__name__) + + +@app.command() +def capture(output_path: Path) -> None: + """Capture CSI data to a file""" + logger.info(f"Capturing data to {output_path}") + + with h5py.File(output_path, "w") as file: + + def callback(antenna_data: npt.NDArray[np.complex128]) -> None: + logger.info(f"Got final CSI data with shape {antenna_data.shape}") + file.create_dataset(datetime.now().isoformat(), data=antenna_data) + + ingest.start_processing(callback) + + +@app.command() +def replay(input_path: Path) -> None: + """Replay CSI data from a file""" + logger.info(f"Replaying data from {input_path}") + + start_time = datetime.now() + + with h5py.File(input_path, "r") as file: + for key in file: + logger.info(f"Sending data from {key}") + ingest.send_data(file[key][:]) diff --git a/uv.lock b/uv.lock index c316283..087930a 100644 --- a/uv.lock +++ b/uv.lock @@ -162,6 +162,32 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/95/04/ff642e65ad6b90db43e668d70ffb6736436c7ce41fcc549f4e9472234127/h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761", size = 58259 }, ] +[[package]] +name = "h5py" +version = "3.12.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "numpy" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cc/0c/5c2b0a88158682aeafb10c1c2b735df5bc31f165bfe192f2ee9f2a23b5f1/h5py-3.12.1.tar.gz", hash = "sha256:326d70b53d31baa61f00b8aa5f95c2fcb9621a3ee8365d770c551a13dbbcbfdf", size = 411457 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/33/61/c463dc5fc02fbe019566d067a9d18746cd3c664f29c9b8b3c3f9ed025365/h5py-3.12.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ccd9006d92232727d23f784795191bfd02294a4f2ba68708825cb1da39511a93", size = 3410828 }, + { url = "https://files.pythonhosted.org/packages/95/9d/eb91a9076aa998bb2179d6b1788055ea09cdf9d6619cd967f1d3321ed056/h5py-3.12.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ad8a76557880aed5234cfe7279805f4ab5ce16b17954606cca90d578d3e713ef", size = 2872586 }, + { url = "https://files.pythonhosted.org/packages/b0/62/e2b1f9723ff713e3bd3c16dfeceec7017eadc21ef063d8b7080c0fcdc58a/h5py-3.12.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1473348139b885393125126258ae2d70753ef7e9cec8e7848434f385ae72069e", size = 5273038 }, + { url = "https://files.pythonhosted.org/packages/e1/89/118c3255d6ff2db33b062ec996a762d99ae50c21f54a8a6047ae8eda1b9f/h5py-3.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:018a4597f35092ae3fb28ee851fdc756d2b88c96336b8480e124ce1ac6fb9166", size = 5452688 }, + { url = "https://files.pythonhosted.org/packages/1d/4d/cbd3014eb78d1e449b29beba1f3293a841aa8086c6f7968c383c2c7ff076/h5py-3.12.1-cp311-cp311-win_amd64.whl", hash = "sha256:3fdf95092d60e8130ba6ae0ef7a9bd4ade8edbe3569c13ebbaf39baefffc5ba4", size = 3006095 }, + { url = "https://files.pythonhosted.org/packages/d4/e1/ea9bfe18a3075cdc873f0588ff26ce394726047653557876d7101bf0c74e/h5py-3.12.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:06a903a4e4e9e3ebbc8b548959c3c2552ca2d70dac14fcfa650d9261c66939ed", size = 3372538 }, + { url = "https://files.pythonhosted.org/packages/0d/74/1009b663387c025e8fa5f3ee3cf3cd0d99b1ad5c72eeb70e75366b1ce878/h5py-3.12.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7b3b8f3b48717e46c6a790e3128d39c61ab595ae0a7237f06dfad6a3b51d5351", size = 2868104 }, + { url = "https://files.pythonhosted.org/packages/af/52/c604adc06280c15a29037d4aa79a24fe54d8d0b51085e81ed24b2fa995f7/h5py-3.12.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:050a4f2c9126054515169c49cb900949814987f0c7ae74c341b0c9f9b5056834", size = 5194606 }, + { url = "https://files.pythonhosted.org/packages/fa/63/eeaacff417b393491beebabb8a3dc5342950409eb6d7b39d437289abdbae/h5py-3.12.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5c4b41d1019322a5afc5082864dfd6359f8935ecd37c11ac0029be78c5d112c9", size = 5413256 }, + { url = "https://files.pythonhosted.org/packages/86/f7/bb465dcb92ca3521a15cbe1031f6d18234dbf1fb52a6796a00bfaa846ebf/h5py-3.12.1-cp312-cp312-win_amd64.whl", hash = "sha256:e4d51919110a030913201422fb07987db4338eba5ec8c5a15d6fab8e03d443fc", size = 2993055 }, + { url = "https://files.pythonhosted.org/packages/23/1c/ecdd0efab52c24f2a9bf2324289828b860e8dd1e3c5ada3cf0889e14fdc1/h5py-3.12.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:513171e90ed92236fc2ca363ce7a2fc6f2827375efcbb0cc7fbdd7fe11fecafc", size = 3346239 }, + { url = "https://files.pythonhosted.org/packages/93/cd/5b6f574bf3e318bbe305bc93ba45181676550eb44ba35e006d2e98004eaa/h5py-3.12.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:59400f88343b79655a242068a9c900001a34b63e3afb040bd7cdf717e440f653", size = 2843416 }, + { url = "https://files.pythonhosted.org/packages/8a/4f/b74332f313bfbe94ba03fff784219b9db385e6139708e55b11490149f90a/h5py-3.12.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d3e465aee0ec353949f0f46bf6c6f9790a2006af896cee7c178a8c3e5090aa32", size = 5154390 }, + { url = "https://files.pythonhosted.org/packages/1a/57/93ea9e10a6457ea8d3b867207deb29a527e966a08a84c57ffd954e32152a/h5py-3.12.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba51c0c5e029bb5420a343586ff79d56e7455d496d18a30309616fdbeed1068f", size = 5378244 }, + { url = "https://files.pythonhosted.org/packages/50/51/0bbf3663062b2eeee78aa51da71e065f8a0a6e3cb950cc7020b4444999e6/h5py-3.12.1-cp313-cp313-win_amd64.whl", hash = "sha256:52ab036c6c97055b85b2a242cb540ff9590bacfda0c03dd0cf0661b311f522f8", size = 2979760 }, +] + [[package]] name = "iniconfig" version = "2.0.0" @@ -682,6 +708,7 @@ source = { virtual = "." } dependencies = [ { name = "flask" }, { name = "flask-sock" }, + { name = "h5py" }, { name = "matplotlib" }, { name = "numpy" }, { name = "pytest" }, @@ -694,8 +721,9 @@ dependencies = [ requires-dist = [ { name = "flask" }, { name = "flask-sock" }, + { name = "h5py", specifier = ">=3.12.1" }, { name = "matplotlib" }, - { name = "numpy" }, + { name = "numpy", specifier = ">=2.0.0" }, { name = "pytest" }, { name = "scipy" }, { name = "scipy-stubs" },