forked from sternalon/Scripts_and_analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiceshelf_mass_file_create.py
executable file
·83 lines (59 loc) · 1.74 KB
/
iceshelf_mass_file_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
#!/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_geometry.nc'
new_filename='output_files/ISOMIP_MIB.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:
ocean_mask = file.variables['openOceanMask'][:,:]
upperSurface = file.variables['upperSurface'][:,:]
lowerSurface = file.variables['lowerSurface'][:,:]
h_ice=upperSurface-lowerSurface
mass=h_ice*rho_ice
x = file.variables['x'][:]
y = file.variables['y'][:]
M= mass.shape
ny=M[0]
nx=M[1]
print nx,ny
print mass.shape
#subsampling data onto a grid half the size
MIB=np.zeros((ny/2,nx/2))
print MIB.shape
for i in range(0,nx,2):
for j in range(0,ny,2):
MIB[j/2,i/2]=mass[j,i]
#Creating the topog file
g=Dataset(new_filename,'w') # w if for creating a file
time=g.createDimension('time',1)
yt=g.createDimension('yt',ny)
xt=g.createDimension('xt',nx)
mass_h=g.createVariable('mass','f4',('time','yt','xt'))
g.variables['mass'][:]=mass
#Creating subsampled version
yh=g.createDimension('yh',ny/2)
xh=g.createDimension('xh',nx/2)
MIB_h=g.createVariable('MIB','f4',('time','yh','xh'))
g.variables['MIB'][:]=MIB
g.sync()
g.close()
print 'Script complete'
if __name__ == '__main__':
main()
#sys.exit(main())