-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STOFS-3D scripts: Minor updates on the driver script and tested on He…
…rcules.
- Loading branch information
1 parent
c421d36
commit f859616
Showing
4 changed files
with
424 additions
and
203 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
72 changes: 47 additions & 25 deletions
72
src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Prop/gen_tvd.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 |
---|---|---|
@@ -1,37 +1,59 @@ | ||
import os | ||
''' | ||
Generate tvd.prop file for the high-order transport schemes in SCHISM | ||
''' | ||
import numpy as np | ||
|
||
from pylib import schism_grid, read_schism_bpfile, inside_polygon | ||
import socket | ||
import pylib | ||
from pylib import read_schism_bpfile, inside_polygon | ||
if 'sciclone' in socket.gethostname(): | ||
from pylib_experimental.schism_file import cread_schism_hgrid as schism_read | ||
else: | ||
from pylib import schism_grid as schism_read | ||
|
||
if __name__ == '__main__': | ||
|
||
#Read hgrid | ||
hgrid_name='hgrid.gr3' | ||
gr3_pkl = 'hgrid.pkl' | ||
if os.path.exists(gr3_pkl): | ||
print('Reading hgrid.pkl') | ||
gd = schism_grid(gr3_pkl) | ||
else: | ||
print('Reading hgrid.gr3') | ||
gd = schism_grid(hgrid_name) | ||
gd.save(gr3_pkl) | ||
|
||
def gen_tvd_prop(hg: pylib.schism_grid, regions: list): | ||
''' | ||
Generate tvd.prop file for the high-order transport schemes in SCHISM | ||
#gd = read_schism_hgrid('hgrid.gr3') | ||
gd.compute_ctr() | ||
Parameters | ||
---------- | ||
hg : schism_grid | ||
SCHISM grid object | ||
regions : list | ||
list of region files, | ||
in the final output tvd.prop: 1 for inside region, 0 for outside region | ||
regions = ['tvd0_1.reg', 'tvd0_2.reg', 'tvd0_3.reg', 'tvd0_4.reg', \ | ||
'tvd0_5.reg', 'tvd0_6.reg', 'tvd0_7.reg', \ | ||
'upwind_east_Carribbean.rgn', 'upwind_west_Carribbean.rgn'] | ||
Returns | ||
------- | ||
None | ||
#write constant (=1) *prop | ||
ab = np.ones(gd.ne) | ||
''' | ||
hg.compute_ctr() | ||
tvd = np.zeros(hg.ne) | ||
|
||
#reset values (=0) within region | ||
for region in regions: | ||
bp = read_schism_bpfile(region, fmt=1) | ||
sind = inside_polygon(np.c_[gd.xctr,gd.yctr], bp.x, bp.y) | ||
ab[sind==1] = 0 | ||
idx = inside_polygon(np.c_[hg.xctr, hg.yctr], bp.x, bp.y) | ||
tvd[idx == 1] = 1 | ||
|
||
hg.write_prop('tvd.prop', value=tvd, fmt='{:d}') | ||
|
||
|
||
gd.write_prop('tvd.prop',value=ab, fmt='{:d}') | ||
def sample_usage(): | ||
''' | ||
Sample usage of gen_tvd_prop | ||
''' | ||
gd = schism_read('hgrid.gr3') | ||
|
||
regions = [ | ||
'tvd0_1.reg', 'tvd0_2.reg', 'tvd0_3.reg', 'tvd0_4.reg', | ||
'tvd0_5.reg', 'tvd0_6.reg', 'tvd0_7.reg', | ||
'upwind_east_Carribbean.rgn', 'upwind_west_Carribbean.rgn' | ||
] | ||
|
||
gen_tvd_prop(gd, regions) | ||
|
||
|
||
if __name__ == '__main__': | ||
sample_usage() |
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
Oops, something went wrong.