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

Plot grid from `grid_ml.txt` instead of `h.nc`

So read `grid_ml.txt` at the beginning of the script and not in
function `plot_grid_bb`, and pass `grid_nml` instead of `shpc_dir` to
function `plot_grid_bb`.
parent 52aa11cd
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
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