Skip to content

Commit

Permalink
feat: force standard gamma and beta in distribution in qceff table read
Browse files Browse the repository at this point in the history
issues #717 #786

Added developer test to check forced values are set correctly
Required changes to run_all.sh for qceff tests to deal with input.nml
  • Loading branch information
hkershaw-brown committed Jan 7, 2025
1 parent 538d238 commit e0fb360
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ test_normal_dist
test_beta_dist
test_kde_dist
test_window
test_force_bounds

# Directories to NOT IGNORE ... same as executable names
# as far as I know, these must be listed after the executables
Expand Down
30 changes: 30 additions & 0 deletions assimilation_code/modules/assimilation/algorithm_info_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,19 @@ subroutine read_qceff_table(qceff_table_filename)
case ('BOUNDED_NORMAL_RH_DISTRIBUTION')
qceff_table_data(row)%probit_inflation%dist_type = BOUNDED_NORMAL_RH_DISTRIBUTION
case ('GAMMA_DISTRIBUTION')
! Force standard Gamma distribution
qceff_table_data(row)%probit_inflation%dist_type = GAMMA_DISTRIBUTION
qceff_table_data(row)%probit_inflation%bounded_above = .false.
qceff_table_data(row)%probit_inflation%bounded_below = .true.
qceff_table_data(row)%probit_inflation%upper_bound = MISSING_R8
qceff_table_data(row)%probit_inflation%lower_bound = 0.0_r8
case ('BETA_DISTRIBUTION')
! Force standard Beta distribution
qceff_table_data(row)%probit_inflation%dist_type = BETA_DISTRIBUTION
qceff_table_data(row)%probit_inflation%bounded_above = .true.
qceff_table_data(row)%probit_inflation%bounded_below = .true.
qceff_table_data(row)%probit_inflation%upper_bound = 1.0_r8
qceff_table_data(row)%probit_inflation%lower_bound = 0.0_r8
case ('LOG_NORMAL_DISTRIBUTION')
qceff_table_data(row)%probit_inflation%dist_type = LOG_NORMAL_DISTRIBUTION
case ('UNIFORM_DISTRIBUTION')
Expand All @@ -242,9 +252,19 @@ subroutine read_qceff_table(qceff_table_filename)
case ('BOUNDED_NORMAL_RH_DISTRIBUTION')
qceff_table_data(row)%probit_state%dist_type = BOUNDED_NORMAL_RH_DISTRIBUTION
case ('GAMMA_DISTRIBUTION')
! Force standard Gamma distribution
qceff_table_data(row)%probit_state%dist_type = GAMMA_DISTRIBUTION
qceff_table_data(row)%probit_state%bounded_above = .false.
qceff_table_data(row)%probit_state%bounded_below = .true.
qceff_table_data(row)%probit_state%upper_bound = MISSING_R8
qceff_table_data(row)%probit_state%lower_bound = 0.0_r8
case ('BETA_DISTRIBUTION')
! Force standard Beta distribution
qceff_table_data(row)%probit_state%dist_type = BETA_DISTRIBUTION
qceff_table_data(row)%probit_state%bounded_above = .true.
qceff_table_data(row)%probit_state%bounded_below = .true.
qceff_table_data(row)%probit_state%upper_bound = 1.0_r8
qceff_table_data(row)%probit_state%lower_bound = 0.0_r8
case ('LOG_NORMAL_DISTRIBUTION')
qceff_table_data(row)%probit_state%dist_type = LOG_NORMAL_DISTRIBUTION
case ('UNIFORM_DISTRIBUTION')
Expand All @@ -266,9 +286,19 @@ subroutine read_qceff_table(qceff_table_filename)
case ('BOUNDED_NORMAL_RH_DISTRIBUTION')
qceff_table_data(row)%probit_extended_state%dist_type = BOUNDED_NORMAL_RH_DISTRIBUTION
case ('GAMMA_DISTRIBUTION')
! Force standard Gamma distribution
qceff_table_data(row)%probit_extended_state%dist_type = GAMMA_DISTRIBUTION
qceff_table_data(row)%probit_extended_state%bounded_above = .false.
qceff_table_data(row)%probit_extended_state%bounded_below = .true.
qceff_table_data(row)%probit_extended_state%upper_bound = MISSING_R8
qceff_table_data(row)%probit_extended_state%lower_bound = 0.0_r8
case ('BETA_DISTRIBUTION')
! Force standard Beta distribution
qceff_table_data(row)%probit_extended_state%dist_type = BETA_DISTRIBUTION
qceff_table_data(row)%probit_extended_state%bounded_above = .true.
qceff_table_data(row)%probit_extended_state%bounded_below = .true.
qceff_table_data(row)%probit_extended_state%upper_bound = 1.0_r8
qceff_table_data(row)%probit_extended_state%lower_bound = 0.0_r8
case ('LOG_NORMAL_DISTRIBUTION')
qceff_table_data(row)%probit_extended_state%dist_type = LOG_NORMAL_DISTRIBUTION
case ('UNIFORM_DISTRIBUTION')
Expand Down
95 changes: 95 additions & 0 deletions developer_tests/qceff/test_force_bounds.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download

