diff --git a/Inst_eddies/Analysis/plot_eddy_contours.py b/Inst_eddies/Analysis/plot_eddy_contours.py index d6c4c4b035841a15bc91ce3812aff1eade881403..13c2fbe14839e051a86408046737ef7d8fe162ac 100755 --- a/Inst_eddies/Analysis/plot_eddy_contours.py +++ b/Inst_eddies/Analysis/plot_eddy_contours.py @@ -131,15 +131,10 @@ def snapshot(ax, ishape_list, handler, *, dashed = False, light = False, if not light: lines[0].set_marker("o") if dashed: lines[0].set_linestyle("dashed") -def plot_grid_bb(shpc_dir, ax): +def plot_grid_bb(grid_nml, ax): """Grid bounding box.""" - - file = path.join(shpc_dir, "grid_nml.txt") - try: - grid_nml = f90nml.read(file)["grid_nml"] - except FileNotFoundError: - print("grid_nml.txt not found. Will not plot bounding box.") - else: + + if grid_nml is not None: step = grid_nml["STEP_DEG"] rect = patches.Rectangle(grid_nml["corner_deg"], (grid_nml["nlon"] - 1) * step[0], @@ -171,17 +166,24 @@ if __name__ == "__main__": help = "Save file to specified format") args = parser.parse_args() + if args.grid or args.window is None: + file = path.join(args.shpc_dir[0], "grid_nml.txt") + + try: + grid_nml = f90nml.read(file)["grid_nml"] + except FileNotFoundError: + print("grid_nml.txt not found. Will not plot bounding box.") + grid_nml = None + if args.grid: - with netCDF4.Dataset("h.nc") as f: - if "lon" in f.variables: - lon = "lon" - lat = "lat" - else: - lon = "longitude" - lat = "latitude" - - longitude = f[lon][:] - latitude = f[lat][:] + width = (grid_nml["NLON"] - 1) * grid_nml["STEP_DEG"][0] + height = (grid_nml["NLat"] - 1) * grid_nml["STEP_DEG"][1] + longitude = np.linspace(grid_nml["CORNER_DEG"][0], + grid_nml["CORNER_DEG"][0] + width, + grid_nml["NLON"]) + latitude = np.linspace(grid_nml["CORNER_DEG"][1], + grid_nml["CORNER_DEG"][1] + height, + grid_nml["NLat"]) if args.window is not None: llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat = args.window @@ -212,7 +214,7 @@ if __name__ == "__main__": ax.plot(lon_2d.reshape(-1), lat_2d.reshape(-1), transform = src_crs, marker = "+", color = "gray", linestyle = "None") - if args.window is None: plot_grid_bb(args.shpc_dir[0], ax) + if args.window is None: plot_grid_bb(grid_nml, ax) for shpc_dir in args.shpc_dir: handler = util_eddies.open_shpc(shpc_dir)