First commit of Model file

dev-brahim
brahim 2023-07-27 12:02:41 +02:00
parent 53f7338c52
commit 2b429bc6a2
5 changed files with 1278 additions and 0 deletions

1104
Model/AquascatDataLoader.py Normal file

File diff suppressed because it is too large Load Diff

39
Model/TableModel.py Normal file
View File

@ -0,0 +1,39 @@
from PyQt5.QtCore import Qt, QAbstractTableModel
class TableModel(QAbstractTableModel):
def __init__(self, data):
super(TableModel, self).__init__()
self._data = data
def data(self, index, role):
if role == Qt.DisplayRole:
value = self._data.iloc[index.row(), index.column()]
# if role == Qt.TextAlignmentRole:
# value = self._data.iloc[index.row(), index.column()]
# if isinstance(value, int) or isinstance(value, float):
# return Qt.AlignVCenter + Qt.AlignRight
return str(value)
# if isinstance(value, float):
# # Render float to 2 dp
# return "%.2f" % value
# if isinstance(value, str):
# # Render strings with quotes
# return '"%s"' % value
def rowCount(self, index):
# The length of the outer list.
return self._data.shape[0]
def columnCount(self, index):
# The following takes the first sub-list, and returns
# the length (only works if all rows are an equal length)
return self._data.shape[1]
def headerData(self, section, orientation, role):
# section is the index of the column/row.
if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return str(self._data.columns[section])
if orientation == Qt.Vertical:
return str(self._data.index[section])

0
Model/__init__.py Normal file
View File

View File

@ -0,0 +1,94 @@
from Model.AquascatDataLoader import RawAquascatData
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
path_BS_raw_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \
"Data/Acoustic_data/20180107123500.aqa"
path_noise_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \
"Data/AcousticNoise_data/20180107121600.aqa"
class AcousticDataLoader():
def __init__(self, path_BS_raw_data: str):
self.path_BS_raw_data = path_BS_raw_data
# --- Load Backscatter acoustic raw data with RawAquascatData class ---
self._data_BS = RawAquascatData(self.path_BS_raw_data)
self._BS_raw_data = self._data_BS.V
self._r = self._data_BS.r
self._freq = self._data_BS.Freq
self._freq_text = self._data_BS.freqText
self._time = np.array([t / self._data_BS.PingRate for t in range(self._data_BS.NumProfiles)])
self._date = self._data_BS.date.date()
self._hour = self._data_BS.date.time()
self._nb_profiles = self._data_BS.NumProfiles
self._nb_profiles_per_sec = self._data_BS.ProfileRate
self._nb_cells = self._data_BS.NumCells
self._cell_size = self._data_BS.cellSize
self._pulse_length = self._data_BS.TxPulseLength
self._nb_pings_per_sec = self._data_BS.PingRate
self._nb_pings_averaged_per_profile = self._data_BS.Average
self._kt = self._data_BS.Kt
self._gain_rx = self._data_BS.RxGain
self._gain_tx = self._data_BS.TxGain
self._snr = np.array([])
self._snr_reshape = np.array([])
self._time_snr = np.array([])
# print(["BS - " + f for f in self._freq_text])
# print(self._time.shape[0]*self._r.shape[0]*4)
# fig, ax = plt.subplots(nrows=1, ncols=1)
# ax.pcolormesh(self._time, self._r, np.flipud(self._BS_raw_data[:, 1, :]),
# cmap='viridis',
# norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud')
# ax.pcolormesh(range(self._BS_raw_data.shape[2]), range(self._BS_raw_data.shape[0]), self._BS_raw_data[:, 1, :], cmap='viridis',
# norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud')
# plt.show()
# print(self.reshape_BS_raw_cross_section()[0, 0])
# self.reshape_r()
# self.reshape_t()
# dataframe = self.concatenate_data()
# print(dataframe)
def reshape_BS_raw_cross_section(self):
BS_raw_cross_section = np.reshape(self._BS_raw_data,
(self._r.shape[0]*len(self._time), self._freq.shape[0]),
order="F")
return BS_raw_cross_section
def reshape_r(self):
r = np.reshape(np.repeat(self._r, self._time.shape[0], axis=1),
self._r.shape[0]*self._time.shape[0],
order="F")
return r
def reshape_t(self):
t = np.reshape(np.repeat(self._time, self._r.shape[0]), (self._time.shape[0]*self._r.shape[0], 1))
return t
def concatenate_data(self):
self.reshape_t()
self.reshape_BS_raw_cross_section()
# print(self.reshape_t().shape)
# print(se.lf.reshape_BS_raw_cross_section().shape)
df = pd.DataFrame(np.concatenate((self.reshape_t(), self.reshape_BS_raw_cross_section()), axis=1),
columns=["time"] + self._freq_text)
return df
# if __name__ == "__main__":
# AcousticDataLoader(path_BS_raw_data)

41
Model/granulo_loader.py Normal file
View File

@ -0,0 +1,41 @@
import numpy as np
import pandas as pd
class GranuloLoader:
""" This class allows to load granulo data file """
def __init__(self, path_fine: str, path_sand: str):
# --- Load fine sediments data file ---
self.path_fine = path_fine
self._data_fine = pd.read_excel(self.path_fine, engine="odf", header=0)
self._y = np.array(self._data_fine.iloc[:, 0]) # distance from left bank (m)
self._z = np.array(self._data_fine.iloc[:, 1]) # depth (m)
self._r_grain = np.array(self._data_fine.columns.values)[4:] # grain radius (um)
self._Ctot_fine = np.array(self._data_fine.iloc[:, 2]) # Total concentration (g/L)
self._D50_fine = np.array(self._data_fine.iloc[:, 3]) # median diameter (um)
self._frac_vol_fine = np.array(self._data_fine.iloc[:, 4:]) # Volume fraction (%)
self._frac_vol_fine_cumul = np.cumsum(self._frac_vol_fine, axis=1) # Cumulated volume fraction (%)
# --- Load sand sediments data file ---
self.path_sand = path_sand
self._data_sand = pd.read_excel(self.path_sand, engine="odf", header=0)
self._Ctot_sand = np.array(self._data_sand.iloc[:, 2]) # Total concentration (g/L)
self._D50_sand = np.array(self._data_sand.iloc[:, 3]) # median diameter (um)
self._frac_vol_sand = np.array(self._data_sand.iloc[:, 4:]) # Volume fraction (%)
self._frac_vol_sand_cumul = np.cumsum(self._frac_vol_sand, axis=1) # Cumulated volume fraction (%)
if __name__ == "__main__":
GranuloLoader("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/Granulo_data/"
"fine_sample_file.ods",
"/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/Granulo_data/"
"fine_sample_file.ods")