Skip to content

Commit

Permalink
Merge pull request #1486 from yyoon4/feature/mogrepsg-bc
Browse files Browse the repository at this point in the history
Update codes for MOGREPS-G precipitation bias-correction
  • Loading branch information
emkemp authored Feb 1, 2024
2 parents 94fe7c3 + 82f8083 commit a2cba2a
Show file tree
Hide file tree
Showing 6 changed files with 676 additions and 258 deletions.
21 changes: 16 additions & 5 deletions lis/configs/lis.config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ endif::devonly[]
Land surface model: Noah.2.7.1
....


`Number of subLSMs:` specifies the number of sub-level LSMs
or specialized models that may interface with other LSMs in LIS.
Entry here can be set to 1 with having a surface model type
Expand Down Expand Up @@ -3062,8 +3061,8 @@ whether the observation error standard deviation is to be scaled using model
and observation standard deviation.

`SMAP(NASA) model CDF file:` specifies the name of the model CDF file
(observations will be scaled into this climatology).
Note: Soil moisture CDF grouped (stratified) by land cover or precipitation climatology or both simultaneously also can be used here.
(observations will be scaled into this climatology).
Note: Soil moisture CDF grouped (stratified) by land cover or precipitation climatology or both simultaneously also can be used here.

`SMAP(NASA) observation CDF file:` specifies the name of the observation
CDF file.
Expand Down Expand Up @@ -3142,7 +3141,6 @@ SMAP(NRT) soil moisture number of bins in the CDF:
SMAP(NRT) CDF read option:
....


[[sssec_cdftransfersmda,Transfering stratified CDFs from one domain to another]]
==== Transfering stratified CDFs from one domain to another

Expand Down Expand Up @@ -6650,11 +6648,25 @@ run mode. Currently, only the forecast mode is supported.
`MOGREPS-G forecast number of ensemble members:` specifies the number of ensembles
of the MOGREPS-G forecast forcing data.
`Apply MOGREPS-G precipitation bias correction:` specifies whether to enable the precipitation
bias correction. Acceptable values are:
|====
|Value | Description
|0 | Do not enable
|1 | Enable
|====
`MOGREPS-G model CDF file:` specifies the location of the MOGREPS-G model CDF file.
.Example _lis.config_ entry
....
MOGREPS-G forecast forcing directory: ./MOGREPS-G
MOGREPS-G forecast run mode: forecast # forecast | analysis
MOGREPS-G forecast number of ensemble members: 18
Apply MOGREPS-G precipitation bias correction: 1 #enter 1 - use; or 0
MOGREPS-G model CDF file: ./input/cdf/MOGREPS_G_leadtime_cdf_10km.nc
....
[[ssec_lsm,Land surface models]]
Expand Down Expand Up @@ -9659,7 +9671,6 @@ AWRAL600 initial sd: 0.5 0.5
AWRAL600 initial mleaf: 0.67 0.2
....
[[ssec_sublsm,Sublevel land surface models]]
=== Sublevel land surface models
Expand Down
212 changes: 212 additions & 0 deletions lis/metforcing/mogreps_g/get_cdf_params.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
!-----------------------BEGIN NOTICE -- DO NOT EDIT-----------------------
! NASA Goddard Space Flight Center
! Land Information System Framework (LISF)
! Version 7.3
!
! Copyright (c) 2020 United States Government as represented by the
! Administrator of the National Aeronautics and Space Administration.
! All Rights Reserved.
!-------------------------END NOTICE -- DO NOT EDIT-----------------------
#include "LIS_misc.h"
!BOP
!
! !ROUTINE: get_cdf_params
! \label{get_cdf_params}
!
! !REVISION HISTORY:
! 01 May 2023: Yeosang Yoon, initial code
!
! !INTERFACE:
subroutine get_cdf_params (n, fname, month, param_a, param_b, mean, std)

!USES:
use LIS_coreMod
use LIS_logMod
#if (defined USE_NETCDF3 || defined USE_NETCDF4)
use netcdf
#endif

implicit none

!ARGUMENTS:
integer, intent(in) :: n
character(len=*), intent(in) :: fname
integer, intent(in) :: month ! month of year (1-12)

!EOP
logical :: file_exists
integer :: ftn
integer :: param_a_id, param_b_id, mean_id, &
std_id, ngrid_id, nlead_id
integer :: ngrid, nlead
integer :: r, c, nc, c1, r1, gid, l
real, allocatable :: param_hires(:,:)
real, allocatable :: param_hires_2d(:,:)
real :: param_a(LIS_rc%ngrid(n),8) !8:lead time
real :: param_b(LIS_rc%ngrid(n),8)
real :: mean(LIS_rc%ngrid(n),8)
real :: std(LIS_rc%ngrid(n),8)

! check file
inquire(file=fname, exist=file_exists)
if (.not. file_exists) then
write(LIS_logunit,*) '[ERR] ', trim(fname) // ' does not exist'
call LIS_endrun()
endif

write(LIS_logunit,*) &
'[INFO] Getting MOGREPS-G bias correction parameters ', trim(fname)
call LIS_verify(nf90_open(path=trim(fname), mode=NF90_NOWRITE, &
ncid=ftn), 'nf90_open failed in get_cdf_params')

call LIS_verify(nf90_inq_dimid(ftn, "ngrid", ngrid_id), &
'nf90_inq_dimid failed for ngrid in get_cdf_params')
call LIS_verify(nf90_inquire_dimension(ftn, ngrid_id, len=ngrid),&
'nf90_inquire_dimension failed for ngrid in get_cdf_params')

if (LIS_rc%gnc(n)*LIS_rc%gnr(n) .ne. ngrid) then
write(LIS_logunit,*) '[ERR] The input dimensions of the '//trim(fname)
write(LIS_logunit,*) '(',ngrid,')'
write(LIS_logunit,*) &
'does not match the dimensions in the LIS parameter file'
write(LIS_logunit,*) '(',LIS_rc%gnc(n)*LIS_rc%gnr(n),')'
call LIS_endrun()
endif

call LIS_verify(nf90_inq_dimid(ftn, "lead_time", nlead_id), &
'nf90_inq_dimid failed for nlead in get_cdf_params')
call LIS_verify(nf90_inquire_dimension(ftn, nlead_id, len=nlead),&
'nf90_inquire_dimension failed for nlead in get_cdf_params')

allocate(param_hires(LIS_rc%gnc(n)*LIS_rc%gnr(n),nlead))
allocate(param_hires_2d(LIS_rc%gnc(n),LIS_rc%gnr(n)))

param_hires = -9999.0
param_hires_2d = -9999.0

! read param_a
call LIS_verify(nf90_inq_varid(ftn, 'cdf_param_a', param_a_id), &
'nf90_inq_varid failed for cdf_param_a in get_cdf_params')
call LIS_verify(nf90_get_var(ftn, param_a_id, param_hires, &
start=(/1,1,month/), count=(/ngrid,nlead,1/)), &
'nf90_get_var failed for cdf_param_a in get_cdf_params')

do l = 1, nlead
! 1D -> 2D
do r = 1, LIS_rc%gnr(n)
do c = 1, LIS_rc%gnc(n)
param_hires_2d(c,r) = param_hires(c+(r-1)*LIS_rc%gnc(n),l)
enddo
enddo

!subsets the data for each processor's domain
nc = (LIS_ewe_halo_ind(n,LIS_localPet+1)-LIS_ews_halo_ind(n,LIS_localPet+1))+1
do r = LIS_nss_halo_ind(n,LIS_localPet+1),LIS_nse_halo_ind(n,LIS_localPet+1)
do c = LIS_ews_halo_ind(n,LIS_localPet+1),LIS_ewe_halo_ind(n,LIS_localPet+1)
c1 = c - LIS_ews_halo_ind(n,LIS_localPet+1)+1
r1 = r - LIS_nss_halo_ind(n,LIS_localPet+1)+1
gid = LIS_domain(n)%gindex(c1,r1)
if (gid .ne. -1) then
param_a(gid,l) = param_hires_2d(c,r)
endif
enddo
enddo
enddo

! read param_b
call LIS_verify(nf90_inq_varid(ftn, 'cdf_param_b', param_b_id), &
'nf90_inq_varid failed for cdf_param_b in get_cdf_params')
call LIS_verify(nf90_get_var(ftn, param_b_id, param_hires, &
start=(/1,1,month/), count=(/ngrid,nlead,1/)),&
'nf90_get_var failed for cdf_param_b in get_cdf_params')

