Skip to content

Commit

Permalink
formatting: format entire repo with black (#49)
Browse files Browse the repository at this point in the history
We added a github workflow that checks PRs for formatting via black with
120 line length. This formats the entire repo with those options so that
we have a clean slate.

Tested by:
```
(squid) ➜  software git:(ian/format-repo) black --config pyproject.toml .                                
All done! ✨ 🍰 ✨
65 files left unchanged.
```
And unit tests still pass.
  • Loading branch information
ianohara authored Jan 2, 2025
1 parent 7b7afd0 commit 90fa325
Show file tree
Hide file tree
Showing 58 changed files with 7,449 additions and 5,172 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# NOTE(imo): This 3.13 python version is just for black to be able to use the use_pyproject option. We
# don't actually require 3.13 in our code!
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: psf/black@stable
with:
options: "--line-length=120"
options: "--config software/pyproject.toml"
src: "./software/"
61 changes: 31 additions & 30 deletions software/control/NL5.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import control.RCM_API as RCM_API
import json


class NL5:

def __init__(self):

self.rcm = RCM_API.RCM_API()
self.rcm.initialize_device(simulated=False)
self.load_settings()

def set_scan_amplitude(self,amplitude):
def set_scan_amplitude(self, amplitude):
self.scan_amplitude = amplitude
self.rcm.set_float_parameter(self.rcm.AMPLITUDE_X,amplitude)
self.rcm.set_float_parameter(self.rcm.AMPLITUDE_X, amplitude)

def set_offset_x(self,offset_x):
def set_offset_x(self, offset_x):
self.offset_x = offset_x
self.rcm.set_float_parameter(self.rcm.OFFSET_SCAN_X,offset_x)
self.rcm.set_float_parameter(self.rcm.OFFSET_SCAN_X, offset_x)

def start_acquisition(self):
ret = self.rcm.start_acquisition()
Expand All @@ -35,33 +36,33 @@ def set_bypass(self, enabled):
def set_active_channel(self, channel):
self.active_channel = channel
for i in range(1, 5):
self.rcm.set_integer_parameter(getattr(self.rcm, f'LASER_{i}_SELECTED'), 1 if i == channel else 0)
self.rcm.set_integer_parameter(getattr(self.rcm, f"LASER_{i}_SELECTED"), 1 if i == channel else 0)

def set_laser_power(self,channel,power):
self.rcm.set_integer_parameter(getattr(self.rcm,f'LASER_{channel}_POWER'),power)
def set_laser_power(self, channel, power):
self.rcm.set_integer_parameter(getattr(self.rcm, f"LASER_{channel}_POWER"), power)

def set_bypass_offset(self, offset):
self.bypass_offset = offset
self.rcm.set_float_parameter(self.rcm.BYPASS_OFFSET,offset)
self.rcm.set_float_parameter(self.rcm.BYPASS_OFFSET, offset)

def set_line_speed(self,speed,save_setting=False):
def set_line_speed(self, speed, save_setting=False):
self.line_speed = speed
self.rcm.set_integer_parameter(self.rcm.LINE_FREQUENCY,speed) # speed in mrad/s
self.rcm.set_integer_parameter(self.rcm.LINE_FREQUENCY, speed) # speed in mrad/s
if save_setting:
self.save_settings()

def set_fov_x(self,fov_x):
def set_fov_x(self, fov_x):
self.fov_x = fov_x
self.rcm.set_integer_parameter(self.rcm.FIELD_OF_VIEW_X,fov_x)
self.rcm.set_integer_parameter(self.rcm.FIELD_OF_VIEW_X, fov_x)
self.save_settings()

def set_exposure_delay(self,exposure_delay_ms):
def set_exposure_delay(self, exposure_delay_ms):
self.exposure_delay_ms = exposure_delay_ms
self.rcm.set_integer_parameter(self.rcm.EXPOSURE_DELAY,exposure_delay_ms)
self.rcm.set_integer_parameter(self.rcm.EXPOSURE_DELAY, exposure_delay_ms)

def load_settings(self):
try:
with open('NL5_settings.json', 'r') as file:
with open("NL5_settings.json", "r") as file:
settings = json.load(file)
self.scan_amplitude = settings.get("scan_amplitude", 70.0)
self.offset_x = settings.get("offset_x", 0.0)
Expand All @@ -77,17 +78,17 @@ def load_settings(self):
self.exposure_delay_ms = 30
self.line_speed = 3000
self.fov_x = 2048

def save_settings(self):
settings = {
"scan_amplitude": self.scan_amplitude,
"offset_x": self.offset_x,
"bypass_offset": self.bypass_offset,
"fov_x": self.fov_x,
"exposure_delay_ms": self.exposure_delay_ms,
"line_speed": self.line_speed
"line_speed": self.line_speed,
}
with open('NL5_settings.json', 'w') as file:
with open("NL5_settings.json", "w") as file:
json.dump(settings, file)


Expand All @@ -96,11 +97,11 @@ class NL5_Simulation:
def __init__(self):
self.load_settings()

def set_scan_amplitude(self,amplitude):
def set_scan_amplitude(self, amplitude):
self.scan_amplitude = amplitude
pass

def set_offset_x(self,offset_x):
def set_offset_x(self, offset_x):
self.offset_x = offset_x
pass

Expand All @@ -119,29 +120,29 @@ def set_bypass(self, enabled):
def set_active_channel(self, channel):
pass

def set_laser_power(self,channel,power):
def set_laser_power(self, channel, power):
pass

def set_bypass_offset(self, offset):
self.bypass_offset = offset
pass

def set_line_speed(self,speed, save_setting = False):
def set_line_speed(self, speed, save_setting=False):
self.line_speed = speed
if save_setting:
self.save_settings()

def set_fov_x(self,fov_x):
def set_fov_x(self, fov_x):
self.fov_x = fov_x
self.save_settings()

def set_exposure_delay(self,exposure_delay_ms):
def set_exposure_delay(self, exposure_delay_ms):
self.exposure_delay_ms = exposure_delay_ms
pass

def load_settings(self):
try:
with open('NL5_settings.json', 'r') as file:
with open("NL5_settings.json", "r") as file:
settings = json.load(file)
self.scan_amplitude = settings.get("scan_amplitude", 70.0)
self.offset_x = settings.get("offset_x", 0.0)
Expand All @@ -157,15 +158,15 @@ def load_settings(self):
self.exposure_delay_ms = 30
self.line_speed = 3000
self.fov_x = 2048

def save_settings(self):
settings = {
"scan_amplitude": self.scan_amplitude,
"offset_x": self.offset_x,
"bypass_offset": self.bypass_offset,
"fov_x": self.fov_x,
"exposure_delay_ms": self.exposure_delay_ms,
"line_speed": self.line_speed
"line_speed": self.line_speed,
}
with open('NL5_settings.json', 'w') as file:
json.dump(settings, file)
with open("NL5_settings.json", "w") as file:
json.dump(settings, file)
57 changes: 35 additions & 22 deletions software/control/NL5Widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QHBoxLayout, QVBoxLayout, QLabel, QDoubleSpinBox, QSpinBox, QPushButton, QCheckBox, QDialog, QDialogButtonBox
from PyQt5.QtWidgets import (
QApplication,
QWidget,
QGridLayout,
QHBoxLayout,
QVBoxLayout,
QLabel,
QDoubleSpinBox,
QSpinBox,
QPushButton,
QCheckBox,
QDialog,
QDialogButtonBox,
)
from PyQt5.QtCore import Qt


Expand All @@ -8,35 +21,35 @@ def __init__(self, nl5):
super().__init__()
self.nl5 = nl5
self.setWindowTitle("NL5 Settings")

layout = QGridLayout()

# Scan amplitude control
layout.addWidget(QLabel("Scan Amplitude"), 0, 0)
self.scan_amplitude_input = QDoubleSpinBox()
self.scan_amplitude_input.setValue(self.nl5.scan_amplitude)
layout.addWidget(self.scan_amplitude_input, 0, 1)

# Offset X control
layout.addWidget(QLabel("Offset X"), 1, 0)
self.offset_x_input = QDoubleSpinBox()
self.offset_x_input.setMinimum(-30)
self.offset_x_input.setValue(self.nl5.offset_x)
layout.addWidget(self.offset_x_input, 1, 1)

# Bypass offset control
layout.addWidget(QLabel("Bypass Offset"), 2, 0)
self.bypass_offset_input = QDoubleSpinBox()
self.bypass_offset_input.setMinimum(-30)
self.bypass_offset_input.setValue(self.nl5.bypass_offset)
layout.addWidget(self.bypass_offset_input, 2, 1)

# Dialog buttons
buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons, 3, 0, 1, 2)

