Skip to content

Commit

Permalink
Format docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
bgottula committed Apr 5, 2023
1 parent b74ae1f commit ceed9ae
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 149 deletions.
2 changes: 1 addition & 1 deletion track/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def camera_separation_callback(


def main():
"""See module docstring"""
"""See module docstring."""

def gamepad_callback(_unused: Tracker) -> bool:
"""Callback for gamepad control.
Expand Down
6 changes: 2 additions & 4 deletions track/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


class Position(Destination):
"""A position for use in alignment procedure"""
"""A position for use in alignment procedure."""

def __init__(
self,
Expand All @@ -59,7 +59,7 @@ def __init__(
self.mount = mount

def distance_to(self, other_destination: "Position") -> int:
"""Returns the cost of moving the mount from this position to another position
"""Returns the cost of moving the mount from this position to another position.
Assumes that the slew rate is the same for all mount axes.
Expand Down Expand Up @@ -178,7 +178,6 @@ def attempt_plate_solving(
Returns:
True on success, False on failure.
"""

# Make all physical measurements (clock, camera, mount encoders) near same time
timestamp = time.time()
frame = camera.get_frame()
Expand Down Expand Up @@ -223,7 +222,6 @@ def remove_empty_dir(directory: str) -> None:

def main():
"""Run the alignment procedure! See module docstring for a description."""

parser = ArgParser(additional_config_files=[os.path.join(CONFIG_PATH, 'align.cfg')])
align_group = parser.add_argument_group(
title='Alignment Configuration',
Expand Down
5 changes: 1 addition & 4 deletions track/autofocus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3

"""
Automatic focus script and associated algorithms.
"""
"""Automatic focus script and associated algorithms."""

import atexit
from datetime import datetime
Expand Down Expand Up @@ -259,7 +257,6 @@ def autofocus(

def main():
"""Run the full autofocus algorithm."""

parser = ArgParser(additional_config_files=[os.path.join(CONFIG_PATH, 'autofocus.cfg')])
parser.add_argument(
'--meridian-side',
Expand Down
1 change: 0 additions & 1 deletion track/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def run_program(args: list[str]) -> None:

def main():
"""See module docstring."""

parser = ArgParser()
logs.add_program_arguments(parser)
gps_client.add_program_arguments(parser)
Expand Down
53 changes: 26 additions & 27 deletions track/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


class Camera(AbstractContextManager):
"""Abstract base class for cameras"""
"""Abstract base class for cameras."""

@property
@abstractmethod
Expand Down Expand Up @@ -183,11 +183,11 @@ def pixel_to_angle(self, position_x: float, position_y: float) -> Angle:


class CameraTimeout(Exception):
"""Raised when a timeout expires"""
"""Raised when a timeout expires."""


class ASICamera(Camera):
"""ZWO ASI Cameras"""
"""ZWO ASI Cameras."""

class BitDepth(enum.IntEnum):
"""Bit depth of pixels."""
Expand All @@ -196,7 +196,7 @@ class BitDepth(enum.IntEnum):
RAW16 = asi.ASI_IMG_RAW16

def bytes_per_pixel(self) -> int:
"""Number of bytes per pixel in raw array of frame data retrieved from ASI driver"""
"""Number of bytes per pixel in raw array of frame data retrieved from ASI driver."""
return 1 if self == self.RAW8 else 2

@staticmethod
Expand Down Expand Up @@ -224,7 +224,7 @@ def add_program_arguments(parser: ArgParser) -> None:

@staticmethod
def from_program_args(args: Namespace) -> ASICamera:
"""Factory to make a WebCam instance from program arguments
"""Factory to make a WebCam instance from program arguments.
Args:
args: Set of program arguments.
Expand Down Expand Up @@ -311,17 +311,17 @@ def _get_ctrl(self, ctrl):

@property
def pixel_scale(self) -> float:
"""Scale of a pixel in degrees per pixel"""
"""Scale of a pixel in degrees per pixel."""
return self._pixel_scale

@property
def binning(self) -> int:
"""Binning configuration"""
"""Binning configuration."""
return self._binning

@property
def frame_shape(self) -> tuple[int, int]:
"""Shape of array returned by get_frame()"""
"""Shape of array returned by get_frame()."""
return self._frame_shape

@property
Expand All @@ -331,12 +331,12 @@ def field_of_view(self) -> tuple[float, float]:

@property
def video_mode(self) -> bool:
"""True if video mode is enabled"""
"""True if video mode is enabled."""
return self._video_mode

@video_mode.setter
def video_mode(self, enabled: bool) -> None:
"""Enable or disable video mode"""
"""Enable or disable video mode."""
self._bit_depth = self.BitDepth.RAW8 if enabled else self.BitDepth.RAW16
height, width = self._frame_shape
self._frame_size_bytes = width * height * self._bit_depth.bytes_per_pixel()
Expand All @@ -361,32 +361,32 @@ def video_mode(self, enabled: bool) -> None:

@property
def gain(self) -> int:
"""Camera gain"""
"""Camera gain."""
return self._get_ctrl(asi.ASI_GAIN)[0]

@gain.setter
def gain(self, gain: int) -> None:
"""Set camera gain"""
"""Set camera gain."""
self._set_ctrl(asi.ASI_GAIN, gain)

@property
def exposure(self) -> float:
"""Exposure time in seconds"""
"""Exposure time in seconds."""
return self._get_ctrl(asi.ASI_EXPOSURE)[0] / 1e6

@exposure.setter
def exposure(self, exposure: float) -> None:
"""Set exposure time in seconds"""
"""Set exposure time in seconds."""
self._set_ctrl(asi.ASI_EXPOSURE, int(exposure * 1e6))

def _reshape_frame_data(self, frame: np.ndarray) -> np.ndarray:
"""Reshape raw byte array from ASI driver to a 2D array image"""
"""Reshape raw byte array from ASI driver to a 2D array image."""
if self._bit_depth == self.BitDepth.RAW16:
frame = frame.view(dtype=np.uint16)
return np.reshape(frame, self._frame_shape)

def get_dropped_frames(self) -> int:
"""Get number of dropped frames so far"""
"""Get number of dropped frames so far."""
return ASICheck(asi.ASIGetDroppedFrames(self.info.CameraID))

def get_frame(self, timeout: float = inf) -> np.ndarray:
Expand Down Expand Up @@ -481,7 +481,7 @@ def add_program_arguments(parser: ArgParser) -> None:

@staticmethod
def from_program_args(args: Namespace) -> WebCam:
"""Factory to make a WebCam instance from program arguments"""
"""Factory to make a WebCam instance from program arguments."""
return WebCam(
dev_path=args.webcam_dev,
ctrl_exposure=args.webcam_exposure,
Expand Down Expand Up @@ -555,12 +555,12 @@ def binning(self) -> int:

@property
def video_mode(self) -> bool:
"""Always returns True because this camera can only be in video mode"""
"""Always returns True because this camera can only be in video mode."""
return True

@video_mode.setter
def video_mode(self, enabled: bool) -> None:
"""Video mode is always enabled for this camera"""
"""Video mode is always enabled for this camera."""
if not enabled:
raise ValueError("Can't disable video mode for Webcam")

Expand All @@ -576,7 +576,6 @@ def get_frame(self, timeout: float = inf) -> np.ndarray:
Returns:
The frame as a numpy array.
"""

self.block_until_frame_ready(timeout)

frames = []
Expand Down Expand Up @@ -620,20 +619,20 @@ def block_until_frame_ready(self, timeout: float = inf) -> bool:
return len(dev_fd_ready) > 0

def has_frames_available(self) -> bool:
"""query whether the webcam has at least one frame ready for us to read (non-blocking)"""
"""Query whether the webcam has at least one frame ready for us to read (non-blocking)."""
readable, _, _ = select.select((self.dev_fd,), (), (), 0.0)
return len(readable) != 0

def start(self) -> None:
"""tell the camera to start capturing"""
"""Tell the camera to start capturing."""
if not self.started:
self._v4l2_ioctl(
v4l2.VIDIOC_STREAMON, ctypes.c_int(int(v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE))
)
self.started = True

def stop(self) -> None:
"""tell the camera to stop capturing"""
"""Tell the camera to stop capturing."""
if self.started:
self._v4l2_ioctl(
v4l2.VIDIOC_STREAMOFF, ctypes.c_int(int(v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE))
Expand Down Expand Up @@ -721,7 +720,7 @@ def _set_jpeg_quality(self, quality):
)

def _set_format(self, shape_wanted: tuple[int, int], fourcc) -> tuple[int, int]:
"""roughly equivalent to v4l2capture's set_format"""
"""Roughly equivalent to v4l2capture's set_format."""
assert not self.started

fmt = v4l2.v4l2_format(type=v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE)
Expand All @@ -739,7 +738,7 @@ def _set_format(self, shape_wanted: tuple[int, int], fourcc) -> tuple[int, int]:
return (fmt.fmt.pix.height, fmt.fmt.pix.width)

def _setup_buffers(self, buf_count: int) -> None:
"""roughly equivalent to v4l2capture's create_buffers"""
"""Roughly equivalent to v4l2capture's create_buffers."""
assert not self.started
assert len(self.bufmaps) == 0

Expand All @@ -759,7 +758,7 @@ def _setup_buffers(self, buf_count: int) -> None:
]

def _queue_all_buffers(self) -> None:
"""roughly equivalent to v4l2capture's queue_all_buffers"""
"""Roughly equivalent to v4l2capture's queue_all_buffers."""
assert not self.started
assert len(self.bufmaps) != 0

Expand All @@ -770,7 +769,7 @@ def _queue_all_buffers(self) -> None:
self._v4l2_ioctl(v4l2.VIDIOC_QBUF, buf)

def _read_and_queue(self):
"""roughly equivalent to v4l2capture's read_and_queue"""
"""Roughly equivalent to v4l2capture's read_and_queue."""
assert self.started

buf = v4l2.v4l2_buffer(type=v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE, memory=v4l2.V4L2_MEMORY_MMAP)
Expand Down
6 changes: 2 additions & 4 deletions track/compvis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Computer vision algorithms for identifying targets in a camera frame"""
"""Computer vision algorithms for identifying targets in a camera frame."""

import numpy as np
import cv2
Expand All @@ -13,7 +13,6 @@ def find_features(frame: np.ndarray) -> list[cv2.KeyPoint]:
Returns:
A list of keypoints.
"""

if frame.dtype != np.uint8:
# No fundamental reason; just hasn't been implemented
raise ValueError('Only uint8 frames are supported')
Expand Down Expand Up @@ -59,7 +58,7 @@ def find_features(frame: np.ndarray) -> list[cv2.KeyPoint]:


class PreviewWindow:
"""Generates an annotated camera frame for display in an OpenCV window"""
"""Generates an annotated camera frame for display in an OpenCV window."""

def __init__(
self,
Expand Down Expand Up @@ -108,7 +107,6 @@ def show_annotated_frame(
keypoints: List of all keypoints.
target_keypoint: The keypoint identified as the target.
"""

frame_annotated = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)

# add grey crosshairs, leaving a gap in the middle so the crosshairs don't obscure objects
Expand Down
2 changes: 1 addition & 1 deletion track/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Package configuration utilities
"""Package configuration utilities.
* Defines paths to configuration and data files.
* Specifies the filename of the default shared configuration file used by all programs.
Expand Down
Loading

0 comments on commit ceed9ae

Please sign in to comment.