Skip to content

Commit

Permalink
feature 1368 PCPCombine use zero accum (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe authored Jan 27, 2022
1 parent baacb56 commit 7d7283f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
16 changes: 16 additions & 0 deletions docs/Users_Guide/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8759,3 +8759,19 @@ METplus Configuration Glossary
:term:`ENSEMBLE_STAT_ENS_VLD_THRESH`.

| *Used by:* EnsembleStat
FCST_PCP_COMBINE_USE_ZERO_ACCUM
Only used if running PCPCombine wrapper with
:term:`FCST_PCP_COMBINE_METHOD` = SUBTRACT. If True, build a -subtract
command using the 0 accumulation as the 2nd input. If False (default),
instead build an -add command with a single input if the 2nd input is
a 0 accumulation.

| *Used by:* PCPCombine
OBS_PCP_COMBINE_USE_ZERO_ACCUM
Only used if running PCPCombine wrapper with
:term:`OBS_PCP_COMBINE_METHOD` = SUBTRACT.
See :term:`FCST_PCP_COMBINE_USE_ZERO_ACCUM` for more information.

| *Used by:* PCPCombine
2 changes: 2 additions & 0 deletions docs/Users_Guide/wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5130,6 +5130,8 @@ METplus Configuration
| :term:`PCP_COMBINE_CUSTOM_LOOP_LIST`
| :term:`FCST_PCP_COMBINE_LOOKBACK`
| :term:`OBS_PCP_COMBINE_LOOKBACK`
| :term:`FCST_PCP_COMBINE_USE_ZERO_ACCUM`
| :term:`OBS_PCP_COMBINE_USE_ZERO_ACCUM`
| :term:`FCST_PCP_COMBINE_EXTRA_NAMES` (optional)
| :term:`FCST_PCP_COMBINE_EXTRA_LEVELS` (optional)
| :term:`FCST_PCP_COMBINE_EXTRA_OUTPUT_NAMES` (optional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ def test_add_method_single_file(metplus_config):
assert cmd == expected_cmd

def test_subtract_method_zero_accum(metplus_config):
data_src = 'FCST'
input_name = 'stratiform_rainfall_amount'
input_level = '"(*,*)"'
in_dir = '/some/input/dir'
Expand Down Expand Up @@ -749,6 +748,8 @@ def test_subtract_method_zero_accum(metplus_config):
config.set('config', 'FCST_PCP_COMBINE_OUTPUT_ACCUM', '1H')
config.set('config', 'FCST_PCP_COMBINE_OUTPUT_NAME', input_name)


# NETCDF example should use zero accum, GRIB example should not (use -add)
expected_cmds_dict = {}
expected_cmds_dict['NETCDF'] = [
(f"-subtract "
Expand All @@ -774,6 +775,9 @@ def test_subtract_method_zero_accum(metplus_config):
if data_type == 'NETCDF':
config.set('config', 'FCST_PCP_COMBINE_INPUT_NAMES', input_name)
config.set('config', 'FCST_PCP_COMBINE_INPUT_LEVELS', input_level)
config.set('config', 'FCST_PCP_COMBINE_USE_ZERO_ACCUM', 'True')
else:
config.set('config', 'FCST_PCP_COMBINE_USE_ZERO_ACCUM', 'False')

wrapper = PCPCombineWrapper(config)
assert wrapper.isOK
Expand Down
13 changes: 10 additions & 3 deletions metplus/wrappers/pcp_combine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def set_fcst_or_obs_dict_items(self, d_type, c_dict):
f'{d_type}_PCP_COMBINE_EXTRA_OUTPUT_NAMES', '')
)

c_dict[f'{d_type}_USE_ZERO_ACCUM'] = self.config.getbool(
'config',
f'{d_type}_PCP_COMBINE_USE_ZERO_ACCUM', False
)

if run_method == 'DERIVE' and not c_dict[f'{d_type}_STAT_LIST']:
self.log_error('Statistic list is empty. Must set '
f'{d_type}_PCP_COMBINE_STAT_LIST if running '
Expand Down Expand Up @@ -364,9 +369,11 @@ def setup_subtract_method(self, time_info, accum, data_src):

# if data is GRIB and second lead is 0, then
# run PCPCombine in -add mode with just the first file
if lead2 == 0 and self.c_dict[data_src+'_INPUT_DATATYPE'] == 'GRIB':
self.logger.debug("Subtracted accumulation is 0 for GRIB data,"
" so running ADD mode on one file")
if lead2 == 0 and not self.c_dict[f'{data_src}_USE_ZERO_ACCUM']:
self.logger.info("Subtracted accumulation is 0,"
" so running ADD mode on one file."
"To use 0 accum data, set "
f"{data_src}_PCP_COMBINE_USE_ZERO_ACCUM = True")
self.args.clear()
self.args.append('-add')
field_info = self.get_field_string(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ FCST_PCP_COMBINE_INPUT_DATATYPE = GRIB
FCST_PCP_COMBINE_OUTPUT_ACCUM = 3H

FCST_PCP_COMBINE_OUTPUT_NAME = APCP_03

FCST_PCP_COMBINE_USE_ZERO_ACCUM = False

0 comments on commit 7d7283f

Please sign in to comment.