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

Replace argument `shp_tr_dir`

Replace argument `shp_tr_dir` by arguments k1, `ishape_last`,
`reader_extr`, `reader_outer`, `reader_m_s`. The idea is to not redo
tasks in function snapshot when calling it for several dates.
parent b13e8570
No related branches found
No related tags found
No related merge requests found
...@@ -28,45 +28,21 @@ import cartopy.crs as ccrs ...@@ -28,45 +28,21 @@ import cartopy.crs as ccrs
from os import path from os import path
from cartopy.mpl import geoaxes from cartopy.mpl import geoaxes
def snapshot(k, shp_tr_dir, window = None, *, dashed = False, light = False, def snapshot(k, k1, ishape_last, reader_extr, reader_outer, reader_m_s = None,
window = None, *, dashed = False, light = False,
new_figure = False, src_crs = ccrs.PlateCarree(), new_figure = False, src_crs = ccrs.PlateCarree(),
projection = ccrs.PlateCarree()): projection = ccrs.PlateCarree()):
"""Plots extrema, outermost contours and max-speed contours. """Plots extrema, outermost contours and max-speed contours.
shp_tr_dir: containing the three shapefiles.
dashed: boolean.""" dashed: boolean."""
reader_extr = shapefile.Reader(path.join(shp_tr_dir, "extremum"))
reader_outer = shapefile.Reader(path.join(shp_tr_dir, "outermost_contour"))
k1 = reader_extr.record(0).date_index
fname = path.join(shp_tr_dir, "ishape_last.txt")
try:
ishape_last = np.loadtxt(fname, dtype = int)
if k is None:
print("No date provided, plotting first date:", k1)
k = k1
except OSError:
print("Could not read", fname)
print("We will use all the shapes.")
ishape_last = [len(reader_extr) - 1]
if k is not None: print("Ignoring value of argument k")
k = k1
if k == k1: if k == k1:
ishape_first = 0 ishape_first = 0
else: elif k > k1:
# {k > k1}
ishape_first = ishape_last[k - k1 - 1] + 1 ishape_first = ishape_last[k - k1 - 1] + 1
else:
try: print("bad k value")
reader_m_s = shapefile.Reader(path.join(shp_tr_dir, return
"max_speed_contour"))
except shapefile.ShapefileException:
print("Shapefile max_speed_contour not found. "
"Max-speed contours will not be plotted.")
reader_m_s = None
if new_figure: if new_figure:
plt.figure() plt.figure()
...@@ -226,9 +202,39 @@ if __name__ == "__main__": ...@@ -226,9 +202,39 @@ if __name__ == "__main__":
marker = "+", color = "gray", linestyle = "None") marker = "+", color = "gray", linestyle = "None")
if args.window is None: plot_grid_bb(args.shp_tr_dir, ax) if args.window is None: plot_grid_bb(args.shp_tr_dir, ax)
plt.suptitle(f"k = {args.k}") reader_extr = shapefile.Reader(path.join(args.shp_tr_dir, "extremum"))
snapshot(args.k, args.shp_tr_dir, args.window, dashed = args.dashed, reader_outer = shapefile.Reader(path.join(args.shp_tr_dir,
light = args.light) "outermost_contour"))
try:
reader_m_s = shapefile.Reader(path.join(args.shp_tr_dir,
"max_speed_contour"))
except shapefile.ShapefileException:
print("Shapefile max_speed_contour not found. "
"Max-speed contours will not be plotted.")
reader_m_s = None
k1 = reader_extr.record(0).date_index
fname = path.join(args.shp_tr_dir, "ishape_last.txt")
try:
ishape_last = np.loadtxt(fname, dtype = int)
if args.k is None:
print("No option k, plotting first date:", k1)
k = k1
else:
k = args.k
except OSError:
print("Could not read", fname)
print("We will use all the shapes.")
ishape_last = [len(reader_extr) - 1]
if args.k is not None: print("Ignoring value of option k")
k = k1
plt.suptitle(f"k = {k}")
snapshot(k, k1, ishape_last, reader_extr, reader_outer, reader_m_s,
args.window, dashed = args.dashed, light = args.light)
if args.velocity: if args.velocity:
with netCDF4.Dataset("uv.nc") as f: with netCDF4.Dataset("uv.nc") as f:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment