-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
107 lines (84 loc) · 2.45 KB
/
app.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
#importing modules
import os
import numpy as np
import errno
import segyio
from flask import Flask, render_template, request
import simplejson
# declaring app name
app = Flask(__name__)
def files_color_map(pasta):
"""
Carrega o caminho dos arquivos dos mapas de cores
:parâmetro pasta: caminho da pasta
return: um dicionário com os caminhos e nomes do mapas de cores
"""
file_list = os.listdir(pasta)
paths = []
colorMaps = []
for f in file_list:
x = f.split('.')
colorMaps.append(x[0])
paths.append('/' + pasta + '/' + f)
l = {
'path': paths,
'colorMaps': colorMaps,
}
return l
def path_hierarchy(path):
"""
Monta a hierarquia das pastas
:parâmetro path: caminho
return: um dicionário com a hierarquia das pastas e arquivos
"""
hierarchy = {
'text': os.path.basename(path),
}
try:
hierarchy['nodes'] = [
path_hierarchy(os.path.join(path, contents))
for contents in os.listdir(path)
]
except OSError as e:
if e.errno != errno.ENOTDIR:
raise
return hierarchy
def loadTreeView():
"""
Carrega a tree view
return: um dicionário com a tree view
"""
path = 'segy'
tree = path_hierarchy(path)
for i in range(len(tree['nodes'])):
node = tree['nodes'][i]
return tree['nodes']
@app.route('/seismic2D', methods=["GET","POST"])
def readSeismic2D():
"""
Carrega os dados do arquivo escolhido
return: um dicionário com as informações do arquivo
"""
global dataSeismic
path = simplejson.loads(request.form['javascript_data_2D'])
with segyio.open('segy/' + path, "r", ignore_geometry=True) as f:
# Memory map file for faster reading (especially if file is big...)
f.mmap()
dataSeismic = f.trace.raw[:].T
response = {"data": (dataSeismic.flatten()).tolist(),
"height": dataSeismic.shape[0],
"width": dataSeismic.shape[1],
"minValue":np.min(dataSeismic).tolist(),
"maxValue":np.max(dataSeismic).tolist(),
}
return response
@app.route('/')
def homepage():
"""
define a home page
"""
path = 'static/textures'
return render_template("index.html", treeData=simplejson.dumps(loadTreeView()), color_Map=files_color_map(path))
if __name__ == '__main__':
# running app
app.run(debug=True)