Skip to content

Commit 6937725

Browse files
committed
Merge PR #403 (Generate monthly mass tables in benchmarks)
This merge brings PR #403 (Generate monthly mass tables in 1-yr benchmarks; Generate mass tables at beginning & end of 1-month benchmarks, by @yantosca) into the GCPy 1.7.0 development stream. PR #403 does the following: 1. Adds convenience function datetime64_to_str in gcpy/date_time.py 2. Modifies make_benchmark_mass_tables and create_benchmark_mass_tables to accept "ref_hdr_label" and "dev_hdr_label" arguments instead of a single "label" argument. These are used to pass date strings for Ref & Dev to be printed in the file header. 3. Generates mass tables at the start and end of each 1-month benchmark period. 4. Generates mass tables at the start of each month (as well as the ending date) of 1-year benchmarks. 5. Adds a newline character before printing "Ref species database", for more readable logfile output. Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
2 parents 8147125 + 8813e05 commit 6937725

File tree

7 files changed

+331
-65
lines changed

7 files changed

+331
-65
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2121
- Added constant `SPECIES_DATABASE` to `gcpy/benchmark/modules/benchmark_utils.py`
2222
- Added manual garbage collection in `create_regridders`, `compare_single_level`, and `compare_zonal_mean` functions.
2323
- Added helpful tips to the `gcpy/benchmark/benchmark.slurm.sh` script
24+
- Added function `datetime64_to_str` to `gcpy/date_time.py`
25+
- Added keyword arguments `ref_hdr_label` and `dev_hdr_label` to `make_benchmark_mass_tables`
2426

2527
### Changed
2628
- Modified criteria for terminating read of log files in `benchmark_scrape_gcclassic_timers.py` to avoid being spoofed by output that is attached by Intel VTune
@@ -51,6 +53,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5153
- Optimized the algorithm to generate `varlist` in `make_benchmark_conc_plots`. Also truncated datasets to only contain variables in `varlist`.
5254
- Updated `make_benchmark_aod_plots` to include column AOD plots for DSTbin1..DSTbin7 species
5355
- Updated `benchmark/modules/aod_species.py` with metadata for DSTbin1..DSTbin7 species
56+
- Updated `make_benchmark_mass_tables` and `create_global_mass_table` to allow Ref and Dev to have different dates if so chosen
57+
- Updated `run_benchmark.py` to generate mass tables at start and end of the simulation
58+
- Updated `run_1yr_fullchem_benchmark.py` and `run_1yr_tt_benchmark.py` to generate mass tables at the 1st day of each month from Jan 2019 thru Jan 2020
5459

5560
### Fixed
5661
- Fixed grid area calculation scripts of `grid_area` in `gcpy/gcpy/cstools.py`
@@ -66,6 +71,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6671
- Removed `.load()` statements from xarray Datasets to improve performance
6772
- Removed `paths:spcdb_dir` YAML tag in benchmark configuration files
6873
- Removed `st_Ox` from `benchmark_categories.yml`; this species is no longer used in TransportTracers simulations
74+
- Removed keyword argument `label` from `make_benchmark_mass_tables`
6975

7076
## [1.6.2] - 2025-06-12
7177
### Added