program test_force_bounds

use algorithm_info_mod, only : init_algorithm_info_mod, end_algorithm_info_mod, probit_dist_info
use distribution_params_mod, only : GAMMA_DISTRIBUTION, BETA_DISTRIBUTION, NORMAL_DISTRIBUTION
use utilities_mod, only : initialize_utilities, finalize_utilities
use obs_kind_mod, only : QTY_AQUIFER_WATER, QTY_AMMONIUM_SULPHATE
use types_mod, only : r8, MISSING_R8

use test

implicit none

logical :: is_state, is_inflation
logical :: bounded_below, bounded_above
real(r8) :: lower_bound, upper_bound
integer :: dist_type


call initialize_utilities('test_table_read')

call init_algorithm_info_mod()

! QTY1
! inflation GAMMA
call probit_dist_info(QTY_AQUIFER_WATER, .false., .true., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == GAMMA_DISTRIBUTION)
call ok(bounded_below)
call ok(.not. bounded_above)
call ok(lower_bound == 0.0_r8)
call ok(upper_bound == MISSING_R8)

! state BETA
call probit_dist_info(QTY_AQUIFER_WATER, .true., .false., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == BETA_DISTRIBUTION)
call ok(bounded_below)
call ok(bounded_above)
call ok(lower_bound == 0.0_r8)
call ok(upper_bound == 1.0_r8)

! extended state NORMAL
call probit_dist_info(QTY_AQUIFER_WATER, .false., .false., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == NORMAL_DISTRIBUTION)
call ok(.not. bounded_below)
call ok(.not. bounded_above)
call ok(lower_bound == MISSING_R8)
call ok(upper_bound == MISSING_R8)


! QTY2
! inflation BETA
call probit_dist_info(QTY_AMMONIUM_SULPHATE , .false., .true., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == BETA_DISTRIBUTION)
call ok(bounded_below)
call ok(bounded_above)
call ok(lower_bound == 0.0_r8)
call ok(upper_bound == 1.0_r8)

! state GAMMA
call probit_dist_info(QTY_AMMONIUM_SULPHATE , .true., .false., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == GAMMA_DISTRIBUTION)
call ok(bounded_below)
call ok(.not. bounded_above)
call ok(lower_bound == 0.0_r8)
call ok(upper_bound == MISSING_R8)

! extended state BETA
call probit_dist_info(QTY_AMMONIUM_SULPHATE , .false., .false., dist_type, &
bounded_below, bounded_above, lower_bound, upper_bound)

call ok(dist_type == BETA_DISTRIBUTION)
call ok(bounded_below)
call ok(bounded_above)
call ok(lower_bound == 0.0_r8)
call ok(upper_bound == 1.0_r8)