self.setLayout(layout)

def accept(self):
Expand All @@ -50,9 +63,9 @@ def accept(self):
class NL5Widget(QWidget):
def __init__(self, nl5):
super().__init__()

self.nl5 = nl5

# Create layout
layout1 = QHBoxLayout()
layout2 = QHBoxLayout()
Expand All @@ -61,7 +74,7 @@ def __init__(self, nl5):
layout1.addWidget(QLabel("Exposure Delay"))
self.exposure_delay_input = QSpinBox()
self.exposure_delay_input.setValue(self.nl5.exposure_delay_ms)
self.exposure_delay_input.setSuffix(' ms')
self.exposure_delay_input.setSuffix(" ms")
self.exposure_delay_input.valueChanged.connect(self.update_exposure_delay)
layout1.addWidget(self.exposure_delay_input)
layout1.addStretch()
Expand All @@ -71,19 +84,18 @@ def __init__(self, nl5):
self.line_speed_input = QSpinBox()
self.line_speed_input.setMaximum(20000)
self.line_speed_input.setValue(self.nl5.line_speed)
self.line_speed_input.setSuffix(' mrad/s')
self.line_speed_input.setSuffix(" mrad/s")
self.line_speed_input.valueChanged.connect(self.update_line_speed)
layout1.addWidget(self.line_speed_input)
layout1.addStretch()


# FOV X control
layout1.addWidget(QLabel("FOV"))
# layout1.addWidget(QLabel("FOV X"))
self.fov_x_input = QSpinBox()
self.fov_x_input.setMaximum(4000)
self.fov_x_input.setValue(self.nl5.fov_x)
self.fov_x_input.setSuffix(' px')
self.fov_x_input.setSuffix(" px")
self.fov_x_input.valueChanged.connect(self.update_fov_x)
layout1.addWidget(self.fov_x_input)

Expand All @@ -92,7 +104,7 @@ def __init__(self, nl5):
self.bypass_button.setCheckable(True)
self.bypass_button.toggled.connect(self.update_bypass)
layout2.addWidget(self.bypass_button)

# Start acquisition button
self.start_acquisition_button = QPushButton("Start Acquisition")
self.start_acquisition_button.clicked.connect(self.nl5.start_acquisition)
Expand All @@ -107,31 +119,32 @@ def __init__(self, nl5):
layout.addLayout(layout1)
layout.addLayout(layout2)
self.setLayout(layout)

def show_settings_dialog(self):
dialog = NL5SettingsDialog(self.nl5)
dialog.exec_()

def update_bypass(self, checked):
self.nl5.set_bypass(checked)
self.start_acquisition_button.setEnabled(not checked)

def update_exposure_delay(self, value):
self.nl5.set_exposure_delay(value)

def update_line_speed(self, value):
self.nl5.set_line_speed(value)

def update_fov_x(self, value):
self.nl5.set_fov_x(value)


if __name__ == "__main__":
app = QApplication(sys.argv)

import NL5

nl5 = NL5.NL5()
widget = NL5Widget(nl5)
widget.show()
sys.exit(app.exec_())

sys.exit(app.exec_())
Loading

0 comments on commit 90fa325

Please sign in to comment.