Compare commits

...

2 Commits

1 changed files with 120 additions and 13 deletions

View File

@ -552,6 +552,27 @@ class AcousticInversionTab(QWidget):
stg.SSC_fine[data_id] = np.array([])
'''
stg.SSC_fine[data_id] = self.inv_hc.SSC_fine(
zeta=stg.zeta[0],
r2D=stg.depth_2D[data_id][stg.frequencies_for_calibration[0][1]],
VBI=stg.VBI_cross_section[data_id],
freq=stg.frequencies_for_calibration[0][0],
X=stg.X_exponent[0],
j_cross_section=stg.J_cross_section[data_id][0],
alpha_w=np.full(
shape=stg.depth_2D[data_id][
stg.frequencies_for_calibration[0][1]
].shape,
fill_value=stg.water_attenuation[data_id][
stg.frequencies_for_calibration[0][1]
]
)
) #Inversion using the first frequency
'''
stg.SSC_fine[data_id] = self.inv_hc.SSC_fine(
zeta=stg.zeta[1],
r2D=stg.depth_2D[data_id][stg.frequency_for_inversion[1]],
@ -567,19 +588,32 @@ class AcousticInversionTab(QWidget):
stg.frequency_for_inversion[1]
]
)
)
) #Inversion using the second frequency
def compute_SSC_sand(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
stg.SSC_sand[data_id] = np.array([])
'''
stg.SSC_sand[data_id] = self.inv_hc.SSC_sand(
VBI=stg.VBI_cross_section[data_id],
freq=stg.frequencies_for_calibration[0][0],
X=stg.X_exponent,
ks=stg.ks[0]
) #Inversion using the first frequency
'''
stg.SSC_sand[data_id] = self.inv_hc.SSC_sand(
VBI=stg.VBI_cross_section[data_id],
freq=stg.frequencies_for_calibration[1][0],
X=stg.X_exponent,
ks=stg.ks[1]
)
) #Inversion using the second frequency
def plot_SSC_fine(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
@ -694,7 +728,7 @@ class AcousticInversionTab(QWidget):
pcm_SSC_fine, ax=self.axis_SSC_fine, shrink=1,
location='right'
)
cbar_SSC_fine.set_label(label='Fine SSC (g/L', rotation=270, labelpad=15)
cbar_SSC_fine.set_label(label='Fine SSC (g/L)', rotation=270, labelpad=15)
self.figure_SSC_fine.supxlabel("Time (sec)", fontsize=10)
self.figure_SSC_fine.supylabel("Depth (m)", fontsize=10)
@ -1259,7 +1293,7 @@ class AcousticInversionTab(QWidget):
pcm_SSC_sand, ax=self.axis_SSC_sand, shrink=1,
location='right'
)
cbar_SSC_sand.set_label(label='Sand SSC (g/L', rotation=270, labelpad=15)
cbar_SSC_sand.set_label(label='Sand SSC (g/L)', rotation=270, labelpad=15)
self.figure_SSC_sand.supxlabel("Time (sec)", fontsize=10)
self.figure_SSC_sand.supylabel("Depth (m)", fontsize=10)
@ -1768,14 +1802,68 @@ class AcousticInversionTab(QWidget):
)
def save_result_in_csv_file(self, dirname, filename):
d_id = []
t = []
r = []
ssc_fine = []
ssc_sand = []
'''
Comments by Bjarne VINCENT
This function exports the acoustic inversion results to a separate .csv
file. In AcouSed, the SSC fields computed for each dataset are stored
as 2D arrays of size M*P, where 'M' is the number of vertical positions and
'P' is the number of time stamps. The idea is to flatten these arrays (i.e.,
convert them to 1D arrays) in order to export the data as a table.
'''
# Define & initialize the lists of 1D arrays to be written to the .csv
# file. Each of these lists shall form one column in the written .csv
# file. Each list is of length N, where 'N' stands for the number of
# datasets loaded into AcouSed:
d_id = [] #List of the datasets' ID (integers ranging from 0 to N-1)
t = [] #List of time stamps (s)
r = [] #List of vertical positions (m)
ssc_fine = [] #List of flattened fine SSC arrays (g/L)
ssc_sand = [] #List of flattened sand SSC arrays (g/L)
# Loop over all datasets loaded into AcouSed:
for k in range(self.combobox_acoustic_data_choice.count()):
'''
Comments by Bjarne VINCENT
Array-flattening convention: the index spanning the number of vertical
positions runs the fastest, followed by the index spanning the number of
time stamps, followed by the index spanning the number of datasets.
Example of file output:
data_id | time (s) | Depth(m)
0 0.0 0.1
0 0.0 0.2
. . .
. . .
. . .
0 0.0 1.0
0 0.1 0.1
0 0.1 0.2
. . .
. . .
. . .
0 5.0 1.0
1 0.0 0.1
1 0.0 0.2
. . .
. . .
. . .
etc.
'''
# Retrieve the time stamps and vertical positions:
if stg.time_cross_section[k].shape != (0,):
time_data = stg.time_cross_section
else:
@ -1787,19 +1875,25 @@ class AcousticInversionTab(QWidget):
depth_data = stg.depth
# Form the 1D arrays of time stamps and vertical positions
# for the k-th dataset:
time_shape = time_data[k].shape[1]
depth_shape = depth_data[k].shape[1]
d_id += np.repeat(k, depth_shape * time_shape).tolist()
d_id += np.repeat(k, depth_shape * time_shape).tolist() #Flattened array of the current dataset's index
tmp_t = np.repeat(
time_data[k][stg.frequency_for_inversion[1]],
depth_shape
)
) #Flattened array of time stamps
tmp_r = np.zeros(
depth_shape * time_shape
)
) #Initialise the flattened array of vertical positions
# Fill the flattened array of vertical positions:
for i in range(time_shape):
for j in range(depth_shape):
@ -1811,18 +1905,31 @@ class AcousticInversionTab(QWidget):
]
)
# Add the flattened arrays of time stamps and vertical positions to their respective
# lists:
t += tmp_t.tolist()
r += tmp_r.tolist()
# If no fine or sand SSC concentrations have been computed, create empty 2D arrays:
if stg.SSC_fine[k].shape == (0,):
stg.SSC_fine[k] = np.zeros(tmp_r.shape[0])
if stg.SSC_sand[k].shape == (0,):
stg.SSC_sand[k] = np.zeros(tmp_r.shape[0])
# Flatten the fine and sand SSC arrays in a column-major order (i.e., "the first index
# runs the fastest"):
ssc_fine += np.reshape( stg.SSC_fine[k], tmp_r.shape[0], 'F' ).tolist()
ssc_sand += np.reshape( stg.SSC_sand[k], tmp_r.shape[0], 'F' ).tolist()
# Finally, create a Pandas 'DataFrame' with all lists, and write that DataFrame to a .csv file:
results = pd.DataFrame(
{
'acoustic data': d_id,