-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from argparse import Namespace | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from pyschism.mesh import Hgrid | ||
|
||
|
||
class HgridCli: | ||
|
||
def __init__(self, args: Namespace): | ||
|
||
if args.action == 'plot': | ||
plot_hgrid(args) | ||
|
||
else: | ||
raise NotImplementedError(f'Unhandled CLI action: {args.action}.') | ||
|
||
@staticmethod | ||
def add_subparser_action(subparsers): | ||
add_hgrid_options_to_parser(subparsers.add_parser('hgrid')) | ||
|
||
|
||
def add_hgrid_options_to_parser(parser): | ||
actions = parser.add_subparsers(dest='action') | ||
add_plot_hgrid(actions) | ||
|
||
|
||
def plot_hgrid(args): | ||
hgrid = Hgrid.open(args.path, crs=args.crs) | ||
ax = None | ||
if not args.no_topobathy: | ||
ax = hgrid.make_plot( | ||
vmin=args.vmin, | ||
vmax=args.vmax, | ||
) | ||
if args.show_elements: | ||
ax = hgrid.triplot(axes=ax) | ||
|
||
# if args.plot_boundaries: | ||
# hgrid.plot_boundaries(axes=ax) | ||
|
||
plt.show() | ||
|
||
|
||
def add_plot_hgrid(subparser): | ||
plot = subparser.add_parser('plot') | ||
plot.add_argument('path') | ||
plot.add_argument('--crs') | ||
plot.add_argument('--vmin') | ||
plot.add_argument('--vmax') | ||
plot.add_argument('--show-elements', action='store_true') | ||
plot.add_argument('--no-topobathy') |
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,24 @@ | ||
from argparse import Namespace | ||
|
||
from pyschism.mesh.hgrid import Hgrid | ||
from pyschism.mesh.vgrid import Vgrid | ||
|
||
|
||
class VgridCli: | ||
|
||
def __init__(self, args: Namespace): | ||
hgrid = Hgrid.open(args.hgrid, crs=args.hgrid_crs) | ||
vgrid = Vgrid.from_binary(hgrid) | ||
vgrid.write('/tmp/temp_vgrid.in') | ||
|
||
@staticmethod | ||
def add_subparser_action(subparsers): | ||
add_vgrid_options_to_parser(subparsers.add_parser('vgrid')) | ||
|
||
|
||
def add_vgrid_options_to_parser(parser): | ||
parser.add_argument('hgrid') | ||
parser.add_argument('--hgrid-crs') | ||
parser.add_argument( | ||
"--overwrite", action="store_true", | ||
help="Allow overwrite of output file.") |