call end_algorithm_info_mod()

call finalize_utilities()

end program test_force_bounds
4 changes: 4 additions & 0 deletions developer_tests/qceff/work/input.nml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
&algorithm_info_nml
qceff_table_filename = 'qcf_force_beta_gamma.csv'
/

&utilities_nml
TERMLEVEL = 1,
module_details = .false.
Expand Down
31 changes: 31 additions & 0 deletions developer_tests/qceff/work/input.nml.no_alg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
&utilities_nml
TERMLEVEL = 1,
module_details = .false.
logfilename = 'dart_log.out'
/

# pick a random set of inputs
&preprocess_nml
overwrite_output = .true.
input_obs_qty_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
output_obs_qty_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
obs_type_files = '../../../observations/forward_operators/obs_def_reanalysis_bufr_mod.f90',
'../../../observations/forward_operators/obs_def_radar_mod.f90',
'../../../observations/forward_operators/obs_def_metar_mod.f90',
'../../../observations/forward_operators/obs_def_dew_point_mod.f90',
'../../../observations/forward_operators/obs_def_rel_humidity_mod.f90',
'../../../observations/forward_operators/obs_def_altimeter_mod.f90',
'../../../observations/forward_operators/obs_def_gps_mod.f90',
'../../../observations/forward_operators/obs_def_vortex_mod.f90',
'../../../observations/forward_operators/obs_def_gts_mod.f90',
'../../../observations/forward_operators/obs_def_QuikSCAT_mod.f90'
quantity_files = '../../../assimilation_code/modules/observations/default_quantities_mod.f90',
/

&obs_kind_nml
/



4 changes: 4 additions & 0 deletions developer_tests/qceff/work/qcf_force_beta_gamma.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
QCEFF table version: 1,obs_error_info,,,,probit_inflation,,,,,probit_state,,,,,probit_extended_state,,,,,obs_inc_info,,,,
QTY_NAME,bounded_below,bounded_above,lower_bound,upper_bound,dist_type,bounded_below,bounded_above,lower_bound,upper_bound,dist_type,bounded_below,bounded_above,lower_bound,upper_bound,dist_type,bounded_below,bounded_above,lower_bound,upper_bound,filter_kind,bounded_below,bounded_above,lower_bound,upper_bound
QTY_AQUIFER_WATER,.false.,.false.,-888888,-888888,GAMMA_DISTRIBUTION,.false.,.true.,-888888,1234,BETA_DISTRIBUTION,.false.,.false.,-888888,-888888,NORMAL_DISTRIBUTION,.false.,.false.,-888888,-888888,EAKF,.false.,.false.,-888888,-888888
QTY_AMMONIUM_SULPHATE ,.false.,.false.,-888888,-888888,BETA_DISTRIBUTION,.false.,.true.,-888888,-145.6,GAMMA_DISTRIBUTION,.false.,.false.,45,44,BETA_DISTRIBUTION,.false.,.false.,-888888,-888888,EAKF,.false.,.false.,-888888,-888888
1 change: 1 addition & 0 deletions developer_tests/qceff/work/quickbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LOCATION="threed_sphere"

serial_programs=(
test_table_read
test_force_bounds
)

# quickbuild arguments
Expand Down
4 changes: 4 additions & 0 deletions developer_tests/qceff/work/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ else
fi
}

cp input.nml input.nml.bak
cp input.nml.no_alg input.nml

run_test ; should_pass "no table"

run_test qcf_table.txt ; should_pass "correct v1 table"
Expand Down Expand Up @@ -69,3 +72,4 @@ run_test all_bnrhf_qceff_table.csv ; should_pass "lower case QTY"

run_test qcf_table_lower_case_dist.txt; should_pass "lower case dist_type"

cp input.nml.bak input.nml

0 comments on commit e0fb360

Please sign in to comment.