### Navigation

- index
- modules |
- next |
- previous |
- mwavepy v1.4 documentation »
- mwavepy API »
- mwavepy Package »

# calibration Package

## `calibration` Package

Provides high-level Calibration class as well as calibration algorithms and parametric standards

## `calibration` Module

Contains the Calibration class, and supporting functions

class `mwavepy.calibration.calibration.``Calibration`(measured, ideals, type=None, frequency=None, is_reciprocal=False, name=None, sloppy_input=False, **kwargs)

  Bases: `object`

  Represents a Calibration object, which can run a calibration algorithm, store results, and apply calibration to measurements.

  see init for more information on usage.

  `Ts`

    T-matricies used for de-embeding, a two-port calibration.

  `apply_cal`(input_ntwk)

    apply the current calibration to a measurement.

    takes:
      input_ntwk: the measurement to apply the calibration to, a
        Network type.
    returns:
      caled: the calibrated measurement, a Network type.
  `apply_cal_to_all_in_dir`(dir, contains=None, f_unit='ghz')

    convience function to apply calibration to an entire directory of measurements, and return a dictionary of the calibrated results, optionally the user can ‘grep’ the direction by using the contains switch.

    takes:

      dir: directory of measurements (string) contains: will only load measurements who’s filename contains

      > this string.

      f_unit: frequency unit, to use for all networks. see
        frequency.Frequency.unit for info.
    returns:
      ntwkDict: a dictionary of calibrated measurements, the keys
        are the filenames.
  `biased_error`(std_names=None)

    estimate of biased error for overdetermined calibration with multiple connections of each standard

    takes:
      std_names: list of strings to uniquely identify each
        standard.*
    returns:
      systematic error: mwavepy.Network type who’s .s_mag is
        proportional to the systematic error metric
    note:
      mathematically, this is
        mean_s(|mean_c(r)|)
      where:
        r: complex residual errors mean_c: complex mean taken accross connection mean_s: complex mean taken accross standard
  `coefs`

    coefs: a dictionary holding the calibration coefficients

    for one port cal’s
      ‘directivity’:e00 ‘reflection tracking’:e01e10 ‘source match’:e11
    for 7-error term two port cal’s
      TODO:
  `error_ntwk`

    a Network type which represents the error network being calibrated out.

  `frequency`

    frequency object for the calibration

  `mean_residuals`()
  `nports`

    the number of ports in the calibration

  `nstandards`

    number of ideal/measurement pairs in calibration

  `output_from_cal`

    a dictionary holding all of the output from the calibration algorithm

  `plot_coefs_db`(ax=None, show_legend=True, **kwargs)

    plot magnitude of the error coeficient dictionary

  `plot_errors`(std_names=None, *args, **kwargs)

    plot calibration error metrics for an over-determined calibration.

    see biased_error, unbiased_error, and total_error for more info

  `plot_residuals`(attribute, *args, **kwargs)

    plots a component of the residual errors on the Calibration-plane.

    takes:
      attribute: name of ploting method of Network class to call
        possible options are:
          ‘mag’, ‘db’, ‘smith’, ‘deg’, etc

      *args,**kwargs: passed to plot_s_‘atttribute’()

    note: the residuals are calculated by:

    > (self.apply_cal(self.measured[k])-self.ideals[k])

  `plot_residuals_db`(*args, **kwargs)

    see plot_residuals

  `plot_residuals_mag`(*args, **kwargs)

    see plot_residuals

  `plot_residuals_smith`(*args, **kwargs)

    see plot_residuals

  `plot_uncertainty_per_standard`(*args, **kwargs)

    see uncertainty_per_standard

  `residual_ntwks`

    returns a the residuals for each calibration standard in the form of a list of Network types.

    these residuals are calculated in the ‘calibrated domain’, meaning they are

    > r = (E.inv ** m - i)

    where,
      r: residual network, E: embedding network, m: measured network i: ideal network

    This way the units of the residual networks are meaningful

    note:
      the residuals are only calculated if they are not existent.

    so, if you want to re-calculate the residual networks then you delete the property ‘_residual_ntwks’.

  `residuals`

    if calibration is overdeteremined, this holds the residuals in the form of a vector.

    also available are the complex residuals in the form of mwavepy.Network’s, see the property ‘residual_ntwks’

    from numpy.lstsq:
      residues: the sum of the residues; squared euclidean norm for each column vector in b (given ax=b)
  `run`()

    runs the calibration algorihtm.

    this is automatically called the first time any dependent property is referenced (like error_ntwk), but only the first time. if you change something and want to re-run the calibration

    > use this.

  `total_error`(std_names=None)

    estimate of total error for overdetermined calibration with multiple connections of each standard. This is the combined effects of both biased and un-biased errors

    takes:
      std_names: list of strings to uniquely identify each
        standard.*
    returns:
      composit error: mwavepy.Network type who’s .s_mag is
        proportional to the composit error metric
    note:
      mathematically, this is
        std_cs(r)
      where:

        r: complex residual errors std_cs: standard deviation taken accross connections

        > and standards

  `type`

    string representing what type of calibration is to be performed. supported types at the moment are:

    ‘one port’: standard one-port cal. if more than
      2 measurement/ideal pairs are given it will calculate the least squares solution.

    ‘two port’: two port calibration based on the error-box model

    note: algorithms referenced by calibration_algorithm_dict, are stored in calibrationAlgorithms.py

  `unbiased_error`(std_names=None)

    estimate of unbiased error for overdetermined calibration with multiple connections of each standard

    takes:
      std_names: list of strings to uniquely identify each
        standard.*
    returns:
      stochastic error: mwavepy.Network type who’s .s_mag is
        proportional to the stochastic error metric
    see also:
      uncertainty_per_standard, for this a measure of unbiased errors for each standard
    note:
      mathematically, this is
        mean_s(std_c(r))
      where:
        r: complex residual errors std_c: standard deviation taken accross connections mean_s: complex mean taken accross standards
  `uncertainty_per_standard`(std_names=None, attribute='s')

    given that you have repeat-connections of single standard, this calculates the complex standard deviation (distance) for each standard in the calibration across connection #.

    takes:
      std_names: list of strings to uniquely identify each
        standard.*
      attribute: string passed to func_on_networks to calculate
        std deviation on a component if desired. [‘s’]
    returns:
      list of mwavepy.Networks, whose magnitude of s-parameters is proportional to the standard deviation for that standard
    *example:
      if your calibration had ideals named like:
        ‘short 1’, ‘short 2’, ‘open 1’, ‘open 2’, etc.
      you would pass this
        mycal.uncertainty_per_standard([‘short’,’open’,’match’])

`mwavepy.calibration.calibration.``error_dict_2_network`(coefs, frequency=None, is_reciprocal=False, **kwargs)

  convert a dictionary holding standard error terms to a Network object.

  takes:

  returns:

`mwavepy.calibration.calibration.``rand`()

  rand(d0, d1, ..., dn)

  Random values in a given shape.

  Create an array of the given shape and propagate it with random samples from a uniform distribution over `[0, 1)`.

  d0, d1, ..., dn : int
    Shape of the output.
  out : ndarray, shape `(d0, d1, ..., dn)`
    Random values.

  random

  This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to random.

      >>> np.random.rand(3,2)
      array([[ 0.14022471,  0.96360618],  #random
             [ 0.37601032,  0.25528411],  #random
             [ 0.49313049,  0.94909878]]) #random

`mwavepy.calibration.calibration.``two_port_error_vector_2_Ts`(error_coefficients)

## `calibrationAlgorithms` Module

Contains calibrations algorithms, used in the Calibration class,

`mwavepy.calibration.calibrationAlgorithms.``abc_2_coefs_dict`(abc)

  converts an abc ndarry to a dictionarry containing the error coefficients.

  takes:
    abc : Nx3 numpy.ndarray, which holds the complex calibration
      coefficients. the components of abc are
        a[:] = abc[:,0] b[:] = abc[:,1] c[:] = abc[:,2],
      a, b and c are related to the error network by
        a = det(e) = e01*e10 - e00*e11 b = e00 c = e11
  returns:
    coefsDict: dictionary containing the following
      ‘directivity’:e00 ‘reflection tracking’:e01e10 ‘source match’:e11
  note:
    e00 = directivity error e10e01 = reflection tracking error e11 = source match error

`mwavepy.calibration.calibrationAlgorithms.``eight_term_2_one_port_coefs`(coefs)

`mwavepy.calibration.calibrationAlgorithms.``guess_length_of_delay_short`(aNtwk, tline)

  guess length of physical length of a Delay Short given by aNtwk

  takes:
    aNtwk: a mwavepy.ntwk type . (note: if this is a measurment
      it needs to be normalized to the short plane
    tline: transmission line class of the medium. needed for the
      calculation of propagation constant

`mwavepy.calibration.calibrationAlgorithms.``one_port`(measured, ideals)

  standard algorithm for a one port calibration. If more than three standards are supplied then a least square algorithm is applied.

  takes:
    measured - list of measured reflection coefficients. can be
      lists of either a kxnxn numpy.ndarray, representing a s-matrix or list of 1-port mwavepy.ntwk types.
    ideals - list of assumed reflection coefficients. can be
      lists of either a kxnxn numpy.ndarray, representing a s-matrix or list of 1-port mwavepy.ntwk types.
  returns:
    a dictionary containing the following keys

      ‘error coeffcients’: dictionary containing standard error coefficients ‘residuals’: a matrix of residuals from the least squared

      > calculation. see numpy.linalg.lstsq() for more info

  note:

    uses numpy.linalg.lstsq() for least squares calculation

    see one_port_nls for a non-linear least square implementation

`mwavepy.calibration.calibrationAlgorithms.``one_port_nls`(measured, ideals)

  one port non-linear least squares.

  takes:
    measured - list of measured reflection coefficients. can be
      lists of either a kxnxn numpy.ndarray, representing a s-matrix or list of 1-port mwavepy.ntwk types.
    ideals - list of assumed reflection coefficients. can be
      lists of either a kxnxn numpy.ndarray, representing a s-matrix or list of 1-port mwavepy.ntwk types.
  returns:
    a dictionary containing the following keys:

      ‘error coeffcients’: dictionary containing standard error coefficients ‘residuals’: a matrix of residuals from the least squared

      > calculation. see numpy.linalg.lstsq() for more info

      ‘cov_x’: covariance matrix

  note:
    uses scipy.optmize.leastsq for non-linear least squares calculation

`mwavepy.calibration.calibrationAlgorithms.``parameterized_self_calibration`(measured, ideals, showProgress=True, **kwargs)

  An iterative, general self-calibration routine which can take any mixture of parameterized standards. The correct parameter values are defined as the ones which minimize the mean residual error.

  takes:
    measured: list of Network types holding actual measurements ideals: list of ParametricStandard types showProgress: turn printing progress on/off [boolean] **kwargs: passed to minimization algorithm (scipy.optimize.fmin)
  returns:

    a dictionary holding: ‘error_coefficients’: dictionary of error coefficients ‘residuals’: residual matrix (shape depends on #stds) ‘parameter_vector_final’: final results for parameter vector ‘mean_residual_list’: the mean, magnitude of the residuals at each

    > iteration of calibration. this is the variable being minimized.

  see parametricStandard sub-module for more info on them

`mwavepy.calibration.calibrationAlgorithms.``parameterized_self_calibration_bounded`(measured, ideals_ps, showProgress=True, **kwargs)

  An iterative, general self-calibration routine which can take any mixture of parameterized standards. The correct parameter values are defined as the ones which minimize the mean residual error.

  takes:
    measured: list of Network types holding actual measurements ideals_ps: list of ParameterizedStandard types showProgress: turn printing progress on/off [boolean] **kwargs: passed to minimization algorithm (scipy.optimize.fmin)
  returns:

    a dictionary holding: ‘error_coefficients’: dictionary of error coefficients ‘residuals’: residual matrix (shape depends on #stds) ‘parameter_vector_final’: final results for parameter vector ‘mean_residual_list’: the mean, magnitude of the residuals at each

    > iteration of calibration. this is the variable being minimized.

  see ParameterizedStandard for more info on them

`mwavepy.calibration.calibrationAlgorithms.``parameterized_self_calibration_nls`(measured, ideals_ps, showProgress=True, **kwargs)

  An iterative, general self-calibration routine which can take any mixture of parametric standards. The correct parameter values are defined as the ones which minimize the mean residual error.

  takes:
    measured: list of Network types holding actual measurements ideals_ps: list of ParametricStandard types showProgress: turn printing progress on/off [boolean] **kwargs: passed to minimization algorithm (scipy.optimize.fmin)
  returns:

    a dictionary holding: ‘error_coefficients’: dictionary of error coefficients ‘residuals’: residual matrix (shape depends on #stds) ‘parameter_vector_final’: final results for parameter vector ‘mean_residual_list’: the mean, magnitude of the residuals at each

    > iteration of calibration. this is the variable being minimized.

  see ParametricStandard for more info on them

`mwavepy.calibration.calibrationAlgorithms.``rand`()

  rand(d0, d1, ..., dn)

  Random values in a given shape.

  Create an array of the given shape and propagate it with random samples from a uniform distribution over `[0, 1)`.

  d0, d1, ..., dn : int
    Shape of the output.
  out : ndarray, shape `(d0, d1, ..., dn)`
    Random values.

  random

  This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to random.

      >>> np.random.rand(3,2)
      array([[ 0.14022471,  0.96360618],  #random
             [ 0.37601032,  0.25528411],  #random
             [ 0.49313049,  0.94909878]]) #random

`mwavepy.calibration.calibrationAlgorithms.``two_port`(measured, ideals, switch_terms=None)

  two port calibration based on the 8-term error model. takes two ordered lists of measured and ideal responses. optionally, switch terms can be taken into account by passing a tuple containing the forward and reverse switch terms as 1-port Networks

  takes:
    measured: ordered list of measured networks. list elements
      should be 2-port Network types. list order must correspond with ideals.
    ideals: ordered list of ideal networks. list elements should be
      2-port Network types.
    switch_terms: tuple of 1-port Network types holding switch terms
      in this order (forward, reverse).
  returns:
    output: a dictionary containing the follwoing keys:
      ‘error coefficients’: ‘error vector’: ‘residuals’:
  note:
    support for gathering switch terms on HP8510C is in mwavepy.virtualInstruments.vna.py

  references

  Doug Rytting ” Network Analyzer Error Models and Calibration Methods” RF 8 Microwave. Measurements for Wireless Applications (ARFTG/NIST)

  > Short Course ...

  Speciale, R.A.; , “A Generalization of the TSD Network-Analyzer Calibration Procedure, Covering n-Port Scattering-Parameter Measurements, Affected by Leakage Errors,” Microwave Theory and Techniques, IEEE Transactions on , vol.25, no.12, pp. 1100- 1115, Dec 1977

`mwavepy.calibration.calibrationAlgorithms.``unterminate_switch_terms`(two_port, gamma_f, gamma_r)

  unterminates switch terms from raw measurements.

  takes:
    two_port: the raw measurement, a 2-port Network type. gamma_f: the measured forward switch term, a 1-port Network type gamma_r: the measured reverse switch term, a 1-port Network type
  returns:
    un-terminated measurement, a 2-port Network type
  see:
    ‘Formulations of the Basic Vector Network Analyzer Error Model including Switch Terms’ by Roger B. Marks

## Subpackages

- parametricStandard Package
  - `parametricStandard` Package
  - `generic` Module
  - `parametricStandard` Module
  - `rectangularWaveguide` Module

### Navigation

- index
- modules |
- next |
- previous |
- mwavepy v1.4 documentation »
- mwavepy API »
- mwavepy Package »