Skip to content

Commit

Permalink
Merge pull request #69 from schism-dev/hgrid
Browse files Browse the repository at this point in the history
Hgrid
  • Loading branch information
cuill authored Apr 21, 2023
2 parents 96aedc3 + 3f4dbfa commit 9636a64
Show file tree
Hide file tree
Showing 48 changed files with 3,484 additions and 712 deletions.
70 changes: 70 additions & 0 deletions examples/Bctides/gen_bctides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from time import time
import os
from datetime import datetime, timedelta
import logging
import pathlib
import f90nml

from pyschism.mesh import Hgrid
from pyschism.forcing.bctides import Bctides, iettype, ifltype, isatype, itetype
from pyschism.forcing.source_sink.nwm import NationalWaterModel, NWMElementPairings
from pyschism.forcing.nws import NWS2, GFS, HRRR

if __name__ == "__main__":

'''
Assume files are already located in:
database='fes2014'
~/.local/share/fes2014/eastward_velocity/
~/.local/share/fes2014/northward_velocity/
~/.local/share/fes2014/ocean_tide_extrapolated/
database = 'tpxo'
~/.local/share/tpxo/
'''
#setup logging
logging.basicConfig(
format = "[%(asctime)s] %(name)s %(levelname)s: %(message)s",
force=True,
)
logging.getLogger("pyschism").setLevel(logging.DEBUG)

start_date = datetime(2017, 12, 1)
rnday = 396
end_date = start_date + timedelta(days=61)
outdir = './'
hgrid = Hgrid.open("./hgrid.gr3", crs="epsg:4326")

#elevation
iet3 = iettype.Iettype3(constituents='major', database='fes2014')
iet4 = iettype.Iettype4()
iet5 = iettype.Iettype5(iettype3=iet3, iettype4=iet4)

#velocity
ifl1 = ifltype.Ifltype1()
ifl3 = ifltype.Ifltype3(constituents='major', database='fes2014')
ifl4 = ifltype.Ifltype4()
ifl5 = ifltype.Ifltype5(ifltype3=ifl3, ifltype4=ifl4)

#salinity
isa4 = isatype.Isatype4()
isa2 = isatype.Isatype2(5, 1)

#temperature
ite4 = itetype.Itetype4()
ite2 = itetype.Itetype2(0, 1)

bctides=Bctides(
hgrid,
iettype={'1': iet5, '2': iet5},
ifltype={'1': ifl5, '2': ifl5, '3': ifl1},
isatype={'1': isa4, '2':isa4, '3': isa2},
itetype={'1': ite4, '2':ite4, '3': ite2}
)

bctides.write(
outdir,
start_date=start_date,
end_date=end_date,
bctides=True,
overwrite=True
)
23 changes: 23 additions & 0 deletions examples/Gr3/Drag/GoME+0.001.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Region written by ACE/gredit
1
20 1
-70.711855 41.847215
-70.588878 41.984546
-70.567176 42.172472
-70.473134 42.729025
-70.205477 43.220526
-69.474846 43.632519
-68.563365 43.950549
-67.196145 44.427594
-66.819978 44.832360
-66.805510 44.933551
-67.268484 45.092566
-68.353580 45.186529
-69.735269 45.034742
-71.804185 43.632519
-72.079076 43.090423
-71.898226 42.541098
-71.138659 42.201384
-70.899938 42.078509
-70.827599 42.042369
-70.762493 41.883354
20 changes: 20 additions & 0 deletions examples/Gr3/Drag/Lake_Charles_0.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Region written by ACE/gredit
1
17 1
-93.248568 30.287045
-93.189017 30.265876
-93.200469 30.222967
-93.231390 30.185778
-93.270327 30.117695
-93.296094 30.045607
-93.316708 30.037597
-93.324152 29.986106
-93.323579 29.943769
-93.317853 29.807030
-93.323579 29.773275
-93.363089 29.773275
-93.363089 29.885412
-93.348201 29.988395
-93.341330 30.082795
-93.350492 30.142869
-93.321862 30.214957
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from pyschism.mesh.hgrid import Hgrid
from pyschism.mesh.fgrid import DragCoefficient

hgrid=Hgrid.open('/sciclone/schism10/whuang07/NWM/Case1/RUN07b_ZG/hgrid.gr3', crs='epsg:4326')
hgrid=Hgrid.open('./hgrid.gr3', crs='epsg:4326')
depth1=-1.0
depth2=-3.0
bfric_river=0.0025
bfric_land=0.025
fgrid=DragCoefficient.linear_with_depth(hgrid, depth1, depth2, bfric_river, bfric_land)

#modify values in regions
regions=['GoME+0.001.reg', 'Lake_Charles_0.reg']
values=[0.001, 0.0]
flags=[1, 0]
flags=[1, 0] # 0: reset to given value, 1: add given value to the current value
for reg, value, flag in zip(regions, values, flags):
fgrid.modify_by_region(hgrid, f'Drag_Python/{reg}', 0.001,depth1, 1)
fgrid.modify_by_region(hgrid, f'./{reg}', value, depth1, flag)

fgrid.write('drag.gr3', overwrite=True)
9 changes: 9 additions & 0 deletions examples/Gr3/Elev_IC/gen_elev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pyschism.mesh.base import Gr3
from pyschism.mesh.gridgr3 import ElevIc

if __name__ == '__main__':

hgrid = Gr3.open('./hgrid.gr3', crs='epsg:4326')

elevic = ElevIc.default(hgrid=hgrid, offset=0.1)
elevic.write('elev.ic', overwrite=True)
100 changes: 100 additions & 0 deletions examples/Gr3/Shapiro/coastal_0.2.cpp.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

1
97 1
-2087974.19892804 2735461.69114659
-2046267.92519898 2858522.40115863
-2035841.34196965 2913215.91823516
-2050438.86055683 3011208.43213511
-2027500.33426503 3093248.84537155
-1967025.86885042 3141105.86693440
-1848162.52744231 3200357.41374636
-1754323.30236814 3264166.71804448
-1664654.96156731 3280119.07046258
-1583328.03311239 3245935.65378028
-1479062.77871217 3216310.14785139
-1443612.61986214 3191242.29593169
-1395650.62825981 3182126.70366696
-1328920.94616267 3223146.84159508
-1295556.11362641 3248214.71207795
-1245508.97358513 3227704.65888461
-1220485.30601345 3236820.15783981
-1189205.77591216 3286955.88916706
-1157926.34976052 3327976.01260565
-1095367.30002346 3327976.01664844
-1034893.64740146 3341649.43003119
-1009869.99155960 3359880.53370987
-957737.49618650 3364438.33868968
-916031.54254958 3357601.68995285
-870154.91374796 3316581.57039991
-863899.05146884 3289234.86073454
-813851.84959525 3257330.23677857
-767975.22361845 3259609.19461440
-724183.98731015 3225425.72426741
-659539.67575409 3143385.59543170
-605321.90278038 3029440.84194120
-544848.26862581 2865360.36119174
-536507.01806169 2774204.62507747
-567786.52933550 2737742.30829268
-513568.75721901 2728626.70139270
-413474.36214879 2749136.76160622
-327977.07926365 2790156.88185876
-313380.06901297 2835734.69426225
-311294.68014425 2906380.48159590
-309209.39297320 2999815.17512957
-323806.50493764 3100086.51825603
-353000.72887166 3207194.62229566
-394706.67592320 3284677.05921303
-419730.32554551 3398621.70152670
-388450.81439184 3503450.95949357
-286271.13232808 3606001.14873164
-213285.67427848 3665252.48296850
-123617.81714054 3713109.25278223
-73570.61978679 3724503.70588242
-42291.10873009 3715388.09887429
-38120.53437502 3767802.67219048
-25608.70961326 3792870.53580273
20267.81168508 3817938.39941500
49462.03556304 3820217.24550671
76570.97226339 3820217.24550672
78656.25944087 3854400.71612716
143300.46703233 3904536.44335163
176665.26526503 3929604.19564317
166238.82937764 3995692.17947167
128703.45678998 4095963.52259992
168324.11655511 4189398.21613237
205860.12695341 4280554.58522318
235053.71302052 4330689.67947690
272589.08560818 4364873.15009736
312209.74537334 4430961.13392587
322636.28295726 4494770.16034198
360171.65554500 4510722.41694602
504057.28436660 4549463.57974983
593725.14149262 4560858.03284954
718843.08408122 4565415.83635253
760549.13276806 4576810.40077240
752207.88234603 4640619.42718910
731354.90884917 4679360.58999345
687563.57299579 4738611.92422672
702160.68494185 4800141.99323051
773060.85582705 4845719.91695078
873155.25071970 4889018.88325953
987846.65615984 4934596.80698683
1067088.07797614 4996126.98733013
1213058.99619721 5041704.91115431
1206803.13460117 5025752.65453882
1081685.19017228 4945991.26010490
1073343.93974961 4900413.44769795
1104623.45139774 4829767.66036284
1146329.39920358 4804699.79675655
1225570.82246726 4836604.31001547
1315238.68271874 4909528.94360159
1375712.42082002 4934596.80740049
1525853.92409735 4977895.88606557
1659313.13598129 5025752.65830226
1782345.81095815 5110071.75004494
1402821.25358723 5155649.66541496
356001.08119003 4957385.82450028
-1476977.37949447 4209908.26326187
-2146364.75561788 3555864.56100148
-2219352.08710189 3104642.21781792
-2198496.24906293 2544033.50007754
91 changes: 91 additions & 0 deletions examples/Gr3/Shapiro/coastal_0.5_1.cpp.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

1
88 1
-2110399.18520885 2759473.72383486
-2081889.68589075 2785073.56786075
-2063382.21061246 2828875.00377477
-2045376.06793056 2860259.28829079
-2041631.15575467 2889859.31897550
-2050273.45831639 2944864.84574453
-2066099.21736074 2999260.29785134
-2059761.59013415 3050835.65094407
-2045204.47150868 3096399.91130284
-2008077.08435444 3136493.72825179
-1978150.61985263 3155831.32141113
-1921370.89089629 3186179.04642157
-1863396.84021269 3212362.60420253
-1814267.94187892 3257106.74178290
-1768008.39598740 3283788.44727055
-1716889.84195376 3301314.99811018
-1678640.52151209 3309575.78697443
-1637781.41386630 3311793.30771635
-1571558.69822787 3290215.93267294
-1540943.09169962 3287693.05928811
-1528630.61329063 3293718.58695410
-1518398.13790829 3303665.52616034
-1490368.31685577 3299219.50771532
-1474697.10182308 3283786.10215843
-1441844.31707609 3251616.99261998
-1401353.14921681 3241526.64277997
-1373217.96164349 3250890.79753969
-1350856.85789183 3254498.93996371
-1329013.18087201 3245960.57331146
-1314354.47629823 3268355.32456693
-1299741.32237654 3275148.86019249
-1256432.42564340 3244295.82893895
-1234975.04701564 3238344.11763361
-1224678.33033147 3244528.12009131
-1240677.70001922 3265343.46807355
-1268144.46963296 3282599.09052713
-1273006.93803143 3291224.62897666
-1252962.16745369 3313543.91366011
-1247674.62477571 3324124.55235404
-1253138.00288865 3342626.38854693
-1267743.33668832 3345798.48187961
-1280910.61764761 3338486.47622982
-1293391.19487411 3353238.48602371
-1260905.06140930 3355870.47426355
-1244134.21608518 3369999.57121295
-1213750.08526171 3377935.87525777
-1170399.47392774 3373085.21418655
-1121329.95529754 3376528.37073100
-1114086.61240031 3402970.49031818
-1101245.90130761 3378039.99759169
-1086464.84718525 3367543.66329230
-1030836.07351491 3373442.46364716
-978429.58011614 3382330.04899383
-920653.90342542 3370067.21322368
-864055.36757060 3345945.81026967
-836220.23518445 3306187.48786777
-808123.82362033 3302131.02595357
-744705.32699062 3323022.98375028
-705832.26634758 3334614.91226253
-663671.58049660 3315495.13165063
-630645.89563965 3266171.57453546
-584275.61149532 3234802.93564763
-572941.16499378 3188870.08573578
-586700.64540248 3128440.66283929
-584973.56490607 3091235.73558275
-560978.75302966 3026675.09217801
-527341.88613622 2953960.51839202
-514483.51927664 2933130.78254744
-496156.57358228 2931248.33890320
-472456.63392595 2868545.87998493
-446799.36500404 2863355.00193600
-422835.81610921 2817054.59683932
-408438.40169585 2786797.55494828
-361811.92086997 2793852.43468602
-328531.34296750 2811030.89660020
-318210.00837721 2843101.23329873
-306038.64532001 2976010.86865396
-316986.67249013 3027394.31296513
-352790.65305549 3133808.23023285
-352440.33273801 3173393.35272890
-400717.80498957 3255997.68513505
-428030.67124798 3327950.82494407
-446629.96550044 3411786.06908229
-436912.32113368 3464794.02532570
-403951.72282368 3541328.20505098
-348470.58474651 3597329.59237861
-390979.85246274 4257886.12245173
-3112804.85869375 3441796.78992251
49 changes: 49 additions & 0 deletions examples/Gr3/Shapiro/coastal_0.5_2.cpp.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

1
46 1
-347729.54378964 3592328.90283183
-287049.50749085 3633932.26631487
-238940.60829766 3671166.00903764
-220603.01641726 3680502.99873341
-213230.99489887 3690855.45476839
-207335.79283072 3717710.72795215
-184848.75778042 3743707.79989715
-161089.81352332 3760345.03390648
-123576.63259316 3770143.90830229
-96616.52158290 3766577.74763832
-82464.16923896 3768389.45051966
-85053.83281319 3775526.16922139
-70136.31755149 3805436.46811014
-42335.13910624 3832741.72637059
-5402.84839885 3851514.81537110
37485.50162728 3858735.17772310
47975.08821008 3851685.63446105
58366.43239770 3849668.35407018
65331.74771613 3862728.97462225
102467.88175704 3893406.54560510
143119.78886254 3916779.50296324
163160.45588122 3921204.80916108
169367.14931525 3968781.87274773
154625.28775288 4002578.92647125
125597.78017109 4071551.94429403
114612.51529213 4104596.88269993
123386.81656259 4128439.25114752
146962.08637912 4163893.71614900
176439.25891736 4223803.51916991
202178.90905483 4264183.69741783
249443.33387059 4359889.60984369
293867.24060720 4401399.22129333
314166.55820454 4456659.46172878
319013.84200704 4496205.91718178
325248.06109014 4509818.55177440
362470.87894428 4516554.51944404
451208.41200986 4537963.22321620
531323.70942565 4568968.81645830
676680.41556462 4599593.57973840
725380.40754349 4634044.56243357
735184.97725482 4660183.65325188
715142.18969791 4687771.05611060
668300.75587200 4755359.15678493
158276.73532632 4703201.81839697
-386028.18928844 4529800.38140454
-576207.03719000 3910267.46264677
Loading

0 comments on commit 9636a64

Please sign in to comment.