Package empro :: Package toolkit :: Module adsDataSet
[frames] | no frames]

Source Code for Module empro.toolkit.adsDataSet

 1  # Copyright 1983-2019 Keysight Technologies, Inc , Keysight Confidential 
 2  ''' 
 3  Module to export network parameters to the ADS dataset format 
 4   
 5   
 6  Example: 
 7   
 8  from empro.toolkit import adsDataSet, citifile 
 9  citi = citifile.CitiFile(path) 
10  adsDataSet.write('results.ds', citi) 
11  ''' 
12   
13  from empro import _deprecation 
14 15 @_deprecation.deprecated(390, message="Use empro.toolkit.citifile.writeAdsDataSet instead.") 16 -def write(path, citiFile):
17 ''' 18 Write the data to disk as a ADS DataSet (".ds") file 19 ''' 20 import empro 21 varName = citiFile.getVarName() 22 if 'FREQUENCY'.startswith(varName): 23 varName = 'freq' 24 depVars = [] 25 numSorted = sorted(citiFile, key=_numeric_key) 26 for key in numSorted: 27 depVars.append(key) 28 dsd = empro.DataSetDescription(citiFile.name,varName,depVars) 29 indepVarValues = citiFile.var 30 depVarValueLists = [] 31 for key in numSorted: 32 depVarValueLists.append(citiFile[key]) 33 ds = empro.DataSet() 34 ds.create(path) 35 dsds = ds.newDataSet(dsd) 36 dsds.fill(indepVarValues,depVarValueLists) 37 ds.close()
38
39 @_deprecation.deprecated(390, message="Use empro.toolkit.citifile._numeric_key instead.") 40 -def _numeric_key(key):
41 ''' 42 The default sort method uses the alphanumeric lexicographical order. 43 For numbers larger than 9 this does not correspond to the desired numerical 44 order. E.g., S(10,1) comes lexicographically before S(1,1), while it should 45 come after it when the elements of a matrix are sorted. 46 47 This function, splits the key in a tuple of a alphanumeric prefix, followed 48 by 0, 1 or 2 numeric indices. Use as sorted(arg,key=_numeric_key) to sort 49 1D and 2D matrices (and of course scalars) in the correct way. 50 ''' 51 import re 52 match = re.match(r"^(.*)[\(\[](\d+),(\d+)[\)\]]$", key) 53 if match: 54 return (match.group(1), int(match.group(2)), int(match.group(3))) 55 match = re.match(r"^(.*)[\(\[](\d+)[\)\]]$", key) 56 if match: 57 return (match.group(1), int(match.group(2))) 58 return (key, )
59