forked from groupeLIAMG/BhTomoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
122 lines (96 loc) · 4.33 KB
/
model.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
# -*- coding: utf-8 -*-
"""
Copyright 2017 Bernard Giroux, Elie Dumas-Lefebvre, Jerome Simon
email: [email protected]
This file is part of BhTomoPy.
BhTomoPy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import numpy as np
from sqlalchemy import Column, String, Table, ForeignKey, PickleType
from utils import Base
from sqlalchemy.orm import relationship
# Relationship definition
model_mogs = Table('model_mogs', Base.metadata,
Column('Mog_name', String, ForeignKey('Mog.name')),
Column('Model_name', String, ForeignKey('Model.name')))
class Model(Base):
__tablename__ = "Model"
name = Column(String, primary_key=True) # Model's name
grid = Column(PickleType) # Model's grid
tt_covar = Column(PickleType) # Model's Traveltime covariance model
amp_covar = Column(PickleType) # Model's Amplitude covariance model
inv_res = Column(PickleType) # Results of inversion
tlinv_res = Column(PickleType) # Time-lapse inversion results
mogs = relationship("Mog", secondary=model_mogs) # The mogs associated with the model (acts like a list).
@property
def boreholes(self):
"""
Returns a list of all the boreholes contained in the mogs of a model, without duplicates.
"""
boreholes = []
for mog in self.mogs:
for borehole in mog.Tx, mog.Rx:
if borehole is not None:
if borehole not in boreholes: # guarantees there is no duplicate
boreholes.append(borehole)
return boreholes
def __init__(self, name=''):
self.name = name
self.grid = None
self.tt_covar = None
self.amp_covar = None
self.inv_res = []
self.tlinv_res = None
@staticmethod
def getModelData(model, selected_mogs, type1, type2=''):
data = np.array([])
type2 = ''
tt = np.array([])
et = np.array([])
in_vect = np.array([])
mogs = []
for i in selected_mogs:
mogs.append(model.mogs[i])
if type1 == 'tt':
fac_dt = 1
mog = mogs[0]
ind = np.not_equal(mog.tt, -1).T
tt, t0 = mog.getCorrectedTravelTimes()
tt = tt.T
et = fac_dt * mog.f_et * mog.et.T
in_vect = mog.in_vect.T
no = np.arange(mog.data.ntrace).T
if len(mogs) > 1:
for n in range(1, len(model.mogs)):
mog = mogs[n]
ind = np.concatenate((ind, np.not_equal(mog.tt, -1).T), axis=0)
tt = np.concatenate((tt, mog.getCorrectedTravelTimes()[0].T), axis=0)
et = np.concatenate((et, fac_dt * mog.et * mog.f_et.T), axis=0)
in_vect = np.concatenate((in_vect, mog.in_vect.T), axis=0)
no = np.concatenate((no, np.arange(mog.ntrace + 1).T), axis=0)
ind = np.equal((ind.astype(int) + in_vect.astype(int)), 2)
data = np.array([tt[ind], et[ind], no[ind]]).T
return data, ind
if type2 == 'depth':
data, ind = getModelData(model, air, selected_mogs, type1) # @UndefinedVariable
mog = mogs[0]
tt = mog.Tx_z_orig.T
et = mog.Rx_z_orig.T
in_vect = mog.in_vect.T
if len(mogs) > 1:
for n in (1, len(mogs)):
tt = np.concatenate((tt, mogs[n].Tx_z_orig.T), axis=0)
et = np.concatenate((et, mogs[n].Rx_z_orig.T), axis=0)
in_vect = np.concatenate((in_vect, mogs[n].in_vect.T), axis=0)
ind = np.equal((ind.astype(int) + in_vect.astype(int)), 2)
data = np.array([tt[ind], et[ind], no[ind]]).T
return data, ind