Commit 7ab11843 authored by Calmel Blaise's avatar Calmel Blaise
Browse files

Merge remote-tracking branch 'origin/main'

No related merge requests found
Showing with 55 additions and 35 deletions
+55 -35
QRAME.ico 0 → 100644
QRAME.ico

229 KB

......@@ -15,8 +15,8 @@ class Qrame:
def __init__(self):
self.data_brm = None
self.root = tk.Tk()
self.root.geometry('250x520')
self.root.resizable(0, 0)
self.root.geometry('250x535')
self.root.resizable(0, 1)
self.root.title('QRAME') # QRevint ADCP Massive Extraction
self.root.wm_iconbitmap(r'QRAME.ico')
# self.root.wm_attributes("-topmost")
......@@ -36,18 +36,18 @@ class Qrame:
self.choice6 = tk.BooleanVar(value=False)
# Import ADCP data
self.label0 = tk.Label(self.root, text="Import folder ADCP data")
self.label0 = tk.Label(self.root, text="ADCP folder: ***", justify=tk.LEFT)
self.label0.pack(side=tk.TOP, anchor=tk.W, padx=15)
self.import_button = tk.Button(self.root, text='Import Data : ***',
self.import_button = tk.Button(self.root, text='Select ADCP data',
command=lambda: Thread(target=self.import_data).start(),
padx=50, pady=4, height=1, width=10)
self.import_button.pack()
# Import Barème HYDRO 2 data
self.label1 = tk.Label(self.root, text="Import HYDRO2 gaugings file from\nBarème (.dat)",
self.label1 = tk.Label(self.root, text="HYDRO2 file: ***",
justify='left')
self.label1.pack(side=tk.TOP, anchor=tk.W, padx=15)
self.brm_button = tk.Button(self.root, text='Import HYDRO2 : ***',
self.brm_button = tk.Button(self.root, text='Select HYDRO2 file',
command=lambda: Thread(target=self.get_brm_export).start(),
padx=50, pady=4, height=1, width=10)
self.brm_button.pack()
......@@ -140,7 +140,7 @@ class Qrame:
def update_progress_label(self, run=True):
if run:
return f"Current Progress: {self.pb['value']}%"
return f"Current Progress: {int(self.pb['value'])}%"
else:
self.pb['value'] = 0
self.pb.update_idletasks()
......@@ -176,7 +176,8 @@ class Qrame:
self.type_meas = type_meas
self.name_meas = name_meas
self.name_folder = self.path_folder.split('\\')[-1]
self.import_button.config(text=f'{self.name_folder}')
self.label0.config(text=f'ADCP folder: {self.name_folder}')
self.label0.config(wraplength=self.label0.winfo_width())
def get_brm_export(self):
self.data_brm = None
......@@ -212,7 +213,8 @@ class Qrame:
range(len(data_brm['time_start']))]
self.data_brm = data_brm
name_brm = path_brm.split('/')[-1]
self.brm_button.config(text=f'{name_brm}')
self.label1.config(text=f'HYDRO2 file: {name_brm}')
self.label1.config(wraplength=self.label1.winfo_width())
except:
tk.messagebox.showerror(title='Invalid Barème import', message='Please enter a valid Barème import.')
else:
......@@ -363,14 +365,14 @@ class Qrame:
navigation_reference=nav_ref,
run_oursin=True)
default_checked.append(str(len(checked_transect)))
# Remove transect with Delta Q > 75%
# Remove transect with Delta Q > 40%
discharge = meas.mean_discharges(meas)
remove = []
for transect_id in checked_transect:
per_diff = np.abs(((meas.discharge[transect_id].total - discharge['total_mean']) /
discharge['total_mean']) * 100)
if per_diff > 75:
if per_diff > 40 and len(checked_transect) >= 4:
remove.append(checked_transect.index(transect_id))
if remove:
......@@ -428,7 +430,7 @@ class Qrame:
# Compute middle date of gauging
date_mid = [date_start[i] + (date_end[i] - date_start[i]) / 2 for i in
range(len(date_start))]
# Get closest date and its difference
# Get the closest date and its difference
closest_date = []
time_diff = []
for date in date_mid:
......@@ -440,7 +442,7 @@ class Qrame:
# Find if duplicate in selected date
set_duplicate = set(
[x for x in closest_date if closest_date.count(x) > 1 and x is not None])
# Keep closest date, remove other
# Keep the closest date, remove other
for date in set_duplicate:
id_duplicate = [i for i, e in enumerate(closest_date) if e == date]
diff_duplicate = [time_diff[i] for i in id_duplicate]
......@@ -518,18 +520,16 @@ class Qrame:
f'Extrap {extrap_str}{exp_str}]'
data_brm.loc[data_brm['time_mid'] == closest_date[i],
['start', 'end', 'debit', 'incertitude', 'sect_mouillee',
'larg_miroir',
['debit', 'incertitude', 'sect_mouillee', 'larg_miroir',
'vitesse_moyenne', 'commentaire']] = \
[date_hour_start[i], date_hour_end[i], q_list_brm[i], np.round(uq_list[i], 2),
np.round(area_list[i], 2), np.round(width_list[i], 2), np.round(mean_vel[i], 2),
comment]
[q_list_brm[i], np.round(uq_list[i], 2), np.round(area_list[i], 2),
np.round(width_list[i], 2), np.round(mean_vel[i], 2), comment]
else:
comment = f'QRAME add [Transect {current_checked[i]}/{default_checked[i]}, ' \
f'Extrap {extrap_str}{exp_str}]'
data_brm.loc[j] = ['C', 'JGG', name_station, -999, date_day_list[i],
date_hour_start[i], date_hour_end[i], -9990, '', '', '',
date_hour_start[i], date_hour_end[i], -320000, '', '', '',
q_list_brm[i], np.round(uq_list[i], 2), '',
np.round(area_list[i], 2), '', np.round(width_list[i], 2),
np.round(mean_vel[i], 2), '', '', '', comment, 'PC', '', '',
......@@ -537,23 +537,43 @@ class Qrame:
j -= 1
# Update num for new gauging
data_brm = data_brm.sort_values(by=['date', 'start'])
data_brm = data_brm.reset_index(drop=True)
unmatch_index = data_brm.index[data_brm['num'] == -999].tolist()
gaps = [[s, e] for s, e in zip(unmatch_index, unmatch_index[1:]) if s + 1 < e]
edges = iter(unmatch_index[:1] + sum(gaps, []) + unmatch_index[-1:])
unmatch = list(zip(edges, edges))
for start, end in unmatch:
if start == 0:
val_before = '0'
else:
val_before = data_brm.loc[[start - 1], 'num'].values[0]
list_num = [f'{val_before} QRAME{i}' for i in range(end - start + 1)]
data_brm.loc[start:end, 'num'] = list_num
unmatch_row = data_brm.loc[unmatch_index].sort_values(by=['date', 'start'])
len_unmatch = len(str(len(unmatch_index)))
zero = '0'
list_unmatch = [f'Q{zero * (len_unmatch - len(str(i)))}{i}' for i in
range(1, len(unmatch_index) + 1)]
unmatch_row['num'] = list_unmatch
unmatch_row.index = unmatch_index
data_brm.loc[unmatch_index] = unmatch_row
# data_brm_by_date = data_brm.sort_values(by=['date', 'start'])
# data_brm_by_date = data_brm_by_date.rename_axis('sort_date').reset_index()
# data_brm = data_brm.sort_values(by=['date', 'start'])
# data_brm = data_brm.rename_axis('sort_date').reset_index()
# unmatch_index = data_brm.index[data_brm['num'] == -999].tolist()
# len_max_str = len(str(unmatch_index[-1]))
# zero = '0'
# list_unmatch = [f'Q{zero*(len_max_str-len(str(i)))}{i}' for i in range(1, len(unmatch_index)+1)]
# data_brm.loc[unmatch_index, 'num'] = list_unmatch
# data_brm = data_brm.sort_values(by=['sort_date'])
# data_brm = data_brm.reset_index(drop=True)
# gaps = [[s, e] for s, e in zip(unmatch_index, unmatch_index[1:]) if s + 1 < e]
# edges = iter(unmatch_index[:1] + sum(gaps, []) + unmatch_index[-1:])
# unmatch = list(zip(edges, edges))
# for start, end in unmatch:
# if start == 0:
# val_before = '0'
# else:
# val_before = data_brm.loc[[start - 1], 'num'].values[0]
# list_num = [f'{val_before} QRAME{i}' for i in range(end - start + 1)]
# data_brm.loc[start:end, 'num'] = list_num
# Delete time columns
data_brm.drop(['time_start', 'time_end', 'time_mid'], axis=1, inplace=True)
self.label0.config(text=f'Import folder data :')
if j < -1:
tk.messagebox.showinfo(title='New gauging added',
......@@ -572,7 +592,7 @@ class Qrame:
data_brm = pd.DataFrame(
{'C': ['C'] * length, 'JGG': ['JGG'] * length, 'station_name': [self.name_folder] * length,
'num': [''] * length, 'date': date_day_list, 'date_start': date_hour_start,
'date_end': date_hour_end, 'cote': [-9990] * length, 'cote_start': [''] * length,
'date_end': date_hour_end, 'cote': [-320000] * length, 'cote_start': [''] * length,
'cote_end': [''] * length, 'code_station': [''] * length,
'debit': q_list_brm, 'incertitude': np.round(uq_list, 2),
'distance_station': [''] * length, 'sect_mouillee': np.round(area_list, 2),
......@@ -585,8 +605,8 @@ class Qrame:
data_brm = data_brm.reset_index(drop=True)
data_brm['num'] = range_length
data_brm = data_brm.sort_values(by=['num'])
data_brm = data_brm.reset_index(drop=True)
# data_brm = data_brm.sort_values(by=['num'])
# data_brm = data_brm.reset_index(drop=True)
length = len(data_brm)
df = data_brm.to_csv(header=None, index=False, sep=';').strip('\r\n').split('\n')
df_str = [i.strip('\r') for i in df]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment