Compare commits

...

7 Commits

11 changed files with 227 additions and 48 deletions

View File

@ -551,7 +551,11 @@ class ReadTableForOpen:
FROM SedimentsFile
'''
data = self.execute(query)[0]
res = self.execute(query)
if len(res) == 0:
return
data = res[0]
stg.path_fine = data[0]
stg.filename_fine = data[1]
@ -594,6 +598,9 @@ class ReadTableForOpen:
stg.frac_vol_sand = []
stg.frac_vol_sand_cumul = []
if len(data) == 0:
return
for d in data:
stg.sample_fine.append((d[0], d[1]))
stg.distance_from_bank_fine.append(d[2])
@ -642,6 +649,9 @@ class ReadTableForOpen:
'''
data = self.execute(query)
if len(data) == 0:
return
it = iter(data[0])
stg.calib_acoustic_data = next(it)
@ -708,6 +718,9 @@ class ReadTableForOpen:
'''
data = self.execute(query)
if len(data) == 0:
return
it = iter(data[0])
stg.path_calibration_file = next(it)

Binary file not shown.

Binary file not shown.

View File

@ -2502,6 +2502,7 @@ class AcousticDataTab(QWidget):
if self.fig_BS is not None:
self.fig_BS.clear()
plt.close(self.fig_BS)
self.fig_BS, self.axis_BS = plt.subplots(
nrows=stg.freq[file_id].shape[0],
@ -2682,6 +2683,7 @@ class AcousticDataTab(QWidget):
# --- Figure to plot profiles ---
if self.fig_profile is not None:
self.fig_profile.clear()
plt.close(self.fig_profile)
self.fig_profile, self.axis_profile = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.canvas_plot_profile = FigureCanvas(self.fig_profile)

View File

@ -21,6 +21,7 @@
# -*- coding: utf-8 -*-
import os
import gc
import logging
import numpy as np
import pandas as pd
@ -408,7 +409,7 @@ class AcousticInversionTab(QWidget):
self.pushbutton_run_inversion\
.clicked.connect(self.function_run_inversion)
self.pushbutton_save_result\
.clicked.connect(self.save_result_in_excel_file)
.clicked.connect(self.save_result)
self.pushbutton_left_to_begin_fine\
.clicked.connect(self.slider_profile_number_to_begin_fine)
@ -601,6 +602,7 @@ class AcousticInversionTab(QWidget):
if self.figure_SSC_fine is not None:
self.figure_SSC_fine.clear()
plt.close(fig=self.figure_SSC_fine)
self.figure_SSC_fine, self.axis_SSC_fine = plt.subplots(
nrows=1, ncols=1, layout="constrained"
@ -729,6 +731,7 @@ class AcousticInversionTab(QWidget):
if self.figure_vertical_profile_SSC_fine is not None:
self.figure_vertical_profile_SSC_fine.clear()
plt.close(fig=self.figure_vertical_profile_SSC_fine)
fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.figure_vertical_profile_SSC_fine = fig
@ -1013,6 +1016,7 @@ class AcousticInversionTab(QWidget):
else:
if self.figure_measured_vs_inverted_fine is not None:
self.figure_measured_vs_inverted_fine.clear()
plt.close(fig=self.figure_measured_vs_inverted_fine)
fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
@ -1156,6 +1160,7 @@ class AcousticInversionTab(QWidget):
else:
if self.figure_SSC_sand is not None:
self.figure_SSC_sand.clear()
plt.close(fig=self.figure_SSC_sand)
self.figure_SSC_sand, self.axis_SSC_sand = plt.subplots(
nrows=1, ncols=1, layout="constrained"
@ -1283,6 +1288,7 @@ class AcousticInversionTab(QWidget):
if self.figure_vertical_profile_SSC_sand is not None:
self.figure_vertical_profile_SSC_sand.clear()
plt.close(fig=self.figure_vertical_profile_SSC_sand)
fig, ax = plt.subplots(
nrows=1, ncols=1, layout="constrained"
@ -1573,6 +1579,7 @@ class AcousticInversionTab(QWidget):
if self.figure_measured_vs_inverted_sand is not None:
self.figure_measured_vs_inverted_sand.clear()
plt.close(fig=self.figure_measured_vs_inverted_sand)
fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.figure_measured_vs_inverted_sand = fig
@ -1663,12 +1670,20 @@ class AcousticInversionTab(QWidget):
self.figure_measured_vs_inverted_sand.canvas.draw_idle()
def save_result_in_excel_file(self):
if self.combobox_acoustic_data_choice.count() > 0:
name, _ = QFileDialog.getSaveFileName(
def save_result(self):
if self.combobox_acoustic_data_choice.count() <= 0:
return
file_type = {
"CSV Files (*.csv)": (self.save_result_in_csv_file, ".csv"),
"Excel Files (*.xlsx)": (self.save_result_in_excel_file, ".xlsx"),
# "LibreOffice Calc Files (*.ods)": (self.save_result_in_excel_file, ".ods"),
}
name, type_ext = QFileDialog.getSaveFileName(
caption="Save As - Inversion results",
directory="",
filter="Excel Files (*.xlsx)",
filter=";;".join(file_type),
options=QFileDialog.DontUseNativeDialog
)
@ -1677,10 +1692,28 @@ class AcousticInversionTab(QWidget):
dirname = os.path.dirname(name)
filename = os.path.basename(name)
_, ext = os.path.splitext(filename)
os.chdir(dirname)
results = []
fun, t_ext = file_type[type_ext]
if t_ext not in filename:
filename += t_ext
logger.info(f"Export results to {os.path.join(dirname, filename)}")
fun(dirname, filename)
logger.info(f"... export done")
def save_result_in_excel_file(self, dirname, filename):
if ".ods" in filename:
engine = "odf"
else:
engine = 'xlsxwriter'
with pd.ExcelWriter(
os.path.join(dirname, filename),
engine=engine
) as writer:
for k in range(self.combobox_acoustic_data_choice.count()):
if stg.time_cross_section[k].shape != (0,):
time_data = stg.time_cross_section
@ -1705,19 +1738,16 @@ class AcousticInversionTab(QWidget):
for j in range(depth_data[k].shape[1]):
r_id = i * depth_data[k].shape[1] + j
r[r_id] = (
depth_data[k][
r[r_id] = depth_data[k][
int(stg.frequency_for_inversion[1]), j
]
)
if stg.SSC_fine[k].shape == (0,):
stg.SSC_fine[k] = np.zeros(r.shape[0])
if stg.SSC_sand[k].shape == (0,):
stg.SSC_sand[k] = np.zeros(r.shape[0])
results.append(
pd.DataFrame(
result = pd.DataFrame(
{
'Time (sec)': list(t),
'Depth (m)': list(r),
@ -1729,17 +1759,78 @@ class AcousticInversionTab(QWidget):
),
}
)
)
if os.path.splitext(filename)[1] != ".xlsx":
filename += ".xlsx"
gc.collect() # Force garbade collection
with pd.ExcelWriter(
os.path.join(dirname, filename)
) as writer:
for k in range(self.combobox_acoustic_data_choice.count()):
results[k].to_excel(
writer, index=False,
engine='xlsxwriter', na_rep='NA',
result.to_excel(
writer, index=False, na_rep='NA',
sheet_name=stg.data_preprocessed[k],
)
def save_result_in_csv_file(self, dirname, filename):
d_id = []
t = []
r = []
ssc_fine = []
ssc_sand = []
for k in range(self.combobox_acoustic_data_choice.count()):
if stg.time_cross_section[k].shape != (0,):
time_data = stg.time_cross_section
else:
time_data = stg.time
if stg.depth_cross_section[k].shape != (0,):
depth_data = stg.depth_cross_section
else:
depth_data = stg.depth
time_shape = time_data[k].shape[1]
depth_shape = depth_data[k].shape[1]
d_id += np.repeat(k, depth_shape * time_shape).tolist()
tmp_t = np.repeat(
time_data[k][stg.frequency_for_inversion[1]],
depth_shape
)
tmp_r = np.zeros(
depth_shape * time_shape
)
for i in range(time_shape):
for j in range(depth_shape):
r_id = i * depth_shape + j
tmp_r[r_id] = (
depth_data[k][
int(stg.frequency_for_inversion[1]), j
]
)
t += tmp_t.tolist()
r += tmp_r.tolist()
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])
ssc_fine += stg.SSC_fine[k].reshape(tmp_r.shape[0]).tolist()
ssc_sand += stg.SSC_sand[k].reshape(tmp_r.shape[0]).tolist()
results = pd.DataFrame(
{
'acoustic data': d_id,
'Time (sec)': t,
'Depth (m)': r,
'SSC_fine (g/L)': ssc_fine,
'SSC_sand (g/L)': ssc_sand,
}
)
results.to_csv(
os.path.join(dirname, filename),
index=False
)

View File

@ -20,7 +20,9 @@ class NoteTab(QWidget):
''' This class generates a enhanced notepad in Note Tab '''
def _path_icon(self, icon):
return os.path.join("icons", icon)
return os.path.join(
os.path.dirname(__file__), "..", "icons", icon
)
def __init__(self, widget_tab):
super().__init__()

View File

@ -799,6 +799,7 @@ class SampleDataTab(QWidget):
if self.figure_plot_sample_position_on_transect is not None:
self.figure_plot_sample_position_on_transect.clear()
plt.close(self.figure_plot_sample_position_on_transect)
fig, axis = plt.subplots(nrows=1, ncols=1, layout="constrained")
@ -1427,6 +1428,7 @@ class SampleDataTab(QWidget):
if self.figure_total_concentration is not None:
self.figure_total_concentration.clear()
plt.close(self.figure_total_concentration)
self.figure_total_concentration, self.axis_total_concentration \
= plt.subplots(nrows=1, ncols=1, layout="constrained")
@ -1715,6 +1717,7 @@ class SampleDataTab(QWidget):
if self.figure_plot_PSD is not None:
self.figure_plot_PSD.clear()
plt.close(self.figure_plot_PSD)
self.figure_plot_PSD, self.axis_plot_PSD \
= plt.subplots(nrows=1, ncols=2, layout="constrained")

View File

@ -1040,6 +1040,7 @@ class SedimentCalibrationTab(QWidget):
if self.fig_BS is not None:
self.fig_BS.clear()
plt.close(self.fig_BS)
self.fig_BS, self.axis_BS = plt.subplots(
nrows=1, ncols=1, sharex=True, sharey=False,
@ -1407,6 +1408,7 @@ class SedimentCalibrationTab(QWidget):
if self.fig_Mfine is not None:
self.fig_Mfine.clear()
plt.close(self.fig_Mfine)
self.fig_Mfine, self.ax_Mfine = plt.subplots(1, 1, layout="constrained")
self.canvas_Mfine = FigureCanvas(self.fig_Mfine)
@ -2302,6 +2304,7 @@ class SedimentCalibrationTab(QWidget):
if self.fig_FCB is not None:
self.fig_FCB.clear()
plt.close(self.fig_FCB)
self.fig_FCB, self.axis_FCB = plt.subplots(
nrows=1, ncols=1, layout="constrained"

View File

@ -639,7 +639,6 @@ class SignalProcessingTab(QWidget):
self.remove_point_with_snr_filter()
self.compute_averaged_BS_data()
@trace
def compute_noise(self, data_id):
if self._is_correct_shape(stg.BS_stream_bed):
BS_data = stg.BS_stream_bed
@ -865,6 +864,7 @@ class SignalProcessingTab(QWidget):
if self.fig_profile_tail is not None:
self.fig_profile_tail.clear()
plt.close(self.fig_profile_tail)
self.fig_profile_tail, self.axis_profile_tail = \
plt.subplots(nrows=1, ncols=1, layout='constrained')
@ -1157,7 +1157,6 @@ class SignalProcessingTab(QWidget):
self.compute_noise_from_profile_tail_value_compute()
@trace
def compute_noise_from_profile_tail_value_compute(self):
data_id = max(0, self.combobox_acoustic_data_choice.currentIndex())
@ -1232,6 +1231,7 @@ class SignalProcessingTab(QWidget):
if self.fig_noise is not None:
self.fig_noise.clear()
plt.close(self.fig_noise)
self.fig_noise, self.axis_noise = plt.subplots(
nrows=1, ncols=1, layout="constrained"
@ -1285,6 +1285,7 @@ class SignalProcessingTab(QWidget):
if self.fig_SNR is not None:
self.fig_SNR.clear()
plt.close(self.fig_SNR)
self.fig_SNR, self.axis_SNR = plt.subplots(
nrows=stg.freq[data_id].shape[0], ncols=1,
@ -1468,6 +1469,7 @@ class SignalProcessingTab(QWidget):
if self.fig_BS is not None:
self.fig_BS.clear()
plt.close(self.fig_BS)
self.fig_BS, self.axis_BS = plt.subplots(
nrows=stg.freq[data_id].shape[0], ncols=1,
@ -1702,6 +1704,7 @@ class SignalProcessingTab(QWidget):
if self.figure_profile is not None:
self.figure_profile.clear()
plt.close(self.figure_profile)
self.figure_profile, self.axis_profile = plt.subplots(
nrows=1, ncols=1, layout="constrained"

62
packages/README.md Normal file
View File

@ -0,0 +1,62 @@
# Build Windows package on Linux
*This README as tested on Guix with Wine 10.*
## Setup
### Wine
Fist, you need to install Wine:
```shell
# Debian
apt install winehq-stable wine64 winetricks
# Guix
guix install wine64 winetricks
```
Init a new custom wine prefix:
```shell
export WINE_PREFIX=$PWD/wine
wine winecfg
# or use env-wine.sh
./env-wine.sh wine winecfg
```
In `winecfg`, set the windows version to Windows 10 and click ok.
### Install windows software
We need to install 7zip and Python into the wine prefix. You can
install 7zip with the command:
```shell
./env-wine.sh winetricks apps 7zip
```
To install Python, you need to download Python installer for windows
on version 3.10.2. Next use this command to run the installer:
```shell
./env-wine.sh wine <path-to-python-installer-exe>
```
And follow the installation procedure without forget to activate setup
Python PATH. Now this command will work and return 'Python 3.10.2'.
```shell
$ ./env-wine.sh wine python --version
Python 3.10.2
```
## Build package
Now, you can run the scripts to build the windows package:
```shell
$ ./env-wine.sh wine windows.bat
```

View File

@ -3,4 +3,4 @@
export WINEPREFIX=$PWD/wine
export WINEDEBUG=-all
wine $@
$@