Skip to content

Commit

Permalink
Merge pull request #35 from davidwilby/plotting_engine
Browse files Browse the repository at this point in the history
add file output to cli plotting
  • Loading branch information
thomaszwagerman authored Feb 4, 2025
2 parents 4866072 + 6be73bf commit a9ee34a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/asli/asli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import logging
import os
import matplotlib.pyplot as plt
from pathlib import Path
from typing import Mapping, Union

Expand Down Expand Up @@ -437,7 +438,7 @@ def _cli_common_args(parser: argparse.ArgumentParser) -> argparse.ArgumentParser
"-o",
"--output",
type=str,
help="Output file path for CSV, relative to <datadir>.",
help="Output file path for file, relative to <datadir>.",
)
parser.add_argument(
"msl_files",
Expand All @@ -463,6 +464,13 @@ def _get_cli_plot_args():
type=str,
help="Input CSV file, relative to <datadir>.",
)
parser.add_argument(
"-y",
"--year",
nargs="?",
type=int,
help="When present, plot only the year specified"
)
parser = _cli_common_args(parser)

return parser.parse_args()
Expand Down Expand Up @@ -501,8 +509,18 @@ def _cli_plot():
a = ASLICalculator(args.datadir, args.mask, args.msl_files[0])
a.read_mask_data()
a.read_msl_data()
a.import_from_csv(args.input)
a.plot_region_all()
# Perform the calculation if no input file is provided
if args.input:
a.import_from_csv(args.input)
else:
a.calculate()
# Plot all if no specific year is provided
if args.year:
a.plot_region_year(args.year)
else:
a.plot_region_all()
if args.output:
plt.savefig(os.path.join(args.datadir, args.output))

def _cli_calc():
"""Command-line interface to ASL calculation."""
Expand All @@ -519,4 +537,4 @@ def _cli_calc():


if __name__ == "__main__":
_cli_calc()
_cli_calc()
2 changes: 1 addition & 1 deletion src/asli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ def plot_lows(
if regionbox:
draw_regional_box(regionbox)

return ax
return ax

0 comments on commit a9ee34a

Please sign in to comment.