-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaleochrono.py
executable file
·582 lines (517 loc) · 22.7 KB
/
paleochrono.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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
"""
TODO: what about symbolic links in github?
TODO: extend the chronology down to the bedrock by extrapolating the accumulation
TODO: optinally use a restart file to have a bootstrap method
TODO: is there an elegant way to unpack the variables vector in the model function?
TODO: allow to save the correction vector to be able to restart while changing the resolution
TODO: include some checks for when ddelta_depth/dz>1
TODO: Delta-depth observations should be lognormal?
TODO: we should superpose two charts for ice and air ages, one for the age and
one for the uncertainty, since the min age is not always near 0.
TODO: also compute the prior uncertainties and show them in the figures.
TODO: is there really a computation gain with the change of variable for the
correction functions? Avoiding this change of variables would make the code
easier to understand. I think there is no gain since solving A^-1 b when we
have the LU factorisation of A does not cost more than computing A^-1 * b
when we have computed A^-1.
TODO: make log plot for sedimentation rate, thinning and LID.
TODO: Divide cost fct by 2 for consistency with least_squares.
"""
import sys
import time
import multiprocessing
import math as m
import numpy as np
import matplotlib.pyplot as mpl
from scipy.optimize import least_squares
from scipy.sparse.linalg import LinearOperator
from scipy import stats
import pccfg
from pcsite import Site
from pcsitepair import SitePair
from functools import partial
import gc
import os
if os.name != 'nt':
import resource
# else:
# import psutil
# Registration of start time
START_TIME = time.perf_counter()
# Read parameter file
pccfg.read_parameters()
if pccfg.is_jax:
from jax.numpy import dot
from jax.scipy.linalg import solve_triangular
from jax.numpy.linalg import cholesky
else:
from numpy import dot
from scipy.linalg import solve_triangular
from numpy.linalg import cholesky
# Opening of output.txt file
OUTPUT_FILE = open(pccfg.datadir+'output.txt', 'w')
# Global
VARIABLES = np.array([])
D = {}
DC = {}
def pcprint(message):
print(message)
OUTPUT_FILE.write(message+'\n')
return
def residuals(var):
"""Calculate the residuals as a function of the variables vector."""
index = 0
for i, dlab in enumerate(pccfg.list_sites):
D[dlab].variables = var[index:index+np.size(D[dlab].variables)]
index = index+np.size(D[dlab].variables)
D[dlab].model(D[dlab].variables)
# pccfg.nb_runs = pccfg.nb_runs + 1
gc.collect()
return resid()
def resid():
"""Calculate the residuals without recalculating the model."""
resi = np.array([])
for i, dlab in enumerate(pccfg.list_sites):
resi = np.concatenate((resi, D[dlab].variables))
resi = np.concatenate((resi, D[dlab].residuals()))
for j, dlab2 in enumerate(pccfg.list_sites):
# Note that if I put a new i loop here, to separate the D and DC
# terms, the model runs slower
if j < i:
resi = np.concatenate((resi, DC[dlab2+'-'+dlab].residuals()))
return resi
def obs_resid():
"""Calculate the observation residuals without recalculating the model."""
resi = np.array([])
for i, dlab in enumerate(pccfg.list_sites):
resi = np.concatenate((resi, D[dlab].residuals()))
for j, dlab2 in enumerate(pccfg.list_sites):
# Note that if I put a new i loop here, to separate the D and DC
# terms, the model runs slower
if j < i:
resi = np.concatenate((resi, DC[dlab2+'-'+dlab].residuals()))
return resi
def prior_resid():
"""Calculate the residuals without recalculating the model."""
resi = np.array([])
for i, dlab in enumerate(pccfg.list_sites):
resi = np.concatenate((resi, D[dlab].variables))
return resi
def residuals_plot():
"""Plot the histogram of the residuals."""
if pccfg.show_prior_residuals:
fig, ax1 = mpl.subplots()
mpl.title('Global residuals')
mpl.xlabel('Residuals (no unit)')
mpl.ylabel('Probability density')
resi = resid()
rms = m.sqrt(np.sum(resi**2)/len(resi))
mini = np.min(resi, initial=0)
maxi = np.max(resi, initial=0)
student = stats.t.fit(resi)
mpl.hist(resi, bins=40, range=(-4., 4.), density=True,
label=f"RMS: {rms:.3}, min: {mini:.3}, max: {maxi:.3},\n"
f"loc: {student[1]:.3}, scale: {student[2]:.3}, df: {student[0]:.3e}")
x_low, x_up, y_low, y_up = mpl.axis()
mpl.axis((-4., 4., y_low, y_up))
mpl.legend()
mpl.savefig(pccfg.datadir+'/residuals.'+pccfg.fig_format,
format=pccfg.fig_format, bbox_inches='tight')
if not pccfg.show_figures:
mpl.close()
if pccfg.show_prior_residuals:
fig, ax1 = mpl.subplots()
mpl.title('Prior residuals')
mpl.xlabel('Residuals (no unit)')
mpl.ylabel('Probability density')
resi = prior_resid()
rms = m.sqrt(np.sum(resi**2)/len(resi))
mini = np.min(resi, initial=0)
maxi = np.max(resi, initial=0)
student = stats.t.fit(resi)
mpl.hist(resi, bins=40, range=(-4., 4.), density=True,
label=f"RMS: {rms:.3}, min: {mini:.3}, max: {maxi:.3},\n"
f"loc: {student[1]:.3}, scale: {student[2]:.3}, df: {student[0]:.3e}")
x_low, x_up, y_low, y_up = mpl.axis()
mpl.axis((-4., 4., y_low, y_up))
mpl.legend()
mpl.savefig(pccfg.datadir+'/prior_residuals.'+pccfg.fig_format,
format=pccfg.fig_format, bbox_inches='tight')
if not pccfg.show_figures:
mpl.close()
fig, ax1 = mpl.subplots()
mpl.title('Observation residuals')
mpl.xlabel('Residuals (no unit)')
mpl.ylabel('Probability density')
resi = obs_resid()
rms = m.sqrt(np.sum(resi**2)/len(resi))
mini = np.min(resi, initial=0)
maxi = np.max(resi, initial=0)
student = stats.t.fit(resi)
mpl.hist(resi, bins=40, range=(-4., 4.), density=True,
label=f"RMS: {rms:.3}, min: {mini:.3}, max: {maxi:.3},\n"
f"loc: {student[1]:.3}, scale: {student[2]:.3}, df: {student[0]:.3e}")
x_low, x_up, y_low, y_up = mpl.axis()
mpl.axis((-4., 4., y_low, y_up))
mpl.legend()
mpl.savefig(pccfg.datadir+'/obs_residuals.'+pccfg.fig_format,
format=pccfg.fig_format, bbox_inches='tight')
if not pccfg.show_figures:
mpl.close()
def cost_function(var):
"""Calculate the cost function terms related to a pair of sites."""
res = residuals(var)
cost = dot(res, np.transpose(res)) / 2.
return cost
def jacob_column(resizero, dlabj, k):
delta = m.sqrt(np.finfo(float).eps) # Stolen from the leastsq code
D[dlabj].variables[k] += delta
D[dlabj].model(D[dlabj].variables)
deriv = [np.array([])]
index = 0
for i, dlab in enumerate(pccfg.list_sites):
index = index+len(D[dlab].variables)
if dlabj == dlab:
der = np.zeros(len(D[dlab].variables))
der[k] = 1.
deriv.append(der)
der = (D[dlab].residuals() -
resizero[index:index+RESI_SIZE[i, i]]) / delta
deriv.append(der)
else:
deriv.append(np.zeros(len(D[dlab].variables)))
deriv.append(np.zeros(RESI_SIZE[i, i]))
index = index+RESI_SIZE[i, i]
for j, dlab2 in enumerate(pccfg.list_sites):
if j < i:
if dlabj == dlab or dlabj == dlab2:
der = (DC[dlab2 + '-' + dlab].residuals() -
resizero[index:index+RESI_SIZE[j, i]])/delta
deriv.append(der)
else:
deriv.append(np.zeros(RESI_SIZE[j, i]))
index = index+RESI_SIZE[j, i]
D[dlabj].variables[k] -= delta
return np.concatenate(deriv)
def jacobian_analytical(var):
"""Calculate the Jacobian of each residual term
with analytical formulas."""
jac_list = []
for k, dlabj in enumerate(pccfg.list_sites):
D[dlabj].corrected_jacobian()
deriv = []
for i, dlab in enumerate(pccfg.list_sites):
if dlabj == dlab:
deriv.append(np.diag(np.ones(len(D[dlab].variables))))
deriv.append(D[dlab].residuals_jacobian())
else:
deriv.append(np.zeros((len(D[dlabj].variables),
len(D[dlab].variables))))
deriv.append(np.zeros((len(D[dlabj].variables),
RESI_SIZE[i, i])))
for j, dlab2 in enumerate(pccfg.list_sites):
if j < i:
if dlabj == dlab:
deriv.append(DC[dlab2+'-'+dlab].residuals_jacobian2())
elif dlabj == dlab2:
deriv.append(DC[dlab2+'-'+dlab].residuals_jacobian1())
else:
deriv.append(np.zeros((len(D[dlabj].variables),
RESI_SIZE[j, i])))
jac_list.append(np.concatenate(deriv, axis=1))
jacob = np.concatenate(jac_list)
# print(np.shape(jacob), np.shape(resid()), len(VARIABLES))
return np.transpose(jacob)
def jacobian_semi_adjoint(var):
jac = np.array([[None for _ in range(len(pccfg.list_sites))]
for _ in range(len(pccfg.list_sites))])
for i, dlab in enumerate(pccfg.list_sites):
D[dlab].corrected_jacobian()
for j, dlab2 in enumerate(pccfg.list_sites):
if j == i:
jac[i, i] = D[dlab].residuals_jacobian()
if j < i:
jac[j, i] = DC[dlab2+'-'+dlab].residuals_jacobian2()
jac[i, j] = DC[dlab2+'-'+dlab].residuals_jacobian1()
def mv(v):
index = 0
resi = np.array([])
for i, dlab in enumerate(pccfg.list_sites):
# Why do we need to sometimes flatten here? Strange.
D[dlab].var_delta = v[index:index+np.size(D[dlab].variables)]\
.flatten()
index = index+np.size(D[dlab].variables)
for i, dlab in enumerate(pccfg.list_sites):
# Why do we need to sometimes flatten here? Strange.
resi = np.concatenate((resi, D[dlab].var_delta))
resi = np.concatenate((resi, dot(np.transpose(jac[i, i]),
D[dlab].var_delta)))
for j, dlab2 in enumerate(pccfg.list_sites):
# Note that if I put a new i loop here,
# to separate the D and DC terms, the model runs slower
if j < i:
resi = np.concatenate((resi,
dot(np.transpose(jac[j, i]),
D[dlab].var_delta) +
dot(np.transpose(jac[i, j]),
D[dlab2].var_delta)))
return resi
def rmv(v):
vari = []
for k, dlabj in enumerate(pccfg.list_sites):
vari = vari + [np.zeros(np.size(D[dlabj].variables))]
index = 0
for i, dlab in enumerate(pccfg.list_sites):
vari[i] = v[index:index+np.size(D[dlab].variables)].flatten()
index = index+np.size(D[dlab].variables)
vari[i] = vari[i] +\
dot(jac[i, i], v[index:index+RESI_SIZE[i, i]])
# vari[i] = vari[i] +
# D[dlab].residuals_adj( v[index:index+RESI_SIZE[i,i]])
index = index+RESI_SIZE[i, i]
for j, dlab2 in enumerate(pccfg.list_sites):
if j < i:
vari[i] = vari[i] + dot(jac[j, i],
v[index:index+RESI_SIZE[j, i]])
vari[j] = vari[j]+dot(jac[i, j],
v[index:index+RESI_SIZE[j, i]])
index = index + RESI_SIZE[j, i]
vari = np.concatenate(vari)
return vari
# return dot(np.transpose(jac), v)
return LinearOperator((RESI_SIZE_TOT, VAR_SIZE), matvec=mv, rmatvec=rmv)
def jacobian_adjoint(var):
"""Full adjoint method. Not ready yet."""
# FIXME: Adjoint give slightly more iterations than semi_adjoint
# on the med exp.
# Check what is the issue.
print('Full adjoint is not ready yet. Exiting.')
sys.exit()
jac = np.array([[None for _ in range(len(pccfg.list_sites))]
for _ in range(len(pccfg.list_sites))])
for i, dlab in enumerate(pccfg.list_sites):
D[dlab].corrected_jacobian()
for j, dlab2 in enumerate(pccfg.list_sites):
if j == i:
jac[i, i] = D[dlab].residuals_jacobian()
if j < i:
jac[j, i] = DC[dlab2+'-'+dlab].residuals_jacobian2()
jac[i, j] = DC[dlab2+'-'+dlab].residuals_jacobian1()
def mv(v):
index = 0
resi = np.array([])
for i, dlab in enumerate(pccfg.list_sites):
# Why do we need to sometimes flatten here? Strange.
D[dlab].var_delta = v[index:index+np.size(D[dlab].variables)]\
.flatten()
index = index+np.size(D[dlab].variables)
resi = np.concatenate((resi, D[dlab].var_delta))
D[dlab].model_delta(D[dlab].var_delta)
resi = np.concatenate((resi, D[dlab].residuals_delta()))
for j, dlab2 in enumerate(pccfg.list_sites):
# Note that if I put a new i loop here,
# to separate the D and DC terms, the model runs slower
if j < i:
resi = np.concatenate((resi,
DC[dlab2 + '-' +
dlab].residuals_delta()))
return resi
def rmv(v):
vari =[]
for k, dlabj in enumerate(pccfg.list_sites):
vari = vari + [np.zeros(np.size(D[dlabj].variables))]
index = 0
for i, dlab in enumerate(pccfg.list_sites):
vari[i] = v[index:index+np.size(D[dlab].variables)].flatten()
index = index+np.size(D[dlab].variables)
vari[i] = vari[i] + dot(jac[i,i], v[index:index+RESI_SIZE[i,i]])
# vari[i] = vari[i] + D[dlab].residuals_adj( v[index:index+RESI_SIZE[i,i]])
index = index+RESI_SIZE[i,i]
for j, dlab2 in enumerate(pccfg.list_sites):
if j < i:
vari[i] = vari[i]+dot(jac[j,i],
v[index:index+RESI_SIZE[j,i]])
vari[j] = vari[j]+dot(jac[i,j],
v[index:index+RESI_SIZE[j,i]])
index = index + RESI_SIZE[j,i]
vari = np.concatenate(vari)
return vari
# return dot(np.transpose(jac), v)
return LinearOperator((RESI_SIZE_TOT, VAR_SIZE), matvec=mv, rmatvec=rmv)
def jacobian_semi_analytical(var):
"""Calculate the Jacobian with a finite difference scheme for each block."""
resizero = residuals(var)
jac_list = []
for k, dlabj in enumerate(pccfg.list_sites):
if pccfg.is_parallel:
list_args = list(range(len(D[dlabj].variables)))
if __name__ == "__main__":
with multiprocessing.Pool(pccfg.nb_nodes) as pool:
results = pool.map(partial(jacob_column, resizero, dlabj),
list_args)
jac_list.append(results)
else:
for l in range(len(D[dlabj].variables)):
# jacob = np.vstack((jacob, jacob_column(resizero, dlabj, l)))
jac_list.append(np.array([jacob_column(resizero, dlabj, l)]))
D[dlabj].model(D[dlabj].variables)
jacob = np.concatenate(jac_list)
return np.transpose(jacob)
def jacobian_numerical(var):
"""Calculate the Jacobian with a finite difference scheme."""
zeropred = residuals(var)
derivparams = []
results = []
delta = m.sqrt(np.finfo(float).eps) #Stolen from the leastsq code
#fixme: This loop is probably sub-optimal. Have a look at what does leastsq to improve this.
# results.append(residuals(derivparams))
if pccfg.is_parallel:
for i in range(len(var)):
copy = np.array(var)
copy[i] += delta
derivparams.append(copy)
if __name__ == "__main__":
pool = multiprocessing.Pool(pccfg.nb_nodes)
results = pool.map(residuals, derivparams)
derivs = [(r - zeropred)/delta for r in results]
else:
list_derivs = []
for i in range(len(var)):
copy = np.array(var)
copy[i] += delta
list_derivs.append(np.array([(residuals(copy)-zeropred)/delta]))
derivs = np.concatenate(list_derivs)
return np.transpose(derivs)
##MAIN
##Initialisation
RESI_SIZE = np.empty((np.size(pccfg.list_sites), np.size(pccfg.list_sites)), dtype=int)
for di, dlabel in enumerate(pccfg.list_sites):
print('Initialization of site '+dlabel)
D[dlabel] = Site(dlabel)
D[dlabel].model(D[dlabel].variables)
# D[dlabel].a_init=D[dlabel].a
# D[dlabel].lid_init=D[dlabel].lid
D[dlabel].write_init()
# D[dlabel].display_init()
VARIABLES = np.concatenate((VARIABLES, D[dlabel].variables))
RESI_SIZE[di, di] = np.size(D[dlabel].residuals())
for di, dlabel in enumerate(pccfg.list_sites):
for dj, dlabel2 in enumerate(pccfg.list_sites):
if dj < di:
print('Initialization of site pair '+dlabel2+'-'+dlabel)
DC[dlabel2+'-'+dlabel] = SitePair(D[dlabel2], D[dlabel])
# DC[dlabel2+'-'+dlabel].display_init()
RESI_SIZE[dj, di] = np.size(DC[dlabel2+'-'+dlabel].residuals())
VAR_SIZE = len(VARIABLES)
RESI_SIZE_TOT = len(resid())
pcprint('Size of VARIABLES vector: '+ str(VAR_SIZE))
pcprint('Size of RESIDUALS vector: '+ str(RESI_SIZE_TOT))
##Optimization
START_TIME_OPT = time.perf_counter()
pcprint('Initial cost function: '+ str(cost_function(VARIABLES)))
#print(jacobian_semi_analytical(VARIABLES))
#print(jacobian_analytical(VARIABLES))
if pccfg.opt_method == 'leastsq':
pccfg.opt_method = 'trf'
pccfg.is_parallel = False
elif pccfg.opt_method == 'leastsq-parallel':
pccfg.opt_method = 'trf'
pccfg.is_parallel = True
if pccfg.opt_method == "trf" or pccfg.opt_method == 'lm':
print('Optimization by:', pccfg.opt_method)
if pccfg.opt_method == 'trf':
print('tr_solver:', pccfg.tr_solver)
print('Jabobian:', pccfg.jacobian)
if pccfg.jacobian == 'automatic':
jac = '2-point'
else:
jac = eval('jacobian_'+pccfg.jacobian)
OptimizeResult = least_squares(residuals, VARIABLES, method=pccfg.opt_method,
jac=jac,
tr_solver=pccfg.tr_solver,
xtol=pccfg.tol, ftol=pccfg.tol, gtol=pccfg.tol, verbose=2)
VARIABLES = OptimizeResult.x
pcprint('Optimized cost function: ' + str(cost_function(VARIABLES)))
pcprint('Optimization execution time: ' + str(time.perf_counter() - START_TIME_OPT) + ' seconds')
if pccfg.jacobian == 'adjoint' or pccfg.jacobian == 'semi_adjoint':
print('Calculating Jacobian matrix.')
JACMAT = jacobian_analytical(VARIABLES)
# print('Size of JACMAT in kbytes',JACMAT.nbytes/1000)
for dlabel in pccfg.list_sites:
D[dlabel].corrected_jacobian_free()
else:
JACMAT = OptimizeResult.jac
print('Calculating Hessian matrix.')
HESS = dot(np.transpose(JACMAT), JACMAT)
JACMAT = None
elif pccfg.opt_method == 'none':
print('No optimization')
VARIABLES = np.zeros(np.size(VARIABLES))
HESS = np.diag(np.ones(np.size(VARIABLES)))
else:
print(pccfg.opt_method, ': Optimization method not recognized.')
sys.exit()
#print 'solution: ',VARIABLES
print('Factorisation of the Hessian matrix')
HESS_chol = cholesky(HESS)
HESS = None
#HESS_chol = cholesky(HESS, overwrite_a=True, check_finite=False)
#HESS_chol = np.transpose(HESS_chol)
#COV = np.linalg.inv(HESS)
#HESS = None
print('Calculation of confidence intervals')
# COV = np.linalg.inv(HESS)
INDEXSITE = 0
for dlabel in pccfg.list_sites:
print('Covariance matrix for '+dlabel)
# input('Before solving the triangular system. Program paused.')
SIZESITE = np.size(D[dlabel].variables)
D[dlabel].variables = VARIABLES[INDEXSITE:INDEXSITE+SIZESITE]
block1 = np.zeros((INDEXSITE, SIZESITE))
block2 = np.diag(np.ones(SIZESITE))
block3 = np.zeros((np.size(VARIABLES)-INDEXSITE-SIZESITE, SIZESITE))
block = np.vstack((block1, block2, block3))
toto = solve_triangular(HESS_chol, block, lower=True)
block = None
D[dlabel].cov = dot(np.transpose(toto), toto)
toto = None
# D[dlabel].cov = COV[INDEXSITE:INDEXSITE+SIZESITE,INDEXSITE:INDEXSITE+SIZESITE]
INDEXSITE = INDEXSITE+np.size(D[dlabel].variables)
# input('Before calculating sigma. Program paused.')
# COV[INDEXSITE:INDEXSITE+SIZESITE,:] = None
# COV[:,INDEXSITE:INDEXSITE+SIZESITE] = None
HESS_chol = None
for dlabel in pccfg.list_sites:
print('Confidence intervals for '+dlabel)
if pccfg.calc_errors:
D[dlabel].sigma()
D[dlabel].cov = None
# Final display and output
print('Figures, outliers detection and saving')
for di, dlabel in enumerate(pccfg.list_sites):
print('Figures, outliers detection and saving of', dlabel)
D[dlabel].save()
D[dlabel].figures()
for di, dlabel in enumerate(pccfg.list_sites):
for dj, dlabel2 in enumerate(pccfg.list_sites):
if dj < di:
print('Display of '+dlabel2+'-'+dlabel+' site pair')
DC[dlabel2+'-'+dlabel].figures()
# Plotting histogram of residuals
residuals_plot()
print('Checking for air age inversion')
for di, dlabel in enumerate(pccfg.list_sites):
if D[dlabel].check_airage_inversion():
print("WARNING: air age inversion for", dlabel)
# Program execution time
pcprint('Program execution time: '+str(time.perf_counter()-START_TIME)+' seconds')
if os.name != 'nt':
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
pcprint('Max memory usage: '+str(mem)+' kbytes')
# else:
# process = psutil.Process(os.getpid())
# mem = int(process.memory_info().rss / 1024)
if pccfg.show_figures:
mpl.show()
# Closing output file
OUTPUT_FILE.close()