Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/misc.xml

This file was deleted.

28 changes: 17 additions & 11 deletions RunWorkFlow_STWAVE.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os, getopt, sys, shutil, glob, platform, logging, yaml
from testbedutils import fileHandling
from getdatatestbed import getDataFRF
import pickle

def Master_STWAVE_run(inputDict):
"""This will run STWAVE with any version prefix given start, end, and timestep
Expand Down Expand Up @@ -81,7 +82,7 @@ def Master_STWAVE_run(inputDict):
# ______________________________gather all data _____________________________
if generateFlag == True:
go = getDataFRF.getObs(projectStart, projectEnd) # initialize get observation
rawspec = go.getWaveSpec(gaugenumber='waverider-26m', specOnly=True)
rawspec = go.getWaveData(gaugenumber='waverider-26m', spec=True)
rawWL = go.getWL()
rawwind = go.getWind(gaugenumber=0)
loc_dict = go.get_sensor_locations(datafile=FRFgaugelocsFile, window_days=14)
Expand All @@ -92,18 +93,20 @@ def Master_STWAVE_run(inputDict):
# run the process through each of the above dates
errors, errorDates, curdir = [], [], os.getcwd()
for time in dateStringList:
print(' ------------------------------ START %s --------------------------------' %time)

# print(' ------------------------------ START %s --------------------------------' %time)
#
try:
datadir = os.path.join(workingDirectory, ''.join(time.split(':'))) # moving to the new simulation's folder
if generateFlag == True:
[nproc_par, nproc_nest] = STsimSetup(time, inputDict, rawwind, rawWL, rawspec, bathy, loc_dict)
pickleSaveFname = os.path.join(datadir, ''.join(time.split(':')) + '_io.pickle')

if nproc_par == -1 or nproc_nest == -1:
print('************************\nNo Data available\naborting run\n***********************')
# remove generated files?
shutil.rmtree(os.path.join(workingDirectory,''.join(time.split(':'))))
continue # this is to return to the next time step if there's no data
if generateFlag == True:
nproc_par, nproc_nest, stio = STsimSetup(time, inputDict, rawwind, rawWL, rawspec, bathy)
pickle.dump(stio, open(pickleSaveFname, 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
if nproc_par == -1 or nproc_nest == -1:
print('************************\nNo Data available\naborting run\n***********************')
# remove generated files?
shutil.rmtree(os.path.join(workingDirectory,''.join(time.split(':'))))
continue # this is to return to the next time step if there's no data

if runFlag == True:
os.chdir(datadir) # changing locations to where simulation files live
Expand All @@ -127,10 +130,13 @@ def Master_STWAVE_run(inputDict):
count = nproc_nest # lower the processors called for to match sim file (otherwise will throw segfault)
child = check_output('mpiexec -n {} {} {}nested.sim'.format(count, executableLocation, ''.join(time.split(':'))), shell=True)
print((' Simulations took {:.2f} hours'.format((DT.datetime.now() - t).total_seconds()/3600)))
pickle.dump(stio, open(pickleSaveFname, 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
# run analyze and archive script
os.chdir(curdir) # change back after runing simulation locally
if analyzeFlag == True:
beachWaves = STanalyze(time, inputDict)
if runFlag is False:
stio = pickle.load(open(pickleSaveFname, 'rb'))
beachWaves = STanalyze(time, inputDict, stio)
if pFlag == True and DT.date.today() == endTime.date():
print('**\n Moving Plots! \n &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&')
# move files
Expand Down
60 changes: 28 additions & 32 deletions frontback/frontBackFUNWAVE.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from testbedutils import sblib as sb
from testbedutils import waveLib as sbwave
from testbedutils import fileHandling
from testbedutils import timeDomain
from plotting.operationalPlots import obs_V_mod_TS
from testbedutils import geoprocess as gp
import multiprocessing
Expand Down Expand Up @@ -63,14 +64,6 @@ def FunwaveSimSetup(startTime, rawWL, rawspec, bathy, inputDict):
assert 'time' in rawspec, "\n++++\nThere's No Wave data"
# preprocess wave spectra


#if version_prefix.lower() == 'base':
# wavepacket1 = prepdata.prep_SWASH_spec(rawspec, version_prefix, model=model, nf=inputDict['modelSettings']['nf'])

#else:
# #raise NotImplementedError('pre-process TS data ')
# wavepacket1 = prepdata.prep_SWASH_spec(rawspec, version_prefix, model=model, nf=inputDict['modelSettings']['nf'])

wavepacket = prepdata.prep_SWASH_spec(rawspec, version_prefix, model=model, nf=nf, phases=phases,
grid=inputDict['modelSettings']['grid'])

Expand Down Expand Up @@ -185,8 +178,8 @@ def FunwaveAnalyze(startTime, inputDict, fio):
######################################################################################################################
######################################################################################################################

outputFolder = os.path.join(fpath,'output')
print('Loading files ',outputFolder)
outputFolder = os.path.join(fpath, 'output')
print('Loading files ', outputFolder)

## upload depth file
depthFile = os.path.join(outputFolder, 'dep.out')
Expand Down Expand Up @@ -216,34 +209,36 @@ def FunwaveAnalyze(startTime, inputDict, fio):
eta = simData['eta'].squeeze()

# now adapting Chuan's runup code, here we use 0.08 m for runup threshold
r_depth = 0.08 # 4.0 * np.nanmax(np.abs(h[runupInd][1:] - h[runupInd][:-1]))

# r_depth = 0.08 # 4.0 * np.nanmax(np.abs(h[runupInd][1:] - h[runupInd][:-1]))
# Preallocate runup variable
runup = np.zeros(eta.shape[0])
x_runup = np.zeros_like(runup)

for aa in range(runup.shape[0]):
# Water depth
wdepth = eta[aa, :] + simData['elevation']
# Find the runup contour (search from left to right)
wdepth_ind = np.argmin(abs(wdepth - r_depth)) # changed from Chuan's original code
# Store the water surface elevation in matrix
runup[aa] = eta[aa, wdepth_ind] # unrealistic values for large r_depth
# runup[aa]= -h[wdepth_ind]
# Store runup position
x_runup[aa] = simData['xFRF'][wdepth_ind]
maxRunup = np.amax(runup)

# runup = np.zeros(eta.shape[0])
# x_runup = np.zeros_like(runup)
#
# for aa in range(runup.shape[0]):
# # Water depth
# wdepth = eta[aa, :] + simData['elevation']
# # Find the runup contour (search from left to right)
# wdepth_ind = np.argmin(abs(wdepth - r_depth)) # changed from Chuan's original code
# # Store the water surface elevation in matrix
# runup[aa] = eta[aa, wdepth_ind] # unrealistic values for large r_depth
# # runup[aa]= -h[wdepth_ind]
# # Store runup position
# x_runup[aa] = simData['xFRF'][wdepth_ind]
# maxRunup = np.amax(runup)

runupTS, x_runup, r_depth = timeDomain.runup_func(eta, Depth1D, simData['xFRF'], r_depth=0.1)
r2, peaks, maxSetup = timeDomain.identifyR2(runupTS, percentile=2)
r2 = r2 + simMeta['WL']
######################################################################################################################
######################################################################################################################
################################## plotting #########################################################################
######################################################################################################################
######################################################################################################################
fileHandling.makeCMTBfileStructure(path_prefix,date_str=datestring)
fileHandling.makeCMTBfileStructure(path_prefix, date_str=datestring)
figureBaseFname = 'CMTB_waveModels_{}_{}_'.format(model, version_prefix)

# make function for processing timeseries data
data = simData['eta'].squeeze()[cutRampingTime:,:]
data = simData['eta'].squeeze()[cutRampingTime:, :]

time = []
for i in range(len(simData['time'].squeeze()[cutRampingTime:])): ## change time from float to datetime
Expand All @@ -253,7 +248,7 @@ def FunwaveAnalyze(startTime, inputDict, fio):
SeaSwellCutoff = 0.05 # cutoff between sea/swell and IG
nSubSample = 5

fspec, freqs = sbwave.timeSeriesAnalysis1D(np.asarray(time), data, bandAvg=3)#6,WindowLength=20)
fspec, freqs = sbwave.timeSeriesAnalysis1D(np.asarray(time), data, bandAvg=3) #6,WindowLength=20)
total = sbwave.stats1D(fspec=fspec, frqbins=freqs, lowFreq=None, highFreq=None)
SeaSwellStats = sbwave.stats1D(fspec=fspec, frqbins=freqs, lowFreq=SeaSwellCutoff, highFreq=None)
IGstats = sbwave.stats1D(fspec=fspec, frqbins=freqs, lowFreq=None, highFreq=SeaSwellCutoff)
Expand All @@ -264,6 +259,7 @@ def FunwaveAnalyze(startTime, inputDict, fio):
#############################################################################################################
WL = simMeta['WL'] #added in editing, should possibly be changed?
setup = np.mean(simData['eta'] + WL, axis=0).squeeze()

if plotFlag == True:
from plotting import operationalPlots as oP
## remove images before making them if reprocessing
Expand Down Expand Up @@ -329,8 +325,8 @@ def FunwaveAnalyze(startTime, inputDict, fio):
'waveHsIG': np.expand_dims(IGstats['Hm0'], axis=0),
'elevation': np.expand_dims(simData['elevation'], axis=0),
'eta': np.expand_dims(simData['eta'], axis=0),
'totalWaterLevel': maxRunup,
'totalWaterLevelTS': np.expand_dims(runup, axis=0),
'totalWaterLevel': r2,
'totalWaterLevelTS': np.expand_dims(runupTS, axis=0),
'velocityU': np.expand_dims(simData['velocityU'], axis=0),
'velocityV': np.expand_dims(simData['velocityV'], axis=0),
'waveHs': np.expand_dims(SeaSwellStats['Hm0'], axis=0), # or from HsTS??
Expand Down
Loading