From 1929dc7a0773bf0af889d74bfc11f4b87761b63c Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ipsl.fr> Date: Mon, 21 Oct 2024 18:19:07 +0200 Subject: [PATCH] Split arguments of function `plot_velocity` --- Inst_eddies/Analysis/plot_velocity.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Inst_eddies/Analysis/plot_velocity.py b/Inst_eddies/Analysis/plot_velocity.py index 88a9f08b..75718ced 100755 --- a/Inst_eddies/Analysis/plot_velocity.py +++ b/Inst_eddies/Analysis/plot_velocity.py @@ -15,8 +15,8 @@ import netCDF4 import wind_cartopy -def plot_velocity(args): - with netCDF4.Dataset(args.input_file) as f: +def plot_velocity(input_file, window, undefined, scale): + with netCDF4.Dataset(input_file) as f: if "lon" in f.variables: lon = "lon" lat = "lat" @@ -34,11 +34,11 @@ def plot_velocity(args): ugos = f["ugos"][:] vgos = f["vgos"][:] - if args.window is None: + if window is None: lon_mask = np.ones(len(longitude), dtype=bool) lat_mask = np.ones(len(latitude), dtype=bool) else: - llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat = args.window + llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat = window if urcrnrlon - llcrnrlon > 360: sys.exit("bad values of urcrnrlon and llcrnrlon") @@ -62,7 +62,7 @@ def plot_velocity(args): fig = plt.figure() ax = plt.axes(projection=projection) - if args.undefined: + if undefined: undef_velocity = np.logical_or(ugos.mask, vgos.mask) lon_2d, lat_2d = np.meshgrid(longitude, latitude) ax.plot( @@ -80,7 +80,7 @@ def plot_velocity(args): latitude, ugos[lat_mask][:, lon_mask], vgos[lat_mask][:, lon_mask], - scale=args.scale, + scale=scale, scale_units="width", ) ax.quiverkey( @@ -124,7 +124,9 @@ if __name__ == "__main__": ) parser.add_argument("input_file", help="NetCDF file containing velocity") args = parser.parse_args() - fig = plot_velocity(args) + fig = plot_velocity( + args.input_file, args.window, args.undefined, args.scale + ) if args.save: fig.savefig(f"plot_velocity.{args.save}") -- GitLab