-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathini_tools.py
230 lines (190 loc) · 9.39 KB
/
ini_tools.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# This script helps to generate a density profile to be used as initial
# state for the subsurface model
#
# Author: Baptiste Vandecrux ([email protected])
# ========================================================================
# clear all
# close all
load ../python_defs/Core_all
station = 'KAN_U'
# Plot in the site you want
# PlotCore(Core,'CoreNum',1)
# Find the index of the core you want to use
# CoreList(CoreAvg)
# search by name rather than by index since index can change in the future
switch station
case 'CP1'
ind = FindCore(Core,'Name','CORE 6945')
case 'DYE-2'
ind = FindCore(Core,'Name','DYE2 1998 core B')
case 'DYE-2_HQ'
ind = FindCore(Core,'Name','core_10_2016')
case 'KAN-U'
ind = FindCore(Core,'Name','core_1_2012')
case 'NASA-SE'
ind = FindCore(Core,'Name','CORE 6642 (B)')
case 'EGP'
ind = FindCore(Core,'Name','NEGIS')
# ind_new = length(Core)+1
# Core{ind_new} = Core{ind1}
# Core{ind_new}.Info.Name = 'NASA-SE_bapt'
# Core{ind_new}.Data.Density(50:110) = NaN
# ind_nan = isnan(Core{ind_new}.Data.Density)
# Core{ind_new}.Data.Density(ind_nan) =# interp1(Core{ind_new}.Data.Depth(~ind_nan),# Core{ind_new}.Data.Density(~ind_nan),# Core{ind_new}.Data.Depth(ind_nan))
# figure
# OverlapPlot(Core,[ind1 ind_new])
# ind = ind_new
# ind2=FindCore(Core,'NearestCodeLocation','NASA-SE')
# figure
# PlotCore(Core,'CoreNumber',ind2)
# figure
# OverlapPlot(Core,[114 23])
case 'Summit'
ind1 = FindCore(Core,'Name','T99_1990')
ind2 = FindCore(Core,'Name','Grip1991Shallow')
ind_new = length(Core)+1
Core{ind_new} = Core{ind2}
Core{ind_new}.Info.Name = 'T99+GRIP_1990'
Core{ind_new}.Data.Density(1:length(Core{ind1}.Data.Density)) = Core{ind1}.Data.Density
ind_nan = isnan(Core{ind_new}.Data.Density)
Core{ind_new}.Data.Density(ind_nan) = interp1(Core{ind_new}.Data.Depth(~ind_nan), Core{ind_new}.Data.Density(~ind_nan),Core{ind_new}.Data.Depth(ind_nan))
ind = ind_new
case 'Miege'
ind = 120#or 8
case 'NASA-U'
ind = FindCore(Core,'Name','CORE 7347')
# ind2 = FindCore(Core,'Name','NASA-U_Herson')
case 'SouthDome'
ind = FindCore(Core,'Name','S. Dome Core A')
# ind = FindCore(Core,'Name','S. Dome Core B')
case 'NASA-E'
ind1 = FindCore(Core,'Name','NASA East Core A')
ind2 = FindCore(Core,'Name','NASA East Core B')
ind_new = length(Core) +1
Core{ind_new} = Core{ind1}
Core{ind_new}.Info.Name = 'NASA East combined'
tmp = length(Core{ind2}.Data.Density)
Core{ind_new}.Data.Density(1:tmp) = Core{ind2}.Data.Density
case 'Saddle'
ind = FindCore(Core,'Name','N. Dye 3 (Saddle) - B')
ind2 = FindCore(Core,'Name','N. Dye 3 (Saddle) - A')
figure
OverlapPlot(Core,[ind ind2])
case 'TUNU-N'
#
# ind2 = FindCore(Core,'Name','B19_NGT19_1994')
# ind2 = FindCore(Core,'Name','Tunu-S7.5')
# tunus7.5 lower than tunu1
# B19 lower than tunu1
# tunuN25 lower than tunu1
# tunuE25 lower than tunu1
# tunuW25 lower than tunu1
ind1 = FindCore(Core,'Name','Tunu-W25')
ind2 = FindCore(Core,'Name','Tunu-E50')
ind = FindCore(Core,'Name','Tunu-1')
figure
OverlapPlot(Core,[ind ind2])
#
case 'NGRIP'
ind = FindCore(Core,'Name','NG97S2~1-3bag')
# ind = FindCore(Core,'Name','NGRIP2001S5')
case 'GITS'
ind = FindCore(Core,'Name','Camp Century')
# ind = FindCore(Core,'Name','NGRIP2001S5')
case 'KAN_U'
ind = FindCore(Core,'Name','core_1_2013')
# ind = FindCore(Core,'Name','NGRIP2001S5')
# Creating density profile and writing it into the Input folder
depth = Core{ind}.Data.Depth/100
density = Core{ind}.Data.Density
ice_perc = Core{ind}.Data.Type_perc
# if strcmp(station,'KAN-U')
# depth = depth'
# density = density'
# ice_perc = ice_perc'
# ice_perc(length(ice_perc):length(density)) = 0
#
# DensProfile = [depth, density, ice_perc]
filename = sprintf('./Input/Initial state/DensityProfile_#s_#i.csv',station,Core{ind}.Info.DateCored.Year)
M = [depth, density]
M_table = array2table(M,'VariableName', {'depth_m', 'density_kgm3'})
writetable(M_table,filename,'Delimiter','')
fprintf('Initial density profile was generated from core#s and placed in Input folder.\n',Core{8}.Info.Name)
PlotCore(Core,'CoreNumber',ind)
return rho_snow
if c.retmip == 0
switch c.station
case {'DYE-2','DYE-2_long'}
filename = './Input/Initial state/density/RetMIP_density_Dye-2 1998.csv'
case {'CP1', 'Summit', 'NASA-SE', 'NASA-E', 'NASA-U', 'SouthDome', 'Saddle', 'TUNU-N'}
filename = ['./Input/Initial state/density/DensityProfile_', c.station,'_1998.csv']
# filename = './Input/Initial state/density/RetMIP_density_Summit 1990.csv'
case 'NGRIP'
filename = './Input/Initial state/density/DensityProfile_NGRIP_1997.csv'
case 'GITS'
filename = './Input/Initial state/density/DensityProfile_GITS_1963.csv'
case 'DYE-2_HQ'
filename = './Input/Initial state/density/RetMIP_density_Dye-2 2016.csv'
case 'NUK_K'
filename = './Input/Initial state/density/DensityProfile_NUK_K.csv'
case 'EGP'
filename = './Input/Initial state/density/DensityProfile_EGP_2012.csv'
case 'KAN-U'
# if c.year(1) == 2012
filename = './Input/Initial state/density/RetMIP_density_KAN-U 2012.csv'
# else
# filename = './Input/Initial state/density/DensityProfile_KAN-U_1989.csv'
#
case 'Miege'
filename = './Input/Initial state/density/RetMIP_density_Firn Aquifer.csv'
otherwise
if c.elev_AWS < 1400
filename = './Input/Initial state/density/DensityProfile_NUK_K.csv'
elseif c.elev_AWS < 1800
filename = './Input/Initial state/density/RetMIP_density_Dye-2 2016.csv'
else
filename = './Input/Initial state/density/DensityProfile_Summit_1998.csv'
warning('Missing initial density profile for requested station.')
else
#reads initial subsurface conditions from file
if c.retmip == 0
switch c.station
case 'DYE-2_HQ'
filename = './Input/Initial state/temperature/RetMIP_temperature_Dye-2 HQ.csv'
case {'DYE-2','DYE-2_long'}
filename = './Input/Initial state/temperature/RetMIP_temperature_Dye-2.csv'
case {'Summit', 'NASA-E', 'NGRIP'}
filename = './Input/Initial state/temperature/RetMIP_temperature_Summit.csv'
case {'NASA-U', 'KAN-U'}
filename = ['./Input/Initial state/temperature/RetMIP_temperature_', c.station,'.csv']
case 'GITS'
filename = './Input/Initial state/temperature/GITS_temperature.csv'
case 'TUNU-N'
filename = './Input/Initial state/temperature/GITS_temperature.csv'
case 'NUK_K'
filename = './Input/Initial state/temperature/InitialTemperatureProfile_NUK_K.csv'
case 'Miege'
filename = './Input/Initial state/temperature/RetMIP_temperature_Firn Aquifer.csv'
otherwise
disp('Using thermistor data')
for i = 1:24*14#we look at the week following the installation
if sum(~isnan(T_obs(i,:)))>1
if sum(~isnan(T_obs(i,:)))<3
continue
if sum(~isnan(depth_thermistor(i,~isnan(T_obs(i,:)))'))<3
continue
depth= depth_thermistor(i,~isnan(T_obs(i,:)))'#in m
depth = depth(depth~=0)
[depth,ind_sorted] = sort(depth)
out(:,1) = depth
oldtemp = T_obs(i,~isnan(T_obs(i,:)))'
oldtemp = oldtemp(depth~=0)
oldtemp = oldtemp(ind_sorted)
out(:,2) = oldtemp
date_Tstring = datestr(time_dt(i))
break
filename = []
if isempty(oldtemp)
disp('no thermistor data availble')
filename = './Input/Initial state/temperature/InitialTemperatureProfile.csv'
else