Skip to content

Commit

Permalink
Run pyupgrade for 3.9 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanielloNTIA committed Nov 7, 2024
1 parent a96ff69 commit 5c45692
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 62 deletions.
3 changes: 1 addition & 2 deletions scos_actions/actions/acquire_sea_data_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import sys
from enum import EnumMeta
from time import perf_counter
from typing import Tuple

import numpy as np
import psutil
Expand Down Expand Up @@ -261,7 +260,7 @@ def __init__(
self.detector = detector
self.impedance_ohms = impedance_ohms

def run(self, iq: ray.ObjectRef) -> Tuple[np.ndarray, np.ndarray]:
def run(self, iq: ray.ObjectRef) -> tuple[np.ndarray, np.ndarray]:
"""
Compute power versus time results from IQ samples.
Expand Down
6 changes: 3 additions & 3 deletions scos_actions/calibration/interfaces/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from abc import abstractmethod
from pathlib import Path
from typing import List, get_origin
from typing import get_origin

from scos_actions.calibration.utils import (
CalibrationParametersMissingException,
Expand All @@ -28,7 +28,7 @@ class Calibration:
updates (if allowed) will be saved.
"""

calibration_parameters: List[str]
calibration_parameters: list[str]
calibration_data: dict
calibration_reference: str
file_path: Path
Expand All @@ -43,7 +43,7 @@ def __post_init__(self):
def _validate_fields(self) -> None:
"""Loosely check that the input types are as expected."""
for f_name, f_def in self.__dataclass_fields__.items():
# Note that nested types are not checked: i.e., "List[str]"
# Note that nested types are not checked: i.e., "list[str]"
# will surely be a list, but may not be filled with strings.
f_type = get_origin(f_def.type) or f_def.type
actual_value = getattr(self, f_name)
Expand Down
3 changes: 1 addition & 2 deletions scos_actions/calibration/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dataclasses
import json
from pathlib import Path
from typing import List

import pytest

Expand Down Expand Up @@ -57,7 +56,7 @@ def test_calibration_dataclass_fields(self):
fields = {f.name: f.type for f in dataclasses.fields(Calibration)}
# Note: does not check field order
assert fields == {
"calibration_parameters": List[str],
"calibration_parameters": list[str],
"calibration_reference": str,
"calibration_data": dict,
"file_path": Path,
Expand Down
12 changes: 6 additions & 6 deletions scos_actions/hardware/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
import json
import logging
from typing import Any, Dict, List, Optional
from typing import Any, Optional

import numpy as np
from its_preselector.preselector import Preselector
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(
capabilities: dict,
gps: Optional[GPSInterface] = None,
preselector: Optional[Preselector] = None,
switches: Optional[Dict[str, WebRelay]] = {},
switches: Optional[dict[str, WebRelay]] = {},
location: Optional[dict] = None,
sensor_cal: Optional[SensorCalibration] = None,
differential_cal: Optional[DifferentialCalibration] = None,
Expand Down Expand Up @@ -93,15 +93,15 @@ def preselector(self, preselector: Preselector):
self._preselector = preselector

@property
def switches(self) -> Dict[str, WebRelay]:
def switches(self) -> dict[str, WebRelay]:
"""
Dictionary of WebRelays, indexed by name. WebRelays may enable/disable other
components within the sensor and/or provide a variety of sensors.
"""
return self._switches

@switches.setter
def switches(self, switches: Dict[str, WebRelay]):
def switches(self, switches: dict[str, WebRelay]):
self._switches = switches

@property
Expand Down Expand Up @@ -213,12 +213,12 @@ def last_calibration_time(self) -> str:
)

@property
def sensor_calibration_data(self) -> Dict[str, Any]:
def sensor_calibration_data(self) -> dict[str, Any]:
"""Sensor calibration data for the current sensor settings."""
return self._sensor_calibration_data

@property
def differential_calibration_data(self) -> Dict[str, float]:
def differential_calibration_data(self) -> dict[str, float]:
"""Differential calibration data for the current sensor settings."""
return self._differential_calibration_data

Expand Down
4 changes: 2 additions & 2 deletions scos_actions/hardware/sigan_iface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import time
from abc import ABC, abstractmethod
from typing import Dict, Optional
from typing import Optional

from its_preselector.web_relay import WebRelay

Expand All @@ -13,7 +13,7 @@
class SignalAnalyzerInterface(ABC):
def __init__(
self,
switches: Optional[Dict[str, WebRelay]] = None,
switches: Optional[dict[str, WebRelay]] = None,
):
self._model = "Unknown"
self._api_version = "Unknown"
Expand Down
4 changes: 2 additions & 2 deletions scos_actions/hardware/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import subprocess
from typing import Dict, Tuple, Union
from typing import Union

import psutil
from its_preselector.web_relay import WebRelay
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_max_cpu_temperature(fahrenheit: bool = False) -> float:
raise e


def power_cycle_sigan(switches: Dict[str, WebRelay]):
def power_cycle_sigan(switches: dict[str, WebRelay]):
"""
Performs a hard power cycle of the signal analyzer. This method requires power to the signal analyzer is
controlled by a Web_Relay (see https://www.github.com/ntia/Preselector) and that the switch id of that
Expand Down
16 changes: 8 additions & 8 deletions scos_actions/metadata/sigmf_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import List, Union
from typing import Union

import msgspec
from sigmf import SigMFFile
Expand Down Expand Up @@ -268,15 +268,15 @@ def set_collection(self, collection: str) -> None:

### ntia-algorithm v2.0.1 ###

def set_data_products(self, data_products: List[Graph]) -> None:
def set_data_products(self, data_products: list[Graph]) -> None:
"""
Set the value of the Global "ntia-algorithm:data_products" field.
:param data_products: List of data products produced for each capture.
"""
self.sigmf_md.set_global_field("ntia-algorithm:data_products", data_products)

def set_processing(self, processing: List[str]) -> None:
def set_processing(self, processing: list[str]) -> None:
"""
Set the value of the Global "ntia-algorithm:processing" field.
Expand All @@ -286,7 +286,7 @@ def set_processing(self, processing: List[str]) -> None:
self.sigmf_md.set_global_field("ntia-algorithm:processing", processing)

def set_processing_info(
self, processing_info: List[Union[DigitalFilter, DFT]]
self, processing_info: list[Union[DigitalFilter, DFT]]
) -> None:
"""
Set the value of the Global "ntia-algorithm:processing_info" field.
Expand Down Expand Up @@ -324,7 +324,7 @@ def set_diagnostics(self, diagnostics: Diagnostics) -> None:
### ntia-nasctn-sea v0.6.0 ###

def set_max_of_max_channel_powers(
self, max_of_max_channel_powers: List[float]
self, max_of_max_channel_powers: list[float]
) -> None:
"""
Set the value of the Global "ntia-nasctn-sea:max_of_max_channel_powers" field.
Expand All @@ -335,7 +335,7 @@ def set_max_of_max_channel_powers(
"ntia-nasctn-sea:max_of_max_channel_powers", max_of_max_channel_powers
)

def set_mean_channel_powers(self, mean_channel_powers: List[float]) -> None:
def set_mean_channel_powers(self, mean_channel_powers: list[float]) -> None:
"""
Set the value of the Global "ntia-nasctn-sea:mean_channel_powers" field.
Expand All @@ -345,7 +345,7 @@ def set_mean_channel_powers(self, mean_channel_powers: List[float]) -> None:
"ntia-nasctn-sea:mean_channel_powers", mean_channel_powers
)

def set_median_channel_powers(self, median_channel_powers: List[float]) -> None:
def set_median_channel_powers(self, median_channel_powers: list[float]) -> None:
"""
Set the value of the Global "ntia-nasctn-sea:median_channel_powers" field.
Expand All @@ -356,7 +356,7 @@ def set_median_channel_powers(self, median_channel_powers: List[float]) -> None:
)

def set_median_of_mean_channel_powers(
self, median_of_mean_channel_powers: List[float]
self, median_of_mean_channel_powers: list[float]
) -> None:
"""
Set the value of the Global "ntia-nasctn-sea:median_of_mean_channel_powers" field.
Expand Down
28 changes: 14 additions & 14 deletions scos_actions/metadata/structs/ntia_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import List, Optional, Union
from typing import Optional, Union

import msgspec

Expand All @@ -16,7 +16,7 @@ class DigitalFilter(msgspec.Struct, tag=True, **SIGMF_OBJECT_KWARGS):
Interface for generating `ntia-algorithm` `DigitalFilter` objects.
:param id: Unique ID of the filter.
:param filter_type: Type of the digital fitler, given by the `FilterType`
:param filter_type: Type of the digital filter, given by the `FilterType`
enum.
:param feedforward_coefficients: Coefficients that define the feedforward
filter stage.
Expand All @@ -32,8 +32,8 @@ class DigitalFilter(msgspec.Struct, tag=True, **SIGMF_OBJECT_KWARGS):

id: str
filter_type: FilterType
feedforward_coefficients: Optional[List[float]] = None
feedback_coefficients: Optional[List[float]] = None
feedforward_coefficients: Optional[list[float]] = None
feedback_coefficients: Optional[list[float]] = None
attenuation_cutoff: Optional[float] = None
frequency_cutoff: Optional[float] = None
description: Optional[str] = None
Expand All @@ -49,19 +49,19 @@ class Graph(msgspec.Struct, **SIGMF_OBJECT_KWARGS):
"""

name: str
series: Optional[List[str]] = None
series: Optional[list[str]] = None
length: Optional[int] = None
x_units: Optional[str] = None
x_axis: Optional[List[Union[int, float, str]]] = None
x_start: Optional[List[float]] = None
x_stop: Optional[List[float]] = None
x_step: Optional[List[float]] = None
x_axis: Optional[list[Union[int, float, str]]] = None
x_start: Optional[list[float]] = None
x_stop: Optional[list[float]] = None
x_step: Optional[list[float]] = None
y_units: Optional[str] = None
y_axis: Optional[List[Union[int, float, str]]] = None
y_start: Optional[List[float]] = None
y_stop: Optional[List[float]] = None
y_step: Optional[List[float]] = None
processing: Optional[List[str]] = None
y_axis: Optional[list[Union[int, float, str]]] = None
y_start: Optional[list[float]] = None
y_stop: Optional[list[float]] = None
y_step: Optional[list[float]] = None
processing: Optional[list[str]] = None
reference: Optional[str] = None
description: Optional[str] = None

Expand Down
6 changes: 3 additions & 3 deletions scos_actions/metadata/structs/ntia_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional

import msgspec

Expand Down Expand Up @@ -57,8 +57,8 @@ class Antenna(msgspec.Struct, rename={"antenna_type": "type"}, **SIGMF_OBJECT_KW
polarization: Optional[float] = None
cross_polar_discrimination: Optional[float] = None
gain: Optional[float] = None
horizontal_gain_pattern: Optional[List[float]] = None
vertical_gain_pattern: Optional[List[float]] = None
horizontal_gain_pattern: Optional[list[float]] = None
vertical_gain_pattern: Optional[list[float]] = None
horizontal_beamwidth: Optional[float] = None
vertical_beamwidth: Optional[float] = None
voltage_standing_wave_ratio: Optional[float] = None
Expand Down
8 changes: 4 additions & 4 deletions scos_actions/metadata/structs/ntia_diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional

import msgspec

Expand Down Expand Up @@ -80,9 +80,9 @@ class SPU(msgspec.Struct, **SIGMF_OBJECT_KWARGS):
ups_healthy: Optional[bool] = None
replace_battery: Optional[bool] = None

temperature_sensors: Optional[List[DiagnosticSensor]] = None
humidity_sensors: Optional[List[DiagnosticSensor]] = None
power_sensors: Optional[List[DiagnosticSensor]] = None
temperature_sensors: Optional[list[DiagnosticSensor]] = None
humidity_sensors: Optional[list[DiagnosticSensor]] = None
power_sensors: Optional[list[DiagnosticSensor]] = None
door_closed: Optional[bool] = None


Expand Down
4 changes: 2 additions & 2 deletions scos_actions/metadata/structs/ntia_scos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional

import msgspec

Expand Down Expand Up @@ -43,4 +43,4 @@ class ScheduleEntry(msgspec.Struct, **SIGMF_OBJECT_KWARGS):
stop: Optional[str] = None
interval: Optional[int] = None
priority: Optional[int] = None
roles: Optional[List[str]] = None
roles: Optional[list[str]] = None
10 changes: 5 additions & 5 deletions scos_actions/metadata/structs/ntia_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List, Optional
from typing import Optional

import msgspec

Expand Down Expand Up @@ -110,10 +110,10 @@ class Preselector(msgspec.Struct, **SIGMF_OBJECT_KWARGS):
"""

preselector_spec: Optional[HardwareSpec] = None
cal_sources: Optional[List[CalSource]] = None
amplifiers: Optional[List[Amplifier]] = None
filters: Optional[List[Filter]] = None
rf_paths: Optional[List[RFPath]] = None
cal_sources: Optional[list[CalSource]] = None
amplifiers: Optional[list[Amplifier]] = None
filters: Optional[list[Filter]] = None
rf_paths: Optional[list[RFPath]] = None


class Calibration(
Expand Down
4 changes: 1 addition & 3 deletions scos_actions/signal_processing/apd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

import numexpr as ne
import numpy as np

Expand All @@ -12,7 +10,7 @@ def get_apd(
min_bin: float = None,
max_bin: float = None,
impedance_ohms: float = None,
) -> Tuple[np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray]:
"""Estimate the APD by sampling the CCDF.
The size of the output depends on ``bin_size_dB``, which
Expand Down
6 changes: 3 additions & 3 deletions scos_actions/signal_processing/calibration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Optional, Tuple
from typing import Optional

import numpy as np
from its_preselector.preselector import Preselector
Expand All @@ -23,7 +23,7 @@ def y_factor(
enr_linear: float,
enbw_hz: float,
temp_kelvins: float = 300.0,
) -> Tuple[float, float]:
) -> tuple[float, float]:
"""
Perform Y-Factor calculations of noise figure and gain.
Expand Down Expand Up @@ -105,7 +105,7 @@ def get_linear_enr(

def get_temperature(
preselector: Preselector, sensor_idx: Optional[int] = None
) -> Tuple[float, float, float]:
) -> tuple[float, float, float]:
"""
Get the temperature from a preselector sensor.
Expand Down
Loading

0 comments on commit 5c45692

Please sign in to comment.