diff --git a/interpolation/ORAS5_enlarge_ORCA025.py b/interpolation/ORAS5_enlarge_ORCA025.py new file mode 100644 index 0000000000000000000000000000000000000000..f960183cb3a0d2f65736107b66ea876d72d6c863 --- /dev/null +++ b/interpolation/ORAS5_enlarge_ORCA025.py @@ -0,0 +1,44 @@ +## Load all this modules before running the script in CTE-POWER: +module load gcc +module load NETCDF +module load HDF5 +module load UDUNITS +module load CDO +module load gsl +module load nco +module load ncview +module load Python/2.7.15-foss-2018b +module load IPython/5.7.0-foss-2018b-Python-2.7.15 +module load Cartopy/0.16.0-foss-2018b-Python-2.7.15 +module load xarray/0.11.2-foss-2018b-Python-2.7.15 +################################################## + +import xarray as xr +import numpy as np + +ds = xr.open_dataset('mesh_mask_ORCA025.L75_ece3.2_2017.nc4').rename({'z':'nav_lev'}) +for year in range(2008,2018): + ds2 = xr.open_dataset('/gpfs/projects/bsc32/repository/nudging/ocean/s5/ORCA025L75_ORAS5/fc0/s5_fc0_'+str(year)+'.nc') + for var in ('votemper','vosaline'): + print var + values = np.empty((ds2.dims['time'],ds2.dims['nav_lev'],ds.dims['y'],ds.dims['x'])) + ds_out = xr.DataArray(values, + coords={'nav_lon':(['y','x'],ds.nav_lon), + 'nav_lat':(['y','x'],ds.nav_lat), + 'nav_lev':(['nav_lev'],ds.nav_lev), + 'time_counter':ds2.time.rename({'time':'time_counter'})}, + dims=('time_counter','nav_lev','y','x'), + name=var) + # select variable + var_os5 = ds2[var] + # extrapolate on land, only for Antarctic case : if find a nan value, then copy the value from the line above. + for j in range(250,0,-1): + var_os5[:,:,j,:]=xr.where(np.isnan(var_os5[:,:,j,:]),var_os5[:,:,j+1,:],var_os5[:,:,j,:]) + # affect to new field on ORCA025 + ds_out[:,:,29:,:]=var_os5*ds.tmask[0,:,29:,:].where(ds.tmask[0,:,29:,:]==1) + # expend to full ORCA025 grid + for i in range(1,30): + ds_out[:,:,i,:]=var_os5[:,:,1,:]*ds.tmask[0,:,i,:].where(ds.tmask[0,:,i,:]==1) + ds_out.to_netcdf('s5_fc0_'+str(year)+'_'+var+'.nc',unlimited_dims='time_counter') + +