-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflat_isomip_create.py
executable file
·71 lines (50 loc) · 1.5 KB
/
flat_isomip_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
#!/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_filename='input_files/isomip_ice_shelf1.nc'
new_filename='output_files/flat_isomip_ice_shelf1.nc'
#f=Dataset(input_geometry_filename,'r')
#g=Dataset(new_filename,'w') # w if for creating a file
rho_ice=850.
with nc.Dataset(input_filename) as file:
thick = file.variables['thick'][:,:]
area = file.variables['area'][:,:]
height = file.variables['height'][:,:]
M= thick.shape
ny=M[0]
nx=M[1]
print nx,ny
print thick.shape
#Setting thickness to a prescribed value
prescribed_thickness=1.
thick[np.where(thick>0)]=prescribed_thickness
#Creating the 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>0
thick_h=g.createVariable('area','f4',('yt','xt'))
g.variables['area'][:]=area
height_h=g.createVariable('height','f4',('yt','xt'))
g.variables['height'][:]=height
g.sync()
g.close()
print 'Script complete'
if __name__ == '__main__':
main()
#sys.exit(main())