-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_s11.py
executable file
·63 lines (45 loc) · 1.76 KB
/
check_s11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import argparse as ap
from glob import iglob
from skrf import Network
def check_nw( nw ):
found, frw, val = 0, 0, 0
for f, s11 in zip( nw.f, nw.s[:,0,0] ): # frequency and S11
a = abs( s11 )
if a > 1:
found += 1
if a > abs( val ):
frq = f
val = s11
if found:
return ( found, frq, val )
def check_files( pattern, verbose ):
for snp in [ fff for fff in iglob( pattern, recursive=True ) if os.path.isfile( fff ) ]:
nw = Network( snp )
check = check_nw( nw )
if check:
n, f, s = check
if verbose:
print( f'{snp}: {n} of {nw.f.size} points with |S| > 1, worst at {f} Hz: |{s}| = {abs(s)}' )
else:
print( snp )
elif verbose:
print( f'{snp}: ok' )
if __name__ == '__main__':
parser = ap.ArgumentParser( description='Check all touchstone files in current directory for values with |S11| > 1' )
group = parser.add_mutually_exclusive_group()
group.add_argument( '-i', '--infile', type=ap.FileType('r', encoding='UTF-8'),
help='check only the touchstone file INFILE' )
group.add_argument( '-r', '--recursive', action='store_true',
help='check also all touchstone files in subdirectories' );
parser.add_argument( '-v', '--verbose', action='store_true',
help='display all checked files, more mismatch details' );
args = parser.parse_args()
if args.infile:
check_files( args.infile.name, args.verbose )
elif args.recursive:
check_files( '**/*.s?p', args.verbose )
else:
check_files( '*.s?p', args.verbose )