Skip to content

Commit

Permalink
starting ruff manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Jun 14, 2024
1 parent 0ac42ca commit 7aaac42
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 51 deletions.
4 changes: 4 additions & 0 deletions miniscope_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
I/O SDK for UCLA Miniscopes
"""

from pathlib import Path

from miniscope_io.io import SDCard
Expand Down
7 changes: 4 additions & 3 deletions miniscope_io/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def frame_nums_must_be_equal(
cls, v: List[SDBufferHeader]
) -> Optional[List[SDBufferHeader]]:
"""
Each frame_number field in each header must be the same (they come from the same frame!)
Each frame_number field in each header must be the same
(they come from the same frame!)
"""

if v is not None and not all(
Expand Down Expand Up @@ -68,8 +69,8 @@ def flatten_headers(
Return flat list of headers, not grouped by frame
Args:
as_dict (bool): If `True`, return a list of dictionaries, if `False` (default),
return a list of :class:`.SDBufferHeader` s.
as_dict (bool): If `True`, return a list of dictionaries, if `False`
(default), return a list of :class:`.SDBufferHeader` s.
"""
h = []
for frame in self.frames:
Expand Down
21 changes: 17 additions & 4 deletions miniscope_io/device_update.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""
Update miniscope device configuration.
.. todo::
What kind of devices does this apply to?
"""

import argparse
import sys
import time
Expand All @@ -15,11 +24,15 @@
updateDeviceParser.add_argument("value", help="LED value")


def updateDevice():
def updateDevice() -> None:
"""
Script to update hardware settings over a generic UART-USB converter.
This script currently supports updating the excitation LED brightness and electrical wetting lens driver gain.
Not tested after separating from stream_daq.py.
This script currently supports updating the excitation LED brightness and
electrical wetting lens driver gain.
.. note::
Not tested after separating from stream_daq.py.
Examples
--------
Expand Down Expand Up @@ -122,7 +135,7 @@ def updateDevice():
logger.info("Open serial port")

for uartCommand in command:
for repeat in range(uartRepeat):
for _ in range(uartRepeat):
# read UART data until preamble and put into queue
serial_port.write(uartCommand)
time.sleep(uartTimeGap)
Expand Down
3 changes: 3 additions & 0 deletions miniscope_io/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Control interfaces for external hardware devices
"""
36 changes: 32 additions & 4 deletions miniscope_io/devices/opalkelly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

"""
Interfaces for OpalKelly (model number?) FPGAs
"""

from miniscope_io.vendor import opalkelly as ok

Expand All @@ -24,7 +26,13 @@ def __init__(self, serial_id: str = ""):
if ret == self.NoError:
print(f"Connected to {self.info.productName}")

def uploadBit(self, bit_file: str):
def uploadBit(self, bit_file: str) -> None:
"""
Upload a configuration bitfile to the FPGA
Args:
bit_file (str): Path to the bitfile
"""

ret = self.ConfigureFPGA(bit_file)
if ret == self.NoError:
Expand All @@ -38,7 +46,18 @@ def uploadBit(self, bit_file: str):
)
ret = self.ResetFPGA()

def readData(self, length: int, addr: int = 0xA0, blockSize: int = 16):
def readData(self, length: int, addr: int = 0xA0, blockSize: int = 16) -> bytearray:
"""
Read a buffer's worth of data
Args:
length (int): Amount of data to read
addr (int): FPGA address to read from
blockSize (int): Size of individual blocks (in what unit?)
Returns:
:class:`bytearray`
"""
buf = bytearray(length)
ret = self.ReadFromBlockPipeOut(addr, data=buf, blockSize=blockSize)
if ret < 0:
Expand All @@ -47,7 +66,16 @@ def readData(self, length: int, addr: int = 0xA0, blockSize: int = 16):
print(f"Only {ret} bytes read")
return buf

def setWire(self, addr: int, val: int):
def setWire(self, addr: int, val: int) -> None:
"""
.. todo::
Phil! what does this do?
Args:
addr: ?
val: ?
"""
ret = self.SetWireInValue(addr, val)
ret = self.UpdateWireIns()
if ret != self.NoError:
Expand Down
7 changes: 6 additions & 1 deletion miniscope_io/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""
Custom exceptions!
"""

class InvalidSDException(Exception):
"""
Raised when :class:`.io.SDCard` is used with a drive that doesn't have the appropriate WRITE KEYS in its header
Raised when :class:`.io.SDCard` is used with a drive that doesn't have the
appropriate WRITE KEYS in its header
"""


Expand Down
Loading

0 comments on commit 7aaac42

Please sign in to comment.