Skip to content

Commit 08e0326

Browse files
Merge pull request #729 from NCAR/stats-tests
Harnesses for distribution tests
2 parents 2d5882c + e9e56c2 commit 08e0326

13 files changed

+241
-5
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ test_quad_irreg_interp
202202
test_quad_reg_interp
203203
test_table_read
204204
test_ran_unif
205+
test_gamma_dist
206+
test_normal_dist
207+
test_beta_dist
205208
test_kde_dist
206209
test_window
207210

assimilation_code/modules/assimilation/beta_distribution_mod.f90

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ subroutine test_beta
6565
cdf_diff(i) = beta_cdf(mx(i), malpha(i), mbeta(i), 0.0_r8, 1.0_r8) - mcdf(i)
6666
write(*, *) i, pdf_diff(i), cdf_diff(i)
6767
end do
68+
if(abs(maxval(pdf_diff)) < 1e-15_r8 .and. abs(maxval(cdf_diff)) < 1e-15_r8) then
69+
write(*, *) 'Matlab Comparison Tests: PASS'
70+
else
71+
write(*, *) 'Matlab Comparison Tests: FAIL'
72+
endif
73+
6874

6975
! Test many x values for cdf and inverse cdf for a single set of alpha and beta
7076
alpha = 5.0_r8
@@ -83,6 +89,13 @@ subroutine test_beta
8389
write(*, *) 'max difference in inversion is ', max_diff
8490
write(*, *) 'max difference should be less than 1e-14'
8591

92+
if(max_diff < 1e-14_r8) then
93+
write(*, *) 'Inversion Tests: PASS'
94+
else
95+
write(*, *) 'Inversion Tests: FAIL'
96+
endif
97+
98+
8699
end subroutine test_beta
87100

88101
!-----------------------------------------------------------------------

assimilation_code/modules/assimilation/gamma_distribution_mod.f90

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ subroutine test_gamma
6565
write(*, *) i, pdf_diff(i), cdf_diff(i)
6666
end do
6767

68+
if(abs(maxval(pdf_diff)) < 1e-15_r8 .and. abs(maxval(cdf_diff)) < 1e-15_r8) then
69+
write(*, *) 'Matlab Comparison Tests: PASS'
70+
else
71+
write(*, *) 'Matlab Compariosn Tests: FAIL'
72+
endif
73+
6874
! Input a mean and variance
6975
mean = 10.0_r8
7076
sd = 1.0_r8
@@ -87,6 +93,13 @@ subroutine test_gamma
8793
write(*, *) 'max difference in inversion is ', max_diff
8894
write(*, *) 'max difference should be less than 1e-11'
8995

96+
if(max_diff < 1e-11_r8) then
97+
write(*, *) 'Inversion Tests: PASS'
98+
else
99+
write(*, *) 'Inversion Tests: FAIL'
100+
endif
101+
102+
90103
end subroutine test_gamma
91104

92105
!-----------------------------------------------------------------------

assimilation_code/modules/assimilation/normal_distribution_mod.f90

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ subroutine test_normal
6666
cdf_diff(i) = normal_cdf(mx(i), mmean(i), msd(i)) - mcdf(i)
6767
end do
6868
max_matlab_diff = maxval(abs(cdf_diff))
69-
if(max_matlab_diff > 1.0e-15_r8) then
70-
write(*, *) 'WARNING: Difference from Matlab baseline is too large ', max_matlab_diff
69+
if(max_matlab_diff < 1.0e-15_r8) then
70+
write(*, *) 'Matlab Comparison Tests: PASS ', max_matlab_diff
7171
else
72-
write(*, *) 'Agreement with Matlab baseline is okay: max diff is < 1e-15 ', max_matlab_diff
72+
write(*, *) 'Matlab Comparison Tests: FAIL ', max_matlab_diff
7373
endif
7474

7575
! Keep track of differences as function of quantile
@@ -92,10 +92,10 @@ subroutine test_normal
9292

