forked from jasonfleming/pputils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
executable file
·125 lines (111 loc) · 4.03 KB
/
scan.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
#
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
# #
# scan.py #
# #
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
#
# Author: Pat Prodanovic, Ph.D., P.Eng.
#
# Date: Aug 9, 2017
#
# Purpose: Scans the selafin file, and outputs the min and max of each
# variable. The number format may need to be adjusted if small variables
# are written in the *.slf file. This script is considerably slower than
# probe.py because it reads data for all variables, for all time steps,
# in order to find the min and max of the data.
#
# Modified: Aug 14, 2017
# Rather than scanning data for all time steps, scan the file for a
# particular time step only.
#
# Uses: Python 2 or 3, Numpy
#
# Example: python scan.py -i input.slf -t 3
#
# where:
# --> -i is the telemac *.slf file being probed
# --> -t is the index of the time step being probed
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Global Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# need future for backward compatibility with python2
from __future__ import absolute_import, division, print_function
import sys
import numpy as np
from ppmodules.selafin_io_pp import *
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# MAIN
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
if len(sys.argv) == 5:
input_file = sys.argv[2] # input *.slf file
t = int(sys.argv[4])
else:
print('Wrong number of Arguments, stopping now...')
print('Example usage:')
print('python scan.py -i input.slf -t 3')
sys.exit()
# constructor for pp_SELAFIN class
slf = ppSELAFIN(input_file)
slf.readHeader()
slf.readTimes()
times = slf.getTimes()
vnames = slf.getVarNames()
vunits = slf.getVarUnits()
ftype,fsize = slf.getPrecision()
nplan = slf.getNPLAN()
if (t >= len(times)):
print('time step is not within the file. Exiting!')
sys.exit()
# gets some of the mesh properties from the *.slf file
NELEM, NPOIN, NDP, IKLE, IPOBO, x, y = slf.getMesh()
# number of variables
numvars = len(vnames)
# this is the min and max for each variable, for each time step
#tempmin = np.zeros((numvars, len(times)))
#tempmax = np.zeros((numvars, len(times)))
# the min max array for each variable
minmax = np.zeros((numvars,2))
# number of planes
if (nplan > 1):
slf_type = '3d'
else:
slf_type = '2d'
# precision of *.slf file
if(ftype == 'f' and fsize == 4):
precision = 'single'
elif(ftype == 'd' and fsize == 8):
precision = 'double'
else:
precision = 'unknown'
# prints variable names and their min and max values from a particular time step
slf.readVariables(t)
master_results = slf.getVarValues()
for j in range(numvars):
minmax[j,0] = np.min(master_results[j,:])
minmax[j,1] = np.max(master_results[j,:])
print('#########################################################')
print("The input file being scaned: " + input_file)
print('Precision: ' + precision )
print('File type: ' + slf_type )
if (slf_type == '3d'):
print('Number of planes: ' + str(nplan))
print('Number of elements: ' + str(NELEM))
print('Number of nodes: ' + str(NPOIN))
print('Number of time steps: ' + str(len(times)))
print('Index of output time step: ' + str(t))
print(' ')
print('#########################################################')
print('Variables in '+input_file+' are: ')
print('---------------------------------------------------------')
print(' v variable min max unit' )
print('---------------------------------------------------------')
for i in range(len(vnames)):
print(' ',i, '-->', vnames[i] + str("{:10.3f}".format(minmax[i,0])) +
' ' + str("{:10.3f}".format(minmax[i,1])) + ' [' + vunits[i].strip() + ']')
print(' ')
print('#########################################################')
print('All done!')