-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_Bamber_greenland.py
executable file
·184 lines (136 loc) · 5.3 KB
/
build_Bamber_greenland.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
import os
import datetime
import subprocess
import argparse
from util import speak
from util import projections
from util.ncfunc import get_nc_file
"""
Build a CISM dataset
"""
#==== Data Locations ====
# Link data here or edit
#========================
lc_bamber = 'data/BamberDEM/Greenland_bedrock_topography_V3.nc'
lc_seaRise = 'data/SeaRise/Greenland1km.nc'
lc_racmo2p0 = 'data/RACMO2.0/Racmo2MeanSMB_1961-1990.nc'
lc_InSAR = 'data/InSAR/Joughin2015/greenland_vel_mosaic500.nc' #NOTE: will build this file from mosaicOffsets.* files
lc_massCon = 'data/IceBridge/Greenland/MCdataset-2014-11-19.nc'
lc_mask = 'data/Ice2Sea/ice2sea_Greenland_geometry_icesheet_mask_Zurich.nc'
#==== SETUP =====
# get args, time
# load data sets
#================
stamp = datetime.date.today().strftime("%Y_%m_%d")
f_base = 'templates/greenland_1km.mcb.nc'
# parse the command line arguments
parser = argparse.ArgumentParser() # -h or --help automatically included!
parser.add_argument('-e', '--extended', help='Produce the extended grid.', action='store_true')
volume = parser.add_mutually_exclusive_group()
volume.add_argument("-v", "--verbose", help="Increase the output verbosity", action="store_true")
volume.add_argument("-q", "--quiet", help="Run silently", action="store_true")
args = parser.parse_args()
speak.notquiet(args,"\nBuilding the Greenland datasets in the Bamber projection.")
speak.notquiet(args, "=========================================================\n")
# load in datasets
speak.notquiet(args,"Loading the datasets.")
from data import bamberdem
nc_bamber = get_nc_file(lc_bamber,'r')
speak.verbose(args," Found Bamber DEM")
from data import searise
nc_seaRise = get_nc_file(lc_seaRise,'r')
speak.verbose(args," Found Sea Rise data")
from data import racmo2p0
nc_racmo2p0 = get_nc_file(lc_racmo2p0,'r')
speak.verbose(args," Found RACMO 2.0 data")
from data import insar
try:
nc_insar = get_nc_file(lc_InSAR,'r')
except Exception:
speak.verbose(args,"\n Building InSAR velocity dataset...\n")
subprocess.call("python util/convert_velocities.py "+os.path.dirname(lc_InSAR), shell=True)
nc_insar = get_nc_file(lc_InSAR,'r')
speak.verbose(args," Found InSAR data")
from data import icebridge
nc_massCon = get_nc_file(lc_massCon,'r')
speak.verbose(args," Found Mass Conserving Bed data")
from data import ice2sea
nc_mask = get_nc_file( lc_mask, 'r' )
speak.verbose(args," Found Zurich mask")
speak.verbose(args,"\n All data files found!")
#===== Bamber DEM ======
# this is a 1km dataset
#=======================
speak.verbose(args,"\nBuilding the base dataset: "+f_base)
speak.notquiet(args,"\nCreating the base grid."),
nc_base, base = bamberdem.build_base(f_base, nc_bamber)
speak.notquiet(args," Done!")
#==== Projections ====
# All the projections
# needed for the data
#=====================
speak.notquiet(args,"\nGetting the projections.")
proj_epsg3413, proj_eigen_gl04c = projections.greenland()
speak.notquiet(args," Done!")
# transform meshes.
speak.verbose(args," Creating the transform meshes: base Bamber grid to EPSG-3413.")
trans = projections.transform(base, proj_eigen_gl04c, proj_epsg3413)
speak.notquiet(args," Done!")
#==== SeaRise Data =====
# this is a 1km dataset
#=======================
speak.notquiet(args,"\nGetting bheatflx and presartm from the SeaRise data.")
searise.bheatflx_artm_bamber(args, nc_seaRise, nc_base, base)
nc_seaRise.close()
#==== RACMO2.0 Data =====
# this is a 1km dataset
#========================
speak.notquiet(args,"\nGetting acab from the RACMO 2.0 data.")
racmo2p0.acab_bamber(args, nc_racmo2p0, nc_base, base)
nc_racmo2p0.close()
#==== InSAR velocity Data ====
# this is a 500m dataset in
# the ESPG-3413 projection
#=============================
speak.notquiet(args,"\nGetting vy, vx, ey, and ex from the InSAR data.")
insar.velocity_bamber(args, nc_insar, nc_base, trans)
nc_insar.close()
#==== Mass Conserving Bed Data ===
# This is the new (2015) bed data
#=================================
speak.notquiet(args,"\nGetting thk, topg, and topgerr from the mass conserving bed data.")
icebridge.mcb_bamber(args, nc_massCon, nc_bamber, nc_base, base, trans, proj_eigen_gl04c, proj_epsg3413)
nc_bamber.close()
nc_massCon.close()
#==== Zurich mask =====
# apply mask, and get
# new surface variable
#======================
speak.notquiet(args,"\nGetting the Zurich Mask.")
base = None
nc_base.close() # need to read in some data from nc_base now
nc_base = get_nc_file(f_base,'r+')
ice2sea.apply_mask(args, nc_mask, nc_base)
nc_mask.close()
#==== Done getting data ====
#===========================
nc_base.close()
#==== add time dim and shrink ====
# apply to all the variables and
# shrink to size around ice sheet
#=================================
speak.notquiet(args,"\nAdding the time dimension and creating the 1km dataset.")
f_1km = 'complete/greenland_1km_'+stamp+'.mcb.nc'
f_template = 'greenland.mcb.config'
bamberdem.add_time(args, f_base, f_1km, f_template)
#==== Coarsen ====
# make 2, 4 and 8
# km datasets
#==================
speak.notquiet(args,"\nCreating coarser datasets.")
coarse_list = [2,4,5,8] # in km
bamberdem.coarsen(args, f_1km, f_template, coarse_list)
#==== and done! ====
#===================
speak.notquiet(args,"\nFinished building the datasets.")