Source code for edges.cal.sparams.devices.input_sources
"""Functions for calibrating input source reflection coefficients."""
from collections.abc import Sequence
from edges.io import CalObsDefEDGES2, CalObsDefEDGES3, LoadS11
from edges.modeling import ComplexRealImagModel, Fourier, ZerotooneTransform
from .. import (
Calkit,
CalkitReadings,
ReflectionCoefficient,
S11ModelParams,
SParams,
average_reflection_coefficients,
)
[docs]
def calibrate_gamma_src(
gamma_src: ReflectionCoefficient,
internal_osl: CalkitReadings,
internal_switch: SParams | None = None,
internal_calkit: Calkit | None = None,
) -> ReflectionCoefficient:
"""Calibrate the reflection coefficient of a calibration source input.
This moves the reference plane of the reflection coefficient measurement from
the VNA to the input of the calibration source, de-embedding any internal switches
and cables.
Parameters
----------
gamma_src
The reflection coefficient measured at the VNA reference plane.
internal_osl
The internal OSL measurements of the calibration source.
internal_switch
The S-parameters of any internal switch to de-embed. If None, no switch is
de-embedded.
internal_calkit
The calkit model for the internal OSL measurements. If None, ideal standards are
assumed.
Returns
-------
gamma_calibrated
The calibrated reflection coefficient at the input of the calibration source.
"""
smatrix = SParams.from_calkit_measurements(
model=internal_calkit, measurements=internal_osl
)
# This de-embeds the internal SP4T subsystem
gamma_src = gamma_src.de_embed(smatrix)
if internal_switch is not None:
gamma_src = gamma_src.de_embed(internal_switch)
return gamma_src
[docs]
def get_gamma_src_from_filespec(
caldef: CalObsDefEDGES2 | CalObsDefEDGES3 | LoadS11 | Sequence[LoadS11],
source: str | None = None,
**kwargs,
) -> ReflectionCoefficient:
"""Get the calibrated receiver reflection coeff from a calibration definition."""
if isinstance(caldef, CalObsDefEDGES2 | CalObsDefEDGES3):
srcdef = getattr(caldef, source)
else:
srcdef = caldef
if not hasattr(srcdef, "__len__"):
srcdef = [srcdef]
gamma_src = []
for src in srcdef:
gsrc = ReflectionCoefficient.from_s1p(src.external)
calkit = CalkitReadings.from_filespec(src.calkit)
gamma_src.append(
calibrate_gamma_src(
gamma_src=gsrc,
internal_osl=calkit,
**kwargs,
)
)
return average_reflection_coefficients(gamma_src)