Index: trunk/tests/test_chunkData.py =================================================================== diff -u --- trunk/tests/test_chunkData.py (revision 0) +++ trunk/tests/test_chunkData.py (revision 118) @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri May 15 13:35:08 2020 + +@author: alvareza +""" + +from netCDF4 import Dataset + +#%% +pathwave = r'p:\metocean-data\open\ERA5\data\Global\Hs\era5_Global_Hs_1986.nc' +pathslp = r'p:\metocean-data\open\ERA5\data\Global\msl_p\era5_Global_msl_p_1986.nc' + +pathchunk=pathwave +#%% CHunk data +dimedict = ['time':1000,'longitude':10,'latitude':10] + +with netCDF4.Dataset(os.path.join(pathchunk),'r') as src, netCDF4.Dataset(os.path.join(os.getcwd(),'chunk_'+os.path.basename(pathchunk)), "w") as chunk: + # copy global attributes all at once via dictionary + dst.setncatts(src.__dict__) + # copy dimensions + for name, dimension in src.dimensions.items(): + dst.createDimension( + name, (dimedict[dimension] if not dimension.isunlimited() else None)) + # copy all file data except for the excluded + for name, variable in src.variables.items(): + if name not in toexclude: + x = dst.createVariable(name, variable.datatype, variable.dimensions) + dst[name][:] = src[name][0:dimedict[name]] + # copy variable attributes all at once via dictionary + dst[name].setncatts(src[name].__dict__) + +## SEALEVEL PRESSURE + \ No newline at end of file