Skip to content

Instantly share code, notes, and snippets.

@nmathewa
Last active April 19, 2021 12:50
Show Gist options
  • Save nmathewa/daa3ac300ecf91ffa8f783168dc372aa to your computer and use it in GitHub Desktop.
Save nmathewa/daa3ac300ecf91ffa8f783168dc372aa to your computer and use it in GitHub Desktop.
scipy_netcdf_create
from scipy.io import netcdf as nc
import numpy as np
#creatin an sample fil
net = nc.netcdf_file("test.nc",'w')
#making an attribute inside the netCDF file similarly an template can be created
net.author = "Made by NMA"
#creating dimension and its length
net.createDimension('time',10)
# setting up space for values for dimensions and variabls (name , datatype , (dims))
time = net.createVariable('time', 'i',('time',))
vals = net.createVariable('vals', 'f', ('time',))
#filling test values
vals[:] = np.arange(10)
time[:] = np.arange(10)
#setting up units
time.units = 'days'
# closing the netcdf file
net.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment