-
Notifications
You must be signed in to change notification settings - Fork 21
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
24 changed files
with
938 additions
and
1,512 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 |
---|---|---|
|
@@ -10,7 +10,6 @@ forecast | |
.vscode | ||
*.swp | ||
*.nc | ||
hgrid.* | ||
fgrid.* | ||
vgrid.* | ||
*.gr3 | ||
*.ll | ||
.idea |
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
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
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,14 @@ | ||
from abc import ABC, abstractmethod | ||
import argparse | ||
|
||
|
||
class CliComponent(ABC): | ||
|
||
@abstractmethod | ||
def __init__(self, args: argparse.Namespace): | ||
self.args = args | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def add_subparser_action(subparsers: argparse._SubParsersAction) -> None: | ||
raise NotImplementedError('Method must be implemented by subclass.') |
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
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,20 +1,53 @@ | ||
from argparse import Namespace | ||
import sys | ||
|
||
from pyschism.cmd import common | ||
from pyschism.outputs.outputs import OutputsCollector | ||
|
||
|
||
class OutputsCli: | ||
|
||
def __init__(self, args: Namespace): | ||
outputs = OutputsCollector(args.outputs_directory) | ||
getattr(outputs, args.variable_name).make_plot(show=True) | ||
if args.action == 'plot': | ||
getattr(outputs, args.variable_name).make_plot(show=True) | ||
|
||
elif args.action == 'animate': | ||
getattr(outputs, args.variable_name).animation( | ||
vmin=args.vmin, | ||
vmax=args.vmax, | ||
show=args.show, | ||
fps=args.fps, | ||
save=args.save, | ||
) | ||
|
||
@staticmethod | ||
def add_subparser_action(subparsers): | ||
add_outputs_options_to_parser(subparsers.add_parser('outputs')) | ||
|
||
|
||
def add_outputs_options_to_parser(parser): | ||
|
||
parser.add_argument('outputs_directory') | ||
parser.add_argument('variable_name') | ||
parser.add_argument('step', type=int) | ||
subparsers = parser.add_subparsers(dest='action') | ||
add_plot_action(subparsers) | ||
add_animate_action(subparsers) | ||
|
||
|
||
def add_plot_action(subparsers): | ||
parser = subparsers.add_parser('plot') | ||
parser.add_argument('step') | ||
|
||
|
||
def add_animate_action(subparsers): | ||
parser = subparsers.add_parser('animate') | ||
common.add_vmin_to_parser(parser) | ||
common.add_vmax_to_parser(parser) | ||
show = parser.add_mutually_exclusive_group() | ||
show.add_argument('--show', dest='show', action='store_true') | ||
show.add_argument('--no-show', dest='show', action='store_false') | ||
parser.set_defaults(show=False if "--save" in " ".join(sys.argv) else True) | ||
parser.add_argument('--fps', type=float) | ||
parser.add_argument('--save') | ||
parser.add_argument('--figsize', nargs=2, type=float) |
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,70 @@ | ||
import argparse | ||
import pathlib | ||
import sys | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from pyschism.cmd.base import CliComponent | ||
from pyschism.forcing.nws.nws2 import NWS2, SfluxDataset | ||
|
||
sflux_variables = { | ||
"air": ["prmsl", "spfh", "stmp", "uwind", "vwind"], | ||
"prc": ["prate"], | ||
"rad": ["dlwrf", "dswrf"], | ||
} | ||
|
||
|
||
class SfluxCli(CliComponent): | ||
def __init__(self, args: argparse.Namespace): | ||
kwargs = {} | ||
if args.sflux_1_glob is not None: | ||
kwargs.setdefault("sflux_1_glob", args.sflux_1_glob) | ||
if args.sflux_2_glob is not None: | ||
kwargs.setdefault("sflux_2_glob", args.sflux_2_glob) | ||
nws2 = NWS2.read(args.sflux_directory, **kwargs) | ||
if args.action == "animate": | ||
sflux = getattr(nws2, f"sflux_{args.level}") | ||
for vargroup, vars in sflux_variables.items(): | ||
component = getattr(sflux, f"{vargroup}") | ||
for variable in vars: | ||
animations = [] | ||
if getattr(args, variable) is True: | ||
animations.append( | ||
getattr(component, f"{variable}").animation( | ||
save=args.save / f"{variable}.gif", | ||
fps=args.fps, | ||
) | ||
) | ||
if args.show is True: | ||
plt.show() | ||
|
||
@staticmethod | ||
def add_subparser_action(subparsers: argparse._SubParsersAction) -> None: | ||
parser = subparsers.add_parser("sflux") | ||
parser.add_argument("sflux_directory") | ||
parser.add_argument("--level", choices=["1", "2"], default="1") | ||
parser.add_argument("--sflux-1-glob") | ||
parser.add_argument("--sflux-2-glob") | ||
subparsers = parser.add_subparsers(dest="action") | ||
add_animate_to_subparsers(subparsers) | ||
|
||
|
||
def add_animate_to_subparsers(subparsers): | ||
parser = subparsers.add_parser("animate") | ||
for vargroup, variables in sflux_variables.items(): | ||
arg_group = parser.add_argument_group(f"{vargroup} variables") | ||
for variable in variables: | ||
arg_group.add_argument(f"--{variable}", action="store_true", default=False) | ||
parser.add_argument("--save", type=lambda x: pathlib.Path(x)) | ||
parser.add_argument("--fps", type=float) | ||
parser.add_argument( | ||
"--show", | ||
action="store_true", | ||
dest="show", | ||
) | ||
parser.add_argument( | ||
"--no-show", | ||
action="store_true", | ||
dest="show", | ||
) | ||
parser.set_defaults(show=False if "--save" in " ".join(sys.argv) else True) |
Oops, something went wrong.