Last active
April 19, 2021 12:50
-
-
Save nmathewa/daa3ac300ecf91ffa8f783168dc372aa to your computer and use it in GitHub Desktop.
scipy_netcdf_create
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
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