-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathLDT_DrangeMod.F90
560 lines (505 loc) · 20.7 KB
/
LDT_DrangeMod.F90
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
!-----------------------BEGIN NOTICE -- DO NOT EDIT-----------------------
! NASA Goddard Space Flight Center
! Land Information System Framework (LISF)
! Version 7.5
!
! Copyright (c) 2024 United States Government as represented by the
! Administrator of the National Aeronautics and Space Administration.
! All Rights Reserved.
!-------------------------END NOTICE -- DO NOT EDIT-----------------------
module LDT_DrangeMod
!
!BOP
! !MODULE: LDT_DrangeMod
!
! !DESCRIPTION:
! This module handles the dynamic range computations
!
! !REVISION HISTORY:
! 2 Oct 2008 Sujay Kumar Initial Specification
! 16 Feb 2022 Mahdi Navari; modified to save stratify CDF
!
!EOP
use LDT_DAobsDataMod
!-----------------------------------------------------------------------------
! !PUBLIC MEMBER FUNCTIONS:
!-----------------------------------------------------------------------------
public :: LDT_diagnoseDrange
public :: LDT_computeDrange
private
contains
!BOP
! !ROUTINE: LDT_diagnoseDrange
! \label{LDT_diagnoseDrange}
!
! !INTERFACE:
subroutine LDT_diagnoseDrange(n)
! !USES:
use LDT_coreMod, only : LDT_rc
use LDT_DAmetricsDataMod, only : LDT_DAmetricsPtr
!
! !DESCRIPTION:
! This subroutine issues the calls to update the Drange calculation for
! desired variables.
!
! The methods invoked are:
! \begin{description}
! \item[diagnoseSingleDrange](\ref{diagnoseSingleDrange})
! updates the Drange computation for a single variable
! \end{description}
!
!EOP
implicit none
integer, intent(in) :: n
integer :: i, index
do index=1,LDT_DA_MOC_COUNT
call diagnoseSingleDrange(n,LDT_DAobsDataPtr(n,index)%dataEntryPtr,&
LDT_DAmetricsPtr(index)%dataEntryPtr)
enddo
end subroutine LDT_diagnoseDrange
!BOP
! !ROUTINE: diagnoseSingleDrange
! \label{diagnoseSingleDrange}
!
! !INTERFACE:
subroutine diagnoseSingleDrange(n,obs, metrics)
! !USES:
use LDT_coreMod
use LDT_DAmetricsDataMod
!
! !DESCRIPTION:
! This routine updates the Drange computation (updates the running
! sum calculations of the squared error)
! The arguments are:
!
! \begin{description}
! \item[obs] observation object
! \item[model] model variable object
! \item[metrics] object to hold the updated statistics
! \end{description}
!EOP
implicit none
integer, intent(in) :: n
type(LDT_DAmetaDataEntry) :: obs
type(DAmetricsEntry) :: metrics
integer :: t,j,k, c,r,c1,r1,t1
integer :: r_min, r_max
integer :: c_min, c_max
if(LDT_rc%cdf_ntimes.eq.12) then
j = LDT_rc%mo
elseif(LDT_rc%cdf_ntimes.eq.1) then
j = 1
endif
if(obs%selectOpt.eq.1.and.metrics%selectOpt.eq.1) then
do r=1,LDT_rc%lnr(n)
do c=1,LDT_rc%lnc(n)
t = LDT_domain(n)%gindex(c,r)
if(t.ge.-1) then
r_min = max(r-LDT_rc%sp_sample_cdf_rad,1)
c_min = max(c-LDT_rc%sp_sample_cdf_rad,1)
r_max = min(r+LDT_rc%sp_sample_cdf_rad,LDT_rc%lnr(n))
c_max = min(c+LDT_rc%sp_sample_cdf_rad,LDT_rc%lnc(n))
do r1=r_min, r_max
do c1=c_min, c_max
t1 = LDT_domain(n)%gindex(c1,r1)
if(t1.ne.-1) then
do k=1,obs%vlevels
if(obs%count(t1,k).ne.0) then
if(obs%value(t1,k).gt.metrics%maxval(t,j,k)) then
metrics%maxval(t,j,k) = obs%value(t1,k)
endif
if(obs%value(t1,k).lt.metrics%minval(t,j,k)) then
metrics%minval(t,j,k) = obs%value(t1,k)
endif
metrics%count_drange_total(t,j,k) = &
metrics%count_drange_total(t,j,k) + 1
endif
enddo
endif
enddo
enddo
endif
enddo
enddo
endif
end subroutine diagnoseSingleDrange
!BOP
!
! !ROUTINE: LDT_computeDrange
! \label{LDT_computeDrange}
!
! !INTERFACE:
subroutine LDT_computeDrange(n)
! !USES:
use LDT_coreMod, only : LDT_rc
use LDT_DAobsDataMod, only : LDT_DAobsDataPtr
use LDT_DAmetricsDataMod, only : LDT_DAmetricsPtr
!
! !DESCRIPTION:
! This subroutine issues the calls to compute Drange values for the
! desired variables
!
! The methods invoked are:
! \begin{description}
! \item[computeSingleDrange](\ref{computeSingleDrange})
! updates the Drange computation for a single variable
! \end{description}
!
! The arguments are:
! \begin{description}
! \end{description}
!EOP
implicit none
integer, intent(in) :: n
integer :: i, index
do index=1,LDT_DA_MOC_COUNT
call computeSingleDrange(n,LDT_DAobsDataPtr(n,index)%dataEntryPtr,&
LDT_DAmetricsPtr(index)%dataEntryPtr)
enddo
end subroutine LDT_ComputeDrange
!BOP
!
! !ROUTINE: computeSingleDrange
! \label{computeSingleDrange}
!
! !INTERFACE:
subroutine computeSingleDrange(n,obs, metrics)
! !USES:
use LDT_coreMod, only : LDT_rc, LDT_domain
use LDT_DAmetricsDataMod
!
! !DESCRIPTION:
! This routine computes the Drange values for a single variable
! The arguments are:
!
! \begin{description}
! \item[obs] observation object
! \item[metrics] object to hold the updated statistics
! \end{description}
!EOP
implicit none
integer, intent(in) :: n
type(LDT_DAmetaDataEntry) :: obs
type(DAmetricsEntry) :: metrics
integer :: t,i,j,k,c,r
integer :: sindex,sindex0,sindex1
real, allocatable :: strat_xrange(:,:,:,:)
real, allocatable :: strat_delta(:,:,:)
real, allocatable :: strat_mask(:,:,:)
real, allocatable :: strat_minval(:,:,:)
real, allocatable :: strat_maxval(:,:,:)
real, allocatable :: strat_drange_total(:,:,:)
if(LDT_rc%endtime.eq.1) then
if(obs%selectOpt.eq.1.and.metrics%selectOpt.eq.1) then
if(LDT_rc%group_cdfs.eq.0 .and. LDT_rc%strat_cdfs.eq.0) then
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
if(metrics%count_drange_total(t,j,k).le.&
LDT_rc%obsCountThreshold) then
metrics%maxval(t,j,k) = LDT_rc%udef
metrics%minval(t,j,k) = LDT_rc%udef
metrics%mask(t,j,k) = LDT_rc%udef
else
metrics%mask(t,j,k) = metrics%count_drange_total(t,j,k)
metrics%delta(t,j,k) = &
(metrics%maxval(t,j,k) - metrics%minval(t,j,k))/&
(LDT_rc%cdf_nbins-1)
metrics%xrange(t,j,k,1) = metrics%minval(t,j,k)
do i=2, LDT_rc%cdf_nbins
metrics%xrange(t,j,k,i) = &
metrics%xrange(t,j,k,i-1) + &
metrics%delta(t,j,k)
enddo
endif
enddo
enddo
enddo
elseif(LDT_rc%group_cdfs.eq.1 .and. LDT_rc%strat_cdfs.eq.0) then
allocate(strat_drange_total(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_maxval(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_minval(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_mask(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_delta(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_xrange(LDT_rc%group_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels, &
LDT_rc%cdf_nbins))
strat_drange_total = 0
strat_maxval = -1000000.0
strat_minval = 1000000.0
strat_mask = 0
strat_delta = 0
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex = LDT_rc%cdf_strat_data(t)
strat_drange_total(sindex,j,k) = &
strat_drange_total(sindex,j,k) + &
metrics%count_drange_total(t,j,k)
if(metrics%maxval(t,j,k).gt.&
strat_maxval(sindex,j,k)) then
strat_maxval(sindex,j,k) = metrics%maxval(t,j,k)
endif
if(metrics%minval(t,j,k).lt.&
strat_minval(sindex,j,k)) then
strat_minval(sindex,j,k) = metrics%minval(t,j,k)
endif
enddo
enddo
enddo
do t=1,LDT_rc%group_cdfs_nbins
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
if(strat_drange_total(t,j,k).le.&
LDT_rc%obsCountThreshold) then
strat_maxval(t,j,k) = LDT_rc%udef
strat_minval(t,j,k) = LDT_rc%udef
strat_mask(t,j,k) = LDT_rc%udef
else
strat_mask(t,j,k) = strat_drange_total(t,j,k)
strat_delta(t,j,k) = &
(strat_maxval(t,j,k) - &
strat_minval(t,j,k))/&
(LDT_rc%cdf_nbins-1)
strat_xrange(t,j,k,1) = strat_minval(t,j,k)
do i=2, LDT_rc%cdf_nbins
strat_xrange(t,j,k,i) = &
strat_xrange(t,j,k,i-1) + &
strat_delta(t,j,k)
enddo
endif
enddo
enddo
enddo
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex = LDT_rc%cdf_strat_data(t)
if(strat_mask(sindex,j,k).eq.LDT_rc%udef) then
metrics%maxval(t,j,k) = LDT_rc%udef
metrics%minval(t,j,k) = LDT_rc%udef
metrics%mask(t,j,k) = LDT_rc%udef
else
metrics%mask(t,j,k) = strat_mask(sindex,j,k)
metrics%delta(t,j,k) = strat_delta(sindex,j,k)
metrics%xrange(t,j,k,:) =strat_xrange(sindex,j,k,:)
metrics%maxval(t,j,k) = strat_maxval(sindex,j,k)
metrics%minval(t,j,k) = strat_minval(sindex,j,k)
endif
enddo
enddo
enddo
metrics%strat_xrange = strat_xrange
deallocate(strat_drange_total)
deallocate(strat_maxval)
deallocate(strat_minval)
deallocate(strat_mask)
deallocate(strat_delta)
!MN: Startification based on monthly precipitation climatology
! monthly total precipitation climatology for each pixel are stored in LDT_rc%stratification_data
elseif(LDT_rc%group_cdfs.eq.0 .and. LDT_rc%strat_cdfs.eq.1) then
allocate(strat_drange_total(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_maxval(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_minval(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_mask(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_delta(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_xrange(LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels, &
LDT_rc%cdf_nbins))
strat_drange_total = 0
strat_maxval = -1000000.0
strat_minval = 1000000.0
strat_mask = 0
strat_delta = 0
strat_xrange = 0
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex = LDT_rc%stratification_data(t,j)
strat_drange_total(sindex,j,k) = &
strat_drange_total(sindex,j,k) + &
metrics%count_drange_total(t,j,k)
if(metrics%maxval(t,j,k).gt.&
strat_maxval(sindex,j,k)) then
strat_maxval(sindex,j,k) = metrics%maxval(t,j,k)
endif
if(metrics%minval(t,j,k).lt.&
strat_minval(sindex,j,k)) then
strat_minval(sindex,j,k) = metrics%minval(t,j,k)
endif
enddo
enddo
enddo
do t=1,LDT_rc%strat_cdfs_nbins
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
if(strat_drange_total(t,j,k).le.&
LDT_rc%obsCountThreshold) then
strat_maxval(t,j,k) = LDT_rc%udef
strat_minval(t,j,k) = LDT_rc%udef
strat_mask(t,j,k) = LDT_rc%udef
else
strat_mask(t,j,k) = strat_drange_total(t,j,k)
strat_delta(t,j,k) = &
(strat_maxval(t,j,k) - &
strat_minval(t,j,k))/&
(LDT_rc%cdf_nbins-1)
strat_xrange(t,j,k,1) = strat_minval(t,j,k)
do i=2, LDT_rc%cdf_nbins
strat_xrange(t,j,k,i) = &
strat_xrange(t,j,k,i-1) + &
strat_delta(t,j,k)
enddo
endif
enddo
enddo
enddo
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex = LDT_rc%stratification_data(t,j)
if(strat_mask(sindex,j,k).eq.LDT_rc%udef) then
metrics%maxval(t,j,k) = LDT_rc%udef
metrics%minval(t,j,k) = LDT_rc%udef
metrics%mask(t,j,k) = LDT_rc%udef
else
metrics%mask(t,j,k) = strat_mask(sindex,j,k)
metrics%delta(t,j,k) = strat_delta(sindex,j,k)
metrics%xrange(t,j,k,:) =strat_xrange(sindex,j,k,:)
metrics%maxval(t,j,k) = strat_maxval(sindex,j,k)
metrics%minval(t,j,k) = strat_minval(sindex,j,k)
endif
enddo
enddo
enddo
metrics%strat_xrange = strat_xrange
deallocate(strat_drange_total)
deallocate(strat_maxval)
deallocate(strat_minval)
deallocate(strat_mask)
deallocate(strat_delta)
deallocate(strat_xrange)
elseif(LDT_rc%group_cdfs.eq.1 .and. LDT_rc%strat_cdfs.eq.1) then
allocate(strat_drange_total(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_maxval(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_minval(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_mask(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_delta(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels))
allocate(strat_xrange(LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins, &
LDT_rc%cdf_ntimes, &
obs%vlevels, &
LDT_rc%cdf_nbins))
strat_drange_total = 0
strat_maxval = -1000000.0
strat_minval = 1000000.0
strat_mask = 0
strat_delta = 0
strat_xrange = 0
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex0 = LDT_rc%stratification_data(t,j)
sindex1 = LDT_rc%cdf_strat_data(t)
sindex = sindex0 + (sindex1 - 1)*LDT_rc%strat_cdfs_nbins
strat_drange_total(sindex,j,k) = &
strat_drange_total(sindex,j,k) + &
metrics%count_drange_total(t,j,k)
if(metrics%maxval(t,j,k).gt.&
strat_maxval(sindex,j,k)) then
strat_maxval(sindex,j,k) = metrics%maxval(t,j,k)
endif
if(metrics%minval(t,j,k).lt.&
strat_minval(sindex,j,k)) then
strat_minval(sindex,j,k) = metrics%minval(t,j,k)
endif
enddo
enddo
enddo
do t=1,LDT_rc%group_cdfs_nbins*LDT_rc%strat_cdfs_nbins
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
if(strat_drange_total(t,j,k).le.&
LDT_rc%obsCountThreshold) then
strat_maxval(t,j,k) = LDT_rc%udef
strat_minval(t,j,k) = LDT_rc%udef
strat_mask(t,j,k) = LDT_rc%udef
else
strat_mask(t,j,k) = strat_drange_total(t,j,k)
strat_delta(t,j,k) = &
(strat_maxval(t,j,k) - &
strat_minval(t,j,k))/&
(LDT_rc%cdf_nbins-1)
strat_xrange(t,j,k,1) = strat_minval(t,j,k)
do i=2, LDT_rc%cdf_nbins
strat_xrange(t,j,k,i) = &
strat_xrange(t,j,k,i-1) + &
strat_delta(t,j,k)
enddo
endif
enddo
enddo
enddo
do t=1,LDT_rc%ngrid(n)
do j=1,LDT_rc%cdf_ntimes
do k=1,obs%vlevels
sindex0 = LDT_rc%stratification_data(t,j)
sindex1 = LDT_rc%cdf_strat_data(t)
sindex = sindex0 + (sindex1 - 1)*LDT_rc%strat_cdfs_nbins
if(strat_mask(sindex,j,k).eq.LDT_rc%udef) then
metrics%maxval(t,j,k) = LDT_rc%udef
metrics%minval(t,j,k) = LDT_rc%udef
metrics%mask(t,j,k) = LDT_rc%udef
else
metrics%mask(t,j,k) = strat_mask(sindex,j,k)
metrics%delta(t,j,k) = strat_delta(sindex,j,k)
metrics%xrange(t,j,k,:) =strat_xrange(sindex,j,k,:)
metrics%maxval(t,j,k) = strat_maxval(sindex,j,k)
metrics%minval(t,j,k) = strat_minval(sindex,j,k)
endif
enddo
enddo
enddo
metrics%strat_xrange = strat_xrange
deallocate(strat_drange_total)
deallocate(strat_maxval)
deallocate(strat_minval)
deallocate(strat_mask)
deallocate(strat_delta)
deallocate(strat_xrange)
endif
endif
endif
end subroutine computeSingleDrange
end module LDT_DrangeMod