do l = 1, nlead
! 1D -> 2D
do r = 1, LIS_rc%gnr(n)
do c = 1,LIS_rc%gnc(n)
param_hires_2d(c,r) = param_hires(c+(r-1)*LIS_rc%gnc(n),l)
enddo
enddo

!subsets the data for each processor's domain
nc = (LIS_ewe_halo_ind(n,LIS_localPet+1)-LIS_ews_halo_ind(n,LIS_localPet+1))+1
do r = LIS_nss_halo_ind(n,LIS_localPet+1), LIS_nse_halo_ind(n,LIS_localPet+1)
do c = LIS_ews_halo_ind(n,LIS_localPet+1), LIS_ewe_halo_ind(n,LIS_localPet+1)
c1 = c - LIS_ews_halo_ind(n,LIS_localPet+1) + 1
r1 = r - LIS_nss_halo_ind(n,LIS_localPet+1) + 1
gid = LIS_domain(n)%gindex(c1,r1)
if (gid.ne.-1) then
param_b(gid,l) = param_hires_2d(c,r)
endif
enddo
enddo
enddo

! read mean
call LIS_verify(nf90_inq_varid(ftn, 'mean', mean_id), &
'nf90_inq_varid failed for mean in get_cdf_params')
call LIS_verify(nf90_get_var(ftn, mean_id, param_hires, &
start=(/1,1,month/), count=(/ngrid,nlead,1/)),&
'nf90_get_var failed for mean in get_cdf_params')

do l = 1, nlead
! 1D -> 2D
do r = 1, LIS_rc%gnr(n)
do c = 1, LIS_rc%gnc(n)
param_hires_2d(c,r) = param_hires(c+(r-1)*LIS_rc%gnc(n),l)
enddo
enddo

!subsets the data for each processor's domain
nc = (LIS_ewe_halo_ind(n,LIS_localPet+1)-LIS_ews_halo_ind(n,LIS_localPet+1))+1
do r = LIS_nss_halo_ind(n,LIS_localPet+1), LIS_nse_halo_ind(n,LIS_localPet+1)
do c = LIS_ews_halo_ind(n,LIS_localPet+1), LIS_ewe_halo_ind(n,LIS_localPet+1)
c1 = c - LIS_ews_halo_ind(n,LIS_localPet+1)+1
r1 = r - LIS_nss_halo_ind(n,LIS_localPet+1)+1
gid = LIS_domain(n)%gindex(c1,r1)
if (gid.ne.-1) then
mean(gid,l) = param_hires_2d(c,r)
endif
enddo
enddo
enddo

! read std
call LIS_verify(nf90_inq_varid(ftn, 'std', std_id), &
'nf90_inq_varid failed for std in get_cdf_params')
call LIS_verify(nf90_get_var(ftn, std_id, param_hires, &
start=(/1,1,month/), count=(/ngrid,nlead,1/)),&
'nf90_get_var failed for std in get_cdf_params')

do l = 1, nlead
! 1D -> 2D
do r = 1, LIS_rc%gnr(n)
do c = 1, LIS_rc%gnc(n)
param_hires_2d(c,r) =param_hires(c+(r-1)*LIS_rc%gnc(n),l)
enddo
enddo

!subsets the data for each processor's domain
nc = (LIS_ewe_halo_ind(n,LIS_localPet+1)-LIS_ews_halo_ind(n,LIS_localPet+1))+1
do r = LIS_nss_halo_ind(n,LIS_localPet+1), LIS_nse_halo_ind(n,LIS_localPet+1)
do c = LIS_ews_halo_ind(n,LIS_localPet+1), LIS_ewe_halo_ind(n,LIS_localPet+1)
c1 = c - LIS_ews_halo_ind(n,LIS_localPet+1) + 1
r1 = r - LIS_nss_halo_ind(n,LIS_localPet+1) + 1
gid = LIS_domain(n)%gindex(c1,r1)
if (gid.ne.-1) then
std(gid,l) = param_hires_2d(c,r)
endif
enddo
enddo
enddo

deallocate(param_hires)
deallocate(param_hires_2d)

call LIS_verify(nf90_close(ftn),'failed to close in get_cdf_params')

write(LIS_logunit,*) &
'[INFO] Done reading MOGREPS-G bias correction parameters data '

end subroutine get_cdf_params

Loading

0 comments on commit a2cba2a

Please sign in to comment.