-
Lionel GUEZ authoredLionel GUEZ authored
examine_ssh_values.py 1.25 KiB
#!/usr/bin/env python3
import netCDF4
import matplotlib.pyplot as plt
import numpy as np
import math
with netCDF4.Dataset("h.nc") as f:
ssh = f.variables["adt"][:].squeeze()
longitude = f.variables["lon"][:]
latitude = f.variables["lat"][:]
lon_center = float(input("longitude of center = ? "))
lat_center = float(input("latitude of center = ? "))
# Base 0 indices, assuming regular grid::
i_center = round(float((lon_center - longitude[0])
/ (longitude[1] - longitude[0])))
j_center = round(float((lat_center - latitude[0]) / (latitude[1] - latitude[0])))
# (float to convert from numpy.float64, so that round produces an int)
level = float(input("level = ? "))
plt.figure()
plt.contour(longitude, latitude, ssh, (level,))
delta = 4
lon_2d, lat_2d = np.meshgrid(longitude[i_center - delta:i_center + delta + 1],
latitude[j_center - delta:j_center + delta + 1])
plt.plot(lon_2d.reshape(-1), lat_2d.reshape(-1), "+")
plt.plot(longitude[i_center], latitude[j_center], "o", markersize = 10,
fillstyle = "none")
for i in np.arange(i_center - delta,i_center + delta + 1):
for j in np.arange(j_center - delta,j_center + delta + 1):
plt.annotate(ssh[j,i], (longitude[i], latitude[j]))
plt.show()