-
Notifications
You must be signed in to change notification settings - Fork 0
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
16 changed files
with
435 additions
and
150 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
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,81 @@ | ||
import click | ||
import logging | ||
from argopy.utils import is_wmo, is_cyc, check_cyc, check_wmo | ||
import argopy.plot as argoplot | ||
from argopy.errors import DataNotFound | ||
from argopy import ArgoIndex | ||
import os | ||
from pathlib import Path | ||
import glob | ||
|
||
from vfrecovery.core.plot import plot_velocity | ||
|
||
root_logger = logging.getLogger("vfrecovery_root_logger") | ||
blank_logger = logging.getLogger("vfrecovery_blank_logger") | ||
|
||
|
||
@click.group() | ||
def cli_group_plot() -> None: | ||
pass | ||
|
||
|
||
@cli_group_plot.command( | ||
"plot", | ||
short_help="Plot VirtualFleet-Recovery data or simulation results", | ||
help=""" | ||
TARGET select what is to be plotted. A string in: 'velocity'. | ||
WMO is the float World Meteorological Organisation number | ||
CYC is the cycle number location to restrict plots to | ||
""", | ||
epilog=""" | ||
Examples: | ||
\b | ||
vfrecovery plot velocity 6903091 80 | ||
""", # noqa | ||
) | ||
@click.option( | ||
"--log-level", | ||
type=click.Choice(["DEBUG", "INFO", "WARN", "ERROR", "CRITICAL", "QUIET"]), | ||
default="INFO", | ||
show_default=True, | ||
help=( | ||
"Set the details printed to console by the command " | ||
"(based on standard logging library)." | ||
), | ||
) | ||
@click.argument('TARGET', nargs=1, type=str) | ||
@click.argument('WMO', nargs=1, type=int) | ||
@click.argument("CYC", nargs=-1, type=int) | ||
def plot( | ||
target, | ||
wmo, | ||
cyc, | ||
log_level, | ||
) -> None: | ||
if log_level == "QUIET": | ||
root_logger.disabled = True | ||
log_level = "CRITICAL" | ||
root_logger.setLevel(level=getattr(logging, log_level.upper())) | ||
|
||
if root_logger.isEnabledFor(logging.DEBUG): | ||
root_logger.debug("DEBUG mode activated") | ||
|
||
# Validate arguments: | ||
if target.lower() not in ["all", "obs", "velocity"]: | ||
raise ValueError("The first argument TARGET must be one in ['all', 'obs', 'velocity']") | ||
|
||
assert is_wmo(wmo) | ||
wmo = check_wmo(wmo)[0] | ||
cyc = list(cyc) | ||
if len(cyc) > 0: | ||
assert is_cyc(cyc) | ||
cyc = check_cyc(cyc) | ||
|
||
if target == 'velocity': | ||
plot_velocity(wmo, cyc, | ||
log_level=log_level, | ||
) |
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,4 +1,4 @@ | ||
# from deployment_plan import setup_deployment_plan | ||
from .trajfile_handler import Trajectories | ||
from .run_handler import Simulation | ||
from .run_handler import RunAnalyser | ||
# from predict import predict_function |
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,66 @@ | ||
import logging | ||
import xarray as xr | ||
from virtualargofleet import Velocity | ||
|
||
from vfrecovery.utils.misc import list_float_simulation_folders | ||
import vfrecovery.plots.velocity as pltvel | ||
|
||
|
||
root_logger = logging.getLogger("vfrecovery_root_logger") | ||
plot_logger = logging.getLogger("vfrecovery_plot") | ||
|
||
|
||
class log_this: | ||
|
||
def __init__(self, txt, log_level): | ||
"""Log text to simulation and possibly root logger(s)""" | ||
getattr(root_logger, log_level.lower())(txt) | ||
getattr(plot_logger, log_level.lower())(txt) | ||
|
||
@staticmethod | ||
def info(txt) -> 'log_this': | ||
return log_this(txt, 'INFO') | ||
|
||
@staticmethod | ||
def debug(txt) -> 'log_this': | ||
return log_this(txt, 'DEBUG') | ||
|
||
@staticmethod | ||
def warning(txt) -> 'log_this': | ||
return log_this(txt, 'WARNING') | ||
|
||
@staticmethod | ||
def error(txt) -> 'log_this': | ||
return log_this(txt, 'ERROR') | ||
|
||
|
||
def plot_velocity( | ||
wmo: int, | ||
cyc: int, | ||
log_level: str, | ||
): | ||
if log_level == "QUIET": | ||
root_logger.disabled = True | ||
log_level = "CRITICAL" | ||
root_logger.setLevel(level=getattr(logging, log_level.upper())) | ||
|
||
# List folders to examine: | ||
plist = list_float_simulation_folders(wmo, cyc) | ||
|
||
# | ||
for c in plist.keys(): | ||
p = plist[c] | ||
log_this.info("Velocity figure(s) for WMO=%s / CYC=%s:" % (wmo, c)) | ||
ilist = sorted(p.glob("velocity_*.png")) | ||
if len(ilist) > 0: | ||
[log_this.info("\t- %s" % i) for i in ilist] | ||
else: | ||
log_this.info("No velocity figures ! Generating new ones from velocity files") | ||
|
||
# Load velocity field | ||
vlist = sorted(p.glob("velocity_*.nc")) | ||
for v in vlist: | ||
log_this.info("Loading '%s'" % v) | ||
# ds_vel = xr.open_dataset(v) | ||
# VEL = Velocity(model='GLORYS12V1' if 'GLORYS' in str(v) else 'ARMOR3D', src=ds_vel) | ||
# pltvel.plot(VEL, wmo, cyc, save_figure=False, workdir=p) |
Oops, something went wrong.