9393
do j = 1, 16
9494
if(max_diff(j) > inv_diff_bound(j)) then
95-
write(*, *) 'WARNING: Max inversion diff ', max_diff(j), ' > bound ', inv_diff_bound(j), &
95+
write(*, *) 'FAIL: Max inversion diff ', max_diff(j), ' > bound ', inv_diff_bound(j), &
9696
'for quantiles < ', max_q(j)
9797
else
98-
write(*, *) 'Max inversion diff ', max_diff(j), ' OK, bound ', inv_diff_bound(j), &
98+
write(*, *) 'PASS: Max inversion diff ', max_diff(j), ' < bound ', inv_diff_bound(j), &
9999
'for quantiles < ', max_q(j)
100100
endif
101101
end do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! DART software - Copyright UCAR. This open source software is provided
2+
! by UCAR, "as is", without charge, subject to all terms of use at
3+
! http://www.image.ucar.edu/DAReS/DART/DART_download
4+
5+
program test_beta_distribution
6+
7+
use utilities_mod, only : initialize_utilities, finalize_utilities
8+
use beta_distribution_mod, only : test_beta
9+
10+
implicit none
11+
12+
call initialize_utilities()
13+
call test_beta()
14+
call finalize_utilities()
15+
16+
end program test_beta_distribution
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
&utilities_nml
2+
module_details = .false.
3+
/
4+
5+
&preprocess_nml
6+
input_obs_qty_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
7+
output_obs_qty_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
8+
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
9+
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
10+
obs_type_files = '../../../observations/forward_operators/obs_def_gps_mod.f90'
11+
quantity_files = '../../../assimilation_code/modules/observations/default_quantities_mod.f90'
12+
/
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
# DART software - Copyright UCAR. This open source software is provided
4+
# by UCAR, "as is", without charge, subject to all terms of use at
5+
# http://www.image.ucar.edu/DAReS/DART/DART_download
6+
7+
main() {
8+
9+
10+
export DART=$(git rev-parse --show-toplevel)
11+
source "$DART"/build_templates/buildfunctions.sh
12+
13+
MODEL="none"
14+
EXTRA="$DART"/models/template/threed_model_mod.f90
15+
dev_test=1
16+
LOCATION="threed_sphere"
17+
TEST="beta_dist"
18+
19+
serial_programs=(
20+
test_beta_dist
21+
)
22+
23+
# quickbuild arguments
24+
arguments "$@"
25+
26+
# clean the directory
27+
\rm -f -- *.o *.mod Makefile .cppdefs
28+
29+
# build and run preprocess before making any other DART executables
30+
buildpreprocess
31+
32+
# build DART
33+
buildit
34+
35+
# clean up
36+
\rm -f -- *.o *.mod
37+
38+
}
39+
40+
main "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! DART software - Copyright UCAR. This open source software is provided
2+
! by UCAR, "as is", without charge, subject to all terms of use at
3+
! http://www.image.ucar.edu/DAReS/DART/DART_download
4+
5+
program test_gamma_distribution
6+
7+
use utilities_mod, only : initialize_utilities, finalize_utilities
8+
use gamma_distribution_mod, only : test_gamma
9+
10+
implicit none
11+
12+
call initialize_utilities()
13+
call test_gamma()
14+
call finalize_utilities()
15+
16+
end program test_gamma_distribution
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
&utilities_nml
2+
module_details = .false.
3+
/
4+
5+
&preprocess_nml
6+
input_obs_qty_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
7+
output_obs_qty_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
8+
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
9+
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
10+
obs_type_files = '../../../observations/forward_operators/obs_def_gps_mod.f90'
11+
quantity_files = '../../../assimilation_code/modules/observations/default_quantities_mod.f90'
12+
/
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
# DART software - Copyright UCAR. This open source software is provided
4+
# by UCAR, "as is", without charge, subject to all terms of use at
5+
# http://www.image.ucar.edu/DAReS/DART/DART_download
6+
7+
main() {
8+
9+
10+
export DART=$(git rev-parse --show-toplevel)
11+
source "$DART"/build_templates/buildfunctions.sh
12+
13+
MODEL="none"
14+
EXTRA="$DART"/models/template/threed_model_mod.f90
15+
dev_test=1
16+
LOCATION="threed_sphere"
17+
TEST="gamma_dist"
18+
19+
serial_programs=(
20+
test_gamma_dist
21+
)
22+
23+
# quickbuild arguments
24+
arguments "$@"
25+
26+
# clean the directory
27+
\rm -f -- *.o *.mod Makefile .cppdefs
28+
29+
# build and run preprocess before making any other DART executables
30+
buildpreprocess
31+
32+
# build DART
33+
buildit
34+
35+
# clean up
36+
\rm -f -- *.o *.mod
37+
38+
}
39+
40+
main "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! DART software - Copyright UCAR. This open source software is provided
2+
! by UCAR, "as is", without charge, subject to all terms of use at
3+
! http://www.image.ucar.edu/DAReS/DART/DART_download
4+
5+
program test_normal_distribution
6+
7+
use utilities_mod, only : initialize_utilities, finalize_utilities
8+
use normal_distribution_mod, only : test_normal
9+
10+
implicit none
11+
12+
call initialize_utilities()
13+
call test_normal()
14+
call finalize_utilities()
15+
16+
end program test_normal_distribution
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
&utilities_nml
2+
module_details = .false.
3+
/
4+
5+
&preprocess_nml
6+
input_obs_qty_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
7+
output_obs_qty_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
8+
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
9+
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
10+
obs_type_files = '../../../observations/forward_operators/obs_def_gps_mod.f90'
11+
quantity_files = '../../../assimilation_code/modules/observations/default_quantities_mod.f90'
12+
/
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
# DART software - Copyright UCAR. This open source software is provided
4+
# by UCAR, "as is", without charge, subject to all terms of use at
5+
# http://www.image.ucar.edu/DAReS/DART/DART_download
6+
7+
main() {
8+
9+
10+
export DART=$(git rev-parse --show-toplevel)
11+
source "$DART"/build_templates/buildfunctions.sh
12+
13+
MODEL="none"
14+
EXTRA="$DART"/models/template/threed_model_mod.f90
15+
dev_test=1
16+
LOCATION="threed_sphere"
17+
TEST="normal_dist"
18+
19+
serial_programs=(
20+
test_normal_dist
21+
)
22+
23+
# quickbuild arguments
24+
arguments "$@"
25+
26+
# clean the directory
27+
\rm -f -- *.o *.mod Makefile .cppdefs
28+
29+
# build and run preprocess before making any other DART executables
30+
buildpreprocess
31+
32+
# build DART
33+
buildit
34+
35+
# clean up
36+
\rm -f -- *.o *.mod
37+
38+
}
39+
40+
main "$@"

0 commit comments

Comments
 (0)