Loader for the data of UBSediFlow is adapted when length in depth (vertical) and time (horizontal) is not the same for each frequencies.

dev-brahim
brahim 2024-02-22 18:16:40 +01:00
parent 343fc27aec
commit bfdbd74720
1 changed files with 181 additions and 76 deletions

View File

@ -174,109 +174,214 @@ class AcousticDataLoaderUBSediFlow:
# self._time_snr = np.append(self._time_snr, time_snr, axis=0)
# # print(f"self._time.shape {self._time.shape}")
# --- US Backscatter raw signal + SNR data ---
# --- 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("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)
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,
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)
#-----------------------------------------------------------------------------------------------------------------------
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[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)
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]}")
# print(f"BS_raw_data shape[2] = {BS_raw_data.shape[2]}")
self._BS_raw_data = np.append(self._BS_raw_data,
BS_data[:, :self._BS_raw_data.shape[1], :self._BS_raw_data.shape[2]],
axis=0)
elif (BS_data.shape[1] < self._BS_raw_data.shape[1]):
self._BS_raw_data = np.append(self._BS_raw_data[:, :BS_data.shape[1], :],
BS_data[:, :, :self._BS_raw_data.shape[2]],
axis=0)
else:
self._BS_raw_data = np.append(self._BS_raw_data,
BS_data[:, :, :self._BS_raw_data.shape[2]],
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)
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]],
BS_data[:, :self._BS_raw_data.shape[1], :],
axis=0)
elif (BS_data.shape[1] < self._BS_raw_data.shape[1]):
self._BS_raw_data = np.append(self._BS_raw_data[:, :BS_data.shape[1], BS_data.shape[2]],
BS_data,
axis=0)
else:
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:
self._BS_raw_data = np.append(self._BS_raw_data, np.array([BS_data.transpose()]), axis=0)
print(f"cas 4 : BS_raw_data shape = {self._BS_raw_data.shape}")
print(f"cas 4 : BS_data shape = {BS_data.shape}")
print("1. BS_raw_data shape ", self._BS_raw_data.shape)
if (BS_data.shape[1] > self._BS_raw_data.shape[1]):
# 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)
self._BS_raw_data = np.append(self._BS_raw_data,
BS_data[:, :self._BS_raw_data.shape[1], :], axis=0)
# --- US Backscatter raw signal ---
elif (BS_data.shape[1] < self._BS_raw_data.shape[1]):
self._BS_raw_data = np.append(self._BS_raw_data[:, :BS_data.shape[1], :],
BS_data, axis=0)
# print(len(self._BS_raw_data))
# print(self._BS_raw_data)
else:
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]]