Skip to content

Commit 2dfbf86

Browse files
committed
Use species database info pertaining to Ref & Dev, and not the union
gcpy/benchmark/modules/benchmark_funcs.py - Obtain separate species metadata from Ref & Dev for use in in unit conversions (MW_g is the most relevant) - Removed some superfluous error checks - In routine make_benchark_operations_budget, use metadata from from both Ref & Dev to determine if it is a wet depositing species - Updated comments gcpy/benchmark/modules/benchmark_utils.py - Added constant SPECIES_DATABASE - Use SPECIES_DATABASE constant when constructing file paths in function get_species_database_files gcpy/benchmark/modules/oh_metrics.py gcpy/benchmark/modules/budget_tt.py gcpy/benchmark/modules/benchmark_mass_cons_table.py - For now, use only the Dev species metadata (e.g. mol. wt.) gcpy/plot/compare_single_level.py gcpy/plot/compare_zonal_mean.py - Now obtain species metadata for Ref & Dev separately - Now use molecular weights from the Ref and Dev species metadata when converting units to ug/m3 (via get_molwt_from_metadata function) gcpy/util.py - In routine "read_species_metadata", reeturn Ref and Dev species metadata separately instead of taking the union. If only one file is passed, return the same metadata for Ref and Dev. - Added routine "get_molwt_from_metadata" CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
1 parent 73e86ea commit 2dfbf86

File tree

9 files changed

+165
-156
lines changed

9 files changed

+165
-156
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1616
- Added new constants for default lon/lat and stretched-grid settings in `gcpy/constants.py`
1717
- Added PyDoc headers in routines where they were missing
1818
- Added `examples/grids/display_gcclassic_grid_info.py` to display info about a GEOS-Chem Classic horizontal grid
19-
- Added function `read_species_metadata` to `gcpy/util.py`
19+
- Added functions `get_molwt_from_metadata` and `read_species_metadata` to `gcpy/util.py`
2020
- Added function `get_species_database_files` to `gcpy/benchmark/modules/benchmark_utils.py`
21-
- Added `species_metadata` YAML tags under `ref:gcc`, `ref:gchp`, `dev:gcc`, `dev:gchp` sections in benchmark configuration files
21+
- Added constant `SPECIES_DATABASE` to `gcpy/benchmark/modules/benchmark_utils.py`
2222

2323
### Changed
2424
- 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
@@ -42,7 +42,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4242
- Updated default GCPy Python environment to use Python 3.13 (instead of 3.12)
4343
- Benchmark routines now look for `species_database.yml` in the `Ref` and `Dev` run directories
4444
- Replaced `get_species_database_dir` with `get_species_database_files` in `gcpy/benchmark/modules/benchmark_funcs.py`
45-
- Replaced `spcdb_dir` YAML tag with directory-specific `species_metadata` tags to specify paths to `species_database.yml` files
4645
- Updated `gcpy/benchmark/modules/benchmark_scrape_gchp_timers.py` to look for GCHP timers in `allPEs.log` if not found in the log file
4746
- Updated routine `make_benchmark_aerosol_tables` to include all dust species in the aerosol burdens table
4847

