Microwave filters GUI  2.0.3
Classes | Functions | Variables
libcommonfunc Namespace Reference

Library of common functions for microwave filters synthesis. More...

Classes

class  parseError
 Parse error catch. More...
class  synthError
 Synthesis error catch. More...
class  licenseError
 License error catch. More...
class  Parameters
 Filter, synthesis and sweep parameters. More...
class  Sparameters
 [S] parameters class. More...
class  MatrixQ
 Class that contains a coupling matrix, its name, the number of non-resonant nodes, the Q of resonators and some operations. More...
class  CouplingMatrices
 Coupling matrices class. More...
class  FrequencyTransformBP
 Frequency transformation fro band pass to low pass prototype. More...

Functions

def setGlobalVariablesLibCommonFunc
 Function to allow the GUI set values to the global variables of libcomonfunc module.
def readVerbose
 Returns the value of the global verbose variable.
def pkgNameVersion
 Retrieves software package name and version from string.
def myPrint
 Prints on standard output if console application.
def printHeader
 Prints application header info.
def readParamFile
 Read parameters file and return a Parameter class instance.
def criticalErrorMsg
 Show critical error message.
def warningMsg
 Show warning message.
def informationMsg
 Show information message.
def askQuestion
 Show dialog to ask question.
def listStr
 Nicely convert list of floats to string, rounding to 'prec' significant digits.
def complexStr
 Nicely convert complex number to string, rounding real and imaginary parts to 'prec' significant digits.
def validate
 

List of Chebash parameters to ignore

chebashIgnoreList = ['n_ceros', 'n_frecpropias_eq', 'real', 'imag', 'tipo_transformacion', 'graf[1]', 'graf[2]', 'graf[3]', 'graf[5]', 'graf[6]', 'graf[7]', 'graf[8]', 'graf[9]', 'graf[10]', 'graf[11]', 'graf[12]', 'graf[13]', 'graf[14]', 'graf[15]', 'graf[16]', 'graf[17]', 'graf[18]']
def copy
 Function to copy instances of the Parameters class (copies the self instance).
def __str__
 Special method to print parameter class (prints the self instance).

Variables

dictionary parameterDict
 Dictionary of parameter keywords and variable names.
int saveSignificantDigits = 14
 Number of significant digits to save in files.
int saveSignificantDigitsEnergy = 4
 Number of significant digits to save in energy and power results.
 mainWindow = None
 Module global variable equal either to None or to the GUI QMainWindow class instance, containing the application main window.
 verbose = False
 Module global variable equal to True if the GUI has been called with the -v flag command line option.
 nogui = False
 Module global variable equal to True if the GUI has been called with the –nogui flag command line option.
string preGuiOutput = ''
 String containing console output generated before the GUI main window exists.
 CP = CMSPNone
list nonSymmZeros = [ ]
 def normRealFreq(f): """ Auxiliary function """ return (f/self.f0 - self.f0/f)*self.f0/self.BW

Detailed Description

Library of common functions for microwave filters synthesis.

Author
J.M. Rius, J. Mateu, J.M. Tamayo, C. Collado, A. Padilla and J. O'Callaghan

Dpt. Signal Tehory and Communications, Universitat Politècnica de Catalunya (UPC).

Version
2.0.3
Date
June 11, 2013

Acknowledgement: The software was developed in the frame of contract 21398/08/NL/GLC with the European Space Agency (ESA). Technical Offer was Christoph Ernst. Further features were developed under contract UPC-C7767 with Thales Alenia Space España (TAS-E). Contributions to the definition of the software functionality and testing have been made by Christoph Ernst, Mónica Martínez Mendoza and other ESA-ESTEC personnel, and Santiago Sobrino and Luis Roglá from TAS-E.

Copyright: © Universitat Politècnica de Catalunya (UPC) 2009.
Contact: lossy.nosp@m.filt.nosp@m.ers@t.nosp@m.sc.u.nosp@m.pc.ed.nosp@m.u

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program in file "LICENSE.GPL3"; if not, download it from http://www.gnu.org/licenses/gpl-3.0.html .

Additional permission under GNU GPL version 3 section 7:

If you modify this Program, or any covered work, by linking or combining it with the "Extra Filters Library" (libextrafilters), the "Lossy Filters Library" (liblossyfilters) or the "License Check Library" (libchecklicense), or modified versions of that libraries, containing parts covered by the terms described in files LICENSE.LIBEXTRAFILTERS and LICENSE.LIBLOSSYFILTERS, the licensors of this Program grant you additional permission to convey the resulting work.

