From 3a62e2a30f44b6bdcb121112a9db18c32d5f938e Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 11 Nov 2024 23:59:06 -0800 Subject: [PATCH] rm sdcard formats --- miniscope_io/formats/__init__.py | 4 --- miniscope_io/formats/sdcard.py | 51 -------------------------------- notebooks/Wire-Free-DAQ.ipynb | 12 ++++---- notebooks/grab_frames.ipynb | 6 ++-- tests/test_formats.py | 3 +- 5 files changed, 9 insertions(+), 67 deletions(-) delete mode 100644 miniscope_io/formats/sdcard.py diff --git a/miniscope_io/formats/__init__.py b/miniscope_io/formats/__init__.py index 5ab7fe30..a1833181 100644 --- a/miniscope_io/formats/__init__.py +++ b/miniscope_io/formats/__init__.py @@ -3,7 +3,3 @@ that describe fixed per-device configurations for the generic config models in :mod:`~.miniscope_io.models.stream` et al. """ - -from miniscope_io.formats.sdcard import WireFreeSDLayout, WireFreeSDLayout_Battery - -__all__ = ["WireFreeSDLayout", "WireFreeSDLayout_Battery"] diff --git a/miniscope_io/formats/sdcard.py b/miniscope_io/formats/sdcard.py deleted file mode 100644 index 006363e3..00000000 --- a/miniscope_io/formats/sdcard.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -SD Card data layout formats for different miniscopes! -""" - -from miniscope_io.models.sdcard import ( - ConfigPositions, - SDBufferHeaderFormat, - SDHeaderPositions, - SDLayout, - SectorConfig, -) - -WireFreeSDLayout = SDLayout( - version="0.1.1", - sectors=SectorConfig(header=1022, config=1023, data=1024, size=512), - write_key0=0x0D7CBA17, - write_key1=0x0D7CBA17, - write_key2=0x0D7CBA17, - write_key3=0x0D7CBA17, - header=SDHeaderPositions( - gain=4, led=5, ewl=6, record_length=7, fs=8, delay_start=9, battery_cutoff=10 - ), - config=ConfigPositions( - width=0, - height=1, - fs=2, - buffer_size=3, - n_buffers_recorded=4, - n_buffers_dropped=5, - ), - buffer=SDBufferHeaderFormat( - length=0, - linked_list=1, - frame_num=2, - buffer_count=3, - frame_buffer_count=4, - write_buffer_count=5, - dropped_buffer_count=6, - timestamp=7, - data_length=8, - ), -) - -WireFreeSDLayout_Battery = SDLayout(**WireFreeSDLayout.model_dump()) -""" -Making another format for now, but added version field so that we could -replace making more top-level classes with a FormatCollection that can store -sets of formats for the same device with multiple versions. -""" -WireFreeSDLayout_Battery.buffer.write_timestamp = 9 -WireFreeSDLayout_Battery.buffer.battery_voltage = 10 diff --git a/notebooks/Wire-Free-DAQ.ipynb b/notebooks/Wire-Free-DAQ.ipynb index ff96fb3d..11c06957 100644 --- a/notebooks/Wire-Free-DAQ.ipynb +++ b/notebooks/Wire-Free-DAQ.ipynb @@ -156,10 +156,10 @@ "ename": "ValueError", "evalue": "read length must be non-negative or -1", "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mdataHeader\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfromstring\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muint32\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mdataHeader\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdataHeader\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfromstring\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdataHeader\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mBUFFER_HEADER_HEADER_LENGTH_POS\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m-\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muint32\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdataHeader\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mValueError\u001b[0m: read length must be non-negative or -1" + "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[1;31mValueError\u001B[0m Traceback (most recent call last)", + "\u001B[1;32m\u001B[0m in \u001B[0;36m\u001B[1;34m\u001B[0m\n\u001B[0;32m 7\u001B[0m \u001B[1;32mfor\u001B[0m \u001B[0mi\u001B[0m \u001B[1;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;36m5000\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 8\u001B[0m \u001B[0mdataHeader\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mfromstring\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mf\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mread\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;36m4\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mdtype\u001B[0m\u001B[1;33m=\u001B[0m\u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0muint32\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m----> 9\u001B[1;33m \u001B[0mdataHeader\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mdataHeader\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mfromstring\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mf\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mread\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mdataHeader\u001B[0m\u001B[1;33m[\u001B[0m\u001B[0mBUFFER_HEADER_HEADER_LENGTH_POS\u001B[0m\u001B[1;33m]\u001B[0m \u001B[1;33m-\u001B[0m \u001B[1;36m1\u001B[0m\u001B[1;33m)\u001B[0m \u001B[1;33m*\u001B[0m \u001B[1;36m4\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mdtype\u001B[0m\u001B[1;33m=\u001B[0m\u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0muint32\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m 10\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 11\u001B[0m \u001B[0mprint\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mdataHeader\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n", + "\u001B[1;31mValueError\u001B[0m: read length must be non-negative or -1" ] } ], @@ -239,7 +239,7 @@ "outputs": [], "source": [ "# Delete data from SD Card\n", - "f.seek(ataStartSector * sectorSize, 0)\n", + "f.seek(dataStartSector * sectorSize, 0)\n", "\n", "zeros = []\n", "for i in range(512):\n", @@ -249,4 +249,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/notebooks/grab_frames.ipynb b/notebooks/grab_frames.ipynb index 06c22a89..6c33874e 100644 --- a/notebooks/grab_frames.ipynb +++ b/notebooks/grab_frames.ipynb @@ -33,7 +33,7 @@ "warnings.filterwarnings(\"ignore\")\n", "\n", "from miniscope_io.io import SDCard\n", - "from miniscope_io.formats import WireFreeSDLayout" + "from miniscope_io.models.sdcard import SDLayout" ] }, { @@ -100,9 +100,7 @@ ] } ], - "source": [ - "pprint(WireFreeSDLayout.dict(), sort_dicts=False)" - ] + "source": "pprint(SDLayout.from_id('wirefree-sd-layout'), sort_dicts=False)" }, { "cell_type": "markdown", diff --git a/tests/test_formats.py b/tests/test_formats.py index 9ac437a6..3930c2aa 100644 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -4,12 +4,11 @@ import json import importlib -from miniscope_io.formats import WireFreeSDLayout from miniscope_io.models.sdcard import SDLayout # More formats can be added here as needed. -@pytest.mark.parametrize("format", [WireFreeSDLayout]) +@pytest.mark.parametrize("format", [SDLayout.from_id("wirefree-sd-layout")]) def test_to_from_json(format): """ A format can be exported and re-imported from JSON and remain equivalent