Skip to content

Commit

Permalink
add hgrid/vgrid files
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Aug 13, 2021
1 parent 24d4c4e commit cdf44f1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pyschism/cmd/hgrid.py
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')
24 changes: 24 additions & 0 deletions pyschism/cmd/vgrid.py
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.")

0 comments on commit cdf44f1

Please sign in to comment.