generated from interTwin-eu/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from interTwin-eu/workflow_offshore
Workflow offshore
- Loading branch information
Showing
24 changed files
with
31,569 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
cache/ | ||
tmp/ | ||
|
||
__pycache__/ | ||
*.py[cod] | ||
|
||
.vscode/ | ||
|
||
DT_flood/workflows/deltares_sfincs-cpu:sfincs-v2.0.3-Cauberg.sfincs | ||
DT_flood/workflows/deltares_wflow:v0.7.3.sif |
Binary file modified
BIN
+438 Bytes
(100%)
DT_flood/utils/__pycache__/fa_scenario_utils.cpython-311.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import pandas as pd | ||
|
||
from cht.misc.deltares_ini import IniStruct | ||
from cht.sfincs.sfincs import FlowBoundaryPoint | ||
from cht.tide.tide_predict import predict | ||
|
||
from earthkit.data import from_source | ||
from earthkit.regrid import interpolate | ||
|
||
|
||
def read_flow_boundary_points(bnd_fn): | ||
flow_boundary_point = [] | ||
|
||
# if not os.path.exists(bnd_fn): | ||
# return | ||
|
||
# Read the bnd file | ||
df = pd.read_csv(bnd_fn, index_col=False, header=None, | ||
delim_whitespace=True, names=['x', 'y']) | ||
|
||
# Loop through points | ||
for ind in range(len(df.x.values)): | ||
name = str(ind + 1).zfill(4) | ||
point = FlowBoundaryPoint(df.x.values[ind], | ||
df.y.values[ind], | ||
name=name) | ||
flow_boundary_point.append(point) | ||
return flow_boundary_point | ||
|
||
|
||
def read_astro_boundary_conditions(flow_boundary_point,bca_fn): | ||
|
||
# Read SFINCS bca file | ||
# if not os.path.exists(bca_fn): | ||
# return | ||
|
||
d = IniStruct(filename=bca_fn) | ||
for ind, point in enumerate(flow_boundary_point): | ||
point.astro = d.section[ind].data | ||
return flow_boundary_point | ||
|
||
def generate_bzs_from_bca(flow_boundary_point, | ||
tref, | ||
tstart, | ||
tstop, | ||
bzs_fn=None, | ||
dt:int=600, | ||
offset=0.0, | ||
write_file=True): | ||
|
||
if bzs_fn is None: | ||
bzs_fn = "sfincs.bzs" | ||
|
||
try: | ||
times = pd.date_range(start=tstart, | ||
end=tstop, | ||
freq=f"{dt}S") | ||
except: | ||
print("Dates fall outside pandas date_range, year 2000 used instead") | ||
tref = tref.replace(year=2000) | ||
tstart = tstart.replace(year=2000) | ||
tstop = tstop.replace(year=2000) | ||
times = pd.date_range(start=tstart, | ||
end=tstop, | ||
freq=f"{dt}S") | ||
|
||
# Make boundary conditions based on bca file | ||
df = pd.DataFrame() | ||
|
||
for i, point in enumerate(flow_boundary_point): | ||
v = predict(point.astro, times) + offset | ||
ts = pd.Series(v, index=times) | ||
point.data = pd.Series(v, index=times) | ||
df = pd.concat([df, point.data], axis=1) | ||
tmsec = pd.to_timedelta(df.index.values - tref, unit="s") | ||
df.index = tmsec.total_seconds() | ||
|
||
if write_file: | ||
# Build a new DataFrame | ||
df.to_csv(bzs_fn, | ||
index=True, | ||
sep=" ", | ||
header=False, | ||
float_format="%0.3f") | ||
return df | ||
|
||
def process_dt_climate(filepath, tstart, tend, bounds, res=.1): | ||
# bounds are list/array in order [minx, miny, maxx, maxy] | ||
|
||
start = int(tstart.strftime("%Y%m%d")) | ||
end = int(tend.strftime("%Y%m%d")) | ||
|
||
print("Loading data") | ||
data = from_source("file", filepath).sel(dataDate=slice(start,end)) | ||
print(f"Interpolating data to grid with resolution {res} deg") | ||
data = interpolate(data, out_grid={"grid": [res,res]}, method='linear') | ||
ds = data.to_xarray(xarray_open_dataset_kwargs={'chunks': {"time": 1}}).squeeze() | ||
|
||
ds = ds.assign_coords( | ||
{"longitude": ((ds.longitude+180)%360)-180} | ||
) | ||
ds.sortby("longitude") | ||
ds.sortby("latitude") | ||
ds = ds.rename( | ||
{ | ||
"longitude": "x", | ||
"latitude": "y", | ||
"sp": "press_msl", | ||
"u10": "wind10_u", | ||
"v10": "wind10_v" | ||
} | ||
) | ||
ds.raster.set_crs(4326) | ||
|
||
ds = ds.sel( | ||
x=slice(bounds[0], bounds[2]), | ||
y=slice(bounds[1], bounds[3]) | ||
) | ||
|
||
return ds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cwlVersion: v1.2 | ||
class: CommandLineTool | ||
|
||
baseCommand: ["python"] | ||
|
||
requirements: | ||
InlineJavascriptRequirement: {} | ||
InitialWorkDirRequirement: | ||
listing: | ||
- $(inputs.pyscript) | ||
- $(inputs.fa_database) | ||
|
||
inputs: | ||
pyscript: | ||
type: File | ||
inputBinding: | ||
position: 1 | ||
fa_database: | ||
type: Directory | ||
inputBinding: | ||
position: 2 | ||
scenario: | ||
type: string | ||
inputBinding: | ||
position: 3 | ||
|
||
|
||
|
||
outputs: | ||
fa_database_out: | ||
type: Directory | ||
outputBinding: | ||
glob: "$(inputs.fa_database.basename)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
update_script: | ||
class: File | ||
path: "../pyscripts/update_ra2ce.py" | ||
run_script: | ||
class: File | ||
path: "../pyscripts/run_ra2ce.py" | ||
fa_database: | ||
class: Directory | ||
path: "/home/wotromp/InterTwin/FloodAdapt_database/Humber" | ||
scenario: "Empty_Event_current_no_measures" | ||
utils_script: | ||
class: File | ||
path: "../../utils/ra2ce_utils_docker.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pyscript: | ||
class: File | ||
path: "../pyscripts/run_ra2ce.py" | ||
fa_database: | ||
class: Directory | ||
path: "/home/wotromp/InterTwin/FloodAdapt_database/Humber" | ||
scenario: "Empty_Event_current_no_measures" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pyscript: | ||
class: File | ||
path: "../pyscripts/update_ra2ce.py" | ||
fa_database: | ||
class: Directory | ||
path: "/home/wotromp/InterTwin/FloodAdapt_database/Humber" | ||
scenario: "Empty_Event_current_no_measures" | ||
utils_script: | ||
class: File | ||
path: "../../utils/ra2ce_utils_docker.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pathlib import Path | ||
from sys import argv | ||
|
||
from flood_adapt.api import scenarios | ||
from DT_flood.utils.fa_scenario_utils import init_scenario | ||
|
||
database, scenario_config = init_scenario(Path(argv[1]), (argv[2]+"_toplevel.toml")) | ||
|
||
scenario = scenarios.get_scenario(scenario_config['name']) | ||
|
||
scenario.direct_impacts.postprocess_fiat() |
Oops, something went wrong.