Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
51d9f09
Break up a long line.
samsrabin Jan 18, 2024
c763d66
use_cropcal_rx_cultivar_gdds not needed in CropPhenology().
samsrabin Jan 18, 2024
846f1cc
PlantCrop(): Be strict about PFT identification.
samsrabin Jan 18, 2024
5b056b7
PlantCrop: Get gdd20 before setting gddmaturity.
samsrabin Jan 18, 2024
08906bb
Correct a comment.
samsrabin Jan 18, 2024
6ef52cd
Remove a troubleshooting write to iulog.
samsrabin Jan 18, 2024
98f68e7
Optionally adjust rx maturity reqt based on recent climate.
samsrabin Jan 18, 2024
b73bcfd
Don't adapt rx cultivar gdd reqts if baseline gdd20 is ≤0.
samsrabin May 23, 2024
20f32c1
Ignore 'invalid' values in stream_fldFileName_gdd20_baseline on read.
samsrabin May 24, 2024
a7cd057
Add generate_gdd20_baseline tool.
samsrabin May 24, 2024
fd5f177
Format generate_gdd20_baseline.py with black.
samsrabin May 28, 2024
5eafae7
Add previous commit to .git-blame-ignore-revs.
samsrabin May 28, 2024
38d6888
Add testmods RxCropCals, RxCropCalsAdapt.
samsrabin May 29, 2024
317f77d
Add cropcals_rx namelist boolean.
samsrabin May 29, 2024
81380ef
CLMBuildNamelist: Fix logic and message for check of sowing window st…
samsrabin May 29, 2024
b195734
CLMBuildNamelist: Use &string_is_undef_or_empty() instead of comparin…
samsrabin May 29, 2024
4b18a5b
CLMBuildNamelist: Use &value_is_true() instead of comparing to '.true.'
samsrabin May 29, 2024
e76fbbc
CLMBuildNamelist: Update setup_logic_cropcal_streams() with cropcals_rx.
samsrabin May 29, 2024
0f729d8
Bugfix: cropcalStreamMod now handles cropcals_rx.
samsrabin May 29, 2024
74411ea
Update RxCropCals testmod to use cropcals_rx true.
samsrabin May 29, 2024
9d1f88d
Add RxCropCals and RxCropCalsAdapt tests to new suite crop_calendars.
samsrabin May 29, 2024
7e5257a
Add cropcals_rx_adapt option.
samsrabin May 29, 2024
5911cea
Move add_default() of model_year_align_cropcal to be with other year …
samsrabin May 31, 2024
ccc228c
Merge pull request #6 from samsrabin/scale-mat-reqs-pr1.1-nml
samsrabin May 31, 2024
d89cb9d
Split streams year params for swindows vs maturity reqts.
samsrabin May 31, 2024
eb27a2d
Explain hard-coding of 2000 when reading GDD20 baseline file.
samsrabin May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ d866510188d26d51bcd6d37239283db690af7e82
0dcd0a3c1abcaffe5529f8d79a6bc34734b195c7
e096358c832ab292ddfd22dd5878826c7c788968
475831f0fb0e31e97f630eac4e078c886558b61c
fd5f177131d63d39e79a13918390bdfb642d781e
# Ran SystemTests and python/ctsm through black python formatter
5364ad66eaceb55dde2d3d598fe4ce37ac83a93c
8056ae649c1b37f5e10aaaac79005d6e3a8b2380
Expand Down
123 changes: 95 additions & 28 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4172,52 +4172,119 @@ sub setup_logic_lai_streams {
sub setup_logic_cropcal_streams {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

# Set first and last stream years
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_first_cropcal',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_last_cropcal',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});

# Set align year, if first and last years are different
if ( $nl->get_value('stream_year_first_cropcal') !=
$nl->get_value('stream_year_last_cropcal') ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
'model_year_align_cropcal', 'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
}

# Set up other crop calendar parameters
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'cropcals_rx');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'cropcals_rx_adapt');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'generate_crop_gdds');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_mxmat');

