| 1 |
""" |
| 2 |
.. module:: skrf.vi.vna.keysight.fieldfox |
| 3 |
================================================= |
| 4 |
Keysight FieldFox (:mod:`skrf.vi.vna.keysight.fieldfox`) |
| 5 |
================================================= |
| 6 |
|
| 7 |
Provides a class to interact with Keysight's FieldFox handheld analyzer. |
| 8 |
|
| 9 |
This module additionally provides some enumerations to make certain commands |
| 10 |
more clear. |
| 11 |
|
| 12 |
Enums |
| 13 |
============ |
| 14 |
|
| 15 |
.. autosummary:: |
| 16 |
:nosignatures: |
| 17 |
:toctree: generated/ |
| 18 |
|
| 19 |
WindowFormat |
| 20 |
|
| 21 |
FieldFox Class |
| 22 |
============== |
| 23 |
|
| 24 |
.. autosummary:: |
| 25 |
:nosignatures: |
| 26 |
:toctree: generated/ |
| 27 |
|
| 28 |
FieldFox |
| 29 |
|
| 30 |
""" |
| 31 |
import itertools |
| 32 |
from enum import Enum |
| 33 |
|
| 34 |
import numpy as np |
| 35 |
|
| 36 |
import skrf |
| 37 |
from skrf.vi import vna |
| 38 |
from skrf.vi.validators import ( |
| 39 |
BooleanValidator, |
| 40 |
EnumValidator, |
| 41 |
FloatValidator, |
| 42 |
FreqValidator, |
| 43 |
IntValidator, |
| 44 |
SetValidator, |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
class WindowFormat(Enum): |
| 49 |
"""How windows are arranged on the display.""" |
| 50 |
|
| 51 |
|
| 52 |
ONE_TRACE = "D1" |
| 53 |
|
| 54 |
TWO_TRACES = "D2" |
| 55 |
|
| 56 |
THREE_TRACES = "D3" |
| 57 |
|
| 58 |
TWO_VERTICAL = "D12H" |
| 59 |
|
| 60 |
|
| 61 |
ONE_FIRST_ROW_TWO_SECOND_ROW = "D11_23" |
| 62 |
|
| 63 |
TWO_BY_TWO = "D12_34" |
| 64 |
|
| 65 |
|
| 66 |
class FieldFox(vna.VNA): |
| 67 |
''' |
| 68 |
Keysight FieldFox. |
| 69 |
|
| 70 |
The FieldFox is a class of handheld analyzers with numerous modes with |
| 71 |
different capabilities. This class only provides methods related to the |
| 72 |
network analyzer mode. |
| 73 |
''' |
| 74 |
|
| 75 |
freq_start = vna.VNA.command( |
| 76 |
get_cmd="SENS:FREQ:STAR?", |
| 77 |
set_cmd="SENS:FREQ:STAR <arg>", |
| 78 |
doc="""The start frequency [Hz]""", |
| 79 |
validator=FreqValidator(), |
| 80 |
) |
| 81 |
|
| 82 |
freq_stop = vna.VNA.command( |
| 83 |
get_cmd="SENS:FREQ:STOP?", |
| 84 |
set_cmd="SENS:FREQ:STOP <arg>", |
| 85 |
doc="""The start frequency [Hz]""", |
| 86 |
validator=FreqValidator(), |
| 87 |
) |
| 88 |
|
| 89 |
freq_center = vna.VNA.command( |
| 90 |
get_cmd="SENS:FREQ:CENT?", |
| 91 |
set_cmd="SENS:FREQ:CENT <arg>", |
| 92 |
doc="""The center frequency [Hz]""", |
| 93 |
validator=FreqValidator(), |
| 94 |
) |
| 95 |
|
| 96 |
freq_span = vna.VNA.command( |
| 97 |
get_cmd="SENS:FREQ:SPAN?", |
| 98 |
set_cmd="SENS:FREQ:SPAN <arg>", |
| 99 |
doc="""The frequency span [Hz]""", |
| 100 |
validator=FreqValidator(), |
| 101 |
) |
| 102 |
|
| 103 |
npoints = vna.VNA.command( |
| 104 |
get_cmd="SENS:SWE:POIN?", |
| 105 |
set_cmd="SENS:SWE:POIN <arg>", |
| 106 |
doc="""The number of frequency points""", |
| 107 |
validator=IntValidator(), |
| 108 |
) |
| 109 |
|
| 110 |
sweep_time = vna.VNA.command( |
| 111 |
get_cmd="SENS:SWE:TIME?", |
| 112 |
set_cmd="SENS:SWE:TIME <arg>", |
| 113 |
doc="""The sweep time [s]""", |
| 114 |
validator=FloatValidator(), |
| 115 |
) |
| 116 |
|
| 117 |
if_bandwidth = vna.VNA.command( |
| 118 |
get_cmd="SENS:BWID?", |
| 119 |
set_cmd="SENS:BWID <arg>", |
| 120 |
doc="""The center frequency [Hz]""", |
| 121 |
validator=SetValidator([10, 30, 100, 300, 1000, 10_000, 30_000, 100_000]), |
| 122 |
) |
| 123 |
|
| 124 |
window_configuration = vna.VNA.command( |
| 125 |
get_cmd="DISP:WIND:SPL?", |
| 126 |
set_cmd="DISP:WIND:SPL <arg>", |
| 127 |
doc="""How multiple trace windows appear on screen""", |
| 128 |
validator=EnumValidator(WindowFormat), |
| 129 |
) |
| 130 |
|
| 131 |
ntraces = vna.VNA.command( |
| 132 |
get_cmd="CALC:PAR:COUN?", |
| 133 |
set_cmd="CALC:PAR:COUN <arg>", |
| 134 |
doc="""The number of active traces.""", |
| 135 |
validator=IntValidator(min=1, max=4), |
| 136 |
) |
| 137 |
|
| 138 |
active_trace = vna.VNA.command( |
| 139 |
set_cmd="CALC:PAR<arg>:SEL", |
| 140 |
doc="""Set the active trace. There is no command to read the active |
| 141 |
trace.""", |
| 142 |
validator=IntValidator(min=1, max=4), |
| 143 |
) |
| 144 |
|
| 145 |
active_trace_sdata = vna.VNA.command( |
| 146 |
get_cmd="CALC:DATA:SDATA?", |
| 147 |
doc="""Get the current trace data as a network""", |
| 148 |
values=True, |
| 149 |
complex_values=True |
| 150 |
) |
| 151 |
|
| 152 |
is_continuous = vna.VNA.command( |
| 153 |
get_cmd="INIT:CONT?", |
| 154 |
set_cmd="INIT:CONT <arg>", |
| 155 |
doc="""Get the current trace data as a network""", |
| 156 |
validator=BooleanValidator() |
| 157 |
) |
| 158 |
|
| 159 |
_cal_term_map = { |
| 160 |
"forward directivity": "ed,1,1", |
| 161 |
"reverse directivity": "ed,2,2", |
| 162 |
"forward source match": "es,1,1", |
| 163 |
"reverse source match": "es,2,2", |
| 164 |
"forward reflection tracking": "er,1,1", |
| 165 |
"reverse reflection tracking": "er,2,2", |
| 166 |
"forward transmission tracking": "et,2,1", |
| 167 |
"reverse transmission tracking": "et,1,2", |
| 168 |
"forward load match": "el,2,1", |
| 169 |
"reverse load match": "el,1,2", |
| 170 |
"forward isolation": "ex,2,1", |
| 171 |
"reverse isolation": "ex,1,2" |
| 172 |
} |
| 173 |
|
| 174 |
def __init__(self, address: str, backend: str = "@py") -> None: |
| 175 |
super().__init__(address, backend) |
| 176 |
|
| 177 |
self._resource.read_termination = "\n" |
| 178 |
self._resource.write_termination = "\n" |
| 179 |
|
| 180 |
_ = self.query_format |
| 181 |
|
| 182 |
@property |
| 183 |
def nports(self) -> int: |
| 184 |
return 2 |
| 185 |
|
| 186 |
@property |
| 187 |
def freq_step(self) -> int: |
| 188 |
"""The frequency step [Hz]""" |
| 189 |
f = self.frequency |
| 190 |
return int(f.step) |
| 191 |
|
| 192 |
@freq_step.setter |
| 193 |
def freq_step(self, f: int) -> None: |
| 194 |
freq = self.frequency |
| 195 |
self.npoints = len(range(int(freq.start), int(freq.stop) + f, f)) |
| 196 |
|
| 197 |
|
| 198 |
@property |
| 199 |
def frequency(self) -> skrf.Frequency: |
| 200 |
"""The frequency bounds as a :class:`skrf.Frequency`""" |
| 201 |
return skrf.Frequency( |
| 202 |
start=self.freq_start, stop=self.freq_stop, npoints=self.npoints, unit='Hz' |
| 203 |
) |
| 204 |
|
| 205 |
@frequency.setter |
| 206 |
def frequency(self, f: skrf.Frequency): |
| 207 |
self.freq_start = f.start |
| 208 |
self.freq_stop = f.stop |
| 209 |
self.npoints = f.npoints |
| 210 |
|
| 211 |
@property |
| 212 |
def calibration(self) -> skrf.Calibration: |
| 213 |
"""The currently defined calibration as a :class:`skrf.calibration.calibration.Calibration`""" |
| 214 |
cal_dict = {} |
| 215 |
for cal_key, term in self._cal_term_map.items(): |
| 216 |
vals = self.query_values(f"SENS:CORR:COEF? {term}", container=np.array, complex_values=True) |
| 217 |
cal_dict[cal_key] = vals |
| 218 |
|
| 219 |
return skrf.Calibration.from_coefs(self.frequency, cal_dict) |
| 220 |
|
| 221 |
@calibration.setter |
| 222 |
def calibration(self, cal: skrf.Calibration) -> None: |
| 223 |
cal_dict = cal.coefs_12term |
| 224 |
for cal_key, term in self._cal_term_map.items(): |
| 225 |
self.write_values(f"SENS:CORR:COEF {term},", cal_dict[cal_key], complex_values=True) |
| 226 |
|
| 227 |
@property |
| 228 |
def query_format(self) -> vna.ValuesFormat: |
| 229 |
""" |
| 230 |
How values are written to / queried from the instrument (ascii or |
| 231 |
binary) |
| 232 |
|
| 233 |
When transferring a large number of values from the instrument (like |
| 234 |
trace data), it can be done either as ascii characters or as binary. |
| 235 |
|
| 236 |
Transferring in binary is much faster, as large numbers can be |
| 237 |
represented much more succinctly. |
| 238 |
""" |
| 239 |
fmt = self.query("FORM?") |
| 240 |
if fmt == "ASC,0": |
| 241 |
self._values_fmt = vna.ValuesFormat.ASCII |
| 242 |
elif fmt == "REAL,32": |
| 243 |
self._values_fmt = vna.ValuesFormat.BINARY_32 |
| 244 |
elif fmt == "REAL,64": |
| 245 |
self._values_fmt = vna.ValuesFormat.BINARY_64 |
| 246 |
return self._values_fmt |
| 247 |
|
| 248 |
@query_format.setter |
| 249 |
def query_format(self, fmt: vna.ValuesFormat) -> None: |
| 250 |
if fmt == vna.ValuesFormat.ASCII: |
| 251 |
self._values_fmt = vna.ValuesFormat.ASCII |
| 252 |
self.write("FORM ASC,0") |
| 253 |
elif fmt == vna.ValuesFormat.BINARY_32: |
| 254 |
self._values_fmt = vna.ValuesFormat.BINARY_32 |
| 255 |
self.write("FORM REAL,32") |
| 256 |
elif fmt == vna.ValuesFormat.BINARY_64: |
| 257 |
self._values_fmt = vna.ValuesFormat.BINARY_64 |
| 258 |
self.write("FORM REAL,64") |
| 259 |
|
| 260 |
def get_measurement_parameter(self, trace: int) -> str: |
| 261 |
"""Get the defined measurement parameter for the specified trace |
| 262 |
|
| 263 |
Parameters |
| 264 |
---------- |
| 265 |
trace: int |
| 266 |
The trace number |
| 267 |
|
| 268 |
Returns |
| 269 |
------- |
| 270 |
str |
| 271 |
Measurement parameter (like 'S11', 'S21', 'A', 'B', 'R1', etc) |
| 272 |
""" |
| 273 |
if trace not in range(1, 5): |
| 274 |
raise ValueError("Trace must be between 1 and 4") |
| 275 |
|
| 276 |
return self.query(f"CALC:PAR{trace}:DEF?") |
| 277 |
|
| 278 |
def define_measurement(self, trace: int, parameter: str) -> None: |
| 279 |
""" |
| 280 |
Define what parameter the specified trace is measuring |
| 281 |
|
| 282 |
Parameters |
| 283 |
---------- |
| 284 |
trace: int |
| 285 |
What trace to set the measurement for |
| 286 |
parameter: str |
| 287 |
What parameter to measure (e.g. 'S11', 'R1', 'A', etc) |
| 288 |
""" |
| 289 |
if trace not in range(1, self.ntraces + 1): |
| 290 |
self.ntraces = trace |
| 291 |
|
| 292 |
self.write(f"CALC:PAR{trace}:DEF {parameter}") |
| 293 |
|
| 294 |
def sweep(self) -> None: |
| 295 |
"""Trigger a fresh sweep.""" |
| 296 |
self._resource.clear() |
| 297 |
was_continuous = self.is_continuous |
| 298 |
self.is_continuous = False |
| 299 |
self.write("INIT") |
| 300 |
self.is_continuous = was_continuous |
| 301 |
|
| 302 |
def get_snp_network(self, ports=None, restore_settings: bool = True) -> skrf.Network: |
| 303 |
""" |
| 304 |
Get trace data as an :class:`skrf.Network` |
| 305 |
|
| 306 |
Parameters |
| 307 |
---------- |
| 308 |
ports: Sequence |
| 309 |
Which ports to get s parameters for. Can only be 1, 2, or (1, 2) |
| 310 |
restore_settings: bool |
| 311 |
Whether the original settings should be saved and restored, like the |
| 312 |
number of traces, the trace parameters, etc. Doing this takes a bit |
| 313 |
more time, so if running multiple repeated measurements, pass False |
| 314 |
(Default True) |
| 315 |
|
| 316 |
Returns |
| 317 |
------- |
| 318 |
:class:`skrf.Network` |
| 319 |
The measured data |
| 320 |
""" |
| 321 |
if ports is None: |
| 322 |
ports = {1, 2} |
| 323 |
msmnts = list(itertools.product(ports, repeat=2)) |
| 324 |
msmnt_params = [f"S{a}{b}" for a, b in msmnts] |
| 325 |
|
| 326 |
if restore_settings: |
| 327 |
original_config = { |
| 328 |
"ntraces": self.ntraces, |
| 329 |
"window_configuration": self.window_configuration, |
| 330 |
"trace_params": [self.get_measurement_parameter(i+1) for i in range(self.ntraces)] |
| 331 |
} |
| 332 |
|
| 333 |
self.ntraces = len(msmnts) |
| 334 |
for i, param in enumerate(msmnt_params): |
| 335 |
self.define_measurement(i+1, param) |
| 336 |
|
| 337 |
ntwk = skrf.Network() |
| 338 |
ntwk.frequency = self.frequency |
| 339 |
ntwk.s = np.empty( |
| 340 |
shape=(ntwk.frequency.npoints, len(ports), len(ports)), dtype=complex |
| 341 |
) |
| 342 |
|
| 343 |
self.sweep() |
| 344 |
for tr, (i, j) in enumerate(msmnts): |
| 345 |
self.active_trace = tr + 1 |
| 346 |
|
| 347 |
sdata = self.active_trace_sdata |
| 348 |
if len(msmnts) == 1: |
| 349 |
ntwk.s[:, 0, 0] = sdata |
| 350 |
else: |
| 351 |
ntwk.s[:, i - 1, j - 1] = sdata |
| 352 |
|
| 353 |
if restore_settings: |
| 354 |
for i, param in enumerate(original_config.pop('trace_params')): |
| 355 |
self.define_measurement(i+1, param) |
| 356 |
for key, val in original_config.items(): |
| 357 |
setattr(self, key, val) |
| 358 |
|
| 359 |
return ntwk |