Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This dummy project required the execution of the following python scripts before the simulations are submitted:.

Create_grid.py

Code Block
languagebash
themeDJango
import os
import shutil

path_bot = snakemake.input.path_bot
path_fxw = snakemake.input.path_fxw
output_bot = snakemake.output.output_bot
output_fxw = snakemake.output.output_fxw

## In this demo only files are copied, but in reality bed and fxw are created based on external data.

shutil.copyfile(path_bot, output_bot)
shutil.copyfile(path_fxw, output_fxw)

...

create_output_locations.py

Code Block
languagebash
themeDJango
import os
import shutil

path_p1 = snakemake.input.path_p1
path_p2 = snakemake.input.path_p2
output_p1 = snakemake.output.output_p1
output_p2 = snakemake.output.output_p2

## In this demo only files are copied, but in reality bed and fxw are created based on external data.

shutil.copyfile(path_p1, output_p1)
shutil.copyfile(path_p2, output_p2) 

create_sims.py

Code Block
languagebash
themeDJango
import os
import numpy as np
from shutil import copyfile
from mako.template import Template

def render_template(data,template):
    '''
    Render template
    input:
        data: dictionary with variables to render
        template: template file
    '''
    with open(template) as f:
        template = f.read()
    ##
    tmpl = Template(text=template)

    with open(os.path.join(data['output_path'], '{}.{}'.format(data['fname'],data['extension']) ),mode='w') as f:
        f.write(tmpl.render(**data))




path_sims = snakemake.output.path_sims
path_template = snakemake.input.path_template

## if file exists overwrite
overwrite            = False
swan_template        = 'swan_template_final.swn'

# =============================================================================
#  wave conditions
# =============================================================================

wind_speed_list           = [30, 20]

# =============================================================================
#  create sims
# =============================================================================


## template file
template        = os.path.join(path_template,swan_template)

run_condition = {'water_level':[],
                 'wind_speed':[],
                 'wind_dir':[]}
## make combinations
for ii, item in enumerate(wind_speed_list):
    ## get conditions
    wind_speed  = item

    fname = 'U{}'.format(wind_speed)

    
    ## data for template
    data = {'output_path':os.path.dirname(path_sims[ii]),
            'extension':'swn',
            'variant':'A',
            'fname':fname,
            'wind_speed': wind_speed,
            'wind_dir': 180,
            'water_level': 0}
    
    ## skip if file already exists
    if os.path.exists(os.path.join(path_sims[ii], '{}.swn'.format(fname))) and overwrite:
        print('skipped {}'.format(fname))
        continue
    ## render template
    render_template(data,template)
    ## copy swan_run

    copyfile(os.path.join(path_template,'swan4131A1c7.sh'), os.path.join(os.path.dirname(path_sims[ii]),'swan4131A1c7.sh'))