# Option checks
my $generate_crop_gdds = $nl->get_value('generate_crop_gdds') ;
my $use_mxmat = $nl->get_value('use_mxmat') ;
# These can't both be true
my $cropcals_rx = $nl->get_value('cropcals_rx') ;
my $cropcals_rx_adapt = $nl->get_value('cropcals_rx_adapt') ;
if (&value_is_true($cropcals_rx) and &value_is_true($cropcals_rx_adapt)) {
$log->fatal_error("cropcals_rx and cropcals_rx_adapt may not both be true" );
}

# Add defaults if using prescribed crop calendars
if ( &value_is_true($cropcals_rx) or &value_is_true($cropcals_rx_adapt) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_fldFileName_swindow_start');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_fldFileName_swindow_end');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_fldfilename_cultivar_gdds');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_meshfile_cropcal');
if ( &value_is_true($cropcals_rx_adapt) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_fldFileName_gdd20_baseline');
}
}

# Add defaults if using any crop calendar input files
my $swindow_start_file = $nl->get_value('stream_fldFileName_swindow_start') ;
my $swindow_end_file = $nl->get_value('stream_fldFileName_swindow_end') ;
my $gdd_file = $nl->get_value('stream_fldFileName_cultivar_gdds') ;
my $gdd20_baseline_file = $nl->get_value('stream_fldFileName_gdd20_baseline') ;
my $mesh_file = $nl->get_value('stream_meshfile_cropcal') ;
if ( ($swindow_start_file eq '' and $swindow_start_file ne '') or ($swindow_start_file ne '' and $swindow_start_file eq '') ) {
$log->fatal_error("When specifying sowing window dates, you must provide both swindow_start_file and swindow_end_file. To specify exact sowing dates, use the same file." );
if ( !&string_is_undef_or_empty($swindow_start_file) or !&string_is_undef_or_empty($swindow_end_file) or !&string_is_undef_or_empty($gdd_file) or !&string_is_undef_or_empty($gdd20_baseline_file) or !&string_is_undef_or_empty($mesh_file)) {

# User gave an input file without specifying cropcals_rx or cropcals_rx_adapt = .true.
# Requiring this means nothing to the code, but helps namelist make more sense
if ( !&value_is_true($cropcals_rx) and !&value_is_true($cropcals_rx_adapt) ){
$log->fatal_error("If providing any crop calendar input file(s), cropcals_rx or cropcals_rx_adapt must be true" );
}

# User set cropcals_rx_adapt to true but set stream_fldFileName_gdd20_baseline to empty
if ( &value_is_true($cropcals_rx_adapt) and &string_is_undef_or_empty($gdd20_baseline_file) ) {
$log->fatal_error("If cropcals_rx_adapt is true, stream_fldFileName_gdd20_baseline must be provided" );
}

# cropcals_rx_adapt is false but user provided stream_fldFileName_gdd20_baseline
if ( !&value_is_true($cropcals_rx_adapt) and !&string_is_undef_or_empty($gdd20_baseline_file) ) {
$log->fatal_error("If stream_fldFileName_gdd20_baseline provided, cropcals_rx_adapt must be true" );
}

# User provided an input file but set mesh file to empty
if ( &string_is_undef_or_empty($mesh_file) ) {
$log->fatal_error("If providing any crop calendar input file(s), you must provide stream_meshfile_cropcal" );
}

# Set stream years
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_first_cropcal_swindows',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_last_cropcal_swindows',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'model_year_align_cropcal_swindows',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_first_cropcal_cultivar_gdds',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_last_cropcal_cultivar_gdds',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'model_year_align_cropcal_cultivar_gdds',
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});

