From 193f65612e1bc89d5b0b6be1f328488e62659807 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Mon, 24 Apr 2023 21:58:30 +0200 Subject: [PATCH] Generalize to no time dimension Because there is no time dimension in `Inst_eddies/Tests/Input/uv_outermost.nc`, for example. --- Inst_eddies/Analysis/plot_velocity.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Inst_eddies/Analysis/plot_velocity.py b/Inst_eddies/Analysis/plot_velocity.py index c5a71d1d..c6a39e60 100755 --- a/Inst_eddies/Analysis/plot_velocity.py +++ b/Inst_eddies/Analysis/plot_velocity.py @@ -55,8 +55,15 @@ projection = ccrs.PlateCarree() ax = plt.axes(projection = projection) with netCDF4.Dataset(args.input_file) as f: + if "time" in f["ugos"].dimensions: + ugos = f["ugos"][0] + vgos = f["vgos"][0] + else: + ugos = f["ugos"][:] + vgos = f["vgos"][:] + if args.undefined: - undef_velocity = np.logical_or(f["ugos"][0].mask, f["vgos"][0].mask) + undef_velocity = np.logical_or(ugos.mask, vgos.mask) lon_2d, lat_2d = np.meshgrid(longitude[lon_mask], latitude[lat_mask]) ax.plot(lon_2d[undef_velocity].reshape(-1), @@ -65,8 +72,8 @@ with netCDF4.Dataset(args.input_file) as f: else: quiver_return = ax.quiver(longitude[lon_mask], latitude[lat_mask], - f["ugos"][0, lat_mask][:, lon_mask], - f["vgos"][0, lat_mask][:, lon_mask], + ugos[lat_mask][:, lon_mask], + vgos[lat_mask][:, lon_mask], scale = args.scale, scale_units = "width", transform = src_crs) -- GitLab