acoustic data loader ubsediflow is cleaned from useless commented lines and useless print
parent
80d570796a
commit
2e9f9c3a3c
|
|
@ -1,49 +1,35 @@
|
|||
# ============================================================================== #
|
||||
# acoustic_data_loder_UBSediFlow.py - AcouSed #
|
||||
# Copyright (C) 2024 INRAE #
|
||||
# #
|
||||
# This program 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 <https://www.gnu.org/licenses/>. #
|
||||
|
||||
# by Brahim MOUDJED #
|
||||
# ============================================================================== #
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.colors import LogNorm, BoundaryNorm
|
||||
from copy import deepcopy
|
||||
|
||||
from scipy.signal import savgol_filter
|
||||
|
||||
from Model.udt_extract.raw_extract import raw_extract
|
||||
# raw_20210519_102332.udt raw_20210520_135452.udt raw_20210525_092759.udt raw_20210525_080454.udt
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/APAVER_2021/Raw_data_udt/")
|
||||
# filename0 = "raw_20210519_135400.udt"
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/"
|
||||
# "APAVER_2021/transect_ubsediflow/01-raw_20210519_115128/Raw_data_udt/")
|
||||
# filename0 = "raw_20210519_115128.udt"
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/"
|
||||
# "APAVER_2021/transect_ubsediflow/02-bb0077eda128f3f7887052eb3e8b0884/Raw_data_udt/")
|
||||
# filename0 = "raw_20210519_161400.udt"
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/"
|
||||
# "APAVER_2021/transect_ubsediflow/04-fb53d0e92c9c88e2a6cf45e0320fbc76/Raw_data_udt/")
|
||||
# filename0 = "raw_20210520_133200.udt"
|
||||
|
||||
# ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/APAVER_2021/"
|
||||
# "Rhone_20210519/Rhone_20210519/record/")
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/Raw_data_udt/")
|
||||
# filename0 = "raw_20210519_130643.udt"
|
||||
|
||||
# path_BS_raw_data0 = ("/home/bmoudjed/Documents/2 Data/APAVER_2021/Raw_data_udt/")
|
||||
# filename0 = "raw_20210520_085958.udt"
|
||||
|
||||
# filename = "raw_20210519_115128.udt"
|
||||
# "raw_20210526_153310.udt"
|
||||
|
||||
|
||||
class AcousticDataLoaderUBSediFlow:
|
||||
|
||||
def __init__(self, path_BS_raw_data: str):
|
||||
|
||||
# path_BS_raw_data = path_BS_raw_data0 + filename0
|
||||
self.path_BS_raw_data = path_BS_raw_data
|
||||
|
||||
# --- Extract Backscatter acoustic raw data with class ---
|
||||
|
|
@ -53,23 +39,10 @@ class AcousticDataLoaderUBSediFlow:
|
|||
device_name, time_begin, time_end, param_us_dicts, data_us_dicts, data_dicts, settings_dict \
|
||||
= raw_extract(self.path_BS_raw_data)
|
||||
|
||||
print(f"device_name : {device_name}")
|
||||
print(f"date begin : {time_begin.date()}")
|
||||
print(f"time begin : {time_begin.time()}")
|
||||
print(f"settings_dict : {settings_dict}")
|
||||
|
||||
# # --- Date and Hour of measurements read on udt data file ---
|
||||
# filename = self.path_BS_raw_data[-23:]
|
||||
# date_and_time = datetime.datetime(year=int(filename[4:8]),
|
||||
# month=int(filename[8:10]),
|
||||
# day=int(filename[10:12]),
|
||||
# hour=int(filename[13:15]),
|
||||
# minute=int(filename[15:17]),
|
||||
# second=int(filename[17:19]))
|
||||
|
||||
self._date = time_begin.date()
|
||||
print(f"date : {self._date}")
|
||||
self._hour = time_begin.time()
|
||||
print(f"time : {self._hour}")
|
||||
|
||||
self._freq = np.array([[]])
|
||||
|
||||
|
|
@ -88,19 +61,11 @@ class AcousticDataLoaderUBSediFlow:
|
|||
self._time = np.array([[]])
|
||||
self._time_snr = np.array([[]])
|
||||
self._BS_raw_data = np.array([[[]]])
|
||||
# self._SNR_data = np.array([[[]]])
|
||||
time_len = []
|
||||
time_snr_len = []
|
||||
|
||||
for config in param_us_dicts.keys():
|
||||
# print("-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x")
|
||||
# print(f"config : {config} \n")
|
||||
|
||||
for channel in param_us_dicts[config].keys():
|
||||
print("-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x")
|
||||
# print(f"channel : {channel} \n")
|
||||
# print("param_us_dicts[config][channel] ", param_us_dicts[config][channel])
|
||||
# print("param_us_dicts ", param_us_dicts)
|
||||
# print(data_us_dicts[config][channel]['echo_avg_profile'])
|
||||
|
||||
# --- Frequencies ---
|
||||
self._freq = np.append(self._freq, param_us_dicts[config][channel]['f0'])
|
||||
|
|
@ -115,31 +80,19 @@ class AcousticDataLoaderUBSediFlow:
|
|||
self._gain_tx = np.append(self._gain_tx, param_us_dicts[config][channel]['a1'])
|
||||
|
||||
# --- Depth for each frequencies ---
|
||||
print("r_dcell : ", param_us_dicts[config][channel]['r_dcell'])
|
||||
print("n_cell : ", param_us_dicts[config][channel]['n_cell'])
|
||||
depth = [param_us_dicts[config][channel]['r_dcell'] * i
|
||||
for i in list(range(param_us_dicts[config][channel]['n_cell']))]
|
||||
print(f"depth : {depth}")
|
||||
print(f"lenght of depth : {len(depth)}")
|
||||
|
||||
if self._r.shape[1] == 0:
|
||||
self._r = np.array([depth])
|
||||
else:
|
||||
if len(depth) == self._r.shape[1]:
|
||||
print("Je suis là")
|
||||
print(f"depth lenght : {len(depth)}")
|
||||
print(f"r shape : {self._r.shape}")
|
||||
self._r = np.append(self._r, np.array([depth]), axis=0)
|
||||
print("C'est encore moi")
|
||||
elif len(depth) < self._r.shape[1]:
|
||||
print(f"depth lenght : {len(depth)}")
|
||||
self._r = self._r[:, :len(depth)]
|
||||
self._r = np.append(self._r, np.array([depth]), axis=0)
|
||||
print(f"r shape : {self._r.shape}")
|
||||
elif len(depth) > self._r.shape[1]:
|
||||
print(f"depth lenght : {len(depth)}")
|
||||
self._r = np.append(self._r, np.array([depth[:self._r.shape[1]]]), axis=0)
|
||||
print(f"r shape : {self._r.shape}")
|
||||
print(f"self._r : {self._r.shape}")
|
||||
|
||||
# --- BS Time for each frequencies ---
|
||||
time = [[(t - data_us_dicts[config][channel]['echo_avg_profile']['time'][0]).total_seconds()
|
||||
|
|
@ -147,69 +100,28 @@ class AcousticDataLoaderUBSediFlow:
|
|||
time_len = np.append(time_len, len(time[0]))
|
||||
|
||||
if len(time_len) == 1:
|
||||
print(f"1 time length : {len(time[0])}")
|
||||
self._time = np.array(time)
|
||||
print(f"self._time.shape {self._time.shape}")
|
||||
elif self._time.shape[1] == len(time[0]):
|
||||
print(f"2 time length : {len(time[0])}")
|
||||
self._time = np.append(self._time, time, axis=0)
|
||||
print(f"self._time.shape {self._time.shape}")
|
||||
elif self._time.shape[1] > len(time[0]):
|
||||
print(f"3 time length : {len(time[0])}")
|
||||
# print(f"self._time.shape {self._time.shape}")
|
||||
# print([int(np.min(time_len)) + int(i) - 1 for i in range(1, int(np.max(time_len))-int(np.min(time_len))+1)])
|
||||
self._time = np.delete(self._time,
|
||||
[int(np.min(time_len)) + int(i) - 1 for i in range(1, int(np.max(time_len))-int(np.min(time_len))+1)],
|
||||
axis=1)
|
||||
self._time = np.append(self._time, time, axis=0)
|
||||
print(f"self._time.shape {self._time.shape}")
|
||||
elif self._time.shape[1] < len(time[0]):
|
||||
print(f"4 time length : {len(time[0])}")
|
||||
time = time[:int(np.max(time_len)) - (int(np.max(time_len)) - int(np.min(time_len)))]
|
||||
self._time = np.append(self._time, time, axis=0)
|
||||
print(f"self._time.shape {self._time.shape}")
|
||||
|
||||
self._nb_profiles = np.append(self._nb_profiles, self._time.shape[1])
|
||||
self._nb_profiles_per_sec = np.append(self._nb_profiles_per_sec,
|
||||
param_us_dicts[config][channel]['n_avg'])
|
||||
|
||||
# --- SNR Time for each frequencies ---
|
||||
# time_snr = [[(t - data_us_dicts[config][channel]['snr_doppler_avg_profile']['time'][0]).total_seconds()
|
||||
# for t in data_us_dicts[config][channel]['snr_doppler_avg_profile']['time']]]
|
||||
# time_snr_len = np.append(time_snr_len, len(time_snr[0]))
|
||||
#
|
||||
# if len(time_snr_len) == 1:
|
||||
# # print(f"1 time length : {len(time[0])}")
|
||||
# self._time_snr = np.array(time_snr)
|
||||
# # print(f"self._time.shape {self._time.shape}")
|
||||
# elif self._time_snr.shape[1] == len(time_snr[0]):
|
||||
# # print(f"2 time length : {len(time[0])}")
|
||||
# self._time_snr = np.append(self._time_snr, time_snr, axis=0)
|
||||
# # print(f"self._time.shape {self._time.shape}")
|
||||
# elif self._time_snr.shape[1] > len(time_snr[0]):
|
||||
# # print(f"3 time length : {len(time[0])}")
|
||||
# # print(f"self._time.shape {self._time.shape}")
|
||||
# # print([int(np.min(time_len)) + int(i) - 1 for i in range(1, int(np.max(time_len))-int(np.min(time_len))+1)])
|
||||
# self._time_snr = np.delete(self._time_snr,
|
||||
# [int(np.min(time_snr_len)) + int(i) - 1 for i in
|
||||
# range(1, int(np.max(time_snr_len)) - int(np.min(time_snr_len)) + 1)],
|
||||
# axis=1)
|
||||
# self._time_snr = np.append(self._time_snr, time_snr, axis=0)
|
||||
# # print(f"self._time.shape {self._time.shape}")
|
||||
# elif self._time_snr.shape[1] < len(time_snr[0]):
|
||||
# # print(f"4 time length : {len(time[0])}")
|
||||
# time_snr = time_snr[:int(np.max(time_snr_len)) - (int(np.max(time_snr_len)) - int(np.min(time_snr_len)))]
|
||||
# self._time_snr = np.append(self._time_snr, time_snr, axis=0)
|
||||
# # print(f"self._time.shape {self._time.shape}")
|
||||
|
||||
# --- US Backscatter raw signal ---
|
||||
BS_data = np.array([[]])
|
||||
|
||||
if config == 1:
|
||||
|
||||
BS_data = np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][0]])
|
||||
print(f"cas 1 : BS_raw_data shape = {self._BS_raw_data.shape}")
|
||||
print(f"cas 1 : BS_data shape = {BS_data.shape}")
|
||||
|
||||
for i in range(self._time.shape[1]):
|
||||
BS_data = np.append(BS_data,
|
||||
|
|
@ -218,27 +130,21 @@ class AcousticDataLoaderUBSediFlow:
|
|||
axis=0)
|
||||
|
||||
self._BS_raw_data = np.array([BS_data[:self._time.shape[1], :].transpose()])
|
||||
# print(f"a) BS_data shape = {BS_data.shape}")
|
||||
# print(f"a) BS_raw_data shape = {BS_raw_data.shape}")
|
||||
|
||||
else:
|
||||
|
||||
BS_data = np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][0]])
|
||||
print(f"{config}) BS_data shape = {BS_data.shape}")
|
||||
|
||||
for j in range(self._time.shape[1]):
|
||||
BS_data = np.append(BS_data,
|
||||
np.array(
|
||||
[data_us_dicts[config][channel]['echo_avg_profile']['data'][j]]),
|
||||
axis=0)
|
||||
BS_data = np.array([BS_data.transpose()])
|
||||
print(f"xxxx BS_data shape = {BS_data.shape}")
|
||||
# print(f"b) BS_raw_data shape = {BS_raw_data.shape}")
|
||||
|
||||
# 1- time shape > BS data shape
|
||||
# <=> data recorded with the frequency are longer than data recorded with the other lower frequencies
|
||||
if (BS_data.shape[2] > self._BS_raw_data.shape[2]):
|
||||
print(f"cas 2 : BS_raw_data shape = {self._BS_raw_data.shape}")
|
||||
print(f"cas 2 : BS_data shape = {BS_data.shape}")
|
||||
|
||||
if (BS_data.shape[1] > self._BS_raw_data.shape[1]):
|
||||
# print(f"BS_data shape[0] = {BS_data.shape[0]}")
|
||||
|
|
@ -260,8 +166,6 @@ class AcousticDataLoaderUBSediFlow:
|
|||
# 2- time shape < BS data shape
|
||||
# <=> data recorded with the frequency are shorter than data recorded with the other lower frequencies
|
||||
elif BS_data.shape[2] < self._BS_raw_data.shape[2]:
|
||||
print(f"cas 3 : BS_raw_data shape = {self._BS_raw_data.shape}")
|
||||
print(f"cas 3 : BS_data shape = {BS_data.shape}")
|
||||
|
||||
if (BS_data.shape[1] > self._BS_raw_data.shape[1]):
|
||||
self._BS_raw_data = np.append(self._BS_raw_data[:, :, BS_data.shape[2]],
|
||||
|
|
@ -277,16 +181,11 @@ class AcousticDataLoaderUBSediFlow:
|
|||
self._BS_raw_data = np.append(self._BS_raw_data[:, :, BS_data.shape[0]],
|
||||
BS_data,
|
||||
axis=0)
|
||||
# print(f"d) BS_data shape = {BS_data.shape}")
|
||||
# print(f"d) BS_raw_data shape = {BS_raw_data.shape}")
|
||||
|
||||
# 3- time shape = BS data shape
|
||||
# <=> data recorded with the frequency have the same duration than data recorded with the other lower frequency
|
||||
else:
|
||||
|
||||
print(f"cas 4 : BS_raw_data shape = {self._BS_raw_data.shape}")
|
||||
print(f"cas 4 : BS_data shape = {BS_data.shape}")
|
||||
|
||||
if (BS_data.shape[1] > self._BS_raw_data.shape[1]):
|
||||
|
||||
self._BS_raw_data = np.append(self._BS_raw_data,
|
||||
|
|
@ -301,115 +200,6 @@ class AcousticDataLoaderUBSediFlow:
|
|||
|
||||
self._BS_raw_data = np.append(self._BS_raw_data,
|
||||
BS_data, axis=0)
|
||||
# print(f"e) BS_data shape = {BS_data.shape}")
|
||||
|
||||
print("Final BS_raw_data shape = ", self._BS_raw_data.shape)
|
||||
|
||||
print("********************************************")
|
||||
|
||||
# # --- US Backscatter raw signal + SNR data ---
|
||||
# BS_data = np.array([[]])
|
||||
#
|
||||
# if config == 1:
|
||||
# BS_data = np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][0]])
|
||||
# # print("BS_data shape ", BS_data.shape)
|
||||
# # print("******************************")
|
||||
# # date_list = [np.abs(datetime.datetime(2021, 5, 19, 14, 10, 00).timestamp()
|
||||
# # - date.timestamp()) for date in data_us_dicts[config][channel]['echo_avg_profile']['time']]
|
||||
# # print(date_list)
|
||||
# # print(np.where(date_list == np.min(date_list)))
|
||||
# # print((data_us_dicts[config][channel]['echo_avg_profile']['time'][np.where(date_list == np.min(date_list))[0][0]] -
|
||||
# # data_us_dicts[config][channel]['echo_avg_profile']['time'][0]).total_seconds())
|
||||
# # # == datetime.datetime(2021, 5, 19, 14, 10, 2, 644000))
|
||||
# # print("******************************")
|
||||
#
|
||||
# for i in range(self._time.shape[1]):
|
||||
# BS_data = np.append(BS_data,
|
||||
# np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][i]]),
|
||||
# axis=0)
|
||||
# print("0. BS_data shape ", BS_data.shape)
|
||||
#
|
||||
# self._BS_raw_data = np.array([BS_data[:self._time.shape[1], :].transpose()])
|
||||
#
|
||||
# print("0. BS_raw_data shape ", self._BS_raw_data.shape)
|
||||
#
|
||||
# # fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
|
||||
# # pcm = ax.pcolormesh(list(range(self._BS_raw_data.shape[2])), list(range(self._BS_raw_data.shape[1])),
|
||||
# # np.log(self._BS_raw_data[0, :, :]),
|
||||
# # cmap='Blues')
|
||||
# # fig.colorbar(pcm, ax=ax, shrink=1, location='right')
|
||||
# # plt.show()
|
||||
#
|
||||
# else:
|
||||
#
|
||||
# BS_data = np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][0]])
|
||||
# # print("BS_data shape ", BS_data.shape)
|
||||
# for i in range(self._time.shape[1]):
|
||||
# BS_data = np.append(BS_data,
|
||||
# np.array(
|
||||
# [data_us_dicts[config][channel]['echo_avg_profile']['data'][i]]),
|
||||
# axis=0)
|
||||
# print("1. BS_data shape ", BS_data.shape)
|
||||
#
|
||||
# #-----------------------------------------------------------------------------------------------------------------------
|
||||
# # Ici il faut écrire les conditions sur les tailles selon r et selon time
|
||||
# # donc sur BS_data.shape[0] (time) et BS_data.shape[1] (depth)
|
||||
# #-----------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# # 1- time shape > BS data shape
|
||||
# # <=> data recorded with the frequency are longer than data recorded with the other lower frequencies
|
||||
# if (BS_data.shape[0] > self._BS_raw_data.shape[2]):
|
||||
# self._BS_raw_data = np.append(self._BS_raw_data,
|
||||
# np.array([BS_data[:self._BS_raw_data.shape[2], :].transpose()]),
|
||||
# axis=0)
|
||||
#
|
||||
# # 2- time shape < BS data shape
|
||||
# # <=> data recorded with the frequency are shorter than data recorded with the other lower frequencies
|
||||
# elif BS_data.shape[0] < self._BS_raw_data.shape[2]:
|
||||
# self._BS_raw_data = np.append(self._BS_raw_data[config-1, :, BS_data.shape[0]],
|
||||
# np.array([BS_data.transpose()]),
|
||||
# axis=0)
|
||||
#
|
||||
# # 3- time shape = BS data shape
|
||||
# # <=> data recorded with the frequency have the same duration than data recorded with the other lower frequency
|
||||
# else:
|
||||
# self._BS_raw_data = np.append(self._BS_raw_data, np.array([BS_data.transpose()]), axis=0)
|
||||
#
|
||||
#
|
||||
# print("1. BS_raw_data shape ", self._BS_raw_data.shape)
|
||||
#
|
||||
# # if f == 0:
|
||||
# # print(np.array(data_us_dicts[config][channel]['echo_avg_profile']['data'][0]).shape)
|
||||
# # self._BS_raw_data[f, :, :] = np.array([data_us_dicts[config][channel]['echo_avg_profile']['data'][0]])
|
||||
# # # self._BS_raw_data = np.array([np.reshape(data_us_dicts[config][channel]['echo_avg_profile']['data'],
|
||||
# # # (self._time.shape[1], self._r.shape[1])).transpose()])
|
||||
# # print("self._BS_raw_data.shape ", self._BS_raw_data.shape)
|
||||
# # self._SNR_data = np.array(
|
||||
# # [np.reshape(np.abs(data_us_dicts[config][channel]['snr_doppler_avg_profile']['data']),
|
||||
# # (self._time.shape[1], self._r.shape[1])).transpose()])
|
||||
# # else:
|
||||
# # # self._BS_raw_data = np.append(self._BS_raw_data,
|
||||
# # # np.array(data_us_dicts[config][channel]['echo_avg_profile']['data']),
|
||||
# # # (self._r.shape[1], self._time.shape[1]))]),
|
||||
# # # axis=0)
|
||||
# # # self._BS_raw_data = np.append(self._BS_raw_data,
|
||||
# # # np.array([np.reshape(np.array(
|
||||
# # # data_us_dicts[config][channel]['echo_avg_profile']['data']),
|
||||
# # # (self._time.shape[1], self._r.shape[1])).transpose()]),
|
||||
# # # axis=0)
|
||||
# #
|
||||
# # self._SNR_data = np.append(self._SNR_data,
|
||||
# # np.array([np.reshape(np.array(
|
||||
# # np.abs(data_us_dicts[config][channel]['snr_doppler_avg_profile']['data'])),
|
||||
# # (self._time.shape[1], self._r.shape[1])).transpose()]),
|
||||
# # axis=0)
|
||||
# # # print(self._BS_raw_data.shape)
|
||||
#
|
||||
# # --- US Backscatter raw signal ---
|
||||
#
|
||||
#
|
||||
# # print(len(self._BS_raw_data))
|
||||
# # print(self._BS_raw_data)
|
||||
|
||||
if self._time.shape[1] > self._BS_raw_data.shape[2]:
|
||||
self._time = self._time[:, :self._BS_raw_data.shape[2]]
|
||||
|
|
@ -420,275 +210,39 @@ class AcousticDataLoaderUBSediFlow:
|
|||
self._BS_raw_data = self._BS_raw_data
|
||||
|
||||
self._time = self._time[:, :self._BS_raw_data.shape[2]]
|
||||
print("self._time.shape ", self._time.shape)
|
||||
# print(f"time : {self._time}")
|
||||
# print("****************************")
|
||||
# for i in range(len(self._time[0, :])-1):
|
||||
# print(self._time[0, i+1] - self._time[0, i])
|
||||
# print("****************************")
|
||||
|
||||
print("self._r.shape ", self._r.shape)
|
||||
|
||||
self._freq_text = np.array([str(f) + " MHz" for f in [np.round(f*1e-6, 2) for f in self._freq]])
|
||||
print("self._freq_text ", self._freq_text)
|
||||
print("self._freq_text ", self._freq)
|
||||
|
||||
# self._BS_raw_data = np.array(np.reshape(self._BS_raw_data, (len(self._freq), self._r.shape[1], self._time.shape[1])))
|
||||
print("self._BS_raw_data.shape ", self._BS_raw_data.shape)
|
||||
|
||||
# print("self._SNR_data.shape ", self._SNR_data.shape)
|
||||
# print(self._SNR_data)
|
||||
|
||||
# print("device_name ", device_name, "\n")
|
||||
|
||||
# print("time_begin ", time_begin, "\n")
|
||||
|
||||
# print("time_end ", time_end, "\n")
|
||||
|
||||
# print(f"param_dicts keys {param_us_dicts.keys()} \n")
|
||||
# print(param_us_dicts, "\n")
|
||||
|
||||
# for i in range(len(list(param_us_dicts.keys()))):
|
||||
# print(f"param_us_dicts {i} : {list(param_us_dicts.items())[i]} \n")
|
||||
|
||||
# # print("settings_dict ", settings_dict, "\n")
|
||||
# print(f"keys in data_us_dicts {data_us_dicts[1][1].keys()} \n")
|
||||
# # les clés du dictionnaire data_us_dicts :
|
||||
# # dict_keys(['echo_avg_profile', 'saturation_avg_profile', 'velocity_avg_profile', 'snr_doppler_avg_profile',
|
||||
# # 'velocity_std_profile', 'a1_param', 'a0_param', 'noise_g_high', 'noise_g_low'])
|
||||
|
||||
# print(f"data_us_dicts keys in echo avg profile {data_us_dicts[1][1]['echo_avg_profile'].keys()} \n")
|
||||
# print(f"number of profiles {len(data_us_dicts[1][1]['echo_avg_profile']['data'])} \n")
|
||||
# print(f"number of cells {data_us_dicts[1][1]['echo_avg_profile']['data'][0].shape} \n")
|
||||
|
||||
# self._data_BS = RawAquascatData(self.path_BS_raw_data)
|
||||
|
||||
# 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(type(self._gain_tx))
|
||||
|
||||
# print(["BS - " + f for f in self._freq_text])
|
||||
# print(self._time.shape[0]*self._r.shape[0]*4)
|
||||
|
||||
# print(self._time[np.where(np.floor(self._time) == 175)])
|
||||
# print(np.where((self._time) == 155)[0][0])
|
||||
|
||||
# --- Plot Backscatter US data ---
|
||||
|
||||
# fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
|
||||
# pcm = ax.pcolormesh(self._time[0, :], -self._r[0, :], np.log(self._BS_raw_data[0, :, :]),
|
||||
# cmap='plasma')#, shading='gouraud')
|
||||
# # pcm = ax.pcolormesh(list(range(self._BS_raw_data.shape[2])), list(range(self._BS_raw_data.shape[1])),
|
||||
# # np.log(self._BS_raw_data[0, :, :]),
|
||||
# # cmap='Blues') # , shading='gouraud')
|
||||
# # norm=LogNorm(vmin=np.min(self._BS_raw_data[f, :, :]), vmax=np.max(self._BS_raw_data[f, :, :])), 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')
|
||||
# fig.colorbar(pcm, ax=ax, shrink=1, location='right')
|
||||
# plt.show()
|
||||
|
||||
# fig, ax = plt.subplots(nrows=len(self._freq), ncols=1, layout="constrained")
|
||||
# for f, freq in enumerate(self._freq):
|
||||
# print(f"{f} : {freq} \n")
|
||||
# # pcm = ax[f].imshow(np.log(self._BS_raw_data[f, :, :self._time.shape[1]]),
|
||||
# # cmap='Blues')
|
||||
# # pcm = ax[f].pcolormesh(list(range(self._BS_raw_data.shape[2])), list(range(self._BS_raw_data.shape[1])),
|
||||
# # np.log(self._BS_raw_data[f, :, :]),
|
||||
# # cmap='Blues', shading='gouraud')
|
||||
# pcm = ax[f].pcolormesh(self._time[f, 50:247], -self._r[f, :], np.log(self._BS_raw_data[f, :, 50:247]),
|
||||
# cmap='Blues')#, shading='gouraud')
|
||||
# # norm=LogNorm(vmin=np.min(self._BS_raw_data[f, :, :]), vmax=np.max(self._BS_raw_data[f, :, :])), 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')
|
||||
# fig.colorbar(pcm, ax=ax[:], shrink=1, location='right')
|
||||
# # plt.show()
|
||||
#
|
||||
# # --- Smooth value with savgol_filter ---
|
||||
# BS_smooth = deepcopy(self._BS_raw_data[0, :, :])
|
||||
# for k in range(self._time[0, :].shape[0]):
|
||||
# BS_smooth[:, k] = savgol_filter(BS_smooth[:, k], 10, 2)
|
||||
#
|
||||
# fig1, ax1 = plt.subplots(nrows=1, ncols=1, layout="constrained")
|
||||
# pcm1 = ax1.pcolormesh(self._time[0, :], -self._r[0, :], np.log(BS_smooth[:, :]), cmap='Blues')
|
||||
# fig1.colorbar(pcm1, ax=ax1, shrink=1, location='right')
|
||||
|
||||
# print("find value in depth", np.where(np.abs(self._r - 3.3) == np.min(np.abs(self._r - 3.3))))
|
||||
#
|
||||
# fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
|
||||
# ax.plot(self._r[0, :], self._BS_raw_data[0, :, 766])
|
||||
# plt.show()
|
||||
|
||||
# # --- Plot vertical profile for bottom detection ---
|
||||
# n = 60
|
||||
# t0 = 200
|
||||
# t1 = np.where(np.abs(self._time[0, :] - t0) == np.nanmin(np.abs(self._time[0, :] - t0)))[0][0]
|
||||
# # print(np.abs(self._time[0, :] - 200))
|
||||
# # print(f"x0 = {x0}")
|
||||
# r1 = 98
|
||||
# r2 = 150
|
||||
# fig2, ax2 = plt.subplots(nrows=1, ncols=n, layout="constrained")
|
||||
# for i in range(n):
|
||||
# ax2[i].plot(self._BS_raw_data[0, r1:r2, t1+i], -self._r[0, r1:r2], 'b')
|
||||
# ax2[i].plot(BS_smooth[r1:r2, t1+i], -self._r[0, r1:r2], 'r')
|
||||
# ax2[i].set_xticks([])
|
||||
# if i != 0:
|
||||
# ax2[i].set_yticks([])
|
||||
# plt.show()
|
||||
|
||||
# --- Plot SNR data ---
|
||||
# fig_snr, ax_snr = plt.subplots(nrows=len(self._freq), ncols=1)
|
||||
#
|
||||
# x, y = np.meshgrid(self._time[0, :], self._r[0, :])
|
||||
#
|
||||
# for f, freq in enumerate(self._freq):
|
||||
#
|
||||
# val_min = np.nanmin(abs(self._SNR_data[f, :, :]))
|
||||
# print(f"val_min = {val_min}")
|
||||
# val_max = np.nanmax(self._SNR_data[f, :, :])
|
||||
# print(f"val_max = {val_max}")
|
||||
# if int(val_min) == 0:
|
||||
# val_min = 1e-5
|
||||
# if int(val_max) < 1000:
|
||||
# levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
|
||||
# bounds = [00.1, 1, 2, 10, 100, 1000, 1e6, 1e6 * 1.2]
|
||||
# else:
|
||||
# levels = np.array([00.1, 1, 2, 10, 100, val_max])
|
||||
# bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
|
||||
# norm = BoundaryNorm(boundaries=bounds, ncolors=300)
|
||||
#
|
||||
# print(f"levels = {levels}")
|
||||
# print(f"norm = {norm.boundaries}")
|
||||
#
|
||||
# cf = ax_snr[f].contourf(x, y, self._SNR_data[f, :, :])#, levels, cmap='gist_rainbow', norm=norm)
|
||||
#
|
||||
# ax_snr[f].text(1, .70, self._freq_text[f],
|
||||
# fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
|
||||
# horizontalalignment='right', verticalalignment='bottom',
|
||||
# transform=ax_snr[f].transAxes)
|
||||
#
|
||||
# fig_snr.supxlabel('Time (sec)', fontsize=10)
|
||||
# fig_snr.supylabel('Depth (m)', fontsize=10)
|
||||
# cbar = fig_snr.colorbar(cf, ax=ax_snr[:], shrink=1, location='right')
|
||||
# cbar.set_label(label='Signal to Noise Ratio', rotation=270, labelpad=10)
|
||||
# # cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$'])
|
||||
# plt.show()
|
||||
|
||||
# fig, ax = plt.subplots(nrows=1, ncols=1)
|
||||
# ax.plot(list(range(self._time.shape[1])), self._time[0, :])
|
||||
# # ax.set_ylim(2, 20)
|
||||
# plt.show()
|
||||
|
||||
# print(self.reshape_BS_raw_cross_section())
|
||||
|
||||
# self.reshape_BS_raw_cross_section()
|
||||
# self.reshape_r()
|
||||
# self.reshape_t()
|
||||
# self.compute_r_2D()
|
||||
|
||||
# Lecture du fichier excel
|
||||
|
||||
# path = ("/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data/APAVER_2021/"
|
||||
# "transect_ubsediflow/01-raw_20210519_115128/Raw_data_csv/config_1/"
|
||||
# "echo_avg_profile_1_1_20210519_115128.csv")
|
||||
#
|
||||
# df = pd.read_csv(path, sep="\t")
|
||||
#
|
||||
# arr = []
|
||||
# for column in df.columns:
|
||||
# arr.append(df[column].to_numpy())
|
||||
# # arr = np.append(arr, np.array([df[column].to_numpy()]), axis=0)
|
||||
# arr = arr[1:]
|
||||
# print(len(arr))
|
||||
#
|
||||
# matrix = np.array([arr[0]])
|
||||
# print(matrix.shape)
|
||||
# for i in range(len(arr)-1):
|
||||
# matrix = np.append(matrix, np.array([arr[i]]), axis=0)
|
||||
# print(matrix.shape)
|
||||
|
||||
# fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
|
||||
# pcm = ax.pcolormesh(list(range(matrix.shape[1])), list(range(matrix.shape[0])), np.log(matrix),
|
||||
# cmap='Blues')#, shading='gouraud')
|
||||
# # norm=LogNorm(vmin=np.min(self._BS_raw_data[f, :, :]), vmax=np.max(self._BS_raw_data[f, :, :])), 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')
|
||||
# fig.colorbar(pcm, ax=ax, shrink=1, location='right')
|
||||
# plt.show()
|
||||
|
||||
def reshape_BS_raw_data(self):
|
||||
BS_raw_cross_section = np.reshape(self._BS_raw_data,
|
||||
(self._r.shape[1]*self._time.shape[1], len(self._freq)),
|
||||
order="F")
|
||||
# print(BS_raw_cross_section.shape)
|
||||
return BS_raw_cross_section
|
||||
|
||||
# def reshape_SNR_data(self):
|
||||
# SNR_data = np.reshape(self._SNR_data,
|
||||
# (self._r.shape[1]*self._time.shape[1], len(self._freq)),
|
||||
# order="F")
|
||||
# # print(BS_raw_cross_section.shape)
|
||||
# return SNR_data
|
||||
|
||||
def reshape_r(self):
|
||||
r = np.zeros((self._r.shape[1]*self._time.shape[1], len(self._freq)))
|
||||
for i, _ in enumerate(self._freq):
|
||||
r[:, i] = np.repeat(self._r[i, :], self._time.shape[1])
|
||||
# print(r.shape)
|
||||
return r
|
||||
|
||||
def compute_r_2D(self):
|
||||
r2D = np.zeros((self._freq.shape[0], self._r.shape[1], self._time.shape[1]))
|
||||
for f, _ in enumerate(self._freq):
|
||||
r2D[f, :, :] = np.repeat(np.transpose(self._r[0, :])[:, np.newaxis], self._time.shape[1], axis=1)
|
||||
print("r2D.shape ", r2D.shape)
|
||||
return r2D
|
||||
|
||||
# def compute_r_2D(self):
|
||||
# r2D = np.repeat(self._r, self._time.size, axis=1)
|
||||
# return r2D
|
||||
|
||||
def reshape_t(self):
|
||||
t = np.zeros((self._r.shape[1]*self._time.shape[1], len(self._freq)))
|
||||
for i, _ in enumerate(self._freq):
|
||||
t[:, i] = np.repeat(self._time[i, :], self._r.shape[1])
|
||||
# print(t.shape)
|
||||
return t
|
||||
|
||||
def reshape_t_snr(self):
|
||||
t = np.zeros((self._r.shape[1]*self._time_snr.shape[1], len(self._freq)))
|
||||
for i, _ in enumerate(self._freq):
|
||||
t[:, i] = np.repeat(self._time_snr[i, :], self._r.shape[1])
|
||||
# print(t.shape)
|
||||
return t
|
||||
|
||||
def detect_bottom(self):
|
||||
rmin = 2.5
|
||||
rmax = 3.5
|
||||
|
||||
|
||||
|
||||
# def concatenate_data(self):
|
||||
|
||||
# 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__":
|
||||
# AcousticDataLoaderUBSediFlow(path_BS_raw_data0 + filename0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue