Skip to content

Commit

Permalink
Merge PR #340 (Replace whitespace in Ref and Dev version labels)
Browse files Browse the repository at this point in the history
This merge brings PR #340 (Replace whitespace in Ref and Dev version
labels in benchmarking code, by @yantosca) into the GCPy 1.6.0
development stream.

This PR makes sure that any spaces in the Ref and Dev version
labels are replaced with underscores.  This will prevent
file names from having spaces.

Signed-off-by: Bob Yantosca <[email protected]>
  • Loading branch information
yantosca committed Sep 13, 2024
2 parents 5958edf + cbee385 commit 8771b50
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- In environment files `read_the_docs_environment.yml` and `read_the_docs_requirements.txt`
- Update `jinja` to 3.1.4 (fixes a security issue)
- Update `gcpy/setup.py` with the new Python package version numbers
- Updated code in `gcpy/benchmark/modules/` to replace whitespace in Ref and Dev labels with underscores

### Fixed
- Fixed formatting error in `.github/workflows/stale.yml` that caused the Mark Stale Issues action not to run
Expand Down
9 changes: 6 additions & 3 deletions gcpy/benchmark/modules/benchmark_drydep.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""
Specific utilities for creating plots from GEOS-Chem benchmark simulations.
"""
import os
import gc
import numpy as np
from gcpy import util
from gcpy.plot.compare_single_level import compare_single_level
from gcpy.benchmark.modules.benchmark_utils import \
get_lumped_species_definitions, make_output_dir, \
pdf_filename, print_sigdiffs, read_ref_and_dev
get_common_varnames, make_output_dir, pdf_filename, \
print_sigdiffs, read_ref_and_dev

# Suppress numpy divide by zero warnings to prevent output spam
np.seterr(divide="ignore", invalid="ignore")
Expand Down Expand Up @@ -95,6 +94,10 @@ def make_benchmark_drydep_plots(
msg = "The spcdb_dir argument has not been specified!"
raise ValueError(msg)

# Replace whitespace in the ref and dev labels
refstr = util.replace_whitespace(refstr)
devstr = util.replace_whitespace(devstr)

# Create directory for plots (if it doesn't exist)
dst = make_output_dir(
dst,
Expand Down
68 changes: 67 additions & 1 deletion gcpy/benchmark/modules/benchmark_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from gcpy import util
from gcpy.regrid import create_regridders
from gcpy.grid import get_troposphere_mask
from gcpy.util import replace_whitespace
from gcpy.units import convert_units
from gcpy.constants import COL_WIDTH, MW_AIR_g, skip_these_vars, TABLE_WIDTH
from gcpy.plot.compare_single_level import compare_single_level
Expand Down Expand Up @@ -155,6 +156,10 @@ def create_total_emissions_table(
quiet=True
)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Get the list of emission variables for which we will print totals
# ==================================================================
Expand Down Expand Up @@ -447,6 +452,10 @@ def create_global_mass_table(
quiet=True
)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Open file for output
# ==================================================================
Expand Down Expand Up @@ -692,6 +701,10 @@ def create_mass_accumulation_table(
quiet=True
)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Open file for output
# ==================================================================
Expand Down Expand Up @@ -1032,6 +1045,10 @@ def make_benchmark_conc_plots(
else:
extra_title_txt = None

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Pick the proper function to read the data
reader = util.dataset_reader(time_mean, verbose=verbose)

Expand Down Expand Up @@ -1710,6 +1727,10 @@ def make_benchmark_emis_plots(
else:
extra_title_txt = None

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Get the function that will read the dataset
reader = util.dataset_reader(time_mean, verbose=verbose)

Expand Down Expand Up @@ -2098,6 +2119,10 @@ def make_benchmark_emis_tables(
if not os.path.isdir(emisdir):
os.mkdir(emisdir)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Read data from netCDF into Dataset objects
# ==================================================================
Expand Down Expand Up @@ -2343,6 +2368,10 @@ def make_benchmark_jvalue_plots(
# Create the directory for output
util.make_directory(dst, overwrite)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Get the function that will read file(s) into a Dataset
reader = util.dataset_reader(time_mean, verbose=verbose)

Expand Down Expand Up @@ -2727,6 +2756,10 @@ def make_benchmark_aod_plots(
else:
extra_title_txt = None

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Get the function that will read file(s) into a dataset
reader = util.dataset_reader(time_mean, verbose=verbose)

Expand Down Expand Up @@ -3009,11 +3042,19 @@ def make_benchmark_mass_tables(
which do not contain the Area variable.
Default value: ''
"""
# ==================================================================
# Initialization
# ==================================================================

