Frequency

class Frequency(value=0.0, units=None)[source]

Bases: object

The Frequency class implements a concept of a frequency in hertz.

This version adapted from the c++ and java implementations, originall authored by Allen Farris.

Attributes Summary

AllowedUnits

GIGAHERTZ

HERTZ

KILOHERTZ

MEGAHERTZ

Methods Summary

almostEquals(otherFrequency, toleranceFrequency)

Return True if and only if otherFrequency and toleranceFrequency are both Frequency instances are if the absolute value of the difference between this and otherFrequency is less than the absolute value of toleranceFrequency.

compareTo(otherFrequency)

Compare this Frequency to the specified otherFrequencyt, which must be a Frequency, returning -1, 0, or +1 if this frequency is less than, equal to, or greater than the specified other Frequency.

divide(f, factor)

Return a new Frequency that is a specified frequency divided by a specified factor, f / factor.

equals(otherFrequency)

Return True if and only if the specified other frequency is a Frequency and its value is equal to this frequency.

from1DBin(eis)

Read a list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

from2DBin(eis)

Read a 2D list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

from3DBin(eis)

Read a 3D list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

fromBin(eis)

Read the binary representation of an Frequency, in Hertz, from an EndianInput instance and use the read value to set a Frequency.

get([units])

Return the value of this frequency as a double in the specified units.

getInstance(stringList)

Retrieve a value from a list of strings and convert that to a Frequency

isZero()

Return True if and only if this frequency is zero (0.0).

listTo1DBin(frequencyList, eos)

Write a 1D list of Frequency to the EndianOutput

listTo2DBin(frequencyList, eos)

Write a 2D list of Frequency to the EndianOutput

listTo3DBin(frequencyList, eos)

Write a 3D list of Frequency to the EndianOutput

listToBin(frequencyList, eos)

Write a list of Frequency to the EndianOutput.

multiply(f, factor)

Return a new Frequency that is the product of a specified frequency and some specified factor, f * factor.

set(value[, units])

Set the value of this frequency to the given value in the specified units.

subtract(f1, f2)

Return a new Frequency that is the difference of the specified frequencies, f1 - f2.

sum(f1, f2)

Return a new Frequency that is the sum of the specified Frequencies, f1 + f2.

toBin(eos)

Write this Frequency out, in Hertz, to a EndianOutput.

unit()

Return the canonical unit associated with this Frequency, hertz.

values(items)

return a list of floats containing the value of the list of Frequency objects passed in the items argument.

Attributes Documentation

AllowedUnits = ['Hz', 'kHz', 'MHz', 'GHz']
GIGAHERTZ = 'GHz'
HERTZ = 'Hz'
KILOHERTZ = 'kHz'
MEGAHERTZ = 'MHz'

Methods Documentation

almostEquals(otherFrequency, toleranceFrequency)[source]

Return True if and only if otherFrequency and toleranceFrequency are both Frequency instances are if the absolute value of the difference between this and otherFrequency is less than the absolute value of toleranceFrequency.

compareTo(otherFrequency)[source]

Compare this Frequency to the specified otherFrequencyt, which must be a Frequency, returning -1, 0, or +1 if this frequency is less than, equal to, or greater than the specified other Frequency.

static divide(f, factor)[source]

Return a new Frequency that is a specified frequency divided by a specified factor, f / factor. param f The base frequency param factor The factor that is used to divide the value. return A new Frequency that is the product of a specified frequency and some specified factor, f / factor.

equals(otherFrequency)[source]

Return True if and only if the specified other frequency is a Frequency and its value is equal to this frequency. param otherFrequency The other frequency to which this frequency is being compared. return True if and only if the specified other frequency is an Frequency and its value is equal to this frequency.

static from1DBin(eis)[source]

Read a list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

static from2DBin(eis)[source]

Read a 2D list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

static from3DBin(eis)[source]

Read a 3D list of binary Frequency values, in Hertz, from an EndianInput instance and return the resulting list.

static fromBin(eis)[source]

Read the binary representation of an Frequency, in Hertz, from an EndianInput instance and use the read value to set a Frequency.

return a Frequency

get(units=None)[source]

Return the value of this frequency as a double in the specified units. When units is None (the default) the returned units are HERTZ. param units The units in which the value of this frequency is to be returned. return The value of this frequency as a double in the specified units. Recognized units are None (HERTZ), KILOHERTZ, MEGAHERTZ, and MILIMETERS

static getInstance(stringList)[source]

Retrieve a value from a list of strings and convert that to a Frequency

This is used when parsing Frequency lists from an XML representation to eventually construct a list of Frequency instances. The string values are float representation of a frequency in Hertz.

Returns a tuple of (Frequency, stringList) where Frequency is the new Frequency created by this call and stringList is the remaining, unused, part of stringList after removing the first element.

isZero()[source]

Return True if and only if this frequency is zero (0.0).

static listTo1DBin(frequencyList, eos)[source]

Write a 1D list of Frequency to the EndianOutput

static listTo2DBin(frequencyList, eos)[source]

Write a 2D list of Frequency to the EndianOutput

static listTo3DBin(frequencyList, eos)[source]

Write a 3D list of Frequency to the EndianOutput

static listToBin(frequencyList, eos)[source]

Write a list of Frequency to the EndianOutput. The list may have 1, 2 or 3 dimensions.

static multiply(f, factor)[source]

Return a new Frequency that is the product of a specified frequency and some specified factor, f * factor. param f The base frequency param factor The factor that is used to multiply the value. return A new Frequency that is the product of a specified frequency and some specified factor, f * factor.

set(value, units=None)[source]

Set the value of this frequency to the given value in the specified units. Any value is valid so long as it can be converted into a float using float(value) (including a parseable string). The units is a string arguments that defaults to HERTZ as definied here. Recognized units are HERTZ, KILOHERTZ, MEGAHERTS, and GIGAHERTS (also definied here).

static subtract(f1, f2)[source]

Return a new Frequency that is the difference of the specified frequencies, f1 - f2. param f1 The first Frequency of the pair. param f2 The second Frequency of the pair. return A new Frequency that is the difference of the specified frequencies, f1 - f2.

static sum(f1, f2)[source]

Return a new Frequency that is the sum of the specified Frequencies, f1 + f2. param f1 The first Frequency of the pair. param f2 The second Frequency of the pair. return A new Frequency that is the sum of the specified Frequencies, f1 + f2.

toBin(eos)[source]

Write this Frequency out, in Hertz, to a EndianOutput.

static unit()[source]

Return the canonical unit associated with this Frequency, hertz. return The unit associated with this Frequency.

static values(items)[source]

return a list of floats containing the value of the list of Frequency objects passed in the items argument. items may also be a list of lists(2D array) of Frequency objects. If the first item is a list then this method assumes that items is a list of lists and the return value is a list of lists of floats. The list of lists case is done by calling this method recursively and so it should work for higher orders of lists of lists. That use case is not tested.