gcpy/benchmark/modules/benchmark_funcs.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ def create_global_mass_table(
377377
devstr,
378378
varlist,
379379
met_and_masks,
380-
label,
381380
spcdb_files,
381+
ref_hdr_label="",
382+
dev_hdr_label="",
382383
trop_only=False,
383384
outfilename="GlobalMass_TropStrat.txt",
384385
verbose=False,
@@ -405,13 +406,16 @@ def create_global_mass_table(
405406
met_and_masks: dict of xarray DataArray
406407
Dictionary containing the meterological variables and
407408
masks for the Ref and Dev datasets.
408-
label: str
409-
Label to go in the header string. Can be used to
410-
pass the month & year.
411409
spcdb_files : list
412410
Paths to species_database.yml files in Ref & Dev rundirs
413411
414412
Keyword Args (optional):
413+
ref_hdr_label : str
414+
Label for Ref, placed after refstr in the file header
415+
Default value: ""
416+
dev_hdr_label : str
417+
Label for Dev, placed after devstr in the file header
418+
Default value: ""
415419
trop_only: bool
416420
Set this switch to True if you wish to print totals
417421
only for the troposphere.
@@ -470,11 +474,11 @@ def create_global_mass_table(
470474
diff_list = []
471475

472476
# Title strings
473-
title1 = f"### Global mass (Gg) {label} (Trop + Strat)"
477+
title1 = f"### Global mass (Gg) (Trop + Strat)"
474478
if trop_only:
475-
title1 = f"### Global mass (Gg) {label} (Trop only)"
476-
title2 = f"### Ref = {refstr}"
477-
title3 = f"### Dev = {devstr}"
479+
title1 = f"### Global mass (Gg) (Trop only)"
480+
title2 = f"### Ref = {refstr} {ref_hdr_label}"
481+
title3 = f"### Dev = {devstr} {dev_hdr_label}"
478482

479483
# Write a placeholder to the file that denotes where
480484
# the list of species with differences will be written
@@ -3533,9 +3537,10 @@ def make_benchmark_mass_tables(
35333537
subdst=None,
35343538
overwrite=False,
35353539
verbose=False,
3536-
label="at end of simulation",
3540+
ref_hdr_label="",
3541+
dev_hdr_label="",
35373542
ref_met_extra=None,
3538-
dev_met_extra=None
3543+
dev_met_extra=None,
35393544
):
35403545
"""
35413546
Creates a text file containing global mass totals by species and
@@ -3582,6 +3587,12 @@ def make_benchmark_mass_tables(
35823587
verbose: bool
35833588
Set this flag to True to print extra informational output.
35843589
Default value: False.
3590+
ref_hdr_label : str
3591+
Label for Ref, placed after refstr in the file header
3592+
Default value: ""
3593+
dev_hdr_label : str
3594+
Label for Dev, placed after devstr in the file header
3595+
Default value: ""
35853596
ref_met_extra: str
35863597
Path to ref Met file containing area data for use with restart files
35873598
which do not contain the Area variable.
@@ -3749,15 +3760,19 @@ def make_benchmark_mass_tables(
37493760
devstr,
37503761
varlist,
37513762
met_and_masks,
3752-
label,
3763+
spcdb_files,
3764+
ref_hdr_label=ref_hdr_label,
3765+
dev_hdr_label=dev_hdr_label,
37533766
outfilename=mass_file,
37543767
verbose=verbose,
3755-
spcdb_files=spcdb_files,
37563768
)
37573769

37583770
# ==================================================================
37593771
# Create tropospheric mass table
37603772
# ==================================================================
3773+
3774+
# If a file name has not been specified, then use the "filename"
3775+
# keyword argument. Otherwise generate a default filename.
37613776
if subdst is not None:
37623777
mass_filename = f"GlobalMass_Trop_{subdst}.txt"
37633778
else:
@@ -3770,11 +3785,12 @@ def make_benchmark_mass_tables(
37703785
devstr,
37713786
varlist,
37723787
met_and_masks,
3773-
label,
3788+
spcdb_files,
3789+
ref_hdr_label=ref_hdr_label,
3790+
dev_hdr_label=dev_hdr_label,
37743791
outfilename=mass_file,
37753792
trop_only=True,
37763793
verbose=verbose,
3777-
spcdb_files=spcdb_files,
37783794
)
37793795

37803796
# -------------------------------------------

gcpy/benchmark/modules/benchmark_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def get_species_database_files(config, ref_model, dev_model):
743743
if not os.path.exists(ref_spcdb_file):
744744
msg = f"Could not find {ref_spcdb_file}!"
745745
raise FileNotFoundError(msg)
746-
msg = f"Ref species database: {ref_spcdb_file}"
746+
msg = f"\nRef species database: {ref_spcdb_file}"
747747
print(msg)
748748

749749
# Species database in the "Dev" simulation folder

gcpy/benchmark/modules/run_1yr_fullchem_benchmark.py

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from gcpy.benchmark.modules.ste_flux import make_benchmark_ste_table
6262
from gcpy.benchmark.modules.oh_metrics import make_benchmark_oh_metrics
6363
from gcpy.benchmark.modules.budget_ox import global_ox_budget
64+
from gcpy.date_time import datetime64_to_str
6465
#TODO: Peel out routines from benchmark_funcs.py into smaller
6566
# routines in the gcpy/benchmark/modules folder, such as these:
6667
from gcpy.benchmark.modules.benchmark_funcs import \
@@ -240,9 +241,13 @@ def run_benchmark(config, bmk_year_ref, bmk_year_dev):
240241
bmk_start_ref = np.datetime64(bmk_year_ref + "-01-01")
241242
bmk_end_ref = np.datetime64(f"{int(bmk_year_ref) + 1}-01-01")
242243
all_months_ref = np.arange(
243-
bmk_start_ref, bmk_end_ref, step=np.timedelta64(1, "M"), dtype="datetime64[M]"
244+
bmk_start_ref,
245+
bmk_end_ref,
246+
step=np.timedelta64(1, "M"),
247+
dtype="datetime64[M]"
244248
)
245249
all_months_gchp_ref = all_months_ref
250+
mass_table_dates_ref = np.append(all_months_ref, bmk_end_ref)
246251

247252
# Get subset of month datetimes and seconds per month for only benchmark months
248253
bmk_mons_ref = all_months_ref[bmk_mon_inds]
@@ -270,6 +275,7 @@ def run_benchmark(config, bmk_year_ref, bmk_year_dev):
270275
bmk_start_dev, bmk_end_dev, step=np.timedelta64(1, "M"), dtype="datetime64[M]"
271276
)
272277
all_months_gchp_dev = all_months_dev
278+
mass_table_dates_dev = np.append(all_months_dev, bmk_end_dev)
273279

274280
# Get subset of month datetimes and seconds per month for only benchmark months
275281
bmk_mons_dev = all_months_dev[bmk_mon_inds]
@@ -668,12 +674,22 @@ def gcc_vs_gcc_mass_table(mon):
668674
refpath = get_filepath(
669675
gcc_vs_gcc_refrstdir,
670676
"Restart",
671-
bmk_mons_ref[mon]
677+
mass_table_dates_ref[mon]
672678
)
673679
devpath = get_filepath(
674680
gcc_vs_gcc_devrstdir,
675681
"Restart",
676-
bmk_mons_dev[mon]
682+
mass_table_dates_dev[mon]
683+
)
684+
685+
# Date strings
686+
date_str_ref = datetime64_to_str(
687+
mass_table_dates_ref[mon],
688+
format_str="%Y%m%dT%H"
689+
)
690+
date_str_dev = datetime64_to_str(
691+
mass_table_dates_dev[mon],
692+
format_str="%Y%m%dT%H"
677693
)
678694

679695
# Create tables
@@ -684,17 +700,18 @@ def gcc_vs_gcc_mass_table(mon):
684700
gcc_vs_gcc_devstr,
685701
spcdb_files,
686702
dst=gcc_vs_gcc_tablesdir,
687-
subdst=bmk_mon_yr_strs_dev[mon],
688-
label=f"at 01{bmk_mon_yr_strs_dev[mon]}",
689703
overwrite=True,
704+
subdst=date_str_dev,
705+
ref_hdr_label=f"at {date_str_ref}",
706+
dev_hdr_label=f"at {date_str_dev}",
690707
)
691708

692709
# Create tables in parallel
693710
# Turn off parallelization if n_jobs==1
694711
if config["options"]["n_cores"] != 1:
695712
results = Parallel(n_jobs=config["options"]["n_cores"])(
696713
delayed(gcc_vs_gcc_mass_table)(mon)
697-
for mon in range(bmk_n_months)
714+
for mon in range(len(mass_table_dates_dev))
698715
)
699716
else:
700717
results = []
@@ -1320,12 +1337,12 @@ def gchp_vs_gcc_mass_table(mon):
13201337
refpath = get_filepath(
13211338
gchp_vs_gcc_refrstdir,
13221339
"Restart",
1323-
bmk_mons_dev[mon]
1340+
mass_table_dates_ref[mon]
13241341
)
13251342
devpath = get_filepath(
13261343
gchp_vs_gcc_devrstdir,
13271344
"Restart",
1328-
bmk_mons_dev[mon],
1345+
mass_table_dates_dev[mon],
13291346
is_gchp=True,
13301347
gchp_res=config["data"]["dev"]["gchp"]["resolution"],
13311348
gchp_is_pre_14_0=config["data"]["dev"]["gchp"][
@@ -1344,6 +1361,16 @@ def gchp_vs_gcc_mass_table(mon):
13441361
"is_pre_14.0"]
13451362
)
13461363

1364+
# Date strings
1365+
date_str_ref = datetime64_to_str(
1366+
mass_table_dates_ref[mon],
1367+
format_str="%Y%m%dT%H"
1368+
)
1369+
date_str_dev = datetime64_to_str(
1370+
mass_table_dates_dev[mon],
1371+
format_str="%Y%m%dT%H"
1372+
)
1373+
13471374
# Create tables
13481375
make_benchmark_mass_tables(
13491376
refpath,
@@ -1352,9 +1379,10 @@ def gchp_vs_gcc_mass_table(mon):
13521379
gchp_vs_gcc_devstr,
13531380
spcdb_files,
13541381
dst=gchp_vs_gcc_tablesdir,
1355-
subdst=bmk_mon_yr_strs_dev[mon],
1356-
label=f"at 01{bmk_mon_yr_strs_dev[mon]}",
1357-
overwrite=True,
1382+
overwrite=True,
1383+
subdst=date_str_dev,
1384+
ref_hdr_label=f"at {date_str_ref}",
1385+
dev_hdr_label=f"at {date_str_dev}",
13581386
dev_met_extra=devareapath
13591387
)
13601388

@@ -1363,11 +1391,11 @@ def gchp_vs_gcc_mass_table(mon):
13631391
if config["options"]["n_cores"] != 1:
13641392
results = Parallel(n_jobs=config["options"]["n_cores"])(
13651393
delayed(gchp_vs_gcc_mass_table)(mon) \
1366-
for mon in range(bmk_n_months)
1394+
for mon in range(len(mass_table_dates_dev))
13671395
)
13681396
else:
13691397
results = []
1370-
for mon in range(bmk_n_months):
1398+
for mon in range(len(mass_table_dates_dev)):
13711399
results.append(gchp_vs_gcc_mass_table(mon))
13721400

13731401
# ==================================================================
@@ -1996,7 +2024,7 @@ def gchp_vs_gchp_mass_table(mon):
19962024
refpath = get_filepath(
19972025
gchp_vs_gchp_refrstdir,
19982026
"Restart",
1999-
bmk_mons_ref[mon],
2027+
mass_table_dates_ref[mon],
20002028
is_gchp=True,
20012029
gchp_res=config["data"]["ref"]["gchp"]["resolution"],
20022030
gchp_is_pre_14_0=config["data"]["ref"]["gchp"][
@@ -2007,7 +2035,7 @@ def gchp_vs_gchp_mass_table(mon):
20072035
devpath = get_filepath(
20082036
gchp_vs_gchp_devrstdir,
20092037
"Restarts",
2010-
bmk_mons_dev[mon],
2038+
mass_table_dates_dev[mon],
20112039
is_gchp=True,
20122040
gchp_res=config["data"]["dev"]["gchp"]["resolution"],
20132041
gchp_is_pre_14_0=config["data"]["dev"]["gchp"][
@@ -2035,6 +2063,16 @@ def gchp_vs_gchp_mass_table(mon):
20352063
"is_pre_14.0"]
20362064
)
20372065

2066+
# Date strings
2067+
date_str_ref = datetime64_to_str(
2068+
mass_table_dates_ref[mon],
2069+
format_str="%Y%m%dT%H"
2070+
)
2071+
date_str_dev = datetime64_to_str(
2072+
mass_table_dates_dev[mon],
2073+
format_str="%Y%m%dT%H"
2074+
)
2075+
20382076
# Create tables
20392077
make_benchmark_mass_tables(
20402078
refpath,
@@ -2043,9 +2081,10 @@ def gchp_vs_gchp_mass_table(mon):
20432081
gchp_vs_gchp_devstr,
20442082
spcdb_files,
20452083
dst=gchp_vs_gchp_tablesdir,
2046-
subdst=bmk_mon_yr_strs_dev[mon],
2047-
label=f"at 01{bmk_mon_yr_strs_dev[mon]}",
20482084
overwrite=True,
2085+
subdst=date_str_dev,
2086+
ref_hdr_label=f"at {date_str_ref}",
2087+
dev_hdr_label=f"at {date_str_dev}",
20492088
ref_met_extra=refareapath,
20502089
dev_met_extra=devareapath
20512090
)
@@ -2055,11 +2094,11 @@ def gchp_vs_gchp_mass_table(mon):
20552094
if config["options"]["n_cores"] != 1:
20562095
results = Parallel(n_jobs=config["options"]["n_cores"])(
20572096
delayed(gchp_vs_gchp_mass_table)(mon) \
2058-
for mon in range(bmk_n_months)
2097+
for mon in range(len(mass_table_dates_dev))
20592098
)
20602099
else:
20612100
results = []
2062-
for mon in range(bmk_n_months):
2101+
for mon in range(len(mass_table_dates_dev)):
20632102
results.append(gchp_vs_gchp_mass_table(mon))
20642103

20652104
# ==================================================================

0 commit comments

Comments
 (0)