-
Notifications
You must be signed in to change notification settings - Fork 1
/
outils.py
executable file
·148 lines (117 loc) · 3.79 KB
/
outils.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 14:24:20 2020
@author: el
"""
import matplotlib.pyplot as plt
import numpy as np
import io
import h5py
import os
import math
import pygimli as pg
#from pygimli.meshtools import polytools as plc
#from pygimli.meshtools import quality
from param_acquisition import Geometry, ParamMVG, ParamGPRMAX
def comparaison_array_number(Array,number,tol):
"""
Parameters
----------
Array : TYPE float
Generalemenet un array de float ou de float 64
number : TYPE float/int, on va le caster si besoin
Generalement un int ou un float, mais il faut bien verifier, dans le doute je caste
Returns
-------
Une array de True/False
"""
return np.isclose(Array,np.float64(number), atol=tol)
def comparaison_number_number(number1,number2,tol):
"""
Parameters
----------
number : TYPE float/int, on va le caster si besoin
Generalement un int ou un float, mais il faut bien verifier, dans le doute je caste
Returns
-------
Un True/False
"""
return math.isclose(np.float64(number1),np.float64(number2),abs_tol=tol)
# def ineg_number_number(number1,number2,tol):
# """
# Parameters
# ----------
# number : TYPE float/int, on va le caster si besoin
# Generalement un int ou un float, mais il faut bien verifier, dans le doute je caste
# Returns
# -------
# Un True/False
# """
# if(np.float64(number1)<=np.float64(number2)):
# return math.isclose(np.abs(np.float64(number1)-np.float64(number2)),0,abs_tol=tol)
def showQuality(mesh, qualities):
fig, axes = plt.subplots(1, 2)
axes[1].hist(qualities, color="grey")
pg.show(mesh, qualities, ax=axes[0], cMin=0.5, cMax=1, hold=True,
logScale=False, label="Mesh quality", cmap="RdYlGn", showMesh=True)
s = "Min: %.2f, Mean: %.2f, Max: %.2f" % (
np.min(qualities), np.mean(qualities), np.max(qualities))
axes[1].set_title(s)
axes[1].set_xlabel("Mesh quality")
axes[1].set_ylabel("Frequency")
axes[1].set_xlim(0, 1)
# Figure resizing according to mesh dimesions
x = mesh.xmax() - mesh.xmin()
y = mesh.ymax() - mesh.ymin()
width, height = fig.get_size_inches()
fig.set_figheight(height * 1.3 * (y / x))
fig.tight_layout()
return fig
####### Lire les fichiers Parameters ######
def read_parameters(filepath):
filename = 'Parameters'
s = io.open(os.path.join(filepath,filename)).read()
p = eval(s)
return p
######## Lire les fichiers TWT #############
def read_TWT(filepath):
filename = 'TWT'
mots=[]
twts=np.zeros(nT)
fTWT=open(filepath + filename,"r")
i=0
for ligne in fTWT:
ligne = ligne.rstrip(']\n')
mots = ligne.split(" ")
for mot in mots:
if (mot != '' and mot != '[0.' and mot != '[' and mot != '0.'):
twts[i] = float(mot)
i=i+1
return twts
fTWT.close()
### Lire les fichiers Volumes ##############
def read_volumes(filepath):
volumes=np.zeros(nT)
filename = 'Volumes'
fVOL=open(filepath + filename,"r")
i=0
for ligne in fVOL:
ligne = ligne.rstrip(']\n')
mots = ligne.split(" ")
for mot in mots:
if (mot != '' and mot != '[0.' and mot != '[' and mot != '0.'):
volumes[i] = float(mot)
i=i+1
return volumes
fVOL.close()
### Plotter un radargramme
def rada_plot(filepath):
filename = 'radargram__merged.out'
f = h5py.File(filepath + filename, 'r')
path = '/rxs/rx1/'
data = f['%s%s' % (path, 'Ez')][:,:]
plt.figure(figsize=(10,15))
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
plt.imshow(data[:,:],aspect=0.005)