Skip to content

Commit d042995

Browse files
author
Sylfest Glimsdal
committed
adding jupyter notebook for inetactive exercises
1 parent b89f3bd commit d042995

10 files changed

Lines changed: 24123 additions & 2418 deletions

File tree

calculate_MIH/calculate_MIH.ipynb

Lines changed: 172 additions & 0 deletions
Large diffs are not rendered by default.

calculate_MIH/calculate_MIH_HySEA.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ def interp_ampfact(inper: float, per: list, af: dict):
113113

114114

115115

116-
def computeMIH(AF_file: str, tms_file: str, tms_id_file: str, results_file: str) -> None:
116+
def computeMIH(af: dict, tms_file: str, tms_id_file: str, results_file: str) -> None:
117117

118-
#read in ampfactors
119-
af=readAF(AF_file)
118+
#dictionary for ampfacts is in af
120119

121120
###################################################################
122121
#
@@ -156,8 +155,9 @@ def computeMIH(AF_file: str, tms_file: str, tms_id_file: str, results_file: str)
156155
#####################################################################
157156

158157
if __name__=="__main__":
159-
ampfact="../ampfactors/global_ampf_v04.txt" #corresponding factors for POIs
158+
ampfact="../ampfactors/global_ampf_v04.txt"
159+
af=readAF(ampfact) #corresponding factors for POIs
160160
tms_file="example_HySEA/result_ts.nc" #output from HySEA, location of POIs from ampfact
161161
tms_id_file="example_HySEA/result_ts.nc_id.txt" #input id file, location of POIs in HySEA with corresponding id
162162
out_results="example_HySEA/calculated_MIH_HySEA.txt" #name of outputfile
163-
computeMIH(ampfact,tms_file, tms_id_file, out_results)
163+
computeMIH(af,tms_file, tms_id_file, out_results)

calculate_MIH/calculate_MIH_general.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/usr/bin/python3
22

3-
import subprocess
4-
import netCDF4
5-
import os
63
import numpy as np
74
import waveform
85
from scipy import interpolate
96

10-
def tms(tms_file: str, af: dict, af_id: str, plot: bool, plot_dir: str, plot_name: str="out"):
7+
def tms(tms_file: str, af: dict, af_id: str, plot: bool, plot_dir: str, plot_name: str="out",tsample: int=30):
118
arr=np.loadtxt(tms_file)
129
e=arr[:,1]
1310
time=arr[:,0]
@@ -17,7 +14,7 @@ def tms(tms_file: str, af: dict, af_id: str, plot: bool, plot_dir: str, plot_nam
1714
#find id
1815
print(f"Prosessing mariogram from {tms_file}")
1916
#extract periode, polarity and height
20-
period,hmax,polarity=waveform.waveform(time,e,plot_name,plot_dir,treshold=0.05,plot=plot,quiet=True)
17+
period,hmax,polarity=waveform.waveform(time,e,plot_name,plot_dir,treshold=0.05,plot=plot,quiet=True, tsample=tsample)
2118

2219
#extract/interp af
2320
if period<0.0:
@@ -78,13 +75,13 @@ def interp_ampfact(inper: float, per: list, af: dict):
7875

7976

8077

81-
def computeMIH(ampfact_file: str, ampfact_id: str, tms_file: str, plot: bool=False, plot_name: str="", plot_dir: str="") -> None:
78+
def computeMIH(ampfact_file: str, ampfact_id: str, tms_file: str, plot: bool=False, plot_name: str="", plot_dir: str="", tsample: int=30) -> None:
8279

8380
#read in ampfactors
8481
af=readAF(ampfact_file)
8582
# extract amp.factor based on wave forms (polarity and periode)
8683
# and offshore surface elevation, and calculate MIH
87-
results=tms(tms_file, af, ampfact_id, plot, plot_dir, plot_name)
84+
results=tms(tms_file, af, ampfact_id, plot, plot_dir, plot_name,tsample=30)
8885

8986

9087
#####################################################################
@@ -96,6 +93,7 @@ def computeMIH(ampfact_file: str, ampfact_id: str, tms_file: str, plot: bool=Fal
9693
if __name__=="__main__":
9794
ampfact="../ampfactors/global_ampf_v04.txt" #table for amplification factors, either using this global set, or calculating your own table from depth profiles
9895
tms_file="example_general/tms_00500.txt" #surface elevation as function of time (sec), two columns ascii file, with time[s] and surf.elev[m]
96+
tms_file="example_general/spletaD4_m.txt"
9997
ampfact_id="id03700" #corresponding id in ampfact-file above
10098
plot_dir="plot"
10199
plot_name="check"

calculate_MIH/example_general/spletaD3_m.txt

Lines changed: 5984 additions & 0 deletions
Large diffs are not rendered by default.

calculate_MIH/example_general/spletaD4_m.txt

Lines changed: 5984 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)