-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiceshelf_geometry_create.py
executable file
·150 lines (107 loc) · 3.06 KB
/
iceshelf_geometry_create.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
#!/usr/bin/env python
###############################################################################################
from netCDF4 import Dataset
import numpy as np
import os
import numpy
import netCDF4 as nc
import matplotlib
import matplotlib.pyplot as plt
from pylab import *
#import pdb
#import argparse
#This combination allows you to access the varibale imputted from the command line.
#import sys
#Clear screen
def main():
os.system('clear')
input_geometry_filename='input_files/Isomip_ocean_geometry.nc'
input_iceshelf_filename='input_files/Ocean1_3D_no_calving.nc'
new_filename='output_files/Ocean1_3D_no_calving_trimmed.nc'
#Parameters
rho_water=1028
rho_ice=918
#f=Dataset(input_geometry_filename,'r')
#g=Dataset(new_filename,'w') # w if for creating a file
with nc.Dataset(input_geometry_filename) as file:
Depth = file.variables['D'][:,:]
with nc.Dataset(input_iceshelf_filename) as file:
thick = file.variables['thick'][:,:]
with nc.Dataset(input_iceshelf_filename) as file:
area= file.variables['area'][:,:]
M=thick.shape
thick_orig=np.zeros((M[0],M[1]))
for i in range(M[0]):
for j in range(M[01]):
thick_orig[i,j]=thick[i,j]
#Making ice shelf symetric
M=thick.shape
thick_tmp=thick
print M
for i in range(M[0]/2):
for j in range(M[1]):
i_sym=(M[0]-1-i)
if j==0:
print i, i_sym
thick_tmp[i,j]=((thick[i,j]+thick[i_sym,j])/2.)
thick_tmp[i_sym,j]=((thick[i,j]+thick[i_sym,j])/2.)
thick=thick_tmp
#Making draft increase going inwards
M=thick.shape
thick_tmp=thick
print M
for k in range(5):
#for i in range(M[0]/2):
#for i in range(M[0]/8):
for i in range(5):
#for j in range(M[1]):
for j in range(118):
i_sym=(M[0]-1-i)
if (thick_tmp[i,j]<thick_tmp[i+1,j]):
thick_tmp[i,j]=thick_tmp[i+1,j]
#thick_tmp[i,j]=((thick_tmp[i+1,j] +thick_tmp[i+2,j])/2)
thick_tmp[i_sym,j]=thick_tmp[i,j]
thick=thick_tmp
draft=thick*(rho_water/rho_ice)
ocean_thick=Depth-draft
ocean_thick[np.where(ocean_thick<0)]=0.
#ocean_thick=draft
subplot(4,1,1)
cNorm = mpl.colors.Normalize(vmin=0, vmax=10)
cmap='jet'
plt.pcolormesh(ocean_thick,norm=cNorm,cmap=cmap)
plt.colorbar()
subplot(4,1,2)
cNorm = mpl.colors.Normalize(vmin=0, vmax=1000)
cmap='jet'
plt.pcolormesh(thick_orig,norm=cNorm,cmap=cmap)
plt.colorbar()
subplot(4,1,3)
cNorm = mpl.colors.Normalize(vmin=0, vmax=1000)
cmap='jet'
plt.pcolormesh(thick,norm=cNorm,cmap=cmap)
plt.colorbar()
subplot(4,1,4)
cNorm = mpl.colors.Normalize(vmin=0, vmax=10)
cmap='jet'
plt.pcolormesh(thick-thick_orig,norm=cNorm,cmap=cmap)
plt.colorbar()
ny=M[0]
nx=M[1]
print nx,ny
#Creating the topog file
g=Dataset(new_filename,'w') # w if for creating a file
yt=g.createDimension('yt',ny)
xt=g.createDimension('xt',nx)
thick_h=g.createVariable('thick','f4',('yt','xt'))
g.variables['thick'][:]=thick
area_h=g.createVariable('area','f4',('yt','xt'))
g.variables['area'][:]=area
print 'Writing file: ' , new_filename
g.sync()
g.close()
plt.show()
print 'Script complete'
if __name__ == '__main__':
main()
#sys.exit(main())