In [131]:
from netCDF4 import Dataset as NetCDFFile
import numpy as np
nc = NetCDFFile('tg_0.44deg_rot_v15.0_JJA_1979_2015_remapbil.nc')
#os.remove(name)
lats = nc.variables['lat'][:]
lons = nc.variables['lon'][:]
t = nc.variables['T_2M'][:]
t2=nc.variables['T_2M']._FillValue
rlats = nc.variables['rlat'][:]  # extract/copy the data
rlons = nc.variables['rlon'][:]
nc.close()
print(t2)


-9999

In [133]:
def f(x):
    if x==-9999:
        return float('NaN')
    else:
        return x
f2 = np.vectorize(f)
t= f2(t)
t=t.squeeze()
#nc.variables['sea_water_temperature'][-1].item() == nc.variables['sea_water_temperature']._FillValue
#False
import math
import matplotlib.pyplot as plt
import numpy as np
from numpy import ma
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal
fig, ax = plt.subplots()
#print(math.isnan(t))

#t[np.isnan(t)]=-200.0
t[t==-500.]=float('NaN')

#t=t*0.0099999998
print(np.amax(t),np.amin(t))
#t[t > 50.]=float('NaN')
cs = ax.contour(lons, lats, np.squeeze(t[10,:,:]),  vmin=-40, vmax=40)
cbar = fig.colorbar(cs)
plt.show()


(35.719997406005859, -5.3499999046325684)

In [ ]: