-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditnc.py
156 lines (120 loc) · 2.75 KB
/
Editnc.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 27 18:01:29 2018
@author: andrew
"""
#print dset3.file_format
import numpy as np
import netCDF4
infile = '/home/andrew/maps/PISM_1km_v3.nc'
#infile4= 'PISM_1km.nc'
#infile3 = '/home/andrew/github/pism/pism/examples/std-greenland/pism_Greenland_5km_v1.2.nc'
infile2 = '/home/andrew/github/pism/pism/examples/std-greenland/pism_Greenland_5km_v1.1.nc'
#dset = netCDF4.Dataset('/home/andrew/github/pism/pism/ARC/PISM_1km_v1.nc',mode='w',format='NETCDF4_CLASSIC')
dset = netCDF4.Dataset(infile,mode='r+')
#dset4 = netCDF4.Dataset(infile4)
dset2 = netCDF4.Dataset(infile2)
#dset = netCDF4.Dataset(infile3)
#tg1 = var
#print dset.dimensions.keys()
#print dset2.file_format
#print dset2.dimensions.keys()
#print dset3.file_format
#print dset
#print dset.dimensions.keys()
#print dset2.dimensions.keys()
#print dset2.dimensions[u'x1']
#print dset.dimensions[u'y']
#print 'dset:'
#print dset.variables.keys()
#print ' '
#print 'dset2:'
#print dset2.variables.keys()
#
tg1 = dset.variables[u'topg']
cmb = dset.variables[u'climatic_mass_balance']
ist = dset.variables[u'ice_surface_temp']
bhf = dset.variables[u'bheatflx']
#tg1d=(tg1[:]).data
cmbd=(cmb[:]).data
ist=(ist[:]).data
bhfd=(bhf[:]).data
#print dset.variables()
#tg4 = dset.variables[u'topg']
#tg3 = dset3.variables[u'topg']
#
#print ' '
#print np.shape(tg1)
#print ' '
#print np.min(tg2[0])
#print ' '
#
#tg1s = tg1[:]
#tg1s = (tg1[:])
#tg1d =tg1s.data
#tg1d[tg1s.mask]=-5000.
#(tg1[:]).data=tg1d
#tg1[:]=tg1d
#### topg #####
#print np.min(tg1s)
#print np.min(tg1s.MaskedData)
#tg1s = tg1s.data
#tg1s[np.isnan(tg1s)] = -5000.
tg1s = (tg1[:])
tg1d =tg1s.data
tg1m = tg1s.mask
tg1d[tg1s.mask]=-5000.
tg1[:]=tg1d
#cmb.units='kg m-2 s-1'
#print 'updated:'
#print cmb[:]
#test=np.isnan(tg1s)
#tg1s = tg1s.getValue()
#tg1s=np.ma.getdata(tg1)
#tg1new = tg1s.data
#tg1new = np.zeros(np.shape(tg1[:,:]))
#tg1new[tg1new==0]=float('nan')
#print np.shape(tg1new)
#print tg1new
#print tg1s[0][:]
#tg1new[tg1s==False]=tg1s
#tg1new = np.ma.getdata(tg1s)
#print np.max(tg1new)
#print np.min(tg1new)
#print type(tg1new)
#tg1s2 = tg1s.compressed()
#tg1s[tg1s=='--']=float('nan')
#print np.shape(tg1s)
#print [tg1s=='--']
#print tg1s[0]
#tg1v2 = dset.variables[u'topg']
#print tg1v2[0]
#### cmb #####
#cmb.units='kg m-2 s-1'
#print 'updated:'
#print cmb[:]
#year = 31557600.
#cmbd = (cmb[:]).data
##print cmbd
#cmbd = cmbd*1000./year
#print cmbd
#cmb[:]=cmbd
#print cmb
#print cmb[:]
##### ist #####
#ist.units = 'Kelvin'
#istd = (ist[:]).data
#print istd
#istd += 273.15
#print istd
#ist[:]=istd
##### bhf #####
#bhf.units='mW m-2'
dset.close()
#print tg3[0]
#print float('nan')
#print 'Other variable:'
#thkl = dset2.variables[u'thk']
#print thkl[0][0]
#print np.shape(thkl)