-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
71 lines (57 loc) · 2 KB
/
run.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
from __future__ import division, absolute_import, print_function
import numpy as np
from mesh.Mesh import Mesh
from EIT.FEM import Forward
from EIT.utils import EIT_scanLines
from solver.InverseSolver import InverseSolver
from socketIO_client import SocketIO, LoggingNamespace
from API.API import API
from config import * # import main variable
import time
socketIO = SocketIO(host, port, LoggingNamespace)
api = API(host, port)
def run(*args):
responseData = args[0]
# get parameter
tipe = str(responseData['tipe'])
token = str(responseData['token'])
arusInjeksi = responseData['arus']
kerapatan = responseData['kerapatan']
iddata = responseData['iddata']
dataVolt = responseData['data']
algor = str(responseData['algor'])
waktu = time.time()
direktori = "./RPi.EIT-web/img/results/"
axisSize = [-1, 1, -1, 1]
jumlahElektroda = 16
datetime = (time.strftime("%Y%m%d-") + time.strftime("%H%M%S"))
if responseData['colorbar']:
colorbar=1
else:
colorbar=0
filename = str(datetime)+'-'+algor+'-'+str(colorbar)+'.png'
# set simulation model
createMesh = Mesh(jumlahElektroda, h0=kerapatan)
mesh = createMesh.getMesh()
elPos = createMesh.getElectrode()
alpha0 = createMesh.setAlpha(background=arusInjeksi)
step = 1
exMat = EIT_scanLines(jumlahElektroda)
# impor data from EIT instrument or file
if(tipe == "fromraspi"):
data = np.hstack(dataVolt)
else:
data = np.loadtxt("./RPi.EIT-web/dataObjek/"+str(dataVolt))
# Solve model with forward problem (FEM)
forward = Forward(mesh, elPos)
f0 = forward.solve(exMat=exMat, step=step, perm=alpha0)
# Solve inverse problem
inv = InverseSolver(mesh=mesh, forward=f0)
inv.solve(algor=algor, data=data)
# plot
fig = inv.plot(size=axisSize,colorbar=responseData['colorbar'], showPlot=False)
fig.savefig(direktori+filename, dpi=300)
waktu = time.time()-waktu
# report to server
api.postImage(filename, kerapatan, algor, iddata)
socketIO.emit('finishReconstruction', {'sukses': True, 'waktu': int(waktu), 'filename': filename, 'session':tipe, 'token':token})