Function Documentation

def libcommonfunc.__str__ (   self)

Special method to print parameter class (prints the self instance).

Floating point variables are printed as strings using str() because str() is inmune to roundoff errors in the floating point representation.

@return st = Human redable printing of the parameters (string).

Definition at line 883 of file libcommonfunc.py.

References complexStr().

Here is the call graph for this function:

def libcommonfunc.askQuestion (   st,
  buttons 
)

Show dialog to ask question.

Parameters
st= Information string. It can contain

and
html tags, that are discarded in console mode.

Parameters
buttons= QMessageBox buttons to show. (e.g.: QMessageBox.Yes | QMessageBox.No)
Returns
reply = button clicked ((e.g.: QMessageBox.Yes)

Definition at line 348 of file libcommonfunc.py.

Referenced by libfreefilters.CharPolys.__init__().

Here is the caller graph for this function:

def libcommonfunc.complexStr (   x,
  prec,
  format = None,
  minWidth = 0,
  eng = False,
  listFormat = False 
)

Nicely convert complex number to string, rounding real and imaginary parts to 'prec' significant digits.

Parameters
x= Complex number.
prec= Number of significant digits (int).
format= None | 'DB' | 'MA' | 'RI' (string). Default is None.
minWidth= Minimum field field (int). Default is 0.
eng= Use engineering notation in formats None and 'RI'. Default is False. Formatted strings of the form 0.x are allowed for exponents 0 and 9.
listFormat= Flag to return a list of strings instead of a string. The list contains [ Magnitude, Angle] or [Real, imag]. Useful to save in .csv format.

The format is borrowed from TouchStone s2p [S] parameter file definition. None: Complex number, like 2.4-j5.3. DB: Decibel Magnitude/Degree Angle. MA: Linear Magnitude/Degree Angle (polar form). RI: Real Part/Imaginary Part (rectangular form).

Returns
st = String representation of x.

Definition at line 386 of file libcommonfunc.py.

Referenced by mwfiltersgui.PredisZeorsDlg.__init__(), __str__(), libcommonfunc.MatrixQ.__str__(), mwfiltersgui.CouplingMatrixDlg.CM_currentCellChanged(), mwfiltersgui.CouplingMatrixDlg.CM_itemChanged(), libfreefilters.factorization(), mwfiltersgui.CouplingMatrixDlg.loadMatrixQ(), libfreefilters.CharPolys.polyStr(), mwfiltersgui.CouplingMatrixDlg.Q_currentCellChanged(), mwfiltersgui.CouplingMatrixDlg.Q_itemChanged(), libfreefilters.CharPolys.saveCharPolys(), libcommonfunc.Sparameters.saveSparam(), and mwfiltersgui.ParamEditDlg.updatewFuncTableEntries().

Here is the caller graph for this function:

def libcommonfunc.copy (   self)

Function to copy instances of the Parameters class (copies the self instance).

Returns
Pcopy = New instance of Parameters class copied from the self instance.

Definition at line 864 of file libcommonfunc.py.

Referenced by libfreefilters.factorization(), mwfiltersgui.CouplingMatrixDlg.on_CM_comboBox_currentIndexChanged(), mwfiltersgui.MatrixEditDlg.on_edit_listWidget_itemDoubleClicked(), and mwfiltersgui.MatrixEditDlg.on_undo_pushButton_clicked().

Here is the caller graph for this function:

def libcommonfunc.criticalErrorMsg (   st)

Show critical error message.

Prints error and exists in console mode. Displays QMessageBox in GUI mode.

Parameters
st= Error string. It can contain

and
html tags, that are discarded in console mode.

Definition at line 290 of file libcommonfunc.py.

Referenced by mwfiltersgui.SpecMask.__init__(), mwfiltersgui.Stouchstone.__init__(), mwfiltersgui.ParamEditDlg.on_TZoptim_pushButton_clicked(), readParamFile(), and mwfiltersgui.runSynthesis().

Here is the caller graph for this function:

def libcommonfunc.informationMsg (   st)

Show information message.

Prints message in console mode. Displays QMessageBox in GUI mode.

Parameters
st= Information string. It can contain

and
html tags, that are discarded in console mode.

Definition at line 332 of file libcommonfunc.py.

def libcommonfunc.listStr (   listX,
  prec = 3 
)

Nicely convert list of floats to string, rounding to 'prec' significant digits.

Parameters
listX= List of floats.
prec= Number of significant digits (int). Default 3.
Returns
st = String representation of x.

Definition at line 362 of file libcommonfunc.py.

Referenced by mwfiltersgui.MatrixEditDlg.on_apply_pushButton_clicked(), and mwfiltersgui.ParamEditDlg.on_TZoptim_pushButton_clicked().

Here is the caller graph for this function:

def libcommonfunc.myPrint (   st)

Prints on standard output if console application.

or on log window if GUI application.

Parameters
st= String.

Definition at line 192 of file libcommonfunc.py.

Referenced by mwfiltersgui.SpecMask.__init__(), libcommonfunc.Parameters.__init__(), mwfiltersgui.Stouchstone.__init__(), mwfiltersgui.MainWindow.__init__(), libfreefilters.factorization(), libcommonfunc.CouplingMatrices.matrixElementsEps(), mwfiltersgui.MainWindow.on_action_Compare_triggered(), mwfiltersgui.CouplingMatrixDlg.on_action_ListAdd_triggered(), mwfiltersgui.MainWindow.on_action_ListRemove_triggered(), mwfiltersgui.CouplingMatrixDlg.on_action_ListRemove_triggered(), mwfiltersgui.CouplingMatrixDlg.on_action_PlotS_triggered(), mwfiltersgui.CouplingMatrixDlg.on_action_Save_triggered(), mwfiltersgui.MatrixEditDlg.on_apply_pushButton_clicked(), mwfiltersgui.CouplingMatrixDlg.on_CM_comboBox_currentIndexChanged(), mwfiltersgui.MainWindow.on_results_comboBox_currentIndexChanged(), mwfiltersgui.ParamEditDlg.on_TZoptim_pushButton_clicked(), mwfiltersgui.MatrixEditDlg.on_undo_pushButton_clicked(), printHeader(), libcommonfunc.CouplingMatrices.readCouplingMatrix(), readParamFile(), mwfiltersgui.SensitivityAnalysis.runAnalysis(), mwfiltersgui.runSynthesis(), libfreefilters.CharPolys.saveCharPolys(), libcommonfunc.CouplingMatrices.saveCouplingMatrices(), libcommonfunc.Sparameters.saveSparam(), libcommonfunc.CouplingMatrices.transCouplingMatrix(), libcommonfunc.CouplingMatrices.updateCM_error(), and mwfiltersgui.MainWindow.updateWindows().

Here is the caller graph for this function:

def libcommonfunc.pkgNameVersion (   st)

Retrieves software package name and version from string.

Parameters
st= String to parse for package name and version. It must be the docstring (doc) of the calling module.
Returns
pkgname = Package name.
version = Package version.

Definition at line 180 of file libcommonfunc.py.

Referenced by printHeader(), libfreefilters.CharPolys.saveCharPolys(), libcommonfunc.MatrixQ.saveMat(), and libcommonfunc.Sparameters.saveSparam().

Here is the caller graph for this function:

def libcommonfunc.printHeader (   applicationName,
  st,
  importModule = False 
)

Prints application header info.

The information shown is read from the file docstring.

Parameters
applicationName= Name of application, usually os.path.basename(sys.argv[0]).
st= String to parse for package name and version. It must be the docstring (doc) of the calling module.
importModule= Flag, set to True when this function is called to acknowledge successful module import.

Definition at line 223 of file libcommonfunc.py.

References myPrint(), and pkgNameVersion().

Here is the call graph for this function:

def libcommonfunc.readParamFile (   fileName)

Read parameters file and return a Parameter class instance.

Parameters
fileName= Parameter file name.
Returns
Parameter class instance.

Definition at line 252 of file libcommonfunc.py.

References criticalErrorMsg(), and myPrint().

Referenced by mwfiltersgui.MainWindow.fileRead().

Here is the call graph for this function:

Here is the caller graph for this function:

def libcommonfunc.readVerbose ( )

Returns the value of the global verbose variable.

Useful to get the value from other modules that were loaded before the value of verbose was updated

Definition at line 169 of file libcommonfunc.py.

Referenced by libfreefilters.factorization().

Here is the caller graph for this function:

def libcommonfunc.setGlobalVariablesLibCommonFunc (   variablesDict)

Function to allow the GUI set values to the global variables of libcomonfunc module.

This function is used in order to avoid circular imports.

Parameters
variablesDict,:Variable keyword argument list. Python creates a dictionary.

Definition at line 159 of file libcommonfunc.py.

Referenced by mwfiltersgui.MainWindow.__init__().

Here is the caller graph for this function:

def libcommonfunc.validate (   self)

List of Chebash parameters to ignore

chebashIgnoreList = ['n_ceros', 'n_frecpropias_eq', 'real', 'imag', 'tipo_transformacion', 'graf[1]', 'graf[2]', 'graf[3]', 'graf[5]', 'graf[6]', 'graf[7]', 'graf[8]', 'graf[9]', 'graf[10]', 'graf[11]', 'graf[12]', 'graf[13]', 'graf[14]', 'graf[15]', 'graf[16]', 'graf[17]', 'graf[18]']

List of Chebash Mask parameters not to read

chebashMaskList = [ 'n_at', 'f_at', 'A_at', 't_at', 'offsetmba', 't_offsetmba', 'n_perd', 'f_abp', 'a_abp', 't_abp', 'offsetmbp', 't_offsetmbp', 'nr_retardo', 'f_retardo', 'r_retardo', 't_retardo', 'offsetrg', 't_offsetrg', 'nptos_pendht', 'f_pendht', 'd_pendht', 't_pendht', 'offsetpendht', 't_offsetpendht', 'nptos_pendre', 'f_pendre', 'd_pendre', 't_pendre', 'offsetpendre', 't_offsetpendre', 'nptos_gdst', 'f_gdst', 'v_gdst', 't_gdst', 'offsetgdst', 't_offsetgdst', 'nptos_gdsp', 'f_gdsp', 'v_gdsp', 't_gdsp', 'offsetgdsp', 't_offsetgdsp', 'n_frecpropias_eq', 'variacion_temp', 'margen_temp', 'modificar_mascaras', 'margen_gdsp'] processingComplex = False # Will be True when we start processing a 3-line complex parameter for (keyChebash, stValue) in paramList:

if not processingComplex:    # int, float, string or 1st line of a complex parameter
    try:
        (keyLossyFilters, type, scale) = chebashTranslateDict[keyChebash]
    except KeyError, err: 
        if keyChebash not in chebashIgnoreList + chebashMaskList: myPrint('Unknown parameter key in Chebash file: %s' % err)
        continue

    if type in ['int', 'float']:

        # First process the special cases
        if keyChebash == 'graf[4]':
            fmin, fmax = tuple( stValue.split(',')[0:2] )
            paramListLF.append( ('minFreq', 'float', str(float(fmin)*scale) ) )
            paramListLF.append( ('maxFreq', 'float', str(float(fmax)*scale) ) )
            continue
        else:
            if stValue != 'X':  # In Chebash, 'X' indicates an empty parameter
                exec("value = [ scale* %s(n) for n in stValue.split(',') ]" % type)
                if len(value) == 1:     # Not a list
                    value = str(value[0])
                else:   # List
                    value = str(value).replace('[', '').replace(']', '')
            else:   # Empty parameter
                value = ' '

    elif type == 'string':
            value = stValue
    elif type == 'complex':
        processingComplex = True
        NComplex = int(stValue)
    else:
        raise parseError, 'Invalid data type'

else:   # 2nd and 3rd lines of a complex parameter
    if keyChebash == 'real':
        if NComplex > 0: 
            complexRe = [ float(n)*scale for n in stValue.split(',') ]
    elif keyChebash == 'imag': 
        if NComplex > 0:
            complexIm = [ float(n)*scale for n in stValue.split(',') ]
            value = str([ complex(nReal, nImag) for nReal, nImag in zip(complexRe, complexIm) ]).replace('[', '').replace(']', '').replace('(', '').replace(')', '')
        else:    
            value = ' '
        processingComplex = False

# Add lossyfilters parameter, for normal or for special case
paramListLF.append((keyLossyFilters, type, value))
    return paramListLF + chebashDefaultList 

     Function to check if parameters have invalid values and make some basic parameter processing.

Definition at line 735 of file libcommonfunc.py.

References warningMsg().

Here is the call graph for this function:

def libcommonfunc.warningMsg (   st)

Show warning message.

Prints warning in console mode. Displays QMessageBox in GUI mode.

Parameters
st= Warning string. It can contain

and
html tags, that are discarded in console mode.

Definition at line 316 of file libcommonfunc.py.

Referenced by libcommonfunc.Sparameters.__init__(), libfreefilters.butterworthFilter(), libcommonfunc.Sparameters.energyPowerFromCM(), libcommonfunc.Sparameters.fromCouplingMatrix(), mwfiltersgui.runSynthesis(), and validate().

Here is the caller graph for this function:

Variable Documentation

libcommonfunc.CP = CMSPNone
Todo:
: See if MainWindow.cleanup() method can be used here. Close the [S] parameters plot and set all results to None

Definition at line 302 of file libcommonfunc.py.

libcommonfunc.mainWindow = None

Module global variable equal either to None or to the GUI QMainWindow class instance, containing the application main window.

It is equal to None (default) when the calling program is the console interface (mwfiltersgui.py –nogui). When creating the main window, the GUI executes the libcommonfunc.setGlobalVariablesLibCommonFunc() function in order to set this variable. The GUI methods do not use this variable. They access the mainWindow class through ParamEditDlg.mainWindow and MainWindow 'self' attributes.

Definition at line 87 of file libcommonfunc.py.

libcommonfunc.nogui = False

Module global variable equal to True if the GUI has been called with the –nogui flag command line option.

Otherwise it is False.

Definition at line 95 of file libcommonfunc.py.

list libcommonfunc.nonSymmZeros = [ ]

def normRealFreq(f): """ Auxiliary function """ return (f/self.f0 - self.f0/f)*self.f0/self.BW

for (keyChebash, stValue) in paramList: if paramList[9][0] == 'real': realEqZs = [ normRealFreq(self.f0 + float(st)*1e6) for st in paramList[9][1].split(',') ]

Definition at line 649 of file libcommonfunc.py.

dictionary libcommonfunc.parameterDict
Initial value:
1 { 'outName': 'outName', 'outDir': 'outDir', 'outDirName': 'outDirName', 'N': 'N', 'f0': 'f0', 'BW': 'BW',
2  'filterTransferFunc': 'filterTransferFunc', 'chebyLr': 'chebyLr', 'qeZero': 'qeZero' , 'qeLr': 'qeLr',
3  'transImagZeros': 'transImagZeros', 'transComplexZeros': 'transComplexZeros', 'genChebyLr': 'genChebyLr',
4  'genChebyLP': 'genChebyLP', 'LPalgor' : 'LPalgor', 'LPmaxIter' : 'LPmaxIter', 'LPNsamples' : 'LPNsamples',
5  'LPcomplexZeros': 'LPcomplexZeros', 'LPrealZeros': 'LPrealZeros', 'LPfracBW': 'LPfracBW', 'LPripple': 'LPripple',
6  'synthTech': 'synthTech', 'zerosArrang': 'zerosArrang', 'adapPredis': 'adapPredis', 'Qef': 'Qef', 'wFunc': 'wFunc',
7  'finiteQo': 'finiteQo', 'Qo': 'Qo', 'QoPredis': 'QoPredis',
8  'nuqK': 'nuqK', 'nuqK11c1': 'nuqK11c1', 'nuqK22c1': 'nuqK22c1', 'nuqK21c1': 'nuqK21c1', 'nuqK21c2': 'nuqK21c2', 'nuqK21c3': 'nuqK21c3',
9  'nuqTech': 'nuqTech', 'nuqDelta': 'nuqDelta',
10  'maxFreq': 'maxFreq', 'minFreq': 'minFreq', 'numFreq': 'numFreq' }

Dictionary of parameter keywords and variable names.

This dictionary allows the developer to change a variable name in the code without having to change the corresponding keyword in all the existing parameter files.

Definition at line 62 of file libcommonfunc.py.

int libcommonfunc.saveSignificantDigitsEnergy = 4

Number of significant digits to save in energy and power results.

Usually less than saveSignificantDigits, because not much precision is needed.

Definition at line 80 of file libcommonfunc.py.

libcommonfunc.verbose = False

Module global variable equal to True if the GUI has been called with the -v flag command line option.

Otherwise it is False.

Definition at line 91 of file libcommonfunc.py.