Extensively commented the 'save_result_in_csv_file' method that I debugged earlier.
parent
4f9d9074ff
commit
f27145f611
|
|
@ -1802,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:
|
||||
|
|
@ -1820,20 +1874,26 @@ class AcousticInversionTab(QWidget):
|
|||
else:
|
||||
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):
|
||||
|
|
@ -1845,17 +1905,30 @@ 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(
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue