-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvmat2nc.py
More file actions
executable file
·29 lines (22 loc) · 860 Bytes
/
Copy pathconvmat2nc.py
File metadata and controls
executable file
·29 lines (22 loc) · 860 Bytes
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
#!/usr/bin/env python
from netCDF4 import Dataset
import scipy.io as spio
# convert .mat file into simple netcdf file
def mat2nc(matnam, ncnam):
m = spio.loadmat(matnam)
rg = Dataset(ncnam, 'w', format='NETCDF4')
x = rg.createDimension('x', 736)
y = rg.createDimension('y', 1555)
xs = rg.createVariable('x', 'f4', ('x',), zlib=True)
ys = rg.createVariable('y', 'f4', ('y',), zlib=True)
for key in m.keys():
if '__' not in key: # ignore keys with two underscores (no real data there)
print "Creating", key, "in", ncnam
var = rg.createVariable(key, 'f4', ('y', 'x',), zlib=True)
var[:] = m[key]
rg.close()
mat2nc('disbot.mat', 'disbot.nc')
mat2nc('dissip.mat', 'dissip.nc')
mat2nc('diswcap.mat', 'diswcap.nc')
mat2nc('nplant.mat', 'nplant.nc')
mat2nc('transp.mat', 'transp.nc')