import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
import scipy.io as sio
import pandas as pd
import datetime
%matplotlib inline
f = nc.Dataset('/data/vdo/MEOPAR/for-devin/seasonal-30_2015.nc', 'a')
mesh = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc')
mask = mesh.variables['e3t_0'][:,:22,:,:]
mask = np.ma.masked_array(mask, mask = 1- mesh.variables['tmask'][:,:22,:,:])
averaged = np.sum((f.variables['votemper'][:] * mask), axis=1) / np.sum(mask, axis = 1)
averaged.shape
(4, 898, 398)
temps = f.createVariable('votemperoverdepth', 'f4', ('time_counter', 'y', 'x'))
temps[:] = averaged
sals = f.createVariable('vosalineoverdepth', 'f4', ('time_counter', 'y', 'x'))
averaged2 = np.sum((f.variables['vosaline'][:] * mask), axis=1) / np.sum(mask, axis = 1)
averaged2.shape
(4, 898, 398)
sals[:] = averaged2
f.variables['vosalineoverdepth']
<class 'netCDF4._netCDF4.Variable'> float32 vosalineoverdepth(time_counter, y, x) unlimited dimensions: time_counter current shape = (4, 898, 398) filling on, default _FillValue of 9.969209968386869e+36 used
f.variables['votemperoverdepth']
<class 'netCDF4._netCDF4.Variable'> float32 votemperoverdepth(time_counter, y, x) unlimited dimensions: time_counter current shape = (4, 898, 398) filling on, default _FillValue of 9.969209968386869e+36 used
f.close()
f = nc.Dataset('/data/vdo/MEOPAR/for-devin/seasonal-30_2015.nc')
f.variables.keys()
odict_keys(['bounds_lat', 'bounds_lon', 'deptht', 'deptht_bounds', 'nav_lat', 'nav_lon', 'time_centered', 'time_centered_bounds', 'time_counter', 'time_counter_bounds', 'vosaline', 'votemper', 'votemperoverdepth', 'vosalineoverdepth'])
plt.pcolormesh(f.variables['deep_T'][0,...],
)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f4ed39453c8>
plt.pcolormesh(f.variables['deep_S'][0,...],
)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f4ed38a9240>
f = nc.Dataset('/home/vdo/Downloads/rivers_month_201702.nc')
f.variables.keys()
odict_keys(['nav_lat', 'nav_lon', 'area', 'time_counter', 'rorunoff', 'rodepth'])