Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Office of Water Prediction NextGen Hydrofabric for Source/Sink Construction of SCHISM mesh #121

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions examples/NGEN/gen_sourcesink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from datetime import datetime
from time import time
import pathlib
import logging

from pyschism.forcing.source_sink.ngen import NextGen, NextGenElementPairings
from pyschism.mesh import Hgrid

logging.basicConfig(
format="[%(asctime)s] %(name)s %(levelname)s: %(message)s",
force=True,
)
logging.captureWarnings(True)

log_level = logging.DEBUG
logging.getLogger('pyschism').setLevel(log_level)

if __name__ == '__main__':

startdate = datetime(2017, 12, 1)
enddate = datetime(2018, 1, 1)
hgrid = Hgrid.open("./hgrid.gr3", crs="epsg:4326")

t0 = time()

#source/sink json files, if not exist, it will call NWMElementPairings to generate.
sources_pairings = pathlib.Path('./sources.json')
sinks_pairings = pathlib.Path('./sinks.json')
output_directory = pathlib.Path('./')

# Pathway to a NextGen hydrofabric geopackage file to extract
# the SCHISM mesh sources/sinks with T-Route's flowpaths
hydrofabric = pathlib.Path('./conus.gpkg')

# check if source/sink json file exists
if all([sources_pairings.is_file(), sinks_pairings.is_file()]) is False:
pairings = NextGenElementPairings(hgrid)
sources_pairings.parent.mkdir(exist_ok=True, parents=True)
pairings.save_json(sources=sources_pairings, sinks=sinks_pairings)
else:
pairings = NextGenElementPairings.load_json(
hgrid,
sources_pairings,
sinks_pairings)

#check nc files, if not exist will download
ngen=NextGen(pairings=pairings)

# Generate the current Source.nc file required to execute the SCHISM
# Basic Model Interface (BMI). This file is set up to essentially just initalize
# SCHISM source/sink element fields and by the external forcing file
# requirements when a user specifies NWM_BMI=1 within the param.nml file.
# This function also includes the NextGen T-Route flow path ids as part of
# the netcdf output that will be utilized as a geospatial field within the
# SCHISM BMI to connect T-Route flowpaths with SCHISM sources/sinks.
ngen.Source_nc_write(startdate, enddate, output_directory, overwrite=True)
print(f'It took {time()-t0} seconds to generate source/sink')
3 changes: 3 additions & 0 deletions pyschism/forcing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
# from pyschism.forcing.tides.bctides import Bctides
from pyschism.forcing.nws.nws2.gfs import GlobalForecastSystem
from pyschism.forcing.source_sink.nwm import NationalWaterModel
from pyschism.forcing.source_sink.nwm import NextGen
from pyschism.forcing.nws.base import NWS

GFS = GlobalForecastSystem
NWM = NationalWaterModel
NGen = NextGen

__all__ = [
"Tides",
"GlobalForecastSystem", 'GFS',
'NationalWaterModel', 'NWM',
'NextGen', 'NGen',
'NWS',
# 'Bctides',
]
5 changes: 5 additions & 0 deletions pyschism/forcing/source_sink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
SourceSink,
)
from pyschism.forcing.source_sink.nwm import NationalWaterModel
from pyschism.forcing.source_sink.ngen import NextGen


NWM = NationalWaterModel
NGen = NextGen

__all__ = [
# "Hydrology",
"NationalWaterModel",
"NextGen",
# "Sources",
# "Sinks",
"Msource",
"Vsource",
"Vsink",
"SourceSink",
'NWM',
'NGen',
]
Loading