Skip to content

Commit b32e8ca

Browse files
jman4162claude
andcommitted
Fix ruff linting errors in Streamlit app
- Remove unused imports - Fix nested if statements (SIM102) - Convert dict() to literals (C408) - Format with ruff Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 215566d commit b32e8ca

5 files changed

Lines changed: 350 additions & 293 deletions

File tree

app/pages/1_Single_Case.py

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
with real-time metrics display and requirement verification.
66
"""
77

8-
import streamlit as st
98
import numpy as np
9+
import streamlit as st
1010

1111
st.set_page_config(
1212
page_title="Single Case Calculator",
@@ -19,10 +19,16 @@
1919

2020
# Try to import the package
2121
try:
22-
from phased_array_systems.architecture import Architecture, ArrayConfig, RFChainConfig, CostConfig
23-
from phased_array_systems.scenarios import CommsLinkScenario
22+
from phased_array_systems.architecture import (
23+
Architecture,
24+
ArrayConfig,
25+
CostConfig,
26+
RFChainConfig,
27+
)
2428
from phased_array_systems.evaluate import evaluate_case
25-
from phased_array_systems.requirements import RequirementSet, Requirement
29+
from phased_array_systems.requirements import Requirement, RequirementSet
30+
from phased_array_systems.scenarios import CommsLinkScenario
31+
2632
PACKAGE_AVAILABLE = True
2733
except ImportError:
2834
PACKAGE_AVAILABLE = False
@@ -42,14 +48,14 @@
4248
"Elements X (nx)",
4349
options=[2, 4, 8, 16, 32, 64],
4450
value=8,
45-
help="Number of elements in X direction (power of 2)"
51+
help="Number of elements in X direction (power of 2)",
4652
)
4753

4854
ny = st.sidebar.select_slider(
4955
"Elements Y (ny)",
5056
options=[2, 4, 8, 16, 32, 64],
5157
value=8,
52-
help="Number of elements in Y direction (power of 2)"
58+
help="Number of elements in Y direction (power of 2)",
5359
)
5460

5561
dx_lambda = st.sidebar.slider(
@@ -58,7 +64,7 @@
5864
max_value=0.7,
5965
value=0.5,
6066
step=0.05,
61-
help="Element spacing in wavelengths"
67+
help="Element spacing in wavelengths",
6268
)
6369

6470
dy_lambda = st.sidebar.slider(
@@ -67,7 +73,7 @@
6773
max_value=0.7,
6874
value=0.5,
6975
step=0.05,
70-
help="Element spacing in wavelengths"
76+
help="Element spacing in wavelengths",
7177
)
7278

7379
st.sidebar.header("RF Chain")
@@ -78,7 +84,7 @@
7884
max_value=5.0,
7985
value=1.0,
8086
step=0.1,
81-
help="Transmit power per element in Watts"
87+
help="Transmit power per element in Watts",
8288
)
8389

8490
pa_efficiency = st.sidebar.slider(
@@ -87,7 +93,7 @@
8793
max_value=0.7,
8894
value=0.3,
8995
step=0.05,
90-
help="Power amplifier efficiency (0-1)"
96+
help="Power amplifier efficiency (0-1)",
9197
)
9298

9399
noise_figure_db = st.sidebar.slider(
@@ -96,7 +102,7 @@
96102
max_value=10.0,
97103
value=3.0,
98104
step=0.5,
99-
help="Receiver noise figure"
105+
help="Receiver noise figure",
100106
)
101107

102108
st.sidebar.header("Cost")
@@ -107,7 +113,7 @@
107113
max_value=1000,
108114
value=100,
109115
step=10,
110-
help="Recurring cost per element in USD"
116+
help="Recurring cost per element in USD",
111117
)
112118

113119
st.sidebar.header("Scenario")
@@ -118,25 +124,15 @@
118124
max_value=40.0,
119125
value=10.0,
120126
step=0.5,
121-
help="Operating frequency"
127+
help="Operating frequency",
122128
)
123129

124130
range_km = st.sidebar.slider(
125-
"Range (km)",
126-
min_value=1.0,
127-
max_value=500.0,
128-
value=100.0,
129-
step=5.0,
130-
help="Link distance"
131+
"Range (km)", min_value=1.0, max_value=500.0, value=100.0, step=5.0, help="Link distance"
131132
)
132133

133134
bandwidth_mhz = st.sidebar.slider(
134-
"Bandwidth (MHz)",
135-
min_value=1.0,
136-
max_value=100.0,
137-
value=10.0,
138-
step=1.0,
139-
help="Signal bandwidth"
135+
"Bandwidth (MHz)", min_value=1.0, max_value=100.0, value=10.0, step=1.0, help="Signal bandwidth"
140136
)
141137

142138
required_snr_db = st.sidebar.slider(
@@ -145,7 +141,7 @@
145141
max_value=30.0,
146142
value=10.0,
147143
step=1.0,
148-
help="SNR required for demodulation"
144+
help="SNR required for demodulation",
149145
)
150146

151147
# Calculate derived values
@@ -159,7 +155,8 @@
159155
# Use the actual package
160156
arch = Architecture(
161157
array=ArrayConfig(
162-
nx=nx, ny=ny,
158+
nx=nx,
159+
ny=ny,
163160
dx_lambda=dx_lambda,
164161
dy_lambda=dy_lambda,
165162
enforce_subarray_constraint=False,
@@ -181,22 +178,26 @@
181178

182179
# Define requirements
183180
requirements = RequirementSet()
184-
requirements.add(Requirement(
185-
id="REQ-SNR",
186-
name="SNR Margin",
187-
metric_key="link_margin_db",
188-
op=">=",
189-
value=0.0,
190-
severity="must",
191-
))
192-
requirements.add(Requirement(
193-
id="REQ-COST",
194-
name="System Cost",
195-
metric_key="cost_usd",
196-
op="<=",
197-
value=100000.0,
198-
severity="should",
199-
))
181+
requirements.add(
182+
Requirement(
183+
id="REQ-SNR",
184+
name="SNR Margin",
185+
metric_key="link_margin_db",
186+
op=">=",
187+
value=0.0,
188+
severity="must",
189+
)
190+
)
191+
requirements.add(
192+
Requirement(
193+
id="REQ-COST",
194+
name="System Cost",
195+
metric_key="cost_usd",
196+
op="<=",
197+
value=100000.0,
198+
severity="should",
199+
)
200+
)
200201

201202
# Evaluate
202203
metrics = evaluate_case(arch, scenario, requirements)
@@ -263,34 +264,24 @@
263264
col1, col2, col3, col4 = st.columns(4)
264265

265266
with col1:
266-
st.metric(
267-
"Total Elements",
268-
f"{n_elements:,}",
269-
help="nx × ny"
270-
)
267+
st.metric("Total Elements", f"{n_elements:,}", help="nx × ny")
271268

272269
with col2:
273-
st.metric(
274-
"Peak Gain",
275-
f"{metrics.get('g_peak_db', 0):.1f} dB",
276-
help="Antenna peak gain"
277-
)
270+
st.metric("Peak Gain", f"{metrics.get('g_peak_db', 0):.1f} dB", help="Antenna peak gain")
278271

279272
with col3:
280273
st.metric(
281-
"EIRP",
282-
f"{metrics.get('eirp_dbw', 0):.1f} dBW",
283-
help="Effective Isotropic Radiated Power"
274+
"EIRP", f"{metrics.get('eirp_dbw', 0):.1f} dBW", help="Effective Isotropic Radiated Power"
284275
)
285276

286-
link_margin = metrics.get('link_margin_db', 0)
277+
link_margin = metrics.get("link_margin_db", 0)
287278
with col4:
288279
st.metric(
289280
"Link Margin",
290281
f"{link_margin:.1f} dB",
291282
delta="PASS" if link_margin >= 0 else "FAIL",
292283
delta_color="normal" if link_margin >= 0 else "inverse",
293-
help="SNR margin above required"
284+
help="SNR margin above required",
294285
)
295286

296287
st.divider()
@@ -308,7 +299,7 @@
308299
st.write(f"- Array Size: {nx} × {ny} = {n_elements} elements")
309300
st.write(f"- Element Spacing: {dx_lambda}λ × {dy_lambda}λ")
310301
st.write(f"- Frequency: {freq_ghz:.1f} GHz")
311-
st.write(f"- Wavelength: {3e8/freq_hz*1000:.1f} mm")
302+
st.write(f"- Wavelength: {3e8 / freq_hz * 1000:.1f} mm")
312303

313304
with col2:
314305
st.markdown("**Performance**")
@@ -325,7 +316,9 @@
325316
with col1:
326317
st.markdown("**Transmit**")
327318
st.write(f"- TX Power/Element: {tx_power_w:.1f} W")
328-
st.write(f"- Total TX Power: {tx_power_w * n_elements:.1f} W ({10*np.log10(tx_power_w * n_elements):.1f} dBW)")
319+
st.write(
320+
f"- Total TX Power: {tx_power_w * n_elements:.1f} W ({10 * np.log10(tx_power_w * n_elements):.1f} dBW)"
321+
)
329322
st.write(f"- Antenna Gain: {metrics.get('g_peak_db', 0):.1f} dB")
330323
st.write(f"- **EIRP: {metrics.get('eirp_dbw', 0):.1f} dBW**")
331324

@@ -341,14 +334,14 @@
341334
col1, col2, col3 = st.columns(3)
342335

343336
with col1:
344-
snr = metrics.get('snr_rx_db', 0)
337+
snr = metrics.get("snr_rx_db", 0)
345338
st.metric("Received SNR", f"{snr:.1f} dB")
346339

347340
with col2:
348341
st.metric("Required SNR", f"{required_snr_db:.1f} dB")
349342

350343
with col3:
351-
margin = metrics.get('link_margin_db', 0)
344+
margin = metrics.get("link_margin_db", 0)
352345
color = "green" if margin >= 0 else "red"
353346
status = "✅ PASS" if margin >= 0 else "❌ FAIL"
354347
st.metric("Link Margin", f"{margin:.1f} dB", status)
@@ -360,14 +353,14 @@
360353

361354
with col1:
362355
st.markdown("**Power**")
363-
prime_power = metrics.get('prime_power_w', tx_power_w * n_elements / pa_efficiency)
356+
prime_power = metrics.get("prime_power_w", tx_power_w * n_elements / pa_efficiency)
364357
st.write(f"- RF Power: {tx_power_w * n_elements:.1f} W")
365-
st.write(f"- PA Efficiency: {pa_efficiency*100:.0f}%")
358+
st.write(f"- PA Efficiency: {pa_efficiency * 100:.0f}%")
366359
st.write(f"- **Prime Power: {prime_power:.1f} W**")
367360

368361
with col2:
369362
st.markdown("**Cost**")
370-
total_cost = metrics.get('cost_usd', cost_per_elem * n_elements)
363+
total_cost = metrics.get("cost_usd", cost_per_elem * n_elements)
371364
st.write(f"- Cost per Element: ${cost_per_elem:,}")
372365
st.write(f"- Number of Elements: {n_elements:,}")
373366
st.write(f"- **Total Cost: ${total_cost:,.0f}**")
@@ -376,7 +369,9 @@
376369
st.divider()
377370
cost_limit = 100000
378371
cost_pct = min(total_cost / cost_limit * 100, 100)
379-
st.progress(cost_pct / 100, f"Cost Budget: ${total_cost:,.0f} / ${cost_limit:,} ({cost_pct:.0f}%)")
372+
st.progress(
373+
cost_pct / 100, f"Cost Budget: ${total_cost:,.0f} / ${cost_limit:,} ({cost_pct:.0f}%)"
374+
)
380375

381376
# Export configuration
382377
st.divider()
@@ -408,5 +403,5 @@
408403
label="Download Configuration",
409404
data=yaml_config,
410405
file_name="phased_array_config.yaml",
411-
mime="text/yaml"
406+
mime="text/yaml",
412407
)

0 commit comments

Comments
 (0)