gcpy/benchmark/modules/benchmark_funcs.py

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def create_total_emissions_table(
118118
This method is mainly intended for model benchmarking purposes,
119119
rather than as a general-purpose tool.
120120
121-
Species properties (such as molecular weights) are read from a
121+
Species metadata (such as molecular weights) are read from a
122122
YAML file called "species_database.yml".
123123
"""
124124

@@ -153,10 +153,12 @@ def create_total_emissions_table(
153153
"dataset containing Met_AREAM2 is not passed!"
154154
raise ValueError(msg)
155155

156-
# Read the species database files in the Ref & Dev rundirs, and
157-
# return a dict containing metadata for the union of species.
158-
# We'll need properties such as mol. wt. for unit conversions, etc.
159-
properties = read_species_metadata(spcdb_files, quiet=True)
156+
# Read the species database files in the Ref & Dev rundirs,
157+
# and return a dict for each containing the species metadata.
158+
ref_metadata, dev_metadata = read_species_metadata(
159+
spcdb_files,
160+
quiet=True
161+
)
160162

161163
# Replace whitespace in the ref and dev labels
162164
refstr = replace_whitespace(refstr)
@@ -263,12 +265,11 @@ def create_total_emissions_table(
263265
else:
264266
spc_name = species_name
265267

266-
# Get a list of properties for the given species
267-
species_properties = properties.get(spc_name)
268-
269-
# If no properties are found, then skip to next species
270-
if species_properties is None:
271-
print(f"No properties found for {spc_name} ... skippping")
268+
# Get metadata for the given species
269+
ref_species_metadata = ref_metadata.get(spc_name)
270+
dev_species_metadata = dev_metadata.get(spc_name)
271+
if ref_species_metadata is None and dev_species_metadata is None:
272+
print(f"No metadata found for {spc_name} ... skipping")
272273
continue
273274

274275
# Convert units of Ref and Dev and save to numpy ndarray objects
@@ -279,7 +280,7 @@ def create_total_emissions_table(
279280
refarray = convert_units(
280281
refdata[v],
281282
spc_name,
282-
species_properties,
283+
ref_species_metadata,
283284
target_units,
284285
interval=ref_interval,
285286
area_m2=refarea,
@@ -299,7 +300,7 @@ def create_total_emissions_table(
299300
devarray = convert_units(
300301
devdata[v],
301302
spc_name,
302-
species_properties,
303+
dev_species_metadata,
303304
target_units,
304305
interval=dev_interval,
305306
area_m2=devarea,
@@ -319,15 +320,15 @@ def create_total_emissions_table(
319320
refarray = convert_units(
320321
refdata[v],
321322
spc_name,
322-
species_properties,
323+
ref_species_metadata,
323324
target_units,
324325
interval=ref_interval,
325326
area_m2=refarea,
326327
)
327328
devarray = convert_units(
328329
devdata[v],
329330
spc_name,
330-
species_properties,
331+
dev_species_metadata,
331332
target_units,
332333
interval=dev_interval,
333334
area_m2=devarea,
@@ -424,7 +425,7 @@ def create_global_mass_table(
424425
This method is mainly intended for model benchmarking purposes,
425426
rather than as a general-purpose tool.
426427
427-
Species properties (such as molecular weights) are read from a
428+
Species metadata (such as molecular weights) are read from a
428429
YAML file called "species_database.yml".
429430
"""
430431

@@ -441,9 +442,11 @@ def create_global_mass_table(
441442
raise ValueError('The "met_and_masks" argument was not passed!')
442443

443444
# Read the species database files in the Ref & Dev rundirs, and
444-
# return a dict containing metadata for the union of species.
445-
# We'll need properties such as mol. wt. for unit conversions, etc.
446-
properties = read_species_metadata(spcdb_files, quiet=True)
445+
# return a dict containing metadata for each.
446+
ref_metadata, dev_metadata = read_species_metadata(
447+
spcdb_files,
448+
quiet=True
449+
)
447450

448451
# Replace whitespace in the ref and dev labels
449452
refstr = replace_whitespace(refstr)
@@ -497,25 +500,17 @@ def create_global_mass_table(
497500
# Get the species name
498501
spc_name = v.split("_")[1]
499502

500-
# Get a list of properties for the given species
501-
species_properties = properties.get(spc_name)
502-
503-
# If no properties are found, then skip to next species
504-
if species_properties is None:
503+
# Get metadta for the given species
504+
ref_species_metadata = ref_metadata.get(spc_name)
505+
dev_species_metadata = dev_metadata.get(spc_name)
506+
if ref_species_metadata is None and dev_species_metadata is None:
505507
if verbose:
506-
msg = f"No properties found for {spc_name} ... skippping"
508+
msg = f"No metadata found for {spc_name} ... skippping"
507509
print(msg)
508510
continue
509511

510512
# Specify target units
511513
target_units = "Gg"
512-
mol_wt_g = species_properties.get("MW_g")
513-
if mol_wt_g is None:
514-
if verbose:
515-
msg = \
516-
f"No molecular weight found for {spc_name} ... skippping"
517-
print(msg)
518-
continue
519514

520515
# ==============================================================
521516
# Convert units of Ref and save to a DataArray
@@ -526,7 +521,7 @@ def create_global_mass_table(
526521
refarray = convert_units(
527522
refarray,
528523
spc_name,
529-
species_properties,
524+
ref_species_metadata,
530525
target_units,
531526
area_m2=met_and_masks["Ref_Area"],
532527
delta_p=met_and_masks["Ref_Delta_P"],
@@ -542,7 +537,7 @@ def create_global_mass_table(
542537
devarray = convert_units(
543538
devarray,
544539
spc_name,
545-
species_properties,
540+
dev_species_metadata,
546541
target_units,
547542
area_m2=met_and_masks["Dev_Area"],
548543
delta_p=met_and_masks["Dev_Delta_P"],
@@ -661,7 +656,7 @@ def create_mass_accumulation_table(
661656
This method is mainly intended for model benchmarking purposes,
662657
rather than as a general-purpose tool.
663658
664-
Species properties (such as molecular weights) are read from a
659+
Species metadata (such as molecular weights) are read from a
665660
YAML file called "species_database.yml".
666661
"""
667662

@@ -680,9 +675,11 @@ def create_mass_accumulation_table(
680675
raise ValueError('The "met_and_masks" argument was not passed!')
681676

682677
# Read the species database files in the Ref & Dev rundirs, and
683-
# return a dict containing metadata for the union of species.
684-
# We'll need properties such as mol. wt. for unit conversions, etc.
685-
properties = read_species_metadata(spcdb_files, quiet=True)
678+
# return a dict containing metadata for each.
679+
ref_metadata, dev_metadata = read_species_metadata(
680+
spcdb_files,
681+
quiet=True
682+
)
686683

687684
# Replace whitespace in the ref and dev labels
688685
refstr = replace_whitespace(refstr)
@@ -744,25 +741,17 @@ def create_mass_accumulation_table(
744741
# Get the species name
745742
spc_name = v.split("_")[1]
746743

747-
# Get a list of properties for the given species
748-
species_properties = properties.get(spc_name)
749-
750-
# If no properties are found, then skip to next species
751-
if species_properties is None:
744+
# Get a list of metadata for the given species
745+
ref_species_metadata = ref_metadata.get(spc_name)
746+
dev_species_metadata = dev_metadata.get(spc_name)
747+
if ref_species_metadata is None and dev_species_metadata is None:
752748
if verbose:
753749
msg = f"No properties found for {spc_name} ... skippping"
754750
print(msg)
755751
continue
756752

757753
# Specify target units
758754
target_units = "Gg"
759-
mol_wt_g = species_properties.get("MW_g")
760-
if mol_wt_g is None:
761-
if verbose:
762-
msg = \
763-
f"No molecular weight found for {spc_name} ... skippping"
764-
print(msg)
765-
continue
766755

767756
# ==============================================================
768757
# Convert units of Ref and save to a DataArray
@@ -773,7 +762,7 @@ def create_mass_accumulation_table(
773762
refarrays = convert_units(
774763
refarrays,
775764
spc_name,
776-
species_properties,
765+
ref_species_metadata,
777766
target_units,
778767
area_m2=met_and_masks["Refs_Area"],
779768
delta_p=met_and_masks["Refs_Delta_P"],
@@ -785,7 +774,7 @@ def create_mass_accumulation_table(
785774
refarraye = convert_units(
786775
refarraye,
787776
spc_name,
788-
species_properties,
777+
ref_species_metadata,
789778
target_units,
790779
area_m2=met_and_masks["Refe_Area"],
791780
delta_p=met_and_masks["Refe_Delta_P"],
@@ -804,7 +793,7 @@ def create_mass_accumulation_table(
804793
devarrays = convert_units(
805794
devarrays,
806795
spc_name,
807-
species_properties,
796+
dev_species_metadata,
808797
target_units,
809798
area_m2=met_and_masks["Devs_Area"],
810799
delta_p=met_and_masks["Devs_Delta_P"],
@@ -817,7 +806,7 @@ def create_mass_accumulation_table(
817806
devarraye = convert_units(
818807
devarraye,
819808
spc_name,
820-
species_properties,
809+
dev_species_metadata,
821810
target_units,
822811
area_m2=met_and_masks["Deve_Area"],
823812
delta_p=met_and_masks["Deve_Delta_P"],
@@ -4627,7 +4616,7 @@ def make_benchmark_aerosol_tables(
46274616
# Read the species database files in the Ref & Dev rundirs, and
46284617
# return a dict containing metadata for the union of species.
46294618
# We'll need properties such as mol. wt. for unit conversions, etc.
4630-
properties = read_species_metadata(spcdb_files, quiet=True)
4619+
_, dev_metadata = read_species_metadata(spcdb_files, quiet=True)
46314620

46324621
# Get the list of relevant AOD diagnostics from a YAML file
46334622
ifile= AOD_SPC
@@ -4664,8 +4653,8 @@ def make_benchmark_aerosol_tables(
46644653
mw = {}
46654654
full_names = {}
46664655
for var in varlist:
4667-
full_names[var] = properties[var]["FullName"].strip()
4668-
mw[var] = properties[var]["MW_g"]
4656+
full_names[var] = dev_metadata[var]["FullName"].strip()
4657+
mw[var] = dev_metadata[var]["MW_g"]
46694658
mw["Air"] = MW_AIR_g
46704659

46714660
# Get troposphere mask
@@ -5109,11 +5098,8 @@ def make_benchmark_operations_budget(
51095098
# ------------------------------------------
51105099

51115100
# Load a YAML file containing species properties
5112-
spc_properties = read_config_file(
5113-
os.path.join(
5114-
os.path.dirname(__file__),
5115-
"species_database.yml"
5116-
),
5101+
ref_metadata, dev_metadata = read_species_metadata(
5102+
spcdb_files,
51175103
quiet=True
51185104
)
51195105

@@ -5127,9 +5113,13 @@ def make_benchmark_operations_budget(
51275113

51285114
# Identify wetdep species
51295115
is_wetdep[spc] = None
5130-
properties = spc_properties.get(spc)
5131-
if properties is not None:
5132-
is_wetdep[spc] = properties.get("Is_WetDep")
5116+
ref_species_metadata = ref_metadata.get(spc)
5117+
dev_species_metadata = dev_metadata.get(spc)
5118+
if ref_species_metadata is not None and \
5119+
dev_species_metadata is not None:
5120+
is_wetdep[spc] = \
5121+
ref_species_metadata.get("Is_WetDep") or \
5122+
dev_species_metadata.get("Is_WetDep")
51335123

51345124
# Unit conversion factors and units
51355125
ref_conv_fac[spc] = ref_interval * 1e-6
@@ -5362,10 +5352,12 @@ def make_benchmark_operations_budget(
53625352
if compute_restart:
53635353
print('Computing RESTART operation budgets...')
53645354

5365-
# Read the species database files in the Ref & Dev rundirs, and
5366-
# return a dict containing metadata for the union of species.
5367-
# We'll need properties such as mol. wt. for unit conversions, etc.
5368-
properties = read_species_metadata(spcdb_files, quiet=True)
5355+
# Read the species database files in the Ref & Dev rundirs,
5356+
# and return a dict containing metadata for each.
5357+
ref_metadata, dev_metadata = read_species_metadata(
5358+
spcdb_files,
5359+
quiet=True
5360+
)
53695361

53705362
# Loop over all column sections
53715363
for col_section in col_sections:
@@ -5387,14 +5379,23 @@ def make_benchmark_operations_budget(
53875379

53885380
# Get ref and dev mass
53895381

5390-
# Get species properties for unit conversion. If none, skip.
5391-
species_properties = properties.get(spc)
5392-
if species_properties is None:
5393-
continue
5394-
mol_wt_g = species_properties.get("MW_g")
5395-
if mol_wt_g is None:
5382+
# Get species metadata for unit conversion. If none, skip.
5383+
ref_species_metadata = ref_metadata.get(spc)
5384+
dev_species_metadata = dev_metadata.get(spc)
5385+
if ref_species_metadata is None and \
5386+
dev_species_metadata is None:
53965387
continue
53975388

5389+
# Get molecular weights
5390+
#ref_mol_wt_g = get_molwt_from_metadata(
5391+
# ref_species_metadata,
5392+
# spc
5393+
#)
5394+
#dev_mol_wt_g = get_molwt_from_metadata(
5395+
# ref_species_metadata,
5396+
# spc
5397+
#)
5398+
53985399
# Specify target units
53995400
target_units = "Gg"
54005401

@@ -5407,7 +5408,7 @@ def make_benchmark_operations_budget(
54075408
refarray = convert_units(
54085409
refarray,
54095410
spc,
5410-
species_properties,
5411+
ref_species_metadata,
54115412
target_units,
54125413
area_m2=met_and_masks["Ref_Area"],
54135414
delta_p=met_and_masks["Ref_Delta_P"],
@@ -5423,7 +5424,7 @@ def make_benchmark_operations_budget(
54235424
devarray = convert_units(
54245425
devarray,
54255426
spc_name,
5426-
species_properties,
5427+
dev_species_metadata,
54275428
target_units,
54285429
area_m2=met_and_masks["Dev_Area"],
54295430
delta_p=met_and_masks["Dev_Delta_P"],

gcpy/benchmark/modules/benchmark_mass_cons_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_passive_tracer_metadata(
8484

8585
# Read the species database files in the Ref & Dev rundirs, and
8686
# return a dict containing metadata for the union of species.
87-
properties = read_species_metadata(spcdb_files, quiet=True)
87+
_, properties = read_species_metadata(spcdb_files, quiet=True)
8888

8989
return properties.get(SPC_NAME)
9090

0 commit comments

Comments
 (0)