# Do not allow maturity requirements to change over time if stream_fldFileName_gdd20_baseline is provided. That would be nonsensical.
if ( $nl->get_value('stream_year_first_cropcal_cultivar_gdds') !=
$nl->get_value('stream_year_last_cropcal_cultivar_gdds')
and !&string_is_undef_or_empty($gdd20_baseline_file) ) {
$log->fatal_error("If cropcals_rx_adapt is true (i.e., stream_fldFileName_gdd20_baseline is provided), baseline maturity requirements are allowed to vary over time (i.e., stream_year_first_cropcal_cultivar_gdds and stream_year_last_cropcal_cultivar_gdds must be the same)." );
}
}
if ( $generate_crop_gdds eq '.true.' ) {
if ( $use_mxmat eq '.true.' ) {

# If running with prescribed crop calendars, certain files must be provided
my $generate_crop_gdds = $nl->get_value('generate_crop_gdds') ;
if ( &value_is_true($cropcals_rx) or &value_is_true($cropcals_rx_adapt) ) {
if ( &string_is_undef_or_empty($swindow_start_file) or &string_is_undef_or_empty($swindow_end_file) ) {
$log->fatal_error("If cropcals_rx or cropcals_rx_adapt is true, sowing window start and end files must be provided. To specify exact sowing dates, use the same file." );
}
if ( &string_is_undef_or_empty($gdd_file) and (! &value_is_true($generate_crop_gdds)) ){
$log->fatal_error("If cropcals_rx or cropcals_rx_adapt is true and generate_crop_gdds is false, maturity requirement file stream_fldFileName_cultivar_gdds must be provided" );
}
}

# Option checks
if ( &string_is_undef_or_empty($gdd_file) and ! &string_is_undef_or_empty($gdd20_baseline_file) ) {
$log->fatal_error("If not providing stream_fldFileName_cultivar_gdds, don't provide stream_fldFileName_gdd20_baseline");
}
if ( &value_is_true($generate_crop_gdds) ) {
my $use_mxmat = $nl->get_value('use_mxmat') ;
if ( &value_is_true($use_mxmat) ) {
$log->fatal_error("If generate_crop_gdds is true, you must also set use_mxmat to false" );
}
if ( $swindow_start_file eq '' or $swindow_end_file eq '' ) {
if ( &string_is_undef_or_empty($swindow_start_file) or &string_is_undef_or_empty($swindow_end_file) ) {
$log->fatal_error("If generate_crop_gdds is true, you must specify stream_fldFileName_swindow_start and stream_fldFileName_swindow_end")
}
if ( $swindow_start_file ne $swindow_end_file ) {
$log->fatal_error("If generate_crop_gdds is true, you must specify exact sowing dates by setting stream_fldFileName_swindow_start and stream_fldFileName_swindow_end to the same file")
}
if ( $gdd_file ne '' ) {
if ( ! &string_is_undef_or_empty($gdd_file) ) {
$log->fatal_error("If generate_crop_gdds is true, do not specify stream_fldFileName_cultivar_gdds")
}
}
if ( $mesh_file eq '' and ( $swindow_start_file ne '' or $gdd_file ne '' ) ) {
$log->fatal_error("If prescribing crop sowing dates and/or maturity requirements, you must specify stream_meshfile_cropcal")
if ( ! &string_is_undef_or_empty($gdd20_baseline_file) ) {
$log->fatal_error("If generate_crop_gdds is true, do not specify stream_fldFileName_gdd20_baseline")
}
}
}

Expand Down
24 changes: 20 additions & 4 deletions bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1686,10 +1686,26 @@ lnd/clm2/surfdata_esmf/NEON/surfdata_1x1_NEON_TOOL_hist_78pfts_CMIP6_simyr2000_c
<lai_mapalgo hgrid="1x1_asphaltjungleNJ" >nn</lai_mapalgo>
<lai_mapalgo hgrid="5x5_amazon" >nn</lai_mapalgo>

<!-- crop calendar streams namelist defaults -->
<stream_year_first_cropcal >1850</stream_year_first_cropcal>
<stream_year_last_cropcal >2100</stream_year_last_cropcal>
<model_year_align_cropcal >1850</model_year_align_cropcal>
<!-- crop calendars: default settings -->
<cropcals_rx>.false.</cropcals_rx>
<cropcals_rx_adapt>.false.</cropcals_rx_adapt>
<stream_year_first_cropcal_swindows >2000</stream_year_first_cropcal_swindows>
<stream_year_last_cropcal_swindows >2000</stream_year_last_cropcal_swindows>
<model_year_align_cropcal_swindows >2000</model_year_align_cropcal_swindows>
<stream_year_first_cropcal_cultivar_gdds >2000</stream_year_first_cropcal_cultivar_gdds>
<stream_year_last_cropcal_cultivar_gdds >2000</stream_year_last_cropcal_cultivar_gdds>
<model_year_align_cropcal_cultivar_gdds >2000</model_year_align_cropcal_cultivar_gdds>

<!-- crop calendars: default input files -->
<stream_fldFileName_swindow_start cropcals_rx=".true.">lnd/clm2/cropdata/calendars/processed/swindow_starts_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc</stream_fldFileName_swindow_start>
<stream_fldFileName_swindow_end cropcals_rx=".true.">lnd/clm2/cropdata/calendars/processed/swindow_ends_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc</stream_fldFileName_swindow_end>
<stream_fldfilename_cultivar_gdds cropcals_rx=".true.">lnd/clm2/cropdata/calendars/processed/gdds_20230829_161011.nc</stream_fldfilename_cultivar_gdds>
<stream_meshfile_cropcal cropcals_rx=".true.">share/meshes/360x720_120830_ESMFmesh_c20210507_cdf5.nc</stream_meshfile_cropcal>
<stream_fldFileName_swindow_start cropcals_rx_adapt=".true.">lnd/clm2/cropdata/calendars/processed/swindow_starts_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc</stream_fldFileName_swindow_start>
<stream_fldFileName_swindow_end cropcals_rx_adapt=".true.">lnd/clm2/cropdata/calendars/processed/swindow_ends_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc</stream_fldFileName_swindow_end>
<stream_fldfilename_cultivar_gdds cropcals_rx_adapt=".true.">lnd/clm2/cropdata/calendars/processed/gdds_20230829_161011.nc</stream_fldfilename_cultivar_gdds>
<stream_fldFileName_gdd20_baseline cropcals_rx_adapt=".true.">lnd/clm2/testdata/gdd20baseline.tmp_dontupload.nc</stream_fldFileName_gdd20_baseline>
<stream_meshfile_cropcal cropcals_rx_adapt=".true.">share/meshes/360x720_120830_ESMFmesh_c20210507_cdf5.nc</stream_meshfile_cropcal>

<!-- lightning streams namelist defaults -->

Expand Down
42 changes: 36 additions & 6 deletions bld/namelist_files/namelist_definition_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1773,19 +1773,44 @@ Mapping method from LAI input file to the model resolution
<!-- ======================================================================================== -->

<!-- Crop calendars -->
<entry id="stream_year_first_cropcal" type="integer" category="datasets"
<entry id="cropcals_rx" type="logical" category="datasets"
group="cropcal_streams" valid_values="" >
First year to loop over for crop calendar data
Flag to enable prescribed crop calendars (sowing window dates and maturity requirement)
</entry>

<entry id="stream_year_last_cropcal" type="integer" category="datasets"
<entry id="cropcals_rx_adapt" type="logical" category="datasets"
group="cropcal_streams" valid_values="" >
Last year to loop over for crop calendar data
Flag to enable prescribed crop calendars (sowing window dates and maturity requirement), with maturity requirement adaptive based on recent climate
</entry>

<entry id="model_year_align_cropcal" type="integer" category="datasets"
<entry id="stream_year_first_cropcal_swindows" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
Simulation year that aligns with stream_year_first_cropcal value
First year to loop over for crop sowing windows
</entry>

<entry id="stream_year_last_cropcal_swindows" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
Last year to loop over for crop sowing windows
</entry>

<entry id="model_year_align_cropcal_swindows" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
Simulation year that aligns with stream_year_first_cropcal_swindows value
</entry>

<entry id="stream_year_first_cropcal_cultivar_gdds" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
First year to loop over for crop maturity requirements
</entry>

<entry id="stream_year_last_cropcal_cultivar_gdds" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
Last year to loop over for crop maturity requirements
</entry>

<entry id="model_year_align_cropcal_cultivar_gdds" type="integer" category="datasets"
group="cropcal_streams" valid_values="" >
Simulation year that aligns with stream_year_first_cropcal_cultivar_gdds value
</entry>

<entry id="allow_invalid_swindow_inputs" type="logical" category="datasets"
Expand All @@ -1808,6 +1833,11 @@ Filename of input stream data for date (day of year) of end of sowing window. Ce
Filename of input stream data for cultivar growing degree-day targets
</entry>

<entry id="stream_fldFileName_gdd20_baseline" type="char*256(30)" category="datasets"
input_pathname="abs" group="cropcal_streams" valid_values="" >
Filename of input stream data for baseline GDD20 values
</entry>

<entry id="stream_meshfile_cropcal" type="char*256" category="datasets"
input_pathname="abs" group="cropcal_streams" valid_values="" >
Filename of input stream data for crop calendar inputs
Expand Down
6 changes: 3 additions & 3 deletions cime_config/SystemTests/rxcropmaturity.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ def _modify_user_nl_allruns(self):
"stream_meshfile_cropcal = '{}'".format(self._case.get_value("LND_DOMAIN_MESH")),
"stream_fldFileName_swindow_start = '{}'".format(self._sdatefile),
"stream_fldFileName_swindow_end = '{}'".format(self._sdatefile),
"stream_year_first_cropcal = 2000",
"stream_year_last_cropcal = 2000",
"model_year_align_cropcal = 2000",
"stream_year_first_cropcal_swindows = 2000",
"stream_year_last_cropcal_swindows = 2000",
"model_year_align_cropcal_swindows = 2000",
" ",
"! (h1) Annual outputs on sowing or harvest axis",
"hist_fincl2 = 'GRAINC_TO_FOOD_PERHARV', 'GRAINC_TO_FOOD_ANN', 'SDATES', 'SDATES_PERHARV', 'SYEARS_PERHARV', 'HDATES', 'GDDHARV_PERHARV', 'GDDACCUM_PERHARV', 'HUI_PERHARV', 'SOWING_REASON_PERHARV', 'HARVEST_REASON_PERHARV'",
Expand Down
18 changes: 18 additions & 0 deletions cime_config/testdefs/testlist_clm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3719,5 +3719,23 @@
</options>
</test>

<test name="SMS_P128x1_Lm25" grid="f10_f10_mg37" compset="IHistClm60BgcCrop" testmods="clm/RxCropCals">
<machines>
<machine name="derecho" compiler="intel" category="crop_calendars"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
</options>
</test>

<test name="ERS_P128x1_Lm25" grid="f10_f10_mg37" compset="IHistClm60BgcCrop" testmods="clm/RxCropCalsAdapt">
<machines>
<machine name="derecho" compiler="intel" category="crop_calendars"/>
</machines>
<options>
<option name="wallclock">01:00:00</option>
</options>
</test>


</testlist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../crop
2 changes: 2 additions & 0 deletions cime_config/testdefs/testmods_dirs/clm/RxCropCals/user_nl_clm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

cropcals_rx = .true.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../RxCropCals
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

cropcals_rx = .false.
cropcals_rx_adapt = .true.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
stream_fldFileName_swindow_start = '$DIN_LOC_ROOT/lnd/clm2/cropdata/calendars/processed/swindow_starts_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc'
stream_fldFileName_swindow_end = '$DIN_LOC_ROOT/lnd/clm2/cropdata/calendars/processed/swindow_ends_ggcmi_crop_calendar_phase3_v1.01.2000-2000.20231005_145103.nc'
stream_meshfile_cropcal = '$DIN_LOC_ROOT/share/meshes/360x720_120830_ESMFmesh_c20210507_cdf5.nc'
stream_year_first_cropcal = 2000
stream_year_last_cropcal = 2000
stream_year_first_cropcal_swindows = 2000
stream_year_last_cropcal_swindows = 2000
Loading