Created
June 29, 2017 22:44
-
-
Save raphaeldussin/ddaac2b051f2491a680c06c5c724473d to your computer and use it in GitHub Desktop.
cloning a netcdf file (base for modifying it)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clone_ncfile(self,filein,fileout): | |
fidin = nc.Dataset(filein,'r') | |
fidout = nc.Dataset(fileout,'w',format='NETCDF3_CLASSIC') | |
fidout.description = '' | |
#Copy dimensions | |
for dname, the_dim in fidin.dimensions.iteritems(): | |
fidout.createDimension(dname, len(the_dim) if not the_dim.isunlimited() else None) | |
# Copy variables | |
for v_name, varin in fidin.variables.iteritems(): | |
outVar = fidout.createVariable(v_name, varin.datatype, varin.dimensions) | |
# Copy variable attributes | |
outVar.setncatts({k: varin.getncattr(k) for k in varin.ncattrs()}) | |
outVar[:] = varin[:] | |
fidin.close() | |
fidout.close() | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment