Skip to content
Snippets Groups Projects
Commit 1929dc7a authored by GUEZ Lionel's avatar GUEZ Lionel
Browse files

Split arguments of function `plot_velocity`

parent 1ebb6e08
No related branches found
No related tags found
No related merge requests found
...@@ -15,8 +15,8 @@ import netCDF4 ...@@ -15,8 +15,8 @@ import netCDF4
import wind_cartopy import wind_cartopy
def plot_velocity(args): def plot_velocity(input_file, window, undefined, scale):
with netCDF4.Dataset(args.input_file) as f: with netCDF4.Dataset(input_file) as f:
if "lon" in f.variables: if "lon" in f.variables:
lon = "lon" lon = "lon"
lat = "lat" lat = "lat"
...@@ -34,11 +34,11 @@ def plot_velocity(args): ...@@ -34,11 +34,11 @@ def plot_velocity(args):
ugos = f["ugos"][:] ugos = f["ugos"][:]
vgos = f["vgos"][:] vgos = f["vgos"][:]
if args.window is None: if window is None:
lon_mask = np.ones(len(longitude), dtype=bool) lon_mask = np.ones(len(longitude), dtype=bool)
lat_mask = np.ones(len(latitude), dtype=bool) lat_mask = np.ones(len(latitude), dtype=bool)
else: else:
llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat = args.window llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat = window
if urcrnrlon - llcrnrlon > 360: if urcrnrlon - llcrnrlon > 360:
sys.exit("bad values of urcrnrlon and llcrnrlon") sys.exit("bad values of urcrnrlon and llcrnrlon")
...@@ -62,7 +62,7 @@ def plot_velocity(args): ...@@ -62,7 +62,7 @@ def plot_velocity(args):
fig = plt.figure() fig = plt.figure()
ax = plt.axes(projection=projection) ax = plt.axes(projection=projection)
if args.undefined: if undefined:
undef_velocity = np.logical_or(ugos.mask, vgos.mask) undef_velocity = np.logical_or(ugos.mask, vgos.mask)
lon_2d, lat_2d = np.meshgrid(longitude, latitude) lon_2d, lat_2d = np.meshgrid(longitude, latitude)
ax.plot( ax.plot(
...@@ -80,7 +80,7 @@ def plot_velocity(args): ...@@ -80,7 +80,7 @@ def plot_velocity(args):
latitude, latitude,
ugos[lat_mask][:, lon_mask], ugos[lat_mask][:, lon_mask],
vgos[lat_mask][:, lon_mask], vgos[lat_mask][:, lon_mask],
scale=args.scale, scale=scale,
scale_units="width", scale_units="width",
) )
ax.quiverkey( ax.quiverkey(
...@@ -124,7 +124,9 @@ if __name__ == "__main__": ...@@ -124,7 +124,9 @@ if __name__ == "__main__":
) )
parser.add_argument("input_file", help="NetCDF file containing velocity") parser.add_argument("input_file", help="NetCDF file containing velocity")
args = parser.parse_args() args = parser.parse_args()
fig = plot_velocity(args) fig = plot_velocity(
args.input_file, args.window, args.undefined, args.scale
)
if args.save: if args.save:
fig.savefig(f"plot_velocity.{args.save}") fig.savefig(f"plot_velocity.{args.save}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment