-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetAge_36Cl_ICE.m
executable file
·287 lines (236 loc) · 12.1 KB
/
GetAge_36Cl_ICE.m
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
function [ ] = GetAge_36Cl_ICE()
% Function of the crep program that calculates exposure ages
addpath(genpath('Functions'));
% Loading data
% ice
%load Data_36_ice;
Data_ICE = Load_data_36('INPUT/DATA_IN_ICE.xlsx');
% load samples data
Data = Load_data_36('INPUT/DATA_IN.xlsx');
%load('Data_36_2.mat')
% Parameters given by user
NumGMDB = 2; % 1: Mush; 2: GLOPIS; 3: LSD; 4: own user geomagnetic db
Scheme = 1; % time dependant scaling model (1: LAL-STONE, 2: LSD)
Muon_model = 1; % 1: Exponential, 2: numeric integration of the flux (Balco 2008)
Atm = 0; % 0: ERA40 (Uppala et al. 2005), 1: standard atmosphere equation (NOAA 1976)
Data.GMDB = 1;
% !!!!!!!!!!!!!!!!! to be given by the user: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% Constants
Data.lambda36 = 2.303e-6 ;
Data.lambda36_uncert = Data.lambda36 .* 0.0066;
% Attenuation length
Data.Lambda_f_e = 160; % effective fast neutron attenuation coefficient (g.cm-2)
Data.Lambda_mu = 1510 ; % slow muon attenuation length (g.cm-2)
Data.Psi_mu_0 = 190 ; % slow negative muon stopping rate at land surface (muon/g/an), Heisinger et al. (2002)
% Unscaled sample specific 36Cl production rate by spallation of target elements
Data.Psi_Cl36_Ca_0 = 42.2 ;% spallation production rate for Ca, SLHL (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_K_0 = 148.1 ;% Spallation production rate at surface of 39K (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_Ti_0 = 13 ; % Spallation production rate at surface of Ti (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_Fe_0 = 1.9 ; % Spallation production rate at surface of Fe (at of Cl36 /g of Ca per yr)
%uncertainties
Data.Psi_Cl36_Ca_0_uncert = 4.8 ;% spallation production rate for Ca, SLHL (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_K_0_uncert = 7.8 ;% Spallation production rate at surface of 39K (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_Ti_0_uncert = 3 ; % Spallation production rate at surface of Ti (at of Cl36 /g of Ca per yr)
Data.Psi_Cl36_Fe_0_uncert = 0.2 ; % Spallation production rate at surface of Fe (at of Cl36 /g of Ca per yr)
% !!!!!!!!!!!!!!!!! to be given by the user: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% Open paths and load cst
addpath Functions
addpath Constants
load('Constants/GMDB.mat');
load('Constants/OtherCst.mat');
Data.Atm = Atm;% atmospheric model
% Geomagnetic data base
if length(Data.GMDB)==1;
%NumGMDB = 2; % 1: Mush; 2: GLOPIS; 3: LSD; 4: own user geomagnetic db
if NumGMDB==1;
SelGMDB=GMDB.Musch;
elseif NumGMDB==2;
SelGMDB=GMDB.GLOPIS;
else % (NumGMDB=3)
SelGMDB=GMDB.LSD;
end
else
NumGMDB=4;
SelGMDB=Data.GMDB;
end
% Get number of samples
VecLat=Data.Lat';
[NbSpl,~]=size(VecLat);
% Formatting Outputs
ExitMat=zeros(NbSpl,4);
CellPDF=cell(1,2*NbSpl);
ErrCol=zeros(NbSpl,1);
StatCell=cell(NbSpl,1);
% Get 36Cl parameters
addpath(genpath('Functions/36Cl_Functions'));
% Muon
if(Muon_model == 1)
flag.muon = 'exp'; % Muon attenuation length approximated by exponential (Schimmelfenning 2009).
elseif(Muon_model == 2)
flag.muon = 'num'; % Muon attenuation length calculated following Heisinger (2002a,b) and Balco et al. (2008)
else
Mess=sprintf('Invlid muon model');
end
% Scaling model
if(Scheme == 1)
flag.scaling_model = 'st'; % LAL-STONE scheme
elseif(Scheme == 2)
flag.scaling_model = 'sa'; % LSD scheme
else
Mess=sprintf('Invlid scaling model');
end
% Constants initialization
[Const_cosmo] = Init_const(Data,flag);
% Variable and Data Initialization
% rock
[Data_formatted,Param_site] = Init_var(Data);
% ice
[Data_formatted_ICE,Param_site_ICE] = Init_var(Data_ICE);
% Scaling factors initialization
%w = 0.2; % water content for Sato & Niita (2006)
w = -1; % water content = default value
w_ICE = 1;
% geomagnetic database
flag.NumGMDB = NumGMDB;
Sf = Func_Sf(Param_site,Data,Atm,w,SelGMDB,flag);
Sf_ICE = Func_Sf(Param_site_ICE,Data_ICE,Atm,w_ICE,SelGMDB,flag);
% Production rates and constants initialization
Param_cosmo = clrock(Data_formatted,Param_site,Const_cosmo,Sf);
Param_cosmo_ICE = clrock(Data_formatted_ICE,Param_site_ICE,Const_cosmo,Sf_ICE);
%% Lets calculate ages
for is=1:1%NbSpl
% Create de dataset
dataset(1,:) = Data.NuclCon(:);
dataset(2,:) = Data.NuclErr(:);
dataset(3,:) = Data.Z(:);
% Fix erosion rate
erosion = 1000; Data.Eros;
% Search parameters
flag.min_bounds = 0.0; % minimum bound for the search
flag.max_bounds = 400000; % maximum bound for the search
flag.search = 'fminsearch'; %flag.search = 'nmsmax';
flag.plot = 1;
flag.plotP = 1;
t_expo = 500000;
t_vector = [0:100:t_expo];
t_LGM = 10000;
t_degla = 8000;
thick_test = [30 60 100 150 200];
for i=1:length(thick_test)
ice_thickness = thick_test(i).*100; % in cm
disp(['Ice thickness = ' num2str(ice_thickness/100) 'm']);
z_history=ones(1,length(t_vector)).*ice_thickness;
i_postgla = find(t_vector<t_degla);
z_history(i_postgla)=.0;
i_degla = find((t_vector>=t_degla)&(t_vector<t_LGM));
z_history(i_degla)=(t_vector(i_degla)-t_degla).*ice_thickness/(t_LGM-t_degla);
depth_profile_speed(t_vector,z_history,...
Const_cosmo,Param_cosmo,Param_cosmo_ICE, ...
Param_site,Param_site_ICE,...
Sf{is},Sf_ICE{is},erosion,t_expo,Data.Z(:),flag);
end
% First guess considering the sample belongs to a surface without erosion.
%t_guess = -log(1-(Data.NuclCon(is)-Param_cosmo{is}.N36Cl.rad-Param_cosmo{is}.N36Cl.inh)*Const_cosmo.lambda36/Param_cosmo{is}.P_cosmo(1))/Const_cosmo.lambda36;
t_guess = -log(1-(Data.NuclCon(is))*Const_cosmo.lambda36/Param_cosmo{is}.P_cosmo(1))/Const_cosmo.lambda36;
%t_guess = 10000;randi([flag.min_bounds flag.max_bounds],1,1);
n_trial = 100;
% preparing dataset integrating data uncertainty
for k=1:n_trial
for j=1:length(NbSpl)
dataset(1,j) = Data.NuclCon(j) + Data.NuclErr(j)*randn(1);
end
d{k} = dataset;
end
% anonymous function
func = @(ik) Find_age(Const_cosmo, Param_cosmo, Param_site, Sf{is}, d{ik}, erosion, t_guess, flag);
age = zeros(1,n_trial);
resolution = 'serial';
% serial resolution
if(strcmp(resolution,'serial')==1)
for k=1:n_trial
%Best_age = Find_age(Const_cosmo, Param_cosmo, Param_site, Sf, dataset, erosion, t_guess, flag);
age(k) = func(k);
t_guess = age(k); % starting age for the next search
h = waitbar(k/n_trial)
end
close(h)
elseif(strcmp(resolution,'parallel')==1)
% parallel resolution
age = [];
if isOctave
%OCTAVE
numCores = nproc();
[age] = pararrayfun (numCores, func, [1:1:n_trial]);
else
%Matlab
parfor k=1:n_trial
age(k) =feval(func,k);
end
end
end
Age_MC = mean(age)./1000
Err_MC = std(age)./1000
% best age
dataset(1,1) = Data.NuclCon(is);
dataset(2,1) = Data.NuclErr(is);
dataset(3,1) = Data.Z(is);
AgeCosmo = Find_age(Const_cosmo, Param_cosmo, Param_site, Sf{is}, dataset, erosion, t_guess, flag);
if isreal(AgeCosmo)==0; % check error
ErrPRflag=1;
AgeCosmo=-100;
end
% 2. Assume there is some value of P_effective that satisfies the simple exposure age equation. N = (P_effective/lambda)*(1-exp(-lambda*t))
P_effective = Data.NuclCon(is).*Const_cosmo.lambda36./(1-exp(-Const_cosmo.lambda36.*AgeCosmo));
% 3. Estimate the total uncertainty on P_effective by adding up uncertainties on the individual production rates from K, Ca, Cl, and then scaling to whatever the value of P_effective is. Each one of those includes both an uncertainty in the element concentration and an uncertainty in the reference production rate.
% get current scaling factors.
t_vector = [0:100:AgeCosmo];
currentsf=getcurrentsf(Sf{is},t_vector./1000,flag);
Sf{is}.currentsf = currentsf;
% Settings to compute uncertainties
% Monte Carlo sampling of p_f_0 to obtain the propagated uncertainty on P_th
% and P_eth ? yes or no. If no, the uncertainty is 25%
flag.uncert.pf0_mc='no';
% uncertainty on the Production rate , in %
P36_uncert = get_36Cl_uncert(Data_formatted,Const_cosmo,Param_cosmo{1},Param_site{1},Sf{is},Data.Z(1).*Param_site{1}.rho_rock,flag);
% 4. Propagate the uncertainty on N (Cl-36 measurement uncertainty) and P_effective (from above) using the normal linear error propagation formula.
ErrCosmo = (((-1/Const_cosmo.lambda36)./(1 - Data_formatted{1}.N36Cl.meas*Const_cosmo.lambda36/P_effective) ...
.*(Data_formatted{1}.N36Cl.meas*Const_cosmo.lambda36/(P_effective.^2)))^2).^.5 ...
.*P36_uncert.*P_effective; % in year
% yr to kyr
AgeCosmo = AgeCosmo./1000
ErrCosmo = ErrCosmo./1000
[XPDFCosmo,PDFCosmo] = PDF_from_Age( AgeCosmo,ErrCosmo );
[XPDF_MC,PDF_MC] = PDF_from_Age( Age_MC,Err_MC );
figure(1)
plot(XPDFCosmo,PDFCosmo); hold on
plot(XPDF_MC,PDF_MC); hold on
figure(2)
if isOctave
hist(age);
else
histogram(age);
end
% OUTPUT
ExitMat(is,1) = .0;
ExitMat(is,2)=AgeCosmo;
ExitMat(is,3)=ErrCosmo;
ExitMat(is,4)=ErrCosmo;
CellPDF{2*is-1}=XPDFCosmo;
CellPDF{2*is}=PDFCosmo;
% Look if there is a problem with the length of the database
if isempty(XPDFCosmo)==1;
ErrCol(is)=1;
if ErrPRflag==1;
Mess=sprintf('Production rate too low');
elseif isnan(AgeCosmo)==1;
Mess=sprintf('Sample too old for the Geomagnetic database');
% elseif Age<2; Chope if to young ?
% Mess=sprintf('Sample too young to provide probability density distribution');
else
Mess=sprintf('Relative error bar too large to provide probability density function (excursion in negative ages or ages older than the Geomagnetic database)');
end
else
Mess=sprintf('Ok');
end
StatCell{is}=Mess;
end % end loop over samples