From e08d769f79646a7d4571fc0508444a08034a5070 Mon Sep 17 00:00:00 2001 From: brahim Date: Mon, 22 Apr 2024 10:56:10 +0200 Subject: [PATCH] Aquascat Data Loader is updated with the Loader of Guillaume Froment (with Dexmes data). Save as and Open actions are added and connected to create_table_for_save_as.py and read_table_for_open.py. Data are saved in sqlite database. Four tables are created : File (acoustic_data (integer) and acoustic file), Measure (acoustic_data, frequencies, kt, nb_profiles, nb_cells and other measurement information), Settings (temperature, tmin, tmax, depth_min, depth_max) and BS_data (backscatter data with time, depth (list of 2D arrays) and BS_raw_data (list of 3D arrays)). 3D arrays are saved with binary (np.tobytes()) in one cell of table BS_data (BLOB type). They are then loaded with np.frombuffer() function. --- Model/AquascatDataLoader.py | 1277 +++++++++++++++++++++++++++-- Model/acoustic_data_loader.py | 6 +- Model/create_table_for_save_as.py | 328 ++++++++ Model/read_table_for_open.py | 157 ++++ View/acoustic_data_tab.py | 287 ++++--- View/mainwindow.py | 136 ++- settings.py | 14 +- 7 files changed, 1986 insertions(+), 219 deletions(-) create mode 100644 Model/create_table_for_save_as.py create mode 100644 Model/read_table_for_open.py diff --git a/Model/AquascatDataLoader.py b/Model/AquascatDataLoader.py index 700d1e2..e2c0885 100644 --- a/Model/AquascatDataLoader.py +++ b/Model/AquascatDataLoader.py @@ -1,3 +1,1113 @@ +# # -*- coding: utf-8 -*- +# """ +# Created on Wen Jun 08 2016 +# +# @author: Adrien Vergne +# """ +# +# ############################################################################### +# # # +# # CLASSES and METHODS for loading AQUASCAT Data # +# # # +# ############################################################################### +# +# # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +# # Adrien VERGNE - Irstea Lyon - 2016 +# # Program Python 3.5 +# # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +# +# +# ############################################################################### +# # LOADING LIBRARIES # +# ############################################################################### +# +# import numpy as np # Matrix scientific computing +# import os # Path / folder access management +# import datetime # for time management +# # Loading binary data +# import struct as st +# import glob +# import pickle +# import time +# +# # ---------------------------------------------------------------------------# +# # ------------------------------ CLASSES -----------------------------------# +# # ---------------------------------------------------------------------------# +# +# class RawAquascatData: +# """ This class loads Aquascat data from Aquascat text file (aqa.txt) or +# Aquascat raw file (.aqa) located in +# +# Data file info +# @ivar path: string, full file location +# @ivar file_name: string, file name +# @ivar folder_name : string, full folder location +# +# Aquascat data +# @ivar NumProfiles: int, number of profiles +# @ivar ProfileRate: int, profile recording rate in Hz +# @ivar Freq: array of float, frequencies in MHz +# @ivar freqText: list of strings, frequencies in text format in MHz +# @ivar At: array of float, transducer radii +# @ivar NumCells: int, number of cells along one profile +# @ivar V: 3 dimensional array of floats, ABS data +# - dim. 0 : r (distance from the transducer) +# - dim. 1 : freq (transducer frequency) +# - dim. 2 : profile (over all the profiles recorded in a burst) +# @ivar r: array, vector column of int, range of the cells in m from +# the transducer +# @ivar cellSize : float, size of the cells in m +# @ivar TxPulseLength: float, length of the pulse in second +# @ivar RxGain: array of float, gain at reception in dB +# @ivar TxGain: array of float, gain at emission in dB +# @ivar Average: int, number of pings averaged in one profile +# @ivar BeamWidth: array of float, width of the acoustic beam in degree +# @ivar Kt: array of float, Kt constant +# @ivar PingRate: int, number of pings per second, in Hz +# @ivar Regime: string, regime name given when using the Aquascat +# """ +# +# def __init__(self, p): +# """ +# @param p: string, full file location path +# """ +# +# # ___________________ File info _______________________________________# +# +# # Source file full location path +# self.path = p +# # Extracting file name +# self.file_name = os.path.basename(self.path) +# # Extracting folder location +# self.folder_name = os.path.dirname(self.path) +# # Extracting beginning time info +# self.date = datetime.datetime(1, 1, 1) +# +# # ________________________ Data _______________________________________# +# +# # Number of profiles +# self.NumProfiles = 0 +# # Profile rate (Hz) +# self.ProfileRate = 0 +# # Transducer frequencies (float) +# self.Freq = np.array([]) +# # Transducer frequencies (string text in MHz) +# self.freqText = [] +# # Transducer radii +# self.At = np.array([]) +# # Number of cells +# self.NumCells = 0 +# # ABS data +# self.V = np.array([]) +# # Cell range data +# self.r = np.array([]) +# # Cell size +# self.cellSize = 0 +# # Pulse length in second +# self.TxPulseLength = 0 +# # Reception gain in dB +# self.RxGain = np.array([]) +# # Gain at emission +# self.TxGain = np.array([]) +# # Averaging +# self.Average = 0 +# # Beam width +# self.BeamWidth = np.array([]) +# # Kt constant +# self.Kt = np.array([]) +# # Ping rate +# self.PingRate = 0 +# # Regime name +# self.Regime = '' +# +# # _____________ Reading and loading Aquascat Data _____________________# +# if p: +# self.date = datetime.datetime(year=np.int(self.file_name[0:4]), +# month=np.int(self.file_name[4:6]), +# day=np.int(self.file_name[6:8]), +# hour=np.int(self.file_name[8:10]), +# minute=np.int(self.file_name[10:12]), +# second=np.int(self.file_name[12:14])) +# +# if self.file_name[-7:] == 'aqa.txt': +# self.load_txt_file() +# +# if self.file_name[-4:] == '.aqa': +# self.load_aqa_file() +# +# def load_txt_file(self): +# # Opening the file ("r" for "read") +# src = open(self.path, "r") +# +# # Line 1 : skipped +# src.readline().rstrip('\n') +# +# # Lines 2-3 : number of profiles +# src.readline().rstrip('\n') # .rstrip('\n') for removing the "end line" +# # character +# +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',')[ +# 0] # string is converted +# +# self.NumProfiles = int(temp) +# +# # Lines 4-5 : profile rate in Hz +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',')[ +# 0] +# self.ProfileRate = temp +# +# # Lines 6-7 : transducer frequencies +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.Freq = temp +# # Creating also an array of strings with the frequencies in MHz +# for i in range(len(self.Freq)): +# self.freqText.append(str(self.Freq[i] / 1e6) + ' MHz') +# +# # Lines 8-9 : transducer radii +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.At = temp +# +# # Lines 10-14 : ABS data +# src.readline().rstrip('\n') +# +# # Reading the lines one by one +# for f in range(len(self.Freq)): +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, +# sep=',') +# # Computing the number of cells +# self.NumCells = int(len(temp) / self.NumProfiles) +# +# # Converting the 1D numpy array to 2D array +# # dim. 0 : r ; dim.1 : profile +# # Have to take the transpose cause numpy reshape function +# # fills the lines one by one, so one profile will fill one +# # line and not one column as we want +# temp = temp.reshape(self.NumProfiles, self.NumCells).T +# +# # stacking the frequency to the already existing array so we get +# # a 3D array where dim. 2 (last dimension) is corresponds to the +# # frequency +# if f == 0: +# self.V = temp +# else: +# self.V = np.dstack((self.V, temp)) +# +# # Finally we exchange axes 1 and 2 so to get dim.1 = frequency and +# # dim. 2 = profile +# self.V = self.V.swapaxes(1, 2) +# +# # Lines 15-19 : Mean ABS over the burst. Not very useful, skipped +# src.readline().rstrip('\n') +# +# # Reading the lines one by one +# for f in range(len(self.Freq)): +# src.readline().rstrip('\n') +# +# # Lines 20-24 : cell range +# src.readline().rstrip('\n') +# # Only reading the first line, they are all the same +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# # Reshaping the array in a column vector +# temp = temp.reshape(self.NumCells, 1) +# self.r = temp +# +# # Computing the cell size +# self.cellSize = self.r[1, 0]-self.r[0, 0] +# +# # Skipping the other r lines +# for f in range(1, len(self.Freq)): +# src.readline() +# +# # Lines 25-26 : pulse length +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',')[ +# 0] +# self.TxPulseLength = temp +# +# # Lines 27-28 : Gain at reception +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.RxGain = temp +# +# # Lines 29-30 : Gain at emission +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.TxGain = temp +# +# # Lines 31-32 : Averaging +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',')[ +# 0] +# self.Average = int(temp) +# +# # Lines 33-34 : Beam width +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.BeamWidth = temp +# +# # Lines 35-36 : Kt +# src.readline().rstrip('\n') +# temp = np.fromstring(src.readline().rstrip('\n'), dtype=float, sep=',') +# self.Kt = temp +# +# # Lines xxx : looking for ping rate +# line = src.readline().rstrip('\n') +# i = 0 +# while line != 'PingRate' and i < 100: +# line = src.readline().rstrip('\n') +# i += 1 +# temp = eval(src.readline().rstrip('\n')) +# self.PingRate = temp +# +# # Lines xxxx : session title +# src.readline().rstrip('\n') +# temp = src.readline().rstrip('\n') +# # Formating the string +# temp = temp.replace(',', '') +# temp = temp.rstrip('\0') +# self.Regime = temp +# +# # Closing the file +# src.close() +# +# def load_aqa_file(self): +# # -------- From G. Fromant 2017 - LEGI, Grenoble (France) ---------- # +# +# # __________________ sub-functions ________________________________ # +# +# def read_next_aquascat1000_header(f, file_size): +# # Reading packet type +# pkt_type_ = f.read(1) +# pkt_type, = st.unpack("B", pkt_type_) +# # Packet version: skipped +# pkt_version_ = f.read(1) +# st.unpack("B", pkt_version_) +# # Reading packet size +# pkt_size_ = f.read(2) +# pkt_size, = st.unpack("H", pkt_size_) +# # Packet checksum: skipped +# pkt_checksum_ = f.read(2) +# st.unpack("H", pkt_checksum_) +# +# if f.tell() == file_size: +# status = 0 +# else: +# status = 1 +# +# return status, pkt_type, pkt_size +# +# def find_aquascat1000_packet(f, type, file_size): +# f.seek(0) +# while f.tell() != file_size: +# status, pkt_type, pkt_size = read_next_aquascat1000_header( +# f, file_size) +# if status == 0: +# break +# elif pkt_type == type: +# break +# else: +# f.seek(2 * pkt_size, 1) +# return status, pkt_size +# +# # Opening the file +# f = open(self.path, 'rb') +# f.seek(0, 2) +# file_size = f.tell() +# f.seek(0) +# ExpType = 'SINGLE' +# +# # Read File Version from File +# status, pkt_size = find_aquascat1000_packet(f, 19, file_size) +# +# if status == 1: +# sdata = [st.unpack("H", f.read(2))[0] for ui in +# range(1, pkt_size + 1)] +# FileVersionMajor = sdata[1] +# FileVersionMinor = sdata[2] +# else: +# FileVersionMajor = 5 +# FileVersionMinor = 0 +# +# del sdata +# +# # Read in the Burst Start Time Information +# status, pkt_size = find_aquascat1000_packet(f, 54, file_size) +# if status == 1: +# sdata = [st.unpack("H", f.read(2))[0] for ui in range(1, 6 + 1)] +# wake_source_ = f.read(2) +# WakeSource, = st.unpack("H", wake_source_) +# burst_number_ = f.read(4) +# BurstNumber, = st.unpack("I", burst_number_) +# junk_ = f.read(2) +# Junk, = st.unpack("H", junk_) +# BurstTime = datetime.datetime(sdata[0], sdata[1], sdata[2], +# sdata[3], sdata[4], sdata[5]) +# else: +# BurstTime = datetime.datetime(0, 0, 0, 0, 0, 0) +# BurstNumber = 0 +# WakeSource = 0 +# +# del sdata +# +# # Deal with reading the personality +# status, pkt_size = find_aquascat1000_packet(f, 53, file_size) +# +# if status == 0: +# print('Error') +# pass +# else: +# pkt_start_pos = f.tell() +# skip_ = f.read(2) +# st.unpack("H", skip_) # Size of Packet +# st.unpack("H", f.read(2)) +# t1, = st.unpack("H", f.read(2)) +# t2, = st.unpack("H", f.read(2)) +# st.unpack("H", f.read(2)) +# LoggerType = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 32 + 1)] +# st.unpack("H", f.read(2)) +# NumAbsChannels, = st.unpack("H", f.read(2)) +# # Number of ABS channels the system supports +# NumAuxChannels, = st.unpack("H", f.read(2)) +# # Number of AUX channels the system supports (8) +# NumAbsTransducers, = st.unpack("H", f.read(2)) +# # Number of ABS Transducer Information that exist in personality table +# +# # Battery capacity (not recorded at this time) +# BatteryCapacity, = st.unpack("f", f.read(4)) +# StandbyPower, = st.unpack("f", f.read(4)) +# ActivePower, = st.unpack("f", f.read(4)) +# +# ############ +# f.seek(pkt_start_pos + 112, 0) +# # Offsets into the packet +# PtrToAuxInfo, = st.unpack("H", f.read(2)) +# PtrToTransducerInfo, = st.unpack("H", f.read(2)) +# +# # Read in the important information for the Aux Channels +# # First Need to assign the multiple dimension arrays +# AuxChannelName = [] +# AuxChannelUnit = [] +# AuxFlags = [] +# AuxNumGain = [] +# AuxCalDate = [] +# AuxNumCoeff = [] +# AuxGainLabel = [] +# AuxGainCoeff = [] +# AuxGainMin = [] +# AuxGainMax = [] +# for i in range(1, NumAuxChannels + 1): +# PtrToThisAux = pkt_start_pos + PtrToAuxInfo * 2 + 400 * (i - 1) +# # Move to the start of the ABS information +# f.seek(PtrToThisAux, 0) +# skip = [st.unpack("H", f.read(2)) for ui in range(1, 2 + 1)] +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 16 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# AuxChannelName = np.append(AuxChannelName, [TTmp2], axis=0) +# st.unpack("H", f.read(2)) +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 8 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# AuxChannelUnit = np.append(AuxChannelUnit, [TTmp2], axis=0) +# st.unpack("H", f.read(2)) +# AuxFlags = np.append(AuxFlags, st.unpack("H", f.read(2))) +# skip = [st.unpack("H", f.read(2)) for ui in range(1, 2 + 1)] +# AuxNumGain = np.append(AuxNumGain, st.unpack("H", f.read(2)), +# axis=0) +# st.unpack("H", f.read(2)) +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 16 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# AuxCalDate = np.append(AuxCalDate, [TTmp2], axis=0) +# st.unpack("H", f.read(2)) +# AuxNumCoeff = np.append(AuxNumCoeff, st.unpack("H", f.read(2)), +# axis=0) +# skip = [st.unpack("H", f.read(2)) for ui in range(1, 5 + 1)] +# +# f.seek(PtrToThisAux + 80, 0) # ensures aligned +# +# AuxGainLabel.append([]) +# AuxGainCoeff.append([]) +# AuxGainMin.append([]) +# AuxGainMax.append([]) +# for j in range(1, int(AuxNumGain[i - 1] + 1)): +# AuxGainLabel[i - 1].append([]) +# AuxGainCoeff[i - 1].append([]) +# AuxGainMin[i - 1].append([]) +# AuxGainMax[i - 1].append([]) +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 4 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# AuxGainLabel[i - 1][j - 1] = np.append( +# AuxGainLabel[i - 1][j - 1], [TTmp2], axis=0) +# [st.unpack("H", f.read(2)) for ui in range(1, 4 + 1)] +# TTmp = [st.unpack("f", f.read(4))[0] for ui in +# range(1, 5 + 1)] +# AuxGainCoeff[i - 1][j - 1] = np.append( +# AuxGainCoeff[i - 1][j - 1], TTmp, axis=0) +# AuxGainMin[i - 1][j - 1] = st.unpack("f", f.read(4))[ +# 0] # Minimum value used in calibration data +# AuxGainMax[i - 1][j - 1] = st.unpack("f", f.read( +# 4)) # Maximum value used in calibration data +# skip = [st.unpack("f", f.read(4)) for ui in +# range(1, 10 + 1)] +# +# # Now Jump to the Transducer Info +# TransducerSerialNum = [] +# TransducerFrequency = [] +# TransducerRadius = [] +# TransducerBeamWidth = [] +# TransducerKt = [] +# for i in range(1, NumAbsTransducers + 1): +# f.seek(pkt_start_pos + PtrToTransducerInfo * 2 + 200 * (i - 1), +# 0) # Move to the start of the ABS information +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 20 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# TransducerSerialNum = np.append(TransducerSerialNum, [TTmp2], +# axis=0) # GV-10 +# st.unpack("H", f.read(2)) +# +# # Transducer frequency in Hz +# TransducerFrequency = np.append(TransducerFrequency, +# st.unpack("f", f.read(4))) +# # Transducer radius in meters +# TransducerRadius = np.append(TransducerRadius, +# st.unpack("f", f.read(4))) +# +# # Transducers beam width in Degrees (3dB beamdidth, derived +# # from acoustic beam pattern) +# TransducerBeamWidth = np.append(TransducerBeamWidth, +# st.unpack("f", f.read(4))[0]) +# +# skip = [st.unpack("f", f.read(4)) for ui in range(1, 4 + 1)] +# +# # Transducer Kt (only if set in the personality) +# TransducerKt = np.append(TransducerKt, +# st.unpack("f", f.read(4))) +# +# # ---------------------------------------------------------------------- +# # Read in the Regime (Logger Set-Up) Information +# # ---------------------------------------------------------------------- +# +# # regime details +# status, pkt_size = find_aquascat1000_packet(f, 21, file_size) +# if 0 == status: +# print('Regime Packet not found abort') +# +# else: +# pkt_start_pos = f.tell() +# # Session Information +# # Not interested in session start time at the moment +# SessionControl = [st.unpack("H", f.read(2)) +# for ui in range(1, 11 + 1)] +# TTmp = [str(st.unpack("s", f.read(1)))[3] for ui in +# range(1, 32 + 1)] +# sss = '' +# TTmp2 = sss.join(TTmp) +# TTmp2 = TTmp2.strip("\\") +# SessionTitle = TTmp2 +# # The Aux channels are sampled at the PingRate divided by +# # the auxPingDiv +# AuxPingDiv, = st.unpack("H", f.read(2)) +# # The serial pressure + Temperature sampling derived as above +# SerialPingDiv, = st.unpack("H", f.read(2)) +# Junk = [st.unpack("H", f.read(2)) for ui in range(1, 2 + 1)] +# # THIS IS INCORRECTLY SAVED BY THE SYSTEM, SHOULD BE 0 or 8 +# NumAuxChans, = st.unpack("H", f.read(2)) +# NumAuxSamples, = st.unpack("I", f.read(4)) +# +# # This is a temp trick to correct---------------------| +# # if NumAuxSamples!=0: +# # NumAuxChans=8 # for NumAuxChans always being 0 +# # # It should be eliminated when corrected by Aquatec---| +# +# Junk = [st.unpack("H", f.read(2)) for ui in range(1, 4 + 1)] +# # Ping rate (base profile rate before averaging) +# PingRate, = st.unpack("H", f.read(2)) +# # This is number of profiles collected prior to averaging +# NumPings, = st.unpack("I", f.read(4)) +# # Number of enabled ABS Channels +# NumAbsTimeSlots, = st.unpack("H", f.read(2)) +# Junk = [st.unpack("H", f.read(2)) for ui in range(1, 3 + 1)] +# +# # These are the offsets into the Packet +# PtrToAuxInfo, = st.unpack("H", f.read(2)) +# PtrToAbsInfo, = st.unpack("H", f.read(2)) +# +# # Calculate Aux Specific Information +# +# # if AuxPingDiv=0 then no aux channels are +# # enabled and NumAuxChannels =0 +# AuxSampleRate = 0 +# if 0 == AuxPingDiv: +# AuxNumSamples = 0 +# NumAuxChans = 0 +# else: +# AuxSampleRate = PingRate / AuxPingDiv +# AuxNumSamples = np.ceil(NumPings / AuxPingDiv) # GV-10 +# if NumAuxChans == 0: +# NumAuxChans = 8 +# +# # Serial Pressure + Temperature information +# if 0 == SerialPingDiv: +# NumSerialSamples = 0 +# SerialSampleRate = 0 +# else: +# NumSerialSamples = np.ceil(NumPings / SerialPingDiv) +# SerialSampleRate = PingRate / SerialPingDiv +# +# # Nothing useful in the channel +# +# # Now read in the ABS Channel information +# +# # Move to the start of the ABS information +# f.seek(pkt_start_pos + PtrToAbsInfo * 2, 0) +# +# AbsComplex = [] +# AbsAverage = [] +# AbsDecimation = [] +# AbsBinLengthMM = [] +# AbsBinLength = [] +# AbsTransducerName = [] +# AbsTransducerRadius = [] +# AbsTransducerBeamWidth = [] +# AbsTransducerKt = [] +# AbsTxFrequency = [] +# AbsRxFrequency = [] +# AbsTxPulseLength = [] +# AbsStartingGain = [] +# AbsTVG = [] +# AbsPowerLevelpc = [] +# AbsPowerLevel = [] +# AbsStartBin = [] +# AbsRxChan = [] +# AbsTxChan = [] +# AbsNumBins = [] +# AbsNumProfiles = [] +# AbsProfileRate = [] +# AbsBinRange = [] +# for j in range(1, NumAbsTimeSlots + 1): +# AbsBinRange.append([]) +# # TransducerRadius = np.append(TransducerRadius, +# # st.unpack("f",f.read(4))) # In meters +# Tmp, = st.unpack("H", f.read(2)) +# # For magnitude=0,complex=2 +# AbsComplex = np.append(AbsComplex, Tmp & 2) +# # No of bursts averaged before saving +# AbsAverage = np.append(AbsAverage, st.unpack("H", f.read(2))) +# # Raw sampling rate along a profile is 19.2MHz, AbsDecimation i +# AbsDecimation = np.append(AbsDecimation, st.unpack("H", +# f.read(2))) +# # Converts to bin size in mm based on speed 1500ms-1 +# AbsBinLengthMM = np.append( +# AbsBinLengthMM, 1.25 * 2 ** AbsDecimation[j - 1]) +# # Stored as time in seconds +# AbsBinLength = AbsBinLengthMM[j - 1] / 1500 +# +# # Using the Trasnducer ID copy the relevant data across +# # Used to look up transducer information from personality +# TransducerId, = st.unpack("H", f.read(2)) +# TransducerId = TransducerId + 1 +# +# AbsTransducerName = np.append( +# AbsTransducerName, TransducerSerialNum[TransducerId - 1]) +# # Transducer radius in m +# AbsTransducerRadius = np.append( +# AbsTransducerRadius, TransducerRadius[TransducerId - 1]) +# # Transducer beam width in degs +# AbsTransducerBeamWidth = np.append( +# AbsTransducerBeamWidth, +# TransducerBeamWidth[TransducerId - 1]) +# AbsTransducerKt = np.append(AbsTransducerKt, +# TransducerKt[TransducerId - 1]) +# +# AbsTxFrequency = np.append(AbsTxFrequency, +# st.unpack("f", f.read(4))) # In Hz +# AbsRxFrequency = np.append(AbsRxFrequency, +# st.unpack("f", f.read(4))) # In Hz +# +# # Pulse length in seconds +# AbsTxPulseLength = np.append( +# AbsTxPulseLength, st.unpack("f", f.read(4))) +# Junk = st.unpack("f", f.read(4)) +# # Gain in dB with reference to default (built-in) Gain of system +# AbsStartingGain = np.append( +# AbsStartingGain, st.unpack("f", f.read(4))) +# # In dB / bin where first bin has StartingGain (not used, =0) +# AbsTVG = np.append(AbsTVG, st.unpack("f", f.read(4))) +# powerlevel, = st.unpack("H", f.read(2)) +# # Power Level in % of Maximum +# AbsPowerLevelpc = np.append(AbsPowerLevelpc, +# 100 / 2 ** (2 * powerlevel)) +# AbsPowerLevel = np.append(AbsPowerLevel, -20 * np.log10( +# 2 ** powerlevel)) # Power Level in dB relative to Maximum Power +# # Number of Bins from Start of Tx pulse before recording +# AbsStartBin = np.append(AbsStartBin, st.unpack("H", f.read(2))) +# # Number of Bins recorded +# AbsNumBins = np.append(AbsNumBins, st.unpack("H", f.read(2))) +# # Indicates which channel on AQUAscat used for TX +# AbsRxChan = np.append(AbsRxChan, st.unpack("B", f.read(1))) +# # Indicates which channel on AQUAscat used for RX +# AbsTxChan = np.append(AbsTxChan, st.unpack("B", f.read(1))) +# +# Junk = [st.unpack("H", f.read(2)) for ui in range(1, 12 + 1)] +# # Calculate the number of profiles that should be recorded +# # for this channel +# AbsNumProfiles = np.append(AbsNumProfiles, +# NumPings / AbsAverage[j - 1]) +# # Calculate the stored profile rate +# AbsProfileRate = np.append(AbsProfileRate, +# PingRate / AbsAverage[j - 1]) +# +# AbsBinRange[j - 1] = np.append( +# AbsBinRange[j - 1], +# np.array([np.arange(( +# AbsStartBin[j - 1]), +# (AbsStartBin[j - 1] + +# AbsNumBins[j - 1]))]) * +# AbsBinLengthMM[j - 1] / 1000) # in m -- +# +# # --------------------------------------------------------------------- +# # Now deal with reading in the data +# # --------------------------------------------------------------------- +# +# # Allocate Memory for the Data +# AuxData = np.zeros((int(AuxNumSamples), NumAuxChans)) +# AbsData = np.zeros((int(AbsNumBins[0]), int(AbsNumProfiles[0]), +# int(NumAbsTimeSlots)), dtype=float, order='C') +# PressTempData = np.zeros((NumSerialSamples, 2)) +# +# AuxIndex = 0 +# SerIndex = 0 +# AbsIndex = np.zeros((NumAbsTimeSlots, 1)) +# f.seek(0, 0) +# +# # Now Read in all the Data +# +# while (f.tell() != file_size): # 0 == feof(fid)) +# status, pktType, pkt_size = read_next_aquascat1000_header(f, +# file_size) +# +# if 1 == status: +# +# if pktType == 22: +# +# # switch(pktType) +# +# # Case 22: Data were saved as magnitude values +# # (normalize by 65536) +# +# # case (22) +# chan = st.unpack("H", f.read(2))[0] + 1 +# AbsIndex[chan - 1] = AbsIndex[ +# chan - 1] + 1 # Increase the Index +# Tmp = [st.unpack("H", f.read(2))[0] for ui in +# np.arange(1, AbsNumBins[chan - 1] + 1)] +# newList = [x / 65536 for x in Tmp] +# AbsData[0:int(AbsNumBins[0]), +# int(AbsIndex[chan - 1] - 1), +# int(chan - 1)] = np.array(newList[:]) +# +# # Case 41: Data were saved as Complex values +# # (normalize by 32768) +# +# elif pktType == 41: # case (41) +# chan = st.unpack("H", f.read(2))[0] + 1 +# AbsIndex[chan - 1] = AbsIndex[ +# chan - 1] + 1 # Increase the Index +# Tmp = [st.unpack("h", f.read(2))[0] for ui in +# np.arange(1, 2 * AbsNumBins[chan - 1] + 1)] +# sss = [x / 32768 for x in Tmp] +# AbsData[:, np.int(AbsIndex[chan - 1]), +# int(chan - 1)] = np.array(sss) +# +# # Case 46: Auxiliary Channel Data +# +# elif pktType == 46: # case (46) +# temp = st.unpack("H", f.read(2))[0] # Gain settings +# AuxGain = [(temp & 3) + 1, ((temp >> 2) & 3) + 1, +# ((temp >> 4) & 3) + 1, ((temp >> 6) & 3) + 1, 1, +# 1, 1, 1] +# Junk = st.unpack("H", f.read(2))[0] # Flags +# AuxIndex = AuxIndex + 1 +# Tmp = [st.unpack("H", f.read(2))[0] for ui in +# np.arange(1, NumAuxChans + 1)] +# try: +# AuxData[AuxIndex - 1, 0:NumAuxChans] = Tmp[:] +# except IndexError: +# pass +# +# # Case 55: External Pressure Channel for upgraded ABS system - +# # details to be provided +# +# elif pktType == 55: # case (55) +# chan = st.unpack("H", f.read(2))[0] + 1 +# SerIndex = SerIndex + 1 # Increase the Index +# Tmp = [st.unpack("f", f.read(4))[0] for ui in +# np.arange(1, 2 + 1)] +# PressTempData[SerIndex - 1, :] = Tmp[:] +# +# else: # otherwise +# f.seek(pkt_size * 2, 1) +# +# +# for i in range(0, NumAuxChans): +# if not AuxGainCoeff[:][i]: +# coeff = np.array(AuxGainCoeff[:][0]) +# AuxGainCoeff[:][i].append(coeff[0] * 0) +# +# # Matlab orders polynomial coeff opposite to Aquatec +# coeff = np.array(AuxGainCoeff[:][i]) +# coeff = coeff.reshape(1, 5) +# coeff = np.fliplr(coeff) +# coeff = coeff.reshape(5) +# AuxData[:, i] = np.polyval(coeff, AuxData[:, i]) +# +# # Need to apply calibration coefficients for the Aux Channels, +# # now that the gain is fixed, auto gain is not supported. +# # Therefore will use last value +# +# ####TO BE DONE USING ACTUAL AUXDATA +# if NumAuxChans == 0: +# AuxData = [] +# +# # ---------------- Add by Adrien Vergne: filling the class ---------- # +# # Number of profiles +# self.NumProfiles = int(AbsNumProfiles[0]) +# # Profile rate +# self.ProfileRate = AbsProfileRate[0] +# # Frequencies +# self.Freq = AbsTxFrequency +# # Frequencies in text format +# for i in range(len(self.Freq)): +# self.freqText.append(str(self.Freq[i] / 1e6) + ' MHz') +# # Transducer radius +# self.At = AbsTransducerRadius +# # Backscatter data +# self.V = AbsData +# # Changing axis order: axis 0 range, axis1 frequency, axis 2 profile +# self.V = self.V.swapaxes(2, 1) +# # Range cells +# self.r = AbsBinRange[0] +# self.r = np.reshape(self.r, (np.size(self.r), 1)) +# # Number of cells +# self.NumCells = np.size(self.r) +# # Cell size +# self.cellSize = self.r[1, 0] - self.r[0, 0] +# # Pulse length +# self.TxPulseLength = AbsTxPulseLength[0] +# # Received gain +# self.RxGain = AbsStartingGain +# # Emitted gain +# self.TxGain = np.round(AbsPowerLevel, 3) +# # Averaging +# self.Average = AbsAverage[0] +# # Beam width +# self.BeamWidth = AbsTransducerBeamWidth +# # Kt +# self.Kt = AbsTransducerKt +# # Ping rate +# self.PingRate = PingRate +# # Session title +# self.Regime = SessionTitle +# +# f.close # Close the *.aqa data file +# +# +# class MeanAquascatProfile: +# """ This class creates an object that contains several data of the mean +# profile computed for one burst +# @ivar file_name: string, name of the raw data file +# @ivar Freq: list of float, frequencies +# @ivar freqText: list of strings, freq in text in MHz +# @ivar NumProfiles: int, number of profiles averaged +# @ivar r: array of float, range cells for the profile +# @ivar rMin: int, minimum range +# @ivar rMax: int, maximum range +# @ivar V: 2D array of float, ABS mean data +# @ivar Average_method: string, 'simple' or 'quadratic' +# @ivar Rx: list of received gain (one for each frequency) +# @ivar Tx: list of emission gain (one for each frequency) +# @ivar average : int, number of pings averaged per profile in the +# initial burst +# @ivar pulseLength: array of floats, length of the pulse in second +# """ +# +# def __init__(self): +# +# # File name of the raw data +# self.file_name = '' +# # Frequencies +# self.Freq = [] +# # Frequencies in text format +# self.freqText = [] +# # Number of profiles averaged +# self.NumProfiles = 0 +# # Range cells +# self.r = np.array([]) +# # Minimum range +# self.rMin = 0 +# # Maximum range +# self.rMax = 0 +# # ABS data +# self.V = np.array([]) +# # Averaging method +# self.Average_method = '' +# # Reception gain +# self.Rx = [] +# # Emission gain +# self.Tx = [] +# # number of pings averaged per profile in the intial burst +# self.average = 0 +# # pulse length (s) +# self.pulseLength = 0 +# +# def compute_mean(self, abs_raw, r_min=0, r_max=-1, mean='quadratic'): +# """This function computes a mean backscatter profile from the +# raw data abs_raw, between r_min and r_max, using average method +# 'quadratic' or 'simple'""" +# # Filling the profile medata +# self.file_name = abs_raw.file_name +# self.Freq = abs_raw.Freq +# self.freqText = abs_raw.freqText +# self.NumProfiles = abs_raw.NumProfiles +# self.Rx = abs_raw.RxGain +# self.Tx = abs_raw.TxGain +# self.average = abs_raw.Average +# self.pulseLength = abs_raw.TxPulseLength +# +# # Filling r values +# if r_min == 0: +# ind_rmin = 0 +# else: +# ind_rmin = np.where(abs_raw.r <= r_min)[0][-1] +# if r_max == -1: +# ind_rmax = abs_raw.r.size +# else: +# ind_rmax = np.where(abs_raw.r >= r_max)[0][0] +# self.r = abs_raw.r[ind_rmin:ind_rmax + 1] +# self.rMin = self.r[0][0] +# self.rMax = self.r[-1][0] +# +# # Filling V values +# if mean == 'quadratic': +# self.Average_method = 'quadratic' +# self.V = np.sqrt( +# np.nanmean(abs_raw.V[ind_rmin:ind_rmax + 1, :, :] ** 2, +# axis=2)) +# elif mean == 'simple': +# self.Average_method = 'simple' +# self.V = np.nanmean(abs_raw.V[ind_rmin:ind_rmax + 1, :, :], axis=2) +# else: +# raise ValueError("mean should be 'quadratic' or 'simple'") +# +# def write_txt_file(self, path): +# """ This method allows to write the mean profile data in a +# text file""" +# +# # Opening the text file to write in +# file = open(path, "w") +# +# # Writing the parameters +# file.write("AQUAscat mean ABS profile\n\n") +# +# # Burst name +# file.write("Initial burst name\n") +# file.write(self.file_name + '\n\n') +# +# # Frequencies +# file.write('Freq\n') +# for i in self.Freq[0:-1]: +# file.write('%s, ' % i) +# file.write(str(self.Freq[-1])+'\n\n') +# +# # Frequencies in text format +# file.write('Freq in text format\n') +# for i in self.freqText[0:-1]: +# file.write(i + ', ') +# file.write(self.freqText[-1]+'\n\n') +# +# # Number of profiles averaged +# file.write('Number of profiles averaged\n') +# file.write('%s \n\n' % self.NumProfiles) +# +# # Range cells +# file.write('r\n') +# for i in self.r[0:-1]: +# file.write('%s, ' % i[0]) +# file.write('%s' % self.r[-1][0]) +# file.write('\n\n') +# +# # Minimum range +# file.write('rMin\n') +# file.write(str(self.rMin) + '\n\n') +# +# # Maximum range +# file.write('rMax\n') +# file.write(str(self.rMax) + '\n\n') +# +# # ABS data +# file.write('V\n') +# for f in range(len(self.Freq)): +# for i in self.V[0:-1, f]: +# file.write('%s, ' % i) +# file.write(str(self.V[-1, f])+'\n') +# file.write('\n') +# +# # Reception gain +# file.write('Rx gain\n') +# for i in self.Rx[0:-1]: +# file.write('%s, ' % i) +# file.write(str(self.Rx[-1])+'\n\n') +# +# # Transmission gain +# file.write('Tx gain\n') +# for i in self.Tx[0:-1]: +# file.write('%s, ' % i) +# file.write(str(self.Tx[-1])+'\n\n') +# +# # Number of pings average +# file.write("Nb pings averaged in 1 profile\n") +# file.write(str(self.average) + '\n\n') +# +# # Pulse length +# file.write("Pulse length (s)\n") +# file.write(str(self.pulseLength) + '\n\n') +# +# file.close() +# +# def load_txt_file(self, path): +# """ This method allows to load the mean profile data from a +# text file""" +# +# # Opening the text file to write in +# file = open(path, "r") +# +# # Line 1 and 2: skipped +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# +# # Lines 3-4 : initial burst name +# file.readline().rstrip('\n') # .rstrip('\n') for removing the "end +# # line" character +# temp = file.readline().rstrip('\n') +# self.file_name = temp +# +# # Lines 6-7 : frequencies +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# self.Freq = temp +# +# # Lines 9-10 : frequencies in text format +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = file.readline().rstrip('\n') +# self.freqText = temp.split(sep=', ') +# +# # Line 12 - 13 : Number of profiles averaged +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = eval(file.readline().rstrip('\n')) +# self.NumProfiles = temp +# +# # Lines 15-16 : range data +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# # Reshaping the array in a column vector +# temp = temp.reshape(len(temp), 1) +# self.r = temp +# +# # Lines 18-19 : minimum range +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = eval(file.readline().rstrip('\n')) +# self.rMin = temp +# +# # Lines 21-22 : maximum range +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = eval(file.readline().rstrip('\n')) +# self.rMax = temp +# +# # Lines 24 --- ABS data +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# # Reading the lines one by one +# for f in range(len(self.Freq)): +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, +# sep=', ') +# +# if f == 0: +# self.V = temp +# else: +# # Adding a column +# self.V = np.c_[self.V, temp] +# +# # Rx gain +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# self.Rx = temp +# +# # Tx gain +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# self.Tx = temp +# +# # Number of pings averaged +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# self.average = temp +# +# # Pulse length +# file.readline().rstrip('\n') +# file.readline().rstrip('\n') +# temp = np.fromstring(file.readline().rstrip('\n'), dtype=float, sep=',') +# self.pulseLength = temp +# +# file.close() +# +# # ------------------------- Test --------------------------------------# +# start_time = time.time() +# +# if __name__ == "__main__": +# # path1 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa' +# path1 = r'//home/brahim.moudjed/Documents/3 Software_Project/river_inversion_project/Data/Aquascat data test/20171213135800.aqa' +# data1 = RawAquascatData(path1) +# +# # path2 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa.txt' +# path2 = r'//home/brahim.moudjed/Documents/3 Software_Project/river_inversion_project/Data/Aquascat data test/20171213135800.txt' +# data2 = RawAquascatData(path2) +# +# print(data1.PingRate) +# print(data2.PingRate) +# +# print("Computational time: %.2f min" %((time.time() - start_time)/60) ) + + +# ********************************************************************************************************************** +# ********************************************************************************************************************** +# ********************************************************************************************************************** + # -*- coding: utf-8 -*- """ Created on Wen Jun 08 2016 @@ -23,13 +1133,14 @@ Created on Wen Jun 08 2016 import numpy as np # Matrix scientific computing import os # Path / folder access management -import datetime # for time management +import datetime # for time management # Loading binary data import struct as st import glob import pickle import time + # ---------------------------------------------------------------------------# # ------------------------------ CLASSES -----------------------------------# # ---------------------------------------------------------------------------# @@ -122,12 +1233,12 @@ class RawAquascatData: # _____________ Reading and loading Aquascat Data _____________________# if p: - self.date = datetime.datetime(year=np.int(self.file_name[0:4]), - month=np.int(self.file_name[4:6]), - day=np.int(self.file_name[6:8]), - hour=np.int(self.file_name[8:10]), - minute=np.int(self.file_name[10:12]), - second=np.int(self.file_name[12:14])) + self.date = datetime.datetime(year=int(self.file_name[0:4]), + month=int(self.file_name[4:6]), + day=int(self.file_name[6:8]), + hour=int(self.file_name[8:10]), + minute=int(self.file_name[10:12]), + second=int(self.file_name[12:14])) if self.file_name[-7:] == 'aqa.txt': self.load_txt_file() @@ -215,7 +1326,7 @@ class RawAquascatData: self.r = temp # Computing the cell size - self.cellSize = self.r[1, 0]-self.r[0, 0] + self.cellSize = self.r[1, 0] - self.r[0, 0] # Skipping the other r lines for f in range(1, len(self.Freq)): @@ -278,7 +1389,7 @@ class RawAquascatData: # __________________ sub-functions ________________________________ # - def read_next_aquascat1000_header(f, file_size): + def readNextAQUAscat1000Header(f, file_size): # Reading packet type pkt_type_ = f.read(1) pkt_type, = st.unpack("B", pkt_type_) @@ -302,7 +1413,7 @@ class RawAquascatData: def find_aquascat1000_packet(f, type, file_size): f.seek(0) while f.tell() != file_size: - status, pkt_type, pkt_size = read_next_aquascat1000_header( + status, pkt_type, pkt_size = readNextAQUAscat1000Header( f, file_size) if status == 0: break @@ -682,95 +1793,107 @@ class RawAquascatData: AbsNumBins[j - 1]))]) * AbsBinLengthMM[j - 1] / 1000) # in m -- - # --------------------------------------------------------------------- + # -------------------------------------------------------------------- # Now deal with reading in the data - # --------------------------------------------------------------------- + # -------------------------------------------------------------------- # Allocate Memory for the Data - AuxData = np.zeros((int(AuxNumSamples), NumAuxChans)) - AbsData = np.zeros((int(AbsNumBins[0]), int(AbsNumProfiles[0]), - int(NumAbsTimeSlots)), dtype=float, order='C') + AuxData = np.zeros((int(AuxNumSamples), int(NumAuxChans))) + AbsData = np.zeros((int( + AbsNumBins[0]), int( + AbsNumProfiles[0]), int( + NumAbsTimeSlots)), dtype=float, order='C') PressTempData = np.zeros((NumSerialSamples, 2)) AuxIndex = 0 SerIndex = 0 - AbsIndex = np.zeros((NumAbsTimeSlots, 1)) + AbsIndex = np.zeros((NumAbsTimeSlots, 1)) - 1 f.seek(0, 0) - # Now Read in all the Data - + # Now Read in all the Data while (f.tell() != file_size): # 0 == feof(fid)) - status, pktType, pkt_size = read_next_aquascat1000_header(f, - file_size) - + status, pktType, pktSize = readNextAQUAscat1000Header(f, file_size) if 1 == status: - if pktType == 22: - - # switch(pktType) - - # Case 22: Data were saved as magnitude values - # (normalize by 65536) - - # case (22) chan = st.unpack("H", f.read(2))[0] + 1 - AbsIndex[chan - 1] = AbsIndex[ - chan - 1] + 1 # Increase the Index - Tmp = [st.unpack("H", f.read(2))[0] for ui in - np.arange(1, AbsNumBins[chan - 1] + 1)] + # Increase the Index + AbsIndex[chan - 1] = AbsIndex[chan - 1] + 1 + Tmp = [st.unpack( + "H", f.read(2))[0] for ui in np.arange( + 1, AbsNumBins[chan - 1] + 1)] newList = [x / 65536 for x in Tmp] - AbsData[0:int(AbsNumBins[0]), - int(AbsIndex[chan - 1] - 1), - int(chan - 1)] = np.array(newList[:]) + AbsData[0:int(AbsNumBins[0]), int( + AbsIndex[chan - 1] - 1), int( + chan - 1)] = np.array(newList[:]) # Case 41: Data were saved as Complex values # (normalize by 32768) - - elif pktType == 41: # case (41) + # case (41) + elif pktType == 41: chan = st.unpack("H", f.read(2))[0] + 1 - AbsIndex[chan - 1] = AbsIndex[ - chan - 1] + 1 # Increase the Index - Tmp = [st.unpack("h", f.read(2))[0] for ui in - np.arange(1, 2 * AbsNumBins[chan - 1] + 1)] + # Increase the Index + + AbsIndex[chan - 1] = AbsIndex[chan - 1] + 1 + Tmp = [st.unpack( + "h", f.read(2))[0] for ui in np.arange( + 1, 2 * AbsNumBins[chan - 1] + 1)] sss = [x / 32768 for x in Tmp] - AbsData[:, np.int(AbsIndex[chan - 1]), - int(chan - 1)] = np.array(sss) + + AbsData[:, int( + AbsIndex[chan - 1]), int(chan - 1)] = np.abs( + np.array(sss[0::2]) + complex(0, 1) * np.array(sss[1::2])) # Case 46: Auxiliary Channel Data - elif pktType == 46: # case (46) - temp = st.unpack("H", f.read(2))[0] # Gain settings - AuxGain = [(temp & 3) + 1, ((temp >> 2) & 3) + 1, - ((temp >> 4) & 3) + 1, ((temp >> 6) & 3) + 1, 1, - 1, 1, 1] - Junk = st.unpack("H", f.read(2))[0] # Flags + # case (46) + elif pktType == 46: + # Gain settings + temp = st.unpack("H", f.read(2))[0] + AuxGain = [(temp & 3) + 1, ((temp >> 2) & 3) + 1, ( + (temp >> 4) & 3) + 1, ( + (temp >> 6) & 3) + 1, 1, 1, 1, 1] + # Flags + Junk = st.unpack("H", f.read(2))[0] AuxIndex = AuxIndex + 1 - Tmp = [st.unpack("H", f.read(2))[0] for ui in - np.arange(1, NumAuxChans + 1)] - try: - AuxData[AuxIndex - 1, 0:NumAuxChans] = Tmp[:] - except IndexError: + Tmp = [st.unpack( + "H", f.read(2))[0] for ui in np.arange( + 1, NumAuxChans + 1)] + + if AuxIndex == AuxNumSamples + 1: + AuxIndex = AuxIndex - 1 pass + else: + AuxData[AuxIndex - 1, 0:NumAuxChans] = Tmp[:] + # AuxData[AuxIndex-1,0:NumAuxChans] = Tmp[:] - # Case 55: External Pressure Channel for upgraded ABS system - - # details to be provided + # Case 55: External Pressure Channel for upgraded + # ABS system - details to be provided - elif pktType == 55: # case (55) + # case (55) + elif pktType == 55: chan = st.unpack("H", f.read(2))[0] + 1 - SerIndex = SerIndex + 1 # Increase the Index - Tmp = [st.unpack("f", f.read(4))[0] for ui in - np.arange(1, 2 + 1)] + # Increase the Index + SerIndex = SerIndex + 1 + Tmp = [st.unpack( + "f", f.read(4))[0] for ui in np.arange(1, 2 + 1)] PressTempData[SerIndex - 1, :] = Tmp[:] else: # otherwise - f.seek(pkt_size * 2, 1) + f.seek(pktSize * 2, 1) + print('Summary of Data Imported') + + for j in range(1, NumAbsTimeSlots + 1): + print('Timeslot {} Total Profiles = {}'.format(j - 1, AbsIndex[j - 1])) + + print('Total Aux Samples = {}'.format(AuxIndex)) for i in range(0, NumAuxChans): if not AuxGainCoeff[:][i]: coeff = np.array(AuxGainCoeff[:][0]) AuxGainCoeff[:][i].append(coeff[0] * 0) + # coeff = AuxGainCoeff(:,AuxGain(i),i) # Matlab orders polynomial coeff opposite to Aquatec coeff = np.array(AuxGainCoeff[:][i]) coeff = coeff.reshape(1, 5) @@ -778,11 +1901,9 @@ class RawAquascatData: coeff = coeff.reshape(5) AuxData[:, i] = np.polyval(coeff, AuxData[:, i]) - # Need to apply calibration coefficients for the Aux Channels, - # now that the gain is fixed, auto gain is not supported. - # Therefore will use last value + # Need to apply calibration coefficients for the Aux Channels, now that the + # gain is fixed, auto gain is not supported. Therefore will use last value - ####TO BE DONE USING ACTUAL AUXDATA if NumAuxChans == 0: AuxData = [] @@ -909,7 +2030,7 @@ class MeanAquascatProfile: self.Average_method = 'quadratic' self.V = np.sqrt( np.nanmean(abs_raw.V[ind_rmin:ind_rmax + 1, :, :] ** 2, - axis=2)) + axis=2)) elif mean == 'simple': self.Average_method = 'simple' self.V = np.nanmean(abs_raw.V[ind_rmin:ind_rmax + 1, :, :], axis=2) @@ -934,13 +2055,13 @@ class MeanAquascatProfile: file.write('Freq\n') for i in self.Freq[0:-1]: file.write('%s, ' % i) - file.write(str(self.Freq[-1])+'\n\n') + file.write(str(self.Freq[-1]) + '\n\n') # Frequencies in text format file.write('Freq in text format\n') for i in self.freqText[0:-1]: file.write(i + ', ') - file.write(self.freqText[-1]+'\n\n') + file.write(self.freqText[-1] + '\n\n') # Number of profiles averaged file.write('Number of profiles averaged\n') @@ -966,20 +2087,20 @@ class MeanAquascatProfile: for f in range(len(self.Freq)): for i in self.V[0:-1, f]: file.write('%s, ' % i) - file.write(str(self.V[-1, f])+'\n') + file.write(str(self.V[-1, f]) + '\n') file.write('\n') # Reception gain file.write('Rx gain\n') for i in self.Rx[0:-1]: file.write('%s, ' % i) - file.write(str(self.Rx[-1])+'\n\n') + file.write(str(self.Rx[-1]) + '\n\n') # Transmission gain file.write('Tx gain\n') for i in self.Tx[0:-1]: file.write('%s, ' % i) - file.write(str(self.Tx[-1])+'\n\n') + file.write(str(self.Tx[-1]) + '\n\n') # Number of pings average file.write("Nb pings averaged in 1 profile\n") @@ -1086,19 +2207,23 @@ class MeanAquascatProfile: file.close() + # ------------------------- Test --------------------------------------# start_time = time.time() if __name__ == "__main__": -# path1 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa' + # path1 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa' path1 = r'//home/brahim.moudjed/Documents/3 Software_Project/river_inversion_project/Data/Aquascat data test/20171213135800.aqa' data1 = RawAquascatData(path1) - -# path2 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa.txt' + + # path2 = r'C:\Users\vergne\Documents\Donnees_aquascat\2017_juillet - experience cuve sediments fins\2017_07_19 - mercredi eau claire\20170719114700.aqa.txt' path2 = r'//home/brahim.moudjed/Documents/3 Software_Project/river_inversion_project/Data/Aquascat data test/20171213135800.txt' data2 = RawAquascatData(path2) print(data1.PingRate) print(data2.PingRate) -print("Computational time: %.2f min" %((time.time() - start_time)/60) ) +print("Computational time: %.2f min" % ((time.time() - start_time) / 60)) + + + diff --git a/Model/acoustic_data_loader.py b/Model/acoustic_data_loader.py index a61cad9..a4fe4b3 100644 --- a/Model/acoustic_data_loader.py +++ b/Model/acoustic_data_loader.py @@ -103,7 +103,11 @@ class AcousticDataLoader: # order="F") r = np.zeros((self._r.shape[1] * self._time.shape[1], self._freq.shape[0])) for i, _ in enumerate(self._freq): - r[:, i] = np.repeat(self._r[i, :], self._time.shape[1]) + for j in range(self._time.shape[1]): + + r[j*self._r.shape[1]:(j+1)*self._r.shape[1], i] = self._r[i, :] + + # r[:, i] = np.repeat(self._r[i, :], self._time.shape[1]) print(r.shape) return r diff --git a/Model/create_table_for_save_as.py b/Model/create_table_for_save_as.py new file mode 100644 index 0000000..4e6bc91 --- /dev/null +++ b/Model/create_table_for_save_as.py @@ -0,0 +1,328 @@ +import numpy as np +from PyQt5.QtWidgets import QFileDialog, QApplication +import sqlite3 +import settings as stg +from os import chdir +import time + + +class CreateTableForSaveAs(): + + def __init__(self): + + self.create_AcousticFile = """CREATE TABLE File( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + acoustic_file STRING)""" + + self.create_Measure = """ CREATE TABLE Measure( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + frequency FLOAT, + kt FLOAT, + NbProfiles INTEGER, + NbProfilesPerSeconds FLOAT, + NbCells INTEGER, + CellSize FLOAT, + PulseLength FLOAT, + NbPingsPerSeconds FLOAT, + NbPingsAveragedPerProfile FLOAT, + GainRx FLOAT, + GainTx FLOAT) + """ + + # for i in stg.acoustic_data: + # exec("self.create_BSRawData_" + str(i) + " = '''CREATE TABLE BSRawData_" + str(i) + + # "(ID INTEGER PRIMARY KEY AUTOINCREMENT, " + + # "acoustic_data INTEGER, " + + # " ".join(["time_" + str(int(f)) + " FLOAT," for f in stg.freq[i][:-1]]) + + # ["time_" + str(int(stg.freq[i][-1]))][0] + " FLOAT" + ")''' ") + + # for i in stg.acoustic_data: + # exec("self.create_BSRawData_" + str(i) + " = '''CREATE TABLE BSRawData_" + str(i) + + # "(ID INTEGER PRIMARY KEY AUTOINCREMENT, " + + # "acoustic_data INTEGER, " + + # " ".join(["time_" + str(int(f)) + " FLOAT," for f in stg.freq[i]]) + + # " ".join(["depth_" + str(int(f)) + " FLOAT," for f in stg.freq[i]]) + + # " ".join(["BS_raw_data_" + str(int(f)) + " FLOAT," for f in stg.freq[i][:-1]]) + + # ["BS_raw_data_" + str(int(stg.freq[i][-1]))][0] + " FLOAT" + ")''' ") + + self.create_BSRawData = '''CREATE TABLE BSRawData( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + time BLOB, + depth BLOB, + BS_raw_data BLOB)''' + + self.create_Settings = '''CREATE TABLE Settings( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + temperature FLOAT, + time_min_ind INTEGER, + time_min_val FLOAT, + time_max_ind INTEGER, + time_max_val FLOAT, + depth_min_ind INTEGER, + depth_min_val FLOAT, + depth_max_ind INTEGER, + depth_max_val FLOAT)''' + + self.open_file_dialog() + start = time.time() + self.create_table() + print(f"end : {time.time() - start} sec") + + def open_file_dialog(self): + options = QFileDialog.Options() + name = QFileDialog.getSaveFileName( + caption="Save As", directory="", filter="AcouSed Files (*.acd)", options=options) + + if name: + + stg.dirname_save_as = "/".join(name[0].split("/")[:-1]) + "/" + stg.filename_save_as = name[0].split("/")[-1] + + chdir(stg.dirname_save_as) + + # file = open(stg.filename_save_as, 'w') + # file.write(self.create_Measure) + # file.close() + + def create_table(self): + + # Create a new database and open a database connection to allow sqlite3 to work with it. + cnx = sqlite3.connect(stg.filename_save_as + '.acd') + + # Create database cursor to execute SQL statements and fetch results from SQL queries. + cur = cnx.cursor() + + # -------------------------------------------------------------------------------------------------------------- + # --- Table File --- + start_table_File = time.time() + + cur.execute("DROP TABLE if exists File") + + cur.execute(self.create_AcousticFile) + + for i in stg.acoustic_data: + query0 = (f"INSERT into File(acoustic_data, acoustic_file)" + f"VALUES({stg.acoustic_data[i]}, {str(stg.filename_BS_raw_data[i]).split('.')[0]})") + + cur.execute(query0) + cnx.commit() + + print(f"table File : {time.time() - start_table_File} sec") + + # -------------------------------------------------------------------------------------------------------------- + # --- Table Measure --- + start_table_Measure = time.time() + + # Drop Table if exists + cur.execute("DROP TABLE if exists Measure") + + # Execute the CREATE TABLE statement + cur.execute(self.create_Measure) + + # Fill the table Measure + for i in stg.acoustic_data: + + for f, k, r, t in zip(stg.freq[i], stg.kt[i], stg.gain_rx[i], stg.gain_tx[i]): + + query = (f"INSERT into Measure(acoustic_data, frequency, kt, NbProfiles, NbProfilesPerSeconds, " + f"NbCells, CellSize, PulseLength, NbPingsPerSeconds, " + f"NbPingsAveragedPerProfile, GainRx, GainTx) " + f"VALUES({i}, {f}, {k}, {stg.nb_profiles[i]}, {stg.nb_profiles_per_sec[i]}, " + f"{stg.nb_cells[i]}, {stg.cell_size[i]}, {stg.pulse_length[i]}, {stg.nb_pings_per_sec[i]}, " + f"{stg.nb_pings_averaged_per_profile[i]}, {r}, {t})") + cur.execute(query) + + # Commit the transaction after executing INSERT. + cnx.commit() + + print(f"table Measure : {time.time() - start_table_Measure} sec") + + # -------------------------------------------------------------------------------------------------------------- + # --- Table BSRawData_i --- + start_table_BSRawData = time.time() + + cur.execute('DROP TABLE if exists BSRawData') + + # # Drop Table BSRawData_i if exists + # for i in stg.acoustic_data: + # exec("cur.execute('DROP TABLE if exists BSRawData_" + str(i) + "')") + # + # # Execute the CREATE TABLE BSRawData_i statement + # for i in stg.acoustic_data: + # exec("cur.execute(self.create_BSRawData_" + str(i) + ")") + + # Fill the table BSRawData_i + + # # --- Fill table BSRawData_i with acoustic data integer --- + # for i in stg.acoustic_data: + # for j in range(stg.time_reshape[i].shape[0]): + # exec(f"query1 = ('''INSERT into BSRawData_" + str(i) + "(acoustic_data)" + + # f" VALUES({i}) ''') ") + # + # exec("cur.execute(query1)") + + # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # for i in stg.acoustic_data: + # , depth, BS_raw_data + cur.execute(self.create_BSRawData) + # homer = np.array([1, 2, 3, 4, 5]) + # bart = np.array([6, 7, 8, 9, 10]) + # lisa = np.array([11, 12, 13, 14, 15]) + # marge = homer.tobytes() + # print("to string : ", homer.tostring()) + # print("to bytes : ", homer.tobytes()) + # query2 = f''' INSERT into BSRawData(acoustic_data, time) VALUES({0}, {marge}) ''' + # cur.execute('''CREATE TABLE IF NOT EXISTS BSRawData(time BLOB)''') + for i in stg.acoustic_data: + + # cur.execute(''' INSERT into BSRawData(acoustic_data, time, depth, BS_raw_data) VALUES(?, ?, ?, ?)''', + # (stg.acoustic_data[i], homer.tobytes(), + # bart.tobytes(), lisa.tobytes())) + + cur.execute(''' INSERT into BSRawData(acoustic_data, time, depth, BS_raw_data, BS_cross_section) + VALUES(?, ?, ?, ?)''', + (stg.acoustic_data[i], stg.time[i].tobytes(), + stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes())) + + # cur.execute(''' INSERT into BSRawData(time) VALUES(?)''', (marge,)) + # query2 = f''' INSERT into BSRawData(acoustic_data, time) VALUES({0}, {stg.time[0][0, :].tobytes()}) ''' # , {stg.depth[i].tobytes()}, {stg.BS_raw_data[i].tobytes()} + + # for j in range(stg.time_reshape[i].shape[0]): + # + # # print("query2 = ('''INSERT into BSRawData_" + str(i) + "(acoustic_data, " + + # # ", ".join(["time_" + str(int(f)) for f in stg.freq[i]]) + ", " + + # # ", ".join(["depth_" + str(int(f)) for f in stg.freq[i]]) + ")" + + # # f" VALUES" + str(eval("0, " + + # # ", ".join(["stg.time_reshape[" + str(i) + "][" + str( + # # j) + ", " + str(k) + "]" for k, _ in + # # enumerate(stg.freq[i])]) + ", " + + # # ", ".join(["stg.depth_reshape[" + str(i) + "][" + str(j) + ", " + str(k) + "]" for k, _ in enumerate(stg.freq[i])]))) + " ''' )") + # + # exec("query2 = ('''INSERT into BSRawData_" + str(i) + "(acoustic_data, " + + # ", ".join(["time_" + str(int(f)) for f in stg.freq[i]]) + ", " + + # ", ".join(["depth_" + str(int(f)) for f in stg.freq[i]]) + ", " + + # ", ".join(["BS_raw_data_" + str(int(f)) for f in stg.freq[i]]) + ")" + # f" VALUES" + str(eval(str(i) + ", " + + # ", ".join(["stg.time_reshape[" + str(i) + "][" + str( + # j) + ", " + str(k) + "]" for k, _ in + # enumerate(stg.freq[i])]) + ", " + + # ", ".join(["stg.depth_reshape[" + str(i) + "][" + str( + # j) + ", " + str(k) + "]" for k, _ in + # enumerate(stg.freq[i])]) + ", " + + # ", ".join(["stg.BS_raw_data_reshape[" + str(i) + "][" + str( + # j) + ", " + str(k) + "]" for k, _ in + # enumerate(stg.freq[i])]))) + " ''' )") + + # cur.execute(query2) + + # Commit the transaction after executing INSERT. + cnx.commit() + + print(f"table BSRawData : {time.time() - start_table_BSRawData} sec") + # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + # # --- Fill table BSRawData_i with data stg.time_reshape --- + # for i in stg.acoustic_data: + # for j in range(stg.time_reshape[i].shape[0]): + # + # # print("query2 = ('''INSERT into BSRawData_" + str(i) + "(acoustic_data, " + + # # ", ".join(["time_" + str(int(f)) for f in stg.freq[i]]) + ")" + + # # f" VALUES" + str(eval("0, " + ", ".join(["stg.time_reshape[" + str(i) + "][" + str(j) + ", " + str(k) + "]" for k, _ in enumerate(stg.freq[i])]))) + " ''' )") + # + # exec("query2 = ('''INSERT into BSRawData_" + str(i) + "(acoustic_data, " + + # ", ".join(["time_" + str(int(f)) for f in stg.freq[i]]) + ")" + + # f" VALUES" + str(eval("0, " + ", ".join(["stg.time_reshape[" + str(i) + "][" + str(j) + ", " + str(k) + "]" for k, _ in enumerate(stg.freq[i])]))) + " ''' )") + # + # exec("cur.execute(query2)") + # + # # Commit the transaction after executing INSERT. + # cnx.commit() + # + # # --- Fill table BSRawData_i with data stg.depth_reshape --- + # for i in stg.acoustic_data: + # for f in stg.freq[i]: + # exec("query3 = ('''ALTER TABLE BSRawData_" + str(i) + + # " ADD " + ["depth_" + str(int(f)) + " FLOAT"][0] + " ''')") + # + # exec("cur.execute(query3)") + # + # # Commit the transaction after executing INSERT. + # cnx.commit() + # + # for i in stg.acoustic_data: + # for k, f in enumerate(stg.freq[i]): + # for j in range(stg.depth_reshape[i].shape[0]): + # exec("query4 = '''UPDATE BSRawData_" + str(i) + + # " SET " + ["depth_" + str(int(f))][0] + " = " + + # str(eval("stg.depth_reshape[" + str(i) + "][" + str(j) + ", " + str(k) + "]")) + + # " WHERE ID = " + str(j + 1) + " ''' ") + # + # exec("cur.execute(query4)") + + # # --- Fill table BSRawData_i with data stg.BS_raw_data_reshape --- + # for i in stg.acoustic_data: + # for f in stg.freq[i]: + # + # exec("query5 = ('''ALTER TABLE BSRawData_" + str(i) + + # " ADD " + ["BS_raw_data_" + str(int(f)) + " FLOAT"][0] + " ''')") + # + # exec("cur.execute(query5)") + # + # # Commit the transaction after executing INSERT. + # cnx.commit() + # + # for i in stg.acoustic_data: + # for k, f in enumerate(stg.freq[i]): + # for j in range(stg.BS_raw_data_reshape[i].shape[0]): + # + # exec("query6 = '''UPDATE BSRawData_" + str(i) + + # " SET " + ["BS_raw_data_" + str(int(f))][0] + " = " + + # str(eval("stg.BS_raw_data_reshape[" + str(i) + "][" + str(j) + ", " + str(k) + "]")) + + # " WHERE ID = " + str(j+1) + " ''' ") + # + # exec("cur.execute(query6)") + # + # cnx.commit() + + # -------------------------------------------------------------------------------------------------------------- + # --- Table Settings --- + start_table_Settings = time.time() + + cur.execute("DROP TABLE if exists Settings") + + cur.execute(self.create_Settings) + + print(stg.acoustic_data, stg.temperature, stg.rmin, stg.rmax, stg.tmin, stg.tmax) + + for i in stg.acoustic_data: + query7 = (f'''INSERT into Settings(acoustic_data, temperature, + time_min_ind, time_min_val, time_max_ind, time_max_val, + depth_min_ind, depth_min_val, depth_max_ind, depth_max_val) + VALUES({stg.acoustic_data[i]}, + {stg.temperature[i]}, + {stg.tmin[i][0]}, + {stg.tmin[i][1]}, + {stg.tmax[i][0]}, + {stg.tmax[i][1]}, + {stg.rmin[i][0]}, + {stg.rmin[i][1]}, + {stg.rmax[i][0]}, + {stg.rmax[i][1]})''') + + cur.execute(query7) + cnx.commit() + + print(f"table Settings : {time.time() - start_table_Settings} sec") + + # Close database cursor + cur.close() + + # Close database connection + cnx.close() + + + diff --git a/Model/read_table_for_open.py b/Model/read_table_for_open.py new file mode 100644 index 0000000..d810365 --- /dev/null +++ b/Model/read_table_for_open.py @@ -0,0 +1,157 @@ +import numpy as np +from PyQt5.QtWidgets import QFileDialog, QApplication +import sqlite3 +from os import path, chdir +import settings as stg + + +class ReadTableForOpen: + + def __init__(self): + + self.open_file_dialog() + + chdir(stg.dirname_open) + self.sql_file_to_open = open(stg.filename_open) + + self.read_table() + + # self.reshape_variables() + + def open_file_dialog(self): + + name = QFileDialog.getOpenFileName(caption="Open Acoused file", directory="", filter="Acoused file (*.acd)") + + if name: + + stg.dirname_open = path.dirname(name[0]) + stg.filename_open = path.basename(name[0]) + + def read_table(self): + + # connexion to File db + cnx = sqlite3.connect(stg.filename_open) + + # Create database cursor to execute SQL statements and fetch results from SQL queries. + cur = cnx.cursor() + + query = '''SELECT acoustic_data, acoustic_file FROM File''' + data = cur.execute(query).fetchall() + stg.acoustic_data, stg.filename_BS_raw_data = [x[0] for x in data], [y[1] for y in data] + + for i in stg.acoustic_data: + + query1 = f'''SELECT frequency, kt, NbProfiles, NbProfilesPerSeconds, " + f"NbCells, CellSize, PulseLength, NbPingsPerSeconds, " + f"NbPingsAveragedPerProfile, GainRx, GainTx + FROM Measure WHERE (acoustic_data = {i})''' + data1 = cur.execute(query1).fetchall() + # print(data1) + # print([x[0] for x in data1]) + stg.freq.append([x[0] for x in data1]) + stg.kt.append([x[1] for x in data1]) + stg.nb_profiles.append([x[2] for x in data1]) + stg.nb_profiles_per_sec.append([x[3] for x in data1]) + stg.nb_cells.append([x[4] for x in data1]) + stg.cell_size.append([x[5] for x in data1]) + stg.pulse_length.append([x[6] for x in data1]) + stg.nb_pings_per_sec.append([x[7] for x in data1]) + stg.nb_pings_averaged_per_profile.append([x[8] for x in data1]) + stg.gain_rx.append([x[9] for x in data1]) + stg.gain_tx.append([x[10] for x in data1]) + + # for f_ind, f_val in enumerate(stg.freq[i]): + # + # exec("query2 = '''SELECT time_" + str(int(f_val)) + ", depth_" + str(int(f_val)) + ", BS_raw_data_" + str(int(f_val)) + + # " FROM BSRawData_" + str(int(i)) + " WHERE (acoustic_data = " + str(i) + ") ''' ") + # exec("data2 = cur.execute(query2).fetchall()") + # # print(eval("data2")) + # + # if f_ind == 0: + # time_reshape_temp = np.array([[x[0] for x in eval("data2")]]) + # # print("1 time_reshape_temp.shape ", time_reshape_temp.shape) + # depth_reshape_temp = np.array([[x[1] for x in eval("data2")]]) + # BS_raw_data_reshape_temp = np.array([[x[2] for x in eval("data2")]]) + # else: + # time_reshape_temp = np.insert(time_reshape_temp, f_ind, [x[0] for x in eval("data2")], axis=0) + # # print("2 time_reshape_temp.shape ", time_reshape_temp.shape) + # depth_reshape_temp = np.insert(depth_reshape_temp, f_ind, [x[1] for x in eval("data2")], axis=0) + # BS_raw_data_reshape_temp = np.insert(BS_raw_data_reshape_temp, f_ind, [x[1] for x in eval("data2")], axis=0) + # + # stg.time_reshape.append(time_reshape_temp.transpose()) + # # print(len(stg.time_reshape)) + # # print(stg.time_reshape[i].shape) + # stg.depth_reshape.append(depth_reshape_temp.transpose()) + # stg.BS_raw_data_reshape.append(BS_raw_data_reshape_temp.transpose()) + + query2 = f'''SELECT acoustic_data, time, depth, BS_raw_data FROM BSRawData WHERE (acoustic_data = {i})''' + + data2 = cur.execute(query2).fetchall() + print("len(data2) ", len(data2[0])) + # print("data2 : ", data2) + # data2_retreived = np.frombuffer(data2[0][1], dtype=np.float64) + # print("", data2_retreived) + + stg.time.append(np.frombuffer(data2[0][1], dtype=np.float64).reshape((len(stg.freq[i]), -1))) + print(stg.time[0].shape) + print(stg.time) + stg.depth.append(np.frombuffer(data2[0][2], dtype=np.float64).reshape(len(stg.freq[i]), -1)) + print(stg.depth[0].shape) + print(stg.depth) + stg.BS_raw_data.append(np.frombuffer(data2[0][3], dtype=np.float64)) + + # time_reshape_temp = np.insert(time_reshape_temp, time_reshape_temp.shape[0], [x[0] for x in eval("data2")], axis=0) + # stg.depth_reshape.append([x[2] for x in data2]) + # stg.BS_raw_data_reshape.append([x[3] for x in data2]) + + # query = '''SELECT acoustic_file FROM File''' + # cur.execute(query) + # stg.acoustic_data = cur.fetchall() + + # Close database cursor + cur.close() + + # Close database connection + cnx.close() + + def reshape_variables(self): + + for i in stg.acoustic_data: + for f, _ in enumerate(stg.freq[i]): + + if f == 0: + + depth_temp = np.array([ + stg.depth_reshape[i][np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0][0]: + np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0][1], f] + ]) + + time_temp = np.array([ + stg.time_reshape[i][ + np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0], f] + ]) + + else: + # print(np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])) + depth_temp = np.insert(depth_temp, + depth_temp.shape[0], + stg.depth_reshape[i][np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0][0]: + np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0][1], f], + axis=0) + time_temp = np.insert(time_temp, + time_temp.shape[0], + stg.time_reshape[i][ + np.where(stg.depth_reshape[i][:, f] == stg.depth_reshape[i][0, f])[0], f], + axis=0) + + stg.depth.append(depth_temp) + stg.time.append(time_temp) + + stg.BS_raw_data.append(np.reshape(stg.BS_raw_data_reshape[i], + (len(stg.freq[i]), stg.depth[i].shape[1], stg.time[i].shape[1]))) + + + + + + diff --git a/View/acoustic_data_tab.py b/View/acoustic_data_tab.py index eef40e2..648d0b2 100644 --- a/View/acoustic_data_tab.py +++ b/View/acoustic_data_tab.py @@ -337,13 +337,13 @@ class AcousticDataTab(QWidget): # layout.addWidget(scroll) self.label_temperature = QLabel("Temperature : ") - self.gridLayout_goupbox_info.addWidget(self.label_temperature, 0, 0, 1, 1) + # self.gridLayout_goupbox_info.addWidget(self.label_temperature, 0, 0, 1, 1) # self.label_temperature.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.spinbox_temperature = QDoubleSpinBox() - - self.gridLayout_goupbox_info.addWidget(self.spinbox_temperature, 0, 1, 1, 1) - self.label_degreCelsius = QLabel("°C") - self.gridLayout_goupbox_info.addWidget(self.label_degreCelsius, 0, 2, 1, 1) + self.spinbox_temperature.setSuffix("°C") + # self.gridLayout_goupbox_info.addWidget(self.spinbox_temperature, 0, 1, 1, 1) + # self.label_degreCelsius = QLabel("°C") + # self.gridLayout_goupbox_info.addWidget(self.label_degreCelsius, 0, 2, 1, 1) # self.label_date_acoustic_file = QLabel() # self.gridLayout_goupbox_info.addWidget(self.label_date_acoustic_file, 1, 0, 1, 2) @@ -1107,6 +1107,7 @@ class AcousticDataTab(QWidget): self.label_date_acoustic_file.show() self.label_hour_acoustic_file.show() + self.label_temperature.show() self.label_profiles.show() self.label_profiles_per_sec.show() self.label_cells.show() @@ -1119,15 +1120,17 @@ class AcousticDataTab(QWidget): self.label_rx.show() self.label_tx.show() - self.gridLayout_goupbox_info.addWidget(self.label_date_acoustic_file, 1, 0, 1, 2) - self.gridLayout_goupbox_info.addWidget(self.label_hour_acoustic_file, 1, 1, 1, 1) + self.gridLayout_goupbox_info.addWidget(self.label_date_acoustic_file, 0, 0, 1, 2) + self.gridLayout_goupbox_info.addWidget(self.label_hour_acoustic_file, 0, 2, 1, 1) + self.gridLayout_goupbox_info.addWidget(self.label_temperature, 1, 0, 1, 1) + # self.gridLayout_goupbox_info.addWidget(self.spinbox_temperature, 1, 1, 1, 1) self.gridLayout_goupbox_info.addWidget(self.label_profiles, 2, 0, 1, 1) - self.gridLayout_goupbox_info.addWidget(self.label_profiles_per_sec, 2, 1, 1, 1) + self.gridLayout_goupbox_info.addWidget(self.label_profiles_per_sec, 2, 2, 1, 1) self.gridLayout_goupbox_info.addWidget(self.label_cells, 3, 0, 1, 1) - self.gridLayout_goupbox_info.addWidget(self.label_cell_size, 3, 1, 1, 1) + self.gridLayout_goupbox_info.addWidget(self.label_cell_size, 3, 2, 1, 1) self.gridLayout_goupbox_info.addWidget(self.label_pulse_length, 4, 0, 1, 1) self.gridLayout_goupbox_info.addWidget(self.label_pings_per_sec, 5, 0, 1, 1) - self.gridLayout_goupbox_info.addWidget(self.label_pings_per_profile, 5, 1, 1, 1) + self.gridLayout_goupbox_info.addWidget(self.label_pings_per_profile, 5, 2, 1, 1) self.gridLayout_goupbox_info.addWidget(self.label_freq, 6, 0, 1, 2) self.gridLayout_goupbox_info.addWidget(self.label_kt, 7, 0, 1, 2) self.gridLayout_goupbox_info.addWidget(self.label_rx, 8, 0, 1, 2) @@ -1138,6 +1141,7 @@ class AcousticDataTab(QWidget): self.label_date_acoustic_file.hide() self.label_hour_acoustic_file.hide() + self.label_temperature.hide() self.label_profiles.hide() self.label_profiles_per_sec.hide() self.label_cells.hide() @@ -1159,7 +1163,7 @@ class AcousticDataTab(QWidget): self.gridLayout_goupbox_info.addWidget(self.label_freq, 0, 0, 1, 1) def temperature_value(self): - stg.temperature = (self.spinbox_temperature.value()) + stg.temperature[self.fileListWidget.currentRow()] = self.spinbox_temperature.value() print(f"stg.temperature : {stg.temperature}") def clicked_pushbutton_noise_level(self): @@ -1183,6 +1187,7 @@ class AcousticDataTab(QWidget): "Aquascat file (*.aqa)") dir_name = path.dirname(filename[0]) name = path.basename(filename[0]) + print(f"dir name : {dir_name} & file name : {name}") # print(dir_name, name) elif self.combobox_ABS_system_choice.currentIndex() == 2: filename = QFileDialog.getOpenFileName(self, "Open file", "", "UBSediFlow file (*.udt)") @@ -1203,9 +1208,11 @@ class AcousticDataTab(QWidget): if self.fileListWidget.count() == 0: stg.path_BS_raw_data = [dir_name] stg.filename_BS_raw_data = [name] + print(f"0 dir name : {dir_name} & file name : {name}") else: stg.path_BS_raw_data.append(dir_name) stg.filename_BS_raw_data.append(name) + print(f"1 dir name : {dir_name} & file name : {name}") self.load_BS_acoustic_raw_data() print("0 Lecture de la donnée BS") except ValueError as e: @@ -1228,12 +1235,12 @@ class AcousticDataTab(QWidget): print("1. Number of filenames in fileListWidget : ", self.fileListWidget.count()) # self.btnToggled() self.fileListWidget.setToolTip(stg.path_BS_raw_data[-1]) - self.label_date_acoustic_file.clear() - self.label_date_acoustic_file.setText( - _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date[self.fileListWidget.currentRow()])) - self.label_hour_acoustic_file.clear() - self.label_hour_acoustic_file.setText( - _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour[self.fileListWidget.currentRow()])) + # self.label_date_acoustic_file.clear() + # self.label_date_acoustic_file.setText( + # _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date[self.fileListWidget.currentRow()])) + # self.label_hour_acoustic_file.clear() + # self.label_hour_acoustic_file.setText( + # _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour[self.fileListWidget.currentRow()])) self.fill_measurements_information_groupbox() self.fill_table() self.set_range_for_doubleRangeSlider_time() @@ -1246,6 +1253,10 @@ class AcousticDataTab(QWidget): # self.combobox_frequency_profile.clear() # self.combobox_frequency_profile.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]]) + stg.acoustic_data = list(range(self.fileListWidget.count())) + print("helloooooooo ", stg.acoustic_data) + + # if self.sender().objectName() == "pushbutton_noise_file": # print("--- 0. Je suis dans le push button noise file ---") # try: @@ -1353,62 +1364,87 @@ class AcousticDataTab(QWidget): self.slider.setMaximum(10) def load_BS_acoustic_raw_data(self): + print("Je suis dans le load_BS_acoustic_raw_data") if self.combobox_ABS_system_choice.currentIndex() == 1: - + print("Je suis dans le load_BS_acoustic_raw_data - 1") acoustic_data = AcousticDataLoader(stg.path_BS_raw_data[-1] + "/" + stg.filename_BS_raw_data[-1]) - if self.fileListWidget.count() == 0: + stg.ABS_name.append(self.combobox_ABS_system_choice.currentText()) + stg.BS_raw_data.append(acoustic_data._BS_raw_data) + stg.BS_raw_data_reshape.append(acoustic_data.reshape_BS_raw_data()) + stg.depth.append(acoustic_data._r) + stg.depth_2D.append(acoustic_data.compute_r_2D()) + stg.depth_reshape.append(acoustic_data.reshape_r()) + stg.time.append(acoustic_data._time) + stg.time_reshape.append(acoustic_data.reshape_time()) + stg.freq.append(acoustic_data._freq) + stg.freq_text.append(acoustic_data._freq_text) + stg.date.append(acoustic_data._date) + stg.hour.append(acoustic_data._hour) + stg.nb_profiles.append(acoustic_data._nb_profiles) + stg.nb_profiles_per_sec.append(acoustic_data._nb_profiles_per_sec) + stg.nb_cells.append(acoustic_data._nb_cells) + stg.cell_size.append(acoustic_data._cell_size) + stg.pulse_length.append(acoustic_data._cell_size) + stg.nb_pings_per_sec.append(acoustic_data._nb_pings_per_sec) + stg.nb_pings_averaged_per_profile.append(acoustic_data._nb_pings_averaged_per_profile) + stg.kt.append(acoustic_data._kt) + stg.gain_rx.append(acoustic_data._gain_rx) + stg.gain_tx.append(acoustic_data._gain_tx) + stg.temperature.append(self.spinbox_temperature.value()) - stg.ABS_name = [self.combobox_ABS_system_choice.currentText()] - stg.BS_raw_data = [acoustic_data._BS_raw_data] - print("len(stg.BS_raw_data) ", len(stg.BS_raw_data)) - print("stg.BS_raw_data[0].shape ", stg.BS_raw_data[0].shape) - stg.BS_raw_data_reshape = [acoustic_data.reshape_BS_raw_data()] - stg.depth = [acoustic_data._r] - stg.depth_2D = [acoustic_data.compute_r_2D()] - # stg.depth_reshape = [acoustic_data.reshape_r()] - stg.time = [acoustic_data._time] - stg.time_reshape = [acoustic_data.reshape_time()] - stg.freq = [acoustic_data._freq] - stg.freq_text = [acoustic_data._freq_text] - print("freq text ", stg.freq_text) - stg.date = [acoustic_data._date] - stg.hour = [acoustic_data._hour] - stg.nb_profiles = [acoustic_data._nb_profiles] - stg.nb_profiles_per_sec = [acoustic_data._nb_profiles_per_sec] - stg.nb_cells = [acoustic_data._nb_cells] - stg.cell_size = [acoustic_data._cell_size] - stg.pulse_length = [acoustic_data._cell_size] - stg.nb_pings_per_sec = [acoustic_data._nb_pings_per_sec] - stg.nb_pings_averaged_per_profile = [acoustic_data._nb_pings_averaged_per_profile] - stg.kt = [acoustic_data._kt] - stg.gain_rx = [acoustic_data._gain_rx] - stg.gain_tx = [acoustic_data._gain_tx] - - else: - - stg.ABS_name.append(self.combobox_ABS_system_choice.currentText()) - stg.BS_raw_data.append(acoustic_data._BS_raw_data) - stg.BS_raw_data_reshape.append(acoustic_data.reshape_BS_raw_data()) - stg.depth.append(acoustic_data._r) - stg.depth_2D.append(acoustic_data.compute_r_2D()) - # stg.depth_reshape = [acoustic_data.reshape_r()] - stg.time.append(acoustic_data._time) - stg.time_reshape.append(acoustic_data.reshape_time()) - stg.freq.append(acoustic_data._freq) - stg.freq_text.append(acoustic_data._freq_text) - stg.date.append(acoustic_data._date) - stg.hour.append(acoustic_data._hour) - stg.nb_profiles.append(acoustic_data._nb_profiles) - stg.nb_profiles_per_sec.append(acoustic_data._nb_profiles_per_sec) - stg.nb_cells.append(acoustic_data._nb_cells) - stg.cell_size.append(acoustic_data._cell_size) - stg.pulse_length.append(acoustic_data._cell_size) - stg.nb_pings_per_sec.append(acoustic_data._nb_pings_per_sec) - stg.nb_pings_averaged_per_profile.append(acoustic_data._nb_pings_averaged_per_profile) - stg.kt.append(acoustic_data._kt) - stg.gain_rx.append(acoustic_data._gain_rx) - stg.gain_tx.append(acoustic_data._gain_tx) + # if self.fileListWidget.count() == 0: + # + # stg.ABS_name = [self.combobox_ABS_system_choice.currentText()] + # stg.BS_raw_data = [acoustic_data._BS_raw_data] + # # print("len(stg.BS_raw_data) ", len(stg.BS_raw_data)) + # # print("stg.BS_raw_data[0].shape ", stg.BS_raw_data[0].shape) + # stg.BS_raw_data_reshape = [acoustic_data.reshape_BS_raw_data()] + # stg.depth = [acoustic_data._r] + # stg.depth_2D = [acoustic_data.compute_r_2D()] + # stg.depth_reshape = [acoustic_data.reshape_r()] + # stg.time = [acoustic_data._time] + # stg.time_reshape = [acoustic_data.reshape_time()] + # stg.freq = [acoustic_data._freq] + # stg.freq_text = [acoustic_data._freq_text] + # # print("freq text ", stg.freq_text) + # stg.date = [acoustic_data._date] + # stg.hour = [acoustic_data._hour] + # stg.nb_profiles = [acoustic_data._nb_profiles] + # stg.nb_profiles_per_sec = [acoustic_data._nb_profiles_per_sec] + # stg.nb_cells = [acoustic_data._nb_cells] + # stg.cell_size = [acoustic_data._cell_size] + # stg.pulse_length = [acoustic_data._cell_size] + # stg.nb_pings_per_sec = [acoustic_data._nb_pings_per_sec] + # stg.nb_pings_averaged_per_profile = [acoustic_data._nb_pings_averaged_per_profile] + # stg.kt = [acoustic_data._kt] + # stg.gain_rx = [acoustic_data._gain_rx] + # stg.gain_tx = [acoustic_data._gain_tx] + # + # else: + # + # stg.ABS_name.append(self.combobox_ABS_system_choice.currentText()) + # stg.BS_raw_data.append(acoustic_data._BS_raw_data) + # stg.BS_raw_data_reshape.append(acoustic_data.reshape_BS_raw_data()) + # stg.depth.append(acoustic_data._r) + # stg.depth_2D.append(acoustic_data.compute_r_2D()) + # stg.depth_reshape.append(acoustic_data.reshape_r()) + # stg.time.append(acoustic_data._time) + # stg.time_reshape.append(acoustic_data.reshape_time()) + # stg.freq.append(acoustic_data._freq) + # stg.freq_text.append(acoustic_data._freq_text) + # stg.date.append(acoustic_data._date) + # stg.hour.append(acoustic_data._hour) + # stg.nb_profiles.append(acoustic_data._nb_profiles) + # stg.nb_profiles_per_sec.append(acoustic_data._nb_profiles_per_sec) + # stg.nb_cells.append(acoustic_data._nb_cells) + # stg.cell_size.append(acoustic_data._cell_size) + # stg.pulse_length.append(acoustic_data._cell_size) + # stg.nb_pings_per_sec.append(acoustic_data._nb_pings_per_sec) + # stg.nb_pings_averaged_per_profile.append(acoustic_data._nb_pings_averaged_per_profile) + # stg.kt.append(acoustic_data._kt) + # stg.gain_rx.append(acoustic_data._gain_rx) + # stg.gain_tx.append(acoustic_data._gain_tx) elif self.combobox_ABS_system_choice.currentIndex() == 2: @@ -1481,31 +1517,74 @@ class AcousticDataTab(QWidget): def fill_measurements_information_groupbox(self): if self.combobox_ABS_system_choice.currentIndex() == 1: - self.label_profiles.setText( - _translate("CONSTANT_STRING", cs.NB_PROFILES) + ": " + str(stg.nb_profiles[self.fileListWidget.currentRow()])) - self.label_profiles_per_sec.setText( - _translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ": " + - str(stg.nb_profiles_per_sec[self.fileListWidget.currentRow()]) + " Hz") + # self.label_date_acoustic_file.setText( + # _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date[self.fileListWidget.currentRow()])) + # self.label_hour_acoustic_file.setText( + # _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour[self.fileListWidget.currentRow()])) + # self.label_profiles.setText( + # _translate("CONSTANT_STRING", cs.NB_PROFILES) + ": " + str(stg.nb_profiles[self.fileListWidget.currentRow()])) + # self.label_profiles_per_sec.setText( + # _translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ": " + + # str(stg.nb_profiles_per_sec[self.fileListWidget.currentRow()]) + " Hz") # print("OL ", self.fileListWidget.currentRow()) - self.label_freq.setText( - _translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(stg.freq_text[self.fileListWidget.currentIndex().row()])) - self.label_cells.setText( - _translate("CONSTANT_STRING", cs.NB_CELLS) + ": " + str(stg.nb_cells[self.fileListWidget.currentRow()])) - self.label_cell_size.setText( - _translate("CONSTANT_STRING", cs.CELL_SIZE) + ": " + str(100*round(stg.cell_size[self.fileListWidget.currentRow()], 3)) + " cm") - self.label_pulse_length.setText( - _translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ": " + str(round(stg.pulse_length[self.fileListWidget.currentRow()], 6)) + "sec") - self.label_pings_per_sec.setText( - _translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC) + ": " + str(stg.nb_pings_per_sec[self.fileListWidget.currentRow()]) + " Hz") - self.label_pings_per_profile.setText( - _translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ": " + - str(stg.nb_pings_averaged_per_profile[self.fileListWidget.currentRow()])) - self.label_kt.setText( - _translate("CONSTANT_STRING", cs.KT) + ": " + ', '.join(map(str, stg.kt[self.fileListWidget.currentRow()]))) - self.label_rx.setText( - _translate("CONSTANT_STRING", cs.GAIN_RX) + ": " + ', '.join(map(str, stg.gain_rx[self.fileListWidget.currentRow()]))) - self.label_tx.setText( - _translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx[self.fileListWidget.currentRow()]))) + # self.label_freq.setText( + # _translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(stg.freq_text[self.fileListWidget.currentIndex().row()])) + # self.label_cells.setText( + # _translate("CONSTANT_STRING", cs.NB_CELLS) + ": " + str(stg.nb_cells[self.fileListWidget.currentRow()])) + # self.label_cell_size.setText( + # _translate("CONSTANT_STRING", cs.CELL_SIZE) + ": " + str(100*round(stg.cell_size[self.fileListWidget.currentRow()], 3)) + " cm") + # self.label_pulse_length.setText( + # _translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ": " + str(round(stg.pulse_length[self.fileListWidget.currentRow()], 6)) + "sec") + # self.label_pings_per_sec.setText( + # _translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC) + ": " + str(stg.nb_pings_per_sec[self.fileListWidget.currentRow()]) + " Hz") + # self.label_pings_per_profile.setText( + # _translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ": " + + # str(stg.nb_pings_averaged_per_profile[self.fileListWidget.currentRow()])) + # self.label_kt.setText( + # _translate("CONSTANT_STRING", cs.KT) + ": " + ', '.join(map(str, stg.kt[self.fileListWidget.currentRow()]))) + # self.label_rx.setText( + # _translate("CONSTANT_STRING", cs.GAIN_RX) + ": " + ', '.join(map(str, stg.gain_rx[self.fileListWidget.currentRow()]))) + # self.label_tx.setText( + # _translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx[self.fileListWidget.currentRow()]))) + + self.label_date_acoustic_file_value = QLabel(str(stg.date[self.fileListWidget.currentRow()])) + self.gridLayout_goupbox_info.addWidget(self.label_date_acoustic_file_value, 0, 1, 1, 1) + self.label_hour_acoustic_file_value = QLabel(str(stg.hour[self.fileListWidget.currentRow()])) + self.gridLayout_goupbox_info.addWidget(self.label_hour_acoustic_file_value, 0, 3, 1, 1) + + self.label_profiles_value = QLabel(str(stg.nb_profiles[self.fileListWidget.currentRow()])) + self.gridLayout_goupbox_info.addWidget(self.label_profiles_value, 2, 1, 1, 1) + self.label_profiles_per_sec_value = QLabel(str(stg.nb_profiles_per_sec[self.fileListWidget.currentRow()]) + " Hz") + self.gridLayout_goupbox_info.addWidget(self.label_profiles_per_sec_value, 2, 3, 1, 1) + + self.label_cells_value = QLabel(str(stg.nb_cells[self.fileListWidget.currentRow()])) + self.gridLayout_goupbox_info.addWidget(self.label_cells_value, 3, 1, 1, 1) + self.label_cell_size_value = QLabel(str(100*round(stg.cell_size[self.fileListWidget.currentRow()], 3)) + " cm") + self.gridLayout_goupbox_info.addWidget(self.label_cell_size_value, 3, 3, 1, 1) + + self.label_pulse_length_value = QLabel(str(round(stg.pulse_length[self.fileListWidget.currentRow()], 6)) + " sec") + self.gridLayout_goupbox_info.addWidget(self.label_pulse_length_value, 4, 1, 1, 1) + + self.label_pings_per_sec_value = QLabel(str(stg.nb_pings_per_sec[self.fileListWidget.currentRow()]) + " Hz") + self.gridLayout_goupbox_info.addWidget(self.label_pings_per_sec_value, 5, 1, 1, 1) + self.label_pings_per_profile_value = QLabel(str(stg.nb_pings_averaged_per_profile[self.fileListWidget.currentRow()])) + self.gridLayout_goupbox_info.addWidget(self.label_pings_per_profile_value, 5, 3, 1, 1) + + # for find, fval in enumerate(stg.freq[self.fileListWidget.currentRow()]): + # print(f"find {find} fval {fval}") + # exec(f"self.spinbox_freq_" + str(int(fval)) + " = QDoubleSpinBox()") + # exec(f"self.spinbox_freq_" + str(int(fval)) + ".setSuffix('Hz')") + # exec(f"self.spinbox_freq_" + str(int(fval)) + ".setValue(" + str(fval) + ")") + # exec(f"self.gridLayout_goupbox_info.addWidget(self.spinbox_freq_" + str(int(fval)) + ", 6, " + str(find+1) + ", 1, 1)") + # self.gridLayout_goupbox_info.addWidget(stg.freq_text[self.fileListWidget.currentIndex().row()]) + + # self.gridLayout_goupbox_info.addWidget(', '.join(map(str, stg.kt[self.fileListWidget.currentRow()]))) + + # self.gridLayout_goupbox_info.addWidget(', '.join(map(str, stg.gain_rx[self.fileListWidget.currentRow()]))) + + # self.gridLayout_goupbox_info.addWidget(', '.join(map(str, stg.gain_tx[self.fileListWidget.currentRow()]))) + + self.spinbox_kt = QDoubleSpinBox() elif self.combobox_ABS_system_choice.currentIndex() == 2: @@ -1519,13 +1598,17 @@ class AcousticDataTab(QWidget): header_list = [] for freq_ind, freq_value in enumerate(stg.freq_text[0]): header_list.append("Time - " + freq_value) + header_list.append("Depth - " + freq_value) header_list.append("BS - " + freq_value) if freq_ind == 0: - table_data = np.vstack((stg.time_reshape[0][:, freq_ind], stg.BS_raw_data_reshape[0][:, freq_ind])) + table_data = np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind], + stg.depth_reshape[0][:, freq_ind])), + stg.BS_raw_data_reshape[0][:, freq_ind])) else: table_data = np.vstack((table_data, - np.vstack((stg.time_reshape[0][:, freq_ind], + np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind], + stg.depth_reshape[0][:, freq_ind])), stg.BS_raw_data_reshape[0][:, freq_ind])) )) @@ -1540,14 +1623,18 @@ class AcousticDataTab(QWidget): header_list.clear() for freq_ind, freq_value in enumerate(stg.freq_text[0]): header_list.append("Time - " + freq_value) + header_list.append("Depth - " + freq_value) header_list.append("BS - " + freq_value) if freq_ind == 0: - table_data = np.vstack((stg.time_reshape[self.fileListWidget.currentRow()][:, freq_ind], + table_data = np.vstack((np.vstack((stg.time_reshape[self.fileListWidget.currentRow()][:, freq_ind], + stg.depth_reshape[self.fileListWidget.currentRow()][:, freq_ind])), stg.BS_raw_data_reshape[self.fileListWidget.currentRow()][:, freq_ind])) + else: table_data = np.vstack((table_data, - np.vstack((stg.time_reshape[self.fileListWidget.currentRow()][:, freq_ind], + np.vstack((np.vstack((stg.time_reshape[self.fileListWidget.currentRow()][:, freq_ind], + stg.depth_reshape[self.fileListWidget.currentRow()][:, freq_ind])), stg.BS_raw_data_reshape[self.fileListWidget.currentRow()][:, freq_ind])) )) @@ -1998,7 +2085,7 @@ class AcousticDataTab(QWidget): np.log(stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, :]), # np.log(stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, int(stg.tmin[self.fileListWidget.currentRow()]):int(stg.tmax[self.fileListWidget.currentRow()])]), cmap='Blues') - + pcm.draw_idle() self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, horizontalalignment='right', verticalalignment='bottom', @@ -2212,6 +2299,8 @@ class AcousticDataTab(QWidget): # --- Plot river bottom line --- if (len(stg.depth_bottom) != 0) and (len(stg.depth_bottom) == self.fileListWidget.count()): + print("stg.depth_bottom ", stg.depth_bottom) + print("len(stg.depth_bottom) ", len(stg.depth_bottom)) self.axis_BS[f].plot(stg.t_cross_section[self.fileListWidget.currentRow()][self.combobox_frequency_bathymetry.currentIndex(), :], -stg.depth_bottom[self.fileListWidget.currentRow()], color='black', linewidth=1, linestyle="solid") @@ -2263,7 +2352,7 @@ class AcousticDataTab(QWidget): # self.axis_profile.cla() self.axis_profile.plot(stg.BS_cross_section[self.fileListWidget.currentRow()][ self.combobox_frequency_profile.currentIndex(), :, self.slider.value() - 1], - -stg.depth[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), :], + -stg.depth_cross_section[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), :], linestyle='solid', color='k', linewidth=1) self.axis_profile.text(.95, .05, stg.freq_text[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex()], fontsize=10, fontweight='bold', fontname="Ubuntu", diff --git a/View/mainwindow.py b/View/mainwindow.py index e91dc47..6a5ce50 100644 --- a/View/mainwindow.py +++ b/View/mainwindow.py @@ -2,13 +2,16 @@ # Form implementation generated from reading ui file 'mainwindow.ui' # -# Created by: PyQt5 UI code generator 5.15.6 +# Created by: PyQt5 UI code generator 5.15.9 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets +from Model.create_table_for_save_as import CreateTableForSaveAs +from Model.read_table_for_open import ReadTableForOpen +from View.about_window import AboutWindow class Ui_MainWindow(object): @@ -31,6 +34,7 @@ class Ui_MainWindow(object): self.tabWidget.setTabBarAutoHide(False) self.tabWidget.setObjectName("tabWidget") self.tab1 = QtWidgets.QWidget() + self.tab1.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.tab1.setObjectName("tab1") self.tabWidget.addTab(self.tab1, "") self.tab2 = QtWidgets.QWidget() @@ -48,6 +52,9 @@ class Ui_MainWindow(object): self.tab6 = QtWidgets.QWidget() self.tab6.setObjectName("tab6") self.tabWidget.addTab(self.tab6, "") + self.tab7 = QtWidgets.QWidget() + self.tab7.setObjectName("tab7") + self.tabWidget.addTab(self.tab7, "") self.verticalLayout.addWidget(self.tabWidget) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) @@ -60,9 +67,13 @@ class Ui_MainWindow(object): self.menuSettings.setObjectName("menuSettings") self.menuLanguage = QtWidgets.QMenu(self.menuSettings) self.menuLanguage.setObjectName("menuLanguage") + self.menuExport = QtWidgets.QMenu(self.menuFile) + self.menuExport.setObjectName("menuExport") self.menuTools = QtWidgets.QMenu(self.menubar) self.menuTools.setLocale(QtCore.QLocale(QtCore.QLocale.French, QtCore.QLocale.France)) self.menuTools.setObjectName("menuTools") + self.menuHelp = QtWidgets.QMenu(self.menubar) + self.menuHelp.setObjectName("menuHelp") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") @@ -71,71 +82,69 @@ class Ui_MainWindow(object): self.toolBar.setObjectName("toolBar") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.actionNew = QtWidgets.QAction(MainWindow) - - # Rajouter par moi - path = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \ - "graphical_interface_for_SSC_acoustic_meas/icons/" - # Re verifier tout les icones QPixmap - icon = QtGui.QIcon() - # icon.addPixmap(QtGui.QPixmap("../icons/new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon.addPixmap(QtGui.QPixmap(path + "new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon.addPixmap(QtGui.QPixmap("icons/new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionNew.setIcon(icon) self.actionNew.setObjectName("actionNew") self.actionOpen = QtWidgets.QAction(MainWindow) icon1 = QtGui.QIcon() - # icon1.addPixmap(QtGui.QPixmap("../icons/icon_folder.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon1.addPixmap(QtGui.QPixmap(path + "icon_folder.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon1.addPixmap(QtGui.QPixmap("icons/icon_folder.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionOpen.setIcon(icon1) self.actionOpen.setObjectName("actionOpen") self.actionSave = QtWidgets.QAction(MainWindow) icon2 = QtGui.QIcon() - # icon2.addPixmap(QtGui.QPixmap("../icons/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon2.addPixmap(QtGui.QPixmap(path + "save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon2.addPixmap(QtGui.QPixmap("icons/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionSave.setIcon(icon2) self.actionSave.setObjectName("actionSave") self.actionCopy = QtWidgets.QAction(MainWindow) icon3 = QtGui.QIcon() - # icon3.addPixmap(QtGui.QPixmap("../icons/copy.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon3.addPixmap(QtGui.QPixmap(path + "copy.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon3.addPixmap(QtGui.QPixmap("icons/copy.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionCopy.setIcon(icon3) self.actionCopy.setObjectName("actionCopy") self.actionCut = QtWidgets.QAction(MainWindow) icon4 = QtGui.QIcon() - # icon4.addPixmap(QtGui.QPixmap("../icons/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon4.addPixmap(QtGui.QPixmap(path + "cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon4.addPixmap(QtGui.QPixmap("icons/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionCut.setIcon(icon4) self.actionCut.setObjectName("actionCut") self.actionPaste = QtWidgets.QAction(MainWindow) icon5 = QtGui.QIcon() - # icon5.addPixmap(QtGui.QPixmap("../icons/paste.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon5.addPixmap(QtGui.QPixmap(path + "paste.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon5.addPixmap(QtGui.QPixmap("icons/paste.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionPaste.setIcon(icon5) self.actionPaste.setObjectName("actionPaste") self.actionEnglish = QtWidgets.QAction(MainWindow) icon6 = QtGui.QIcon() - # icon6.addPixmap(QtGui.QPixmap("../icons/en.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon6.addPixmap(QtGui.QPixmap(path + "en.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon6.addPixmap(QtGui.QPixmap("icons/en.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionEnglish.setIcon(icon6) self.actionEnglish.setObjectName("actionEnglish") self.actionFrench = QtWidgets.QAction(MainWindow) icon7 = QtGui.QIcon() - # icon7.addPixmap(QtGui.QPixmap("../icons/fr.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - icon7.addPixmap(QtGui.QPixmap(path + "fr.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon7.addPixmap(QtGui.QPixmap("icons/fr.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionFrench.setIcon(icon7) self.actionFrench.setObjectName("actionFrench") + self.actionTable_of_Backscatter_values = QtWidgets.QAction(MainWindow) + self.actionTable_of_Backscatter_values.setObjectName("actionTable_of_Backscatter_values") + self.actionSave_As = QtWidgets.QAction(MainWindow) + self.actionSave_As.setObjectName("actionSave_As") + self.actionAbout = QtWidgets.QAction(MainWindow) + self.actionAbout.setObjectName("actionAbout") + self.actionDB_Browser_for_SQLite = QtWidgets.QAction(MainWindow) + self.actionDB_Browser_for_SQLite.setObjectName("actionDB_Browser_for_SQLite") self.menuLanguage.addAction(self.actionEnglish) self.menuLanguage.addAction(self.actionFrench) self.menuSettings.addAction(self.menuLanguage.menuAction()) - self.menuFile.addAction(self.actionNew) + self.menuExport.addAction(self.actionTable_of_Backscatter_values) self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) + self.menuFile.addAction(self.actionSave_As) + self.menuFile.addSeparator() self.menuFile.addAction(self.menuSettings.menuAction()) - self.menuTools.addAction(self.actionCopy) - self.menuTools.addAction(self.actionCut) - self.menuTools.addAction(self.actionPaste) + self.menuFile.addSeparator() + self.menuFile.addAction(self.menuExport.menuAction()) + self.menuTools.addAction(self.actionDB_Browser_for_SQLite) + self.menuHelp.addAction(self.actionAbout) self.menubar.addAction(self.menuFile.menuAction()) self.menubar.addAction(self.menuTools.menuAction()) + self.menubar.addAction(self.menuHelp.menuAction()) self.toolBar.addAction(self.actionNew) self.toolBar.addAction(self.actionOpen) self.toolBar.addAction(self.actionSave) @@ -151,35 +160,82 @@ class Ui_MainWindow(object): self.tabWidget.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) + # --- Connect Action Save As --- + self.actionSave_As.triggered.connect(self.save_as) + + # --- Connect Action Open --- + self.actionOpen.triggered.connect(self.open) + + # --- Connect Action DB_Browser_for_SQLite --- + self.actionDB_Browser_for_SQLite.triggered.connect(self.db_browser_for_sqlite) + + # --- Connect Action About --- + self.actionAbout.triggered.connect(self.about_window) + + def save_as(self): + CreateTableForSaveAs() + + def open(self): + ReadTableForOpen() + + def db_browser_for_sqlite(self): + import argparse + import sys + parser = argparse.ArgumentParser() + print(parser) + print(sys.argv[:]) + parser.parse_args() + + def about_window(self): + print("about") + AboutWindow() + # w.show() + # self.main_window = QtWidgets.QMainWindow() + # self.window = AboutWindow(mainWindow=self.main_window) + # self.main_window.show() + # import sys + # new_app = QtWidgets.QApplication(sys.argv) + # w = AboutWindow() + # w.show() + # sys.exit(new_app.exec_()) + + def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab1), _translate("MainWindow", "Acoustic data")) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab2), _translate("MainWindow", "Signal processing")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab2), _translate("MainWindow", "Signal preprocessing")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab3), _translate("MainWindow", "Sample data")) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab4), _translate("MainWindow", "Acoustic inversion")) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab5), _translate("MainWindow", "Note")) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab6), _translate("MainWindow", "User manual")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab4), _translate("MainWindow", "Sediment Calibration")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab5), _translate("MainWindow", "Acoustic inversion")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab6), _translate("MainWindow", "Note")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab7), _translate("MainWindow", "User manual")) self.menuFile.setTitle(_translate("MainWindow", "File")) self.menuSettings.setTitle(_translate("MainWindow", "Settings")) self.menuLanguage.setTitle(_translate("MainWindow", "Language")) + self.menuExport.setTitle(_translate("MainWindow", "Export")) self.menuTools.setTitle(_translate("MainWindow", "Tools")) + self.menuHelp.setTitle(_translate("MainWindow", "Help")) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar")) self.actionNew.setText(_translate("MainWindow", "New")) - self.actionOpen.setText(_translate("MainWindow", "Open")) + self.actionOpen.setText(_translate("MainWindow", "Open ...")) self.actionSave.setText(_translate("MainWindow", "Save")) self.actionCopy.setText(_translate("MainWindow", "Copy")) self.actionCut.setText(_translate("MainWindow", "Cut")) self.actionPaste.setText(_translate("MainWindow", "Paste")) self.actionEnglish.setText(_translate("MainWindow", "English")) self.actionFrench.setText(_translate("MainWindow", "French")) + self.actionTable_of_Backscatter_values.setText(_translate("MainWindow", "Table of Backscatter values")) + self.actionSave_As.setText(_translate("MainWindow", "Save As ...")) + self.actionAbout.setText(_translate("MainWindow", "About")) + self.actionDB_Browser_for_SQLite.setText(_translate("MainWindow", "DB Browser for SQLite")) -if __name__ == "__main__": - import sys - app = QtWidgets.QApplication(sys.argv) - MainWindow = QtWidgets.QMainWindow() - ui = Ui_MainWindow() - ui.setupUi(MainWindow) - MainWindow.show() - sys.exit(app.exec_()) +# if __name__ == "__main__": +# import sys +# app = QtWidgets.QApplication(sys.argv) +# MainWindow = QtWidgets.QMainWindow() +# ui = Ui_MainWindow() +# ui.setupUi(MainWindow) +# MainWindow.show() +# sys.exit(app.exec_()) diff --git a/settings.py b/settings.py index 2238a6a..daeaec4 100644 --- a/settings.py +++ b/settings.py @@ -12,7 +12,7 @@ path_BS_raw_data = [] filename_BS_raw_data = [] BS_raw_data = [] # BS raw data : all measurement (go and back) depth = [] -r_2D = [] +depth_2D = [] freq = [] freq_text = [] time = [] @@ -43,7 +43,7 @@ time_snr = np.array([]) # --- reshape raw data for table of values in Acoustic Data tab --- time_reshape = [] time_snr_reshape = np.array([]) -r_reshape = [] +depth_reshape = [] BS_raw_data_reshape = [] SNR_reshape = np.array([]) # snr is reshape to be included in table of values in acoustic data tab DataFrame_acoustic = pd.DataFrame() @@ -130,7 +130,7 @@ Ctot_sand_per_cent = np.array([]) # --- Acoustic inversion method --- -temperature = 0 +temperature = [] water_attenuation = np.array([]) water_velocity = 0 @@ -156,6 +156,14 @@ alpha_s = 0 SSC_fine = np.array(()) SSC_sand = np.array([]) +# --- Save study --- + +acoustic_data = [] +dirname_save_as = "" +filename_save_as = "" +dirname_open = "" +filename_open = "" +