Skip to content

Commit 908560a

Browse files
committed
ruff formatting
1 parent 2408012 commit 908560a

7 files changed

Lines changed: 62 additions & 27 deletions

File tree

python/PiFinder/server.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -851,26 +851,39 @@ def list_log_configs():
851851
import glob
852852

853853
configs = []
854-
active = os.path.realpath("pifinder_logconf.json") if os.path.exists("pifinder_logconf.json") else None
854+
active = (
855+
os.path.realpath("pifinder_logconf.json")
856+
if os.path.exists("pifinder_logconf.json")
857+
else None
858+
)
855859
for path in sorted(glob.glob("logconf_*.json")):
856-
stem = path[len("logconf_"):-len(".json")]
860+
stem = path[len("logconf_") : -len(".json")]
857861
display = stem.replace("_", " ").title()
858-
configs.append({
859-
"file": path,
860-
"name": display,
861-
"active": os.path.realpath(path) == active,
862-
})
862+
configs.append(
863+
{
864+
"file": path,
865+
"name": display,
866+
"active": os.path.realpath(path) == active,
867+
}
868+
)
863869
return {"configs": configs}
864870

865871
@app.route("/logs/switch_config", method="post")
866872
@auth_required
867873
def switch_log_config():
868874
"""Atomically repoint pifinder_logconf.json to the chosen config, then restart."""
869875
logconf_file = request.forms.get("logconf_file", "").strip()
870-
if not logconf_file or not logconf_file.startswith("logconf_") or not logconf_file.endswith(".json"):
876+
if (
877+
not logconf_file
878+
or not logconf_file.startswith("logconf_")
879+
or not logconf_file.endswith(".json")
880+
):
871881
return {"status": "error", "message": "Invalid log config file name"}
872882
if not os.path.exists(logconf_file):
873-
return {"status": "error", "message": f"Log config file not found: {logconf_file}"}
883+
return {
884+
"status": "error",
885+
"message": f"Log config file not found: {logconf_file}",
886+
}
874887
try:
875888
link = "pifinder_logconf.json"
876889
tmp = link + ".tmp"
@@ -891,9 +904,15 @@ def upload_log_config():
891904
return {"status": "error", "message": "No file provided"}
892905
filename = upload.filename
893906
if not filename.startswith("logconf_") or not filename.endswith(".json"):
894-
return {"status": "error", "message": "File must be named logconf_<name>.json"}
907+
return {
908+
"status": "error",
909+
"message": "File must be named logconf_<name>.json",
910+
}
895911
if os.path.exists(filename):
896-
return {"status": "error", "message": f"File already exists: {filename}"}
912+
return {
913+
"status": "error",
914+
"message": f"File already exists: {filename}",
915+
}
897916
try:
898917
upload.save(filename, overwrite=False)
899918
logger.info("Uploaded log config: %s", filename)

python/PiFinder/sqm/save_sweep_metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def save_sweep_metadata(
8080
# Noise floor estimation details (from NoiseFloorEstimator)
8181
if noise_floor_details is not None:
8282
metadata["noise_floor_estimator"] = {
83-
k: v for k, v in noise_floor_details.items()
83+
k: v
84+
for k, v in noise_floor_details.items()
8485
if k != "request_zero_sec_sample" # Exclude internal flags
8586
}
8687
if camera_type is not None:

python/PiFinder/sqm/sqm.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def _load_calibration(self) -> bool:
6565
)
6666

6767
if not calibration_file.exists():
68-
logger.debug(f"No calibration file found at {calibration_file}, using defaults")
68+
logger.debug(
69+
f"No calibration file found at {calibration_file}, using defaults"
70+
)
6971
return False
7072

