from netCDF4 import Dataset as dst from matplotlib import pyplot as plt nc = dst('air.mon.mean.nc',mode='r') time = 120 limit = 852 init = limit-time #nc.variables['level'][2] --> 850 millibar #air --> time --> level --> latitude --> longitude count = 0 #print(nc.variables['level'][:]) def latitudinal(level): iterator = -120 while iterator < 0: profile = [] for latitude in list(nc.variables['air'])[iterator][level]: item = [] for longitude in latitude: item.append(longitude) iterator += 1 average = sum(item)/len(item) profile.append(average) return profile profile850 = latitudinal(2) profile250 = latitudinal(8) a = plt.plot(nc.variables['lat'][:],profile850, color='r', label='850mbar') b = plt.plot(nc.variables['lat'][:],profile250, color='g', label='250mbar') plt.xlabel("Latitude (°)") plt.ylabel("Temperature (m/s)")
from netCDF4 import Dataset as dst from numpy import mean, array from matplotlib.pyplot import contourf, plot, show, savefig, colorbar, figure, setp, xlabel, ylabel def slice_per(source, step): return [source[i::step] for i in range(step)] nc = dst("../vwnd.mon.mean.nc", mode='r') months = range(853)[-61:-1] avgs = [] levels = range(17)[1:12] for l in levels: item = [] for m in months: for latitude in nc.variables['vwnd'][m][l]: item.append(mean(latitude)) item = slice_per(item, 73) for elem in item: average = mean(elem) avgs.append(average) avgs = array(slice_per(avgs, 73)) x = nc.variables['lat'][:] levels = [ '925', '850', '700', '600', '500', '400', '300', '250', '200', '150', '100' ] avgs = avgs.T cs = contourf(x, levels, avgs, 15, cmap='nipy_spectral') colorbar()
from netCDF4 import Dataset as dst from matplotlib import pyplot as plt nc = dst('../uwnd.mon.mean.nc', mode='r') iterator = -120 while iterator < 0: profile850 = [] for latitude in list(nc.variables['uwnd'])[iterator][2]: item = [] for longitude in latitude: item.append(longitude) iterator += 1 average = sum(item) / len(item) profile850.append(average) iterator_a = -120 while iterator_a < 0: profile250 = [] for latitude in list(nc.variables['uwnd'])[iterator_a][8]: item2 = [] for longitude in latitude: item2.append(longitude) iterator_a += 1 average = sum(item2) / len(item2) profile250.append(average) print(nc.variables['level'][:]) a = plt.plot(nc.variables['lat'][:], profile850, color='r', label='850 mbar') b = plt.plot(nc.variables['lat'][:], profile250, color='g', label='250 mbar') plt.xlabel("Latitude (°)") plt.ylabel("Wind (m/s)") plt.legend() plt.savefig("plot_250v850.png")
from netCDF4 import Dataset as dst from matplotlib import pyplot as plt import numpy as np from pathlib import Path import matplotlib.patheffects as pe nc = dst(str(Path.home()) + '/Desktop/vwnd.mon.mean.nc', mode='r') def slice_per(source, step): return [source[i::step] for i in range(step)] def seasonalLatprof(month_index, alt): a = range(858)[-128 - month_index:-8 - month_index:12] res = [] for month in a: #YEARLY PROFILE profileMonthly = [] #np.empty(73,0) for latitude in nc.variables['vwnd'][month][alt]: profileMonthly.append(np.average(latitude)) res.append(profileMonthly) print(np.array(res).shape) res = np.average(res, axis=0) print(np.array(res).shape) return res if __name__ == "__main__": jun250 = seasonalLatprof(6, 8) jul250 = seasonalLatprof(7, 8)
from netCDF4 import Dataset as dst from matplotlib import pyplot as plt import numpy as np nc = dst("../air.mon.mean.nc", mode="r") time_range = range(-12, 0) months = [] for month in time_range: m = [] for lvl in nc.variables['air'][month]: l = np.sum(lvl) / (73 * 144) m.append(l) months.append(m) levels = np.array(months).mean(axis=0) print(nc.variables['level'][:]) print((levels[8] - levels[2])) plt.xlabel("Temperature (°C)") plt.ylabel("Pressure (mbar)") plt.plot(levels, nc.variables['level']) plt.gca().invert_yaxis() plt.savefig("img_meanTemp.png") plt.show()
from netCDF4 import Dataset as dst import cartopy.crs as ccrs from numpy import mean, empty, shape, array, arange, sqrt from matplotlib import pyplot as plt u = dst('../../Zonal/uwnd.mon.mean.nc', mode='r') v = dst('../../Meridional/vwnd.mon.mean.nc', mode='r') months = range(853)[-68:-8] level = 8 def slice_per(source, step): return [source[i::step] for i in range(step)] def zonal_timeMean(v, dstname, months, level): avgs = [] for month in months: for latitude in v.variables[dstname][month][8]: avgs.append(latitude) avgs = array(avgs).flatten() avgs = slice_per(avgs, 10512) avg = [] for elem in avgs: avg.append(mean(elem)) avg = array(avg).reshape(73, 144) return avg vwnd = zonal_timeMean(v, 'vwnd', months, level)
from netCDF4 import Dataset as dst import numpy as np from matplotlib import pyplot as plt tempnc = dst("../air.mon.mean.nc", mode='r') zonalnc = dst("../uwnd.mon.mean.nc", mode='r') #Datasets downloaded 21 Aug 2020 #Time length- 871 ==> 871/12 --> 7/12 def slice_per(source, step): return [source[i::step] for i in range(step)] def zonal_data(): months = range(871)[-68:-8] avgs = [] levels = range(17)[0:12] for l in levels: item = [] for m in months: for latitude in zonalnc.variables['uwnd'][m][l]: item.append(np.mean(latitude)) item = slice_per(item, 73) for elem in item: average = np.mean(elem) avgs.append(average) avgs = np.array(slice_per(avgs, 73)) return avgs.T