forked from sternalon/Scripts_and_analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtopog_file_create.py
executable file
·69 lines (47 loc) · 1.31 KB
/
topog_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
#!/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'
#Flags
use_flat_iceshelf=False
if use_flat_iceshelf==True:
new_filename='output_files/topog_flat.nc'
else:
new_filename='output_files/topog.nc'
#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'][:,:]
M= Depth.shape
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)
depth_h=g.createVariable('depth','f4',('yt','xt'))
if use_flat_iceshelf==True:
g.variables['depth'][:]=Depth*0
else:
g.variables['depth'][:]=Depth
g.sync()
g.close()
print 'Script complete'
if __name__ == '__main__':
main()
#sys.exit(main())