7173
try:
@@ -193,7 +195,9 @@ def _measure_star_flux_with_local_background(
193195

194196
# Check for saturation in aperture
195197
aperture_pixels = image_patch[aperture_mask]
196-
max_aperture_pixel = np.max(aperture_pixels) if len(aperture_pixels) > 0 else 0
198+
max_aperture_pixel = (
199+
np.max(aperture_pixels) if len(aperture_pixels) > 0 else 0
200+
)
197201

198202
if max_aperture_pixel >= saturation_threshold:
199203
# Mark saturated star with flux=-1 to be excluded from mzero calculation
@@ -202,7 +206,6 @@ def _measure_star_flux_with_local_background(
202206
n_saturated += 1
203207
continue
204208

205-
206209
# Total flux in aperture (includes background)
207210
total_flux = np.sum(aperture_pixels)
208211

@@ -263,9 +266,7 @@ def _calculate_mzero(
263266
# Flux-weighted mean: brighter stars contribute more
264267
valid_mzeros_arr = np.array(valid_mzeros)
265268
valid_fluxes_arr = np.array(valid_fluxes)
266-
weighted_mzero = float(
267-
np.average(valid_mzeros_arr, weights=valid_fluxes_arr)
268-
)
269+
weighted_mzero = float(np.average(valid_mzeros_arr, weights=valid_fluxes_arr))
269270

270271
return weighted_mzero, mzeros
271272

@@ -540,7 +541,9 @@ def calculate(
540541
# Following ASTAP: zenith is reference point where extinction = 0
541542
# Only ADDITIONAL extinction below zenith is added: 0.28 * (airmass - 1)
542543
# This allows comparing measurements at different altitudes
543-
extinction_for_altitude = self._atmospheric_extinction(altitude_deg) # 0.28*(airmass-1)
544+
extinction_for_altitude = self._atmospheric_extinction(
545+
altitude_deg
546+
) # 0.28*(airmass-1)
544547

545548
# Main SQM value: no extinction correction (raw measurement)
546549
sqm_final = sqm_uncorrected

python/PiFinder/ui/sqm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ def _is_calibrated(self) -> bool:
262262
camera_type = self.shared_state.camera_type()
263263
camera_type_processed = f"{camera_type}_processed"
264264
calibration_file = (
265-
Path.home() / "PiFinder_data" / f"sqm_calibration_{camera_type_processed}.json"
265+
Path.home()
266+
/ "PiFinder_data"
267+
/ f"sqm_calibration_{camera_type_processed}.json"
266268
)
267269
return calibration_file.exists()
268270

python/PiFinder/ui/sqm_calibration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,9 @@ def _analyze_calibration(self):
701701
# 2. Compute read noise using temporal variance (not spatial)
702702
# Spatial std includes fixed pattern noise (PRNU), which is wrong.
703703
# Temporal variance at each pixel measures true read noise.
704-
temporal_variance = np.var(bias_stack, axis=0) # variance across frames per pixel
704+
temporal_variance = np.var(
705+
bias_stack, axis=0
706+
) # variance across frames per pixel
705707
self.read_noise = float(np.sqrt(np.mean(temporal_variance)))
706708

707709
# 3. Compute dark current rate

python/PiFinder/ui/sqm_sweep.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def _add_detailed_metadata(self):
288288
# Find the sweep directory
289289
captures_dir = Path(utils.data_dir) / "captures"
290290
sweep_dirs = [
291-
d for d in captures_dir.glob("sweep_*")
291+
d
292+
for d in captures_dir.glob("sweep_*")
292293
if d.stat().st_ctime >= (self.start_time - 1)
293294
]
294295
if not sweep_dirs:
@@ -313,7 +314,8 @@ def _add_detailed_metadata(self):
313314
"pifinder_value": sqm_state.value,
314315
"reference_value": self.reference_sqm,
315316
"difference": (self.reference_sqm - sqm_state.value)
316-
if self.reference_sqm and sqm_state.value else None,
317+
if self.reference_sqm and sqm_state.value
318+
else None,
317319
"source": sqm_state.source,
318320
}
319321

@@ -327,7 +329,8 @@ def _add_detailed_metadata(self):
327329
if image_metadata:
328330
metadata["image"] = {
329331
"exposure_us": image_metadata.get("exposure_time"),
330-
"exposure_sec": image_metadata.get("exposure_time", 0) / 1_000_000.0,
332+
"exposure_sec": image_metadata.get("exposure_time", 0)
333+
/ 1_000_000.0,
331334
"gain": image_metadata.get("gain"),
332335
"imu_delta": image_metadata.get("imu_delta"),
333336
}
@@ -348,8 +351,11 @@ def _add_detailed_metadata(self):
348351
# Add NoiseFloorEstimator output
349352
camera_type = self.shared_state.camera_type()
350353
camera_type_processed = f"{camera_type}_processed"
351-
exposure_sec = (image_metadata.get("exposure_time", 500000) / 1_000_000.0
352-
if image_metadata else 0.5)
354+
exposure_sec = (
355+
image_metadata.get("exposure_time", 500000) / 1_000_000.0
356+
if image_metadata
357+
else 0.5
358+
)
353359

354360
if self.camera_image is not None:
355361
image_array = np.array(self.camera_image.convert("L"))

python/tests/test_sqm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ def test_calculate_extinction_applied(self):
256256

257257
# Check extinction values (ASTAP convention: 0 at zenith)
258258
# Pickering airmass at 30° ≈ 1.995, so extinction ≈ 0.28 * 0.995 ≈ 0.279
259-
assert details_zenith["extinction_for_altitude"] == pytest.approx(0.0, abs=0.001)
259+
assert details_zenith["extinction_for_altitude"] == pytest.approx(
260+
0.0, abs=0.001
261+
)
260262
expected_ext_30 = 0.28 * (sqm._pickering_airmass(30.0) - 1)
261263
assert details_30deg["extinction_for_altitude"] == pytest.approx(
262264
expected_ext_30, abs=0.001

0 commit comments

Comments
 (0)