# Make sure the species database folder is passed
if spcdb_dir is None:
msg = "The 'spcdb_dir' argument has not been specified!"
raise ValueError(msg)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Define destination directory
# ==================================================================
Expand Down Expand Up @@ -3275,11 +3316,19 @@ def make_benchmark_mass_accumulation_tables(
Directory of species_datbase.yml file
Default value: None
"""
# ==================================================================
# Initialization
# ==================================================================

# Make sure the species database folder is passed
if spcdb_dir is None:
msg = "The 'spcdb_dir' argument has not been specified!"
raise ValueError(msg)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Define destination directory
# ==================================================================
Expand Down Expand Up @@ -3543,10 +3592,16 @@ def make_benchmark_oh_metrics(
"""

# ==================================================================
# Define destination directory
# Initialization
# ==================================================================

# Define destination directory
util.make_directory(dst, overwrite)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ==================================================================
# Read data from netCDF into Dataset objects
# ==================================================================
Expand Down Expand Up @@ -3833,6 +3888,10 @@ def make_benchmark_wetdep_plots(
if not os.path.isdir(targetdst):
os.mkdir(targetdst)

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Get the function that will read file(s) into a dataset
reader = util.dataset_reader(time_mean, verbose=verbose)

Expand Down Expand Up @@ -4388,6 +4447,9 @@ def make_benchmark_operations_budget(
Directory containing the species_database.yml file.
Default value: None
"""
# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# ------------------------------------------
# Column sections
Expand Down Expand Up @@ -5083,6 +5145,10 @@ def create_benchmark_summary_table(
# Open file for output
# ==================================================================

# Replace whitespace in the ref and dev labels
refstr = replace_whitespace(refstr)
devstr = replace_whitespace(devstr)

# Create the directory for output
util.make_directory(dst, overwrite)

Expand Down
8 changes: 6 additions & 2 deletions gcpy/benchmark/modules/benchmark_gcclassic_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
import sys
import requests
from gcpy.util import verify_variable_type
from gcpy.util import replace_whitespace, verify_variable_type

# ----------------------------------------------------------------------
# Global variables
Expand Down Expand Up @@ -113,7 +113,7 @@ def scrape_stats(text):
stats["CH3CCl3"] = line.split(":")[1].strip()
if line_count == 18 and "Dev" in line:
stats["Mean OH"] = line.split(":")[1].strip()

# Skip commands
if "++ sed" in line:
line_count += 1
Expand Down Expand Up @@ -168,6 +168,10 @@ def main(ref_label, dev_label):
verify_variable_type(ref_label, str)
verify_variable_type(dev_label, str)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Scrape the log file text into a variable
bmk_id = f"gcc-4x5-1Mon-{dev_label}"
text = get_text_from_web(LOG_TEMPLATE.replace("ID", bmk_id))
Expand Down
8 changes: 6 additions & 2 deletions gcpy/benchmark/modules/benchmark_mass_cons_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from gcpy.constants import skip_these_vars
from gcpy.units import convert_units
from gcpy.util import \
replace_whitespace, dataset_reader, get_area_from_dataset, \
make_directory, read_config_file, verify_variable_type
dataset_reader, get_area_from_dataset, make_directory, \
read_config_file, replace_whitespace, verify_variable_type
from gcpy.benchmark.modules.benchmark_utils import \
get_datetimes_from_filenames

Expand Down Expand Up @@ -317,6 +317,10 @@ def make_benchmark_mass_conservation_table(
# Create the destination folder
make_directory(dst, overwrite)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Get a list of properties for the given species
metadata = get_passive_tracer_metadata(spcdb_dir)

Expand Down
25 changes: 17 additions & 8 deletions gcpy/benchmark/modules/benchmark_models_vs_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import numpy as np
import xarray as xr
from gcpy.constants import skip_these_vars
from gcpy.util import verify_variable_type, dataset_reader, make_directory
from gcpy.util import \
dataset_reader, make_directory, replace_whitespace, verify_variable_type
from gcpy.cstools import extract_grid
from gcpy.grid import get_nearest_model_data
from gcpy.benchmark.modules.benchmark_utils import \
Expand Down Expand Up @@ -51,6 +52,11 @@ def read_nas(
if verbose:
print(f"read_nas: Reading {input_file}")

# Initialize
lon = 0.0
lat = 0.0
alt = 0.0

with open(input_file, encoding='UTF-8') as the_file:
header = np.array(
[next(the_file) for x in range(155) ]
Expand Down Expand Up @@ -113,11 +119,11 @@ def read_nas(
index=obs_dataframe.index
)
obs_site_coords = { site:
{
'lon': lon,
'lat': lat,
'alt': alt
}
{
'lon': lon,
'lat': lat,
'alt': alt
}
}

return obs_dataframe, obs_site_coords
Expand Down Expand Up @@ -194,13 +200,12 @@ def read_model_data(
Returns
dataarray : xr.DataArray : GEOS-Chem data read from disk
"""

# Read the Ref and Dev model data
reader = dataset_reader(
multi_files=True,
verbose=verbose,
)

# Read data and rename SpeciesConc_ to SpeciesConcVV_, if necessary
# (needed for backwards compatibility with older versions.)
dataset = reader(filepaths,drop_variables=skip_these_vars).load()
Expand Down Expand Up @@ -755,6 +760,10 @@ def make_benchmark_models_vs_obs_plots(
verify_variable_type(dev_filepaths, (str, list))
verify_variable_type(dev_label, str)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Create the destination folder
make_directory(
dst,
Expand Down
6 changes: 5 additions & 1 deletion gcpy/benchmark/modules/benchmark_models_vs_sondes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import matplotlib.pyplot as plt
from gcpy.cstools import extract_grid
from gcpy.grid import get_nearest_model_data, get_vert_grid
from gcpy.util import make_directory, verify_variable_type
from gcpy.util import make_directory, replace_whitespace, verify_variable_type
from gcpy.benchmark.modules.benchmark_utils import \
read_ref_and_dev, rename_speciesconc_to_speciesconcvv

Expand Down Expand Up @@ -522,6 +522,10 @@ def make_benchmark_models_vs_sondes_plots(
verify_variable_type(dev_filepaths, (str, list))
verify_variable_type(dev_label, str)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Create the destination folder
make_directory(
dst,
Expand Down
4 changes: 4 additions & 0 deletions gcpy/benchmark/modules/benchmark_scrape_gcclassic_timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def make_benchmark_gcclassic_timing_table(
# Create the destination folder
make_directory(dst, overwrite)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Strip timing info from JSON/text file(s) and sum the them.
ref_timers = sum_timers(read_gcclassic(ref_files))
dev_timers = sum_timers(read_gcclassic(dev_files))
Expand Down
4 changes: 4 additions & 0 deletions gcpy/benchmark/modules/benchmark_scrape_gchp_timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def make_benchmark_gchp_timing_table(
# Create the destination folder
make_directory(dst, overwrite)

# Replace whitespace in the ref and dev labels
ref_label = replace_whitespace(ref_label)
dev_label = replace_whitespace(dev_label)

# Strip timing info from JSON/text file(s) and sum the them.
ref_timers = sum_timers(read_timing_data(ref_files))
dev_timers = sum_timers(read_timing_data(dev_files))
Expand Down
Loading

0 comments on commit 8771b50

Please sign in to comment.