def on_regpars(self): """Decides which two parameters to use for regular waves""" if self.ui.combobox_regparams.currentIndex() == 0: self.parameters = "HT" wl = self.ui.spinbox_wavelength.value() wp = 2*np.pi/wml.revdispsolver(2*np.pi/wl, water_depth, decimals=1) self.ui.spinbox_wave_period.setEnabled(True) self.ui.spinbox_wavelength.setDisabled(True) self.ui.slider_horiz.setRange(0.5, 5.0, 0.001, 10) self.ui.slider_horiz.setValue(wp) self.ui.spinbox_wavelength.setMinimum(0) self.ui.spinbox_wavelength.setMaximum(30) self.ui.spinbox_wave_period.setMaximum(5) self.ui.spinbox_wave_period.setMinimum(0.5) elif self.ui.combobox_regparams.currentIndex() == 1: self.parameters = "HL" wp = self.ui.spinbox_wave_period.value() wl = 2*np.pi/wml.dispsolver(2*np.pi/wp, water_depth, decimals=1) self.ui.spinbox_wave_period.setEnabled(False) self.ui.spinbox_wavelength.setDisabled(False) self.ui.slider_horiz.setRange(minL, maxL, 0.001, 10) self.ui.slider_horiz.setValue(wl) self.ui.spinbox_wavelength.setMaximum(maxL) self.ui.spinbox_wavelength.setMinimum(minL)
def elev2stroke(ts_elev, waveheight, waveperiod): """Computes piston stroke from elevation time series. Still needs to be checked for random waves parameters.""" k = dispsolver(2*pi/waveperiod, water_depth, decimals=2) kh = k*water_depth factor = paddle_height/water_depth stroke = 4*(sinh(kh)/kh)*(kh*sinh(kh)-cosh(kh)+1)/(sinh(2*kh)+2*kh) return ts_elev*factor/stroke
def on_wp_changed(self): wp = self.ui.spinbox_wave_period.value() if self.parameters == "HT": hmax = maxH[np.where(periods==np.round(wp, decimals=2))[0]] self.ui.spinbox_wave_height.setMaximum(np.mean(hmax)) self.ui.slider_height.setRange(0, np.mean(hmax), 0.001, 10) wl = 2*np.pi/wml.dispsolver(2*np.pi/wp, water_depth, decimals=1) self.ui.spinbox_wavelength.setValue(wl) self.ui.slider_horiz.setValue(wp)
def elev2stroke(ts_elev, waveheight, waveperiod): """Computes piston stroke from elevation time series. Still needs to be checked for random waves parameters.""" k = dispsolver(2 * pi / waveperiod, water_depth, decimals=2) kh = k * water_depth factor = paddle_height / water_depth stroke = 4 * (sinh(kh) / kh) * (kh * sinh(kh) - cosh(kh) + 1) / (sinh(2 * kh) + 2 * kh) return ts_elev * factor / stroke
def elev2stroke2(ts_elev, sr): """Converts a random elevation time series to piston stroke time series HS=(4*sinh(x)/x)*((x*sinh(x)-cosh(x)+1)/(sinh(2*x)+2*x)); """ # Find kh vector for omegas N = len(ts_elev) HS = np.ones(N)*1e12 # Only compute HS for frequencies corresponding to T = 0.25--8 Hz for n in range(N//1024, N//32): f = n*sr/N*(1 - 2/N) + 1/(sr*N) omega = 2*pi*f kh = water_depth*dispsolver(omega, water_depth, decimals=1) HS[n] = (4*sinh(kh)/kh)*((kh*sinh(kh)-cosh(kh)+1)/(sinh(2*kh)+2*kh)) HS[np.where(np.isnan(HS))[0]] = 1e12 fft_ts = np.fft.fft(ts_elev) A = np.absolute(fft_ts)/HS*paddle_height/water_depth ts_stroke = np.fft.ifft(A*np.exp(1j*np.angle(fft_ts))) return ts_stroke.real
def elev2stroke2(ts_elev, sr): """Converts a random elevation time series to piston stroke time series HS=(4*sinh(x)/x)*((x*sinh(x)-cosh(x)+1)/(sinh(2*x)+2*x)); """ # Find kh vector for omegas N = len(ts_elev) HS = np.ones(N) * 1e12 # Only compute HS for frequencies corresponding to T = 0.25--8 Hz for n in range(N // 1024, N // 32): f = n * sr / N * (1 - 2 / N) + 1 / (sr * N) omega = 2 * pi * f kh = water_depth * dispsolver(omega, water_depth, decimals=1) HS[n] = (4 * sinh(kh) / kh) * ((kh * sinh(kh) - cosh(kh) + 1) / (sinh(2 * kh) + 2 * kh)) HS[np.where(np.isnan(HS))[0]] = 1e12 fft_ts = np.fft.fft(ts_elev) A = np.absolute(fft_ts) / HS * paddle_height / water_depth ts_stroke = np.fft.ifft(A * np.exp(1j * np.angle(fft_ts))) return ts_stroke.real
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.wavegen = None # Add a label to the status bar self.slabel = QLabel() self.ui.statusbar.addWidget(self.slabel) self.slabel.setText("Stopped ") # Add file path combobox to toolbar self.line_edit_fpath = QLineEdit() self.ui.toolbar_main.addWidget(self.line_edit_fpath) self.fpath = "C:\temp" self.line_edit_fpath.setText("C:\\temp") self.toolbutton_fpath = QToolButton() self.ui.toolbar_main.addWidget(self.toolbutton_fpath) self.toolbutton_fpath.setIcon(QIcon(":icons/folder_yellow.png")) # Add file name and extension controls to toolbar self.line_edit_fname = QLineEdit() self.ui.toolbar_main.addWidget(self.line_edit_fname) self.line_edit_fname.setFixedWidth(50) self.line_edit_fname.setText("run") self.spinbox_run = QSpinBox() self.ui.toolbar_main.addWidget(self.spinbox_run) self.spinbox_run.setValue(1) self.combobox_ftype = QComboBox() self.ui.toolbar_main.addWidget(self.combobox_ftype) self.combobox_ftype.addItem("*.npy") self.combobox_ftype.addItem("*.csv") self.combobox_ftype.addItem("*.mat") # Set up a timer self.timer = QTimer() self.timer.timeout.connect(self.on_timer) # Set up a control variable for parameters self.parameters = "HT" # Set default tab to regular waves self.ui.tabwidget.setCurrentIndex(0) # Initialize slider values self.ui.slider_height.setRange(0.0, 0.4, 0.001, 10) self.ui.slider_height.setValue(self.ui.spinbox_wave_height.value()) self.ui.slider_height.setScaleMaxMajor(12) self.ui.slider_horiz.setRange(0.5, 5, 0.001, 10) self.ui.slider_horiz.setScaleMaxMajor(12) self.ui.slider_horiz.setValue(self.ui.spinbox_wave_period.value()) # Initialize wavelength value wl = 2*np.pi/wml.dispsolver(2*np.pi/1.0, water_depth, decimals=2) self.ui.spinbox_wavelength.setValue(wl) # Connect signals and slots using function defined below self.connectslots() # Initialize plot settings self.initialize_plots() # Add dock widgets to right dock widget area and tabify them self.tabifyDockWidget(self.ui.dock_measure, self.ui.dock_time_series) self.tabifyDockWidget(self.ui.dock_measure, self.ui.dock_spectrum) self.tabifyDockWidget(self.ui.dock_time_series, self.ui.dock_measure)
# Some universal constants physchan = "Dev1/ao0" samprate = 200.0 stroke_cal = 7.8564 # Volts per meter stroke or wave height? paddle_height = 1.0 water_depth = 2.44 minperiod = 0.5 maxperiod = 5.0 max_halfstroke = 0.16 max_H_L = 0.1 max_H_D = 0.65 periods = np.round(np.load("periods.npy"), decimals=3) maxH = np.load("maxH.npy") minL = 2*np.pi/wml.dispsolver(2*np.pi/0.65, water_depth, decimals=2) maxL = 2*np.pi/wml.dispsolver(2*np.pi/4.50, water_depth, decimals=2) # Constants specific to rand waves buffsize_rand = 65536 sub_buffsize = 128 minperiod_rand = 0.90 maxperiod_rand = 3.5 cutoff_freq = 2.0 max_H_L_rand = 0.07 max_H_d_rand = 0.50 class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self)