-
Notifications
You must be signed in to change notification settings - Fork 0
/
netCDFreader.py
50 lines (32 loc) · 1.05 KB
/
netCDFreader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import netCDF4
from netCDF4 import Dataset
def open(netcdf_file,format):
dataset = Dataset(netcdf_file, 'r', format=format)
return dataset
def readVar(dataset,varName):
return dataset.variables[varName]
def readValue(dataset,varName):
return readVar(dataset,varName)[:]
def printVariable(dataset,varName):
print dataset.variables[varName]
def printVariables(dataset):
for var in dataset.variables:
print dataset.variables[var]
def printVariablesName(dataset):
for var in dataset.variables:
print var
def printAllValues(dataset):
for var in dataset.variables:
print var,dataset.variables[var][:]
# if run as script
if __name__ == "__main__":
import sys
if len(sys.argv) != 3:
print 'Use: python netCDFreader.py [netcdf file] [netcdf format]'
exit()
netcdf_file = sys.argv[1]
format = sys.argv[2]
# format example: NETCDF4
dataset = open(netcdf_file,format)
#printAllValues(dataset)
printVariables(dataset)