API

Global variables

Named tuples

Functions

Waveform pseudo-type

Class

Functions

Contracts pseudo-types

Introduction

The pseudo-types defined below can be used in contracts of the PyContracts or Pexdoc libraries. As an example, with the latter:

>>> from __future__ import print_function
>>> import pexdoc
>>> from peng.ptypes import engineering_notation_suffix
>>> @pexdoc.pcontracts.contract(suffix='engineering_notation_suffix')
... def myfunc(suffix):
...     print('Suffix received: '+str(suffix))
...
>>> myfunc('m')
Suffix received: m
>>> myfunc(35)
Traceback (most recent call last):
    ...
RuntimeError: Argument `suffix` is not valid

Alternatively each pseudo-type has a checker function associated with it that can be used to verify membership. For example:

>>> import peng.ptypes
>>> # None is returned if object belongs to pseudo-type
>>> peng.ptypes.engineering_notation_suffix('m')
>>> # ValueError is raised if object does not belong to pseudo-type
>>> peng.ptypes.engineering_notation_suffix(3.5) 
Traceback (most recent call last):
    ...
ValueError: [START CONTRACT MSG: engineering_notation_suffix]...

Description

EngineeringNotationNumber

Import as engineering_notation_number. String with a number represented in engineering notation. Optional leading whitespace can precede the mantissa; optional whitespace can also follow the engineering suffix. An optional sign (+ or -) can precede the mantissa after the leading whitespace. The suffix must be one of 'y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', ' ' (space), 'k', 'M', 'G', 'T', 'P', 'E', 'Z' or 'Y'. The correspondence between suffix and floating point exponent is:

Exponent Name Suffix
1E-24 yocto y
1E-21 zepto z
1E-18 atto a
1E-15 femto f
1E-12 pico p
1E-9 nano n
1E-6 micro u
1E-3 milli m
1E+0    
1E+3 kilo k
1E+6 mega M
1E+9 giga G
1E+12 tera T
1E+15 peta P
1E+18 exa E
1E+21 zetta Z
1E+24 yotta Y

EngineeringNotationSuffix

Import as engineering_notation_suffix. A single character string, one of 'y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', ' ' (space), 'k', 'M', 'G', 'T', 'P', 'E', 'Z' or 'Y'. EngineeringNotationNumber lists the correspondence between suffix and floating point exponent

IncreasingRealNumpyVector

Import as increasing_real_numpy_vector. Numpy vector in which all elements are real (integers and/or floats) and monotonically increasing (each element is strictly greater than the preceding one)

NumberNumpyVector

Import as number_numpy_vector. Numpy vector in which all elements are integers and/or floats and/or complex

RealNumpyVector

Import as real_numpy_vector. Numpy vector in which all elements are real (integers and/or floats)

TouchstoneData

Import as touchstone_data. A dictionary with the following structure:

  • points (integer) – Number of data points
  • freq (IncreasingRealNumpyVector) – Frequency vector
  • pars (NumberNumpyVector) – Parameter data, its size is equal to nports x nports x points where nports represents the number of ports in the file

The dictionary keys are case sensitive

TouchstoneNoiseData

Import as touchstone_noise_data. A dictionary with the following structure:

The dictionary keys are case sensitive

TouchstoneOptions

Import as touchstone_options. A dictionary with the following structure:

  • units (string) – Frequency units, one of 'GHz', 'MHz', 'KHz' or 'Hz' (case insensitive, default 'GHz')
  • ptype (string) – Parameter type, one of 'S', 'Y', 'Z', 'H' or 'G' (case insensitive, default 'S')
  • pformat (string) – Data point format type, one of 'DB' (decibels), 'MA' (magnitude and angle), or 'RI' (real and imaginary) (case insensitive, default 'MA')
  • z0 (float) – Reference resistance in Ohms, default 50 Ohms

The dictionary keys are case sensitive

WaveInterpOption

Import as wave_interp_option. String representing a waveform interpolation type, one of 'CONTINUOUS' or 'STAIRCASE' (case insensitive)

WaveScaleOption

Import as wave_scale_option. String representing a waveform scale type, one of 'LINEAR' or 'LOG' (case insensitive)

WaveVectors

Import as wave_vectors. Non-empty list of tuples in which each tuple is a waveform point. The first item of a point tuple is its independent variable and the second item of a point tuple is its dependent variable. The vector formed by the first item of the point tuples is of IncreasingRealNumpyVector pseudo-type; the vector formed by the second item of the point tuples is of RealNumpyVector pseudo-type

Checker functions