Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address diffs v2.12.1 to v3 #907

Merged
merged 26 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a84b860
address_diffs_v2.12.1_to_v3
chengzhuzhang Dec 11, 2024
796ca4c
Revert "address_diffs_v2.12.1_to_v3"
chengzhuzhang Dec 11, 2024
0591c39
add_test_scripts
chengzhuzhang Dec 11, 2024
ee009c1
Fix incorrect logic for `udunits` conversions in `convert_units()`
tomvothecoder Dec 12, 2024
528bac6
Add complete run script
tomvothecoder Dec 16, 2024
8982c31
Update run script to save netCDF
tomvothecoder Dec 16, 2024
09e853c
Update dev dir for regression notebook
tomvothecoder Dec 16, 2024
b9da444
Add time slicing before `.load()` for performance
tomvothecoder Dec 17, 2024
4ad47a7
Add arm_diags and merra2 debug scripts
tomvothecoder Jan 7, 2025
b1a5a77
Fix hanging for derived vars with convert_units()
tomvothecoder Jan 8, 2025
3ea5422
Add arm_diags back into complete run script
tomvothecoder Jan 8, 2025
a76cfd8
Squeeze time dim for climo files before loading into memory
tomvothecoder Jan 9, 2025
af046a2
Update arm diags debug scripts with info on specific issues
tomvothecoder Jan 9, 2025
65f61ac
Add script debug H2OLNZ
tomvothecoder Jan 9, 2025
45277e6
Add H2OLNZ unit conversion from PR #874
tomvothecoder Jan 10, 2025
f346c51
Add v3 regression testing results
tomvothecoder Jan 10, 2025
94959cc
Add v2 data regression testing
tomvothecoder Jan 10, 2025
9221c5b
Update regression testing scripts
tomvothecoder Jan 10, 2025
313a641
update site data pre-processing script based on xarray
chengzhuzhang Jan 11, 2025
7020a25
Update v2 regression test notebooks
tomvothecoder Jan 14, 2025
d94ed40
Add `pywavelets` dependency to fix scipy `cwt` deprecation
tomvothecoder Jan 14, 2025
2144f51
Clean up postprocessing script for arm_diags
tomvothecoder Jan 14, 2025
60f53bc
figure out how to use pywavelets
tomvothecoder Jan 14, 2025
dd19a17
Add final v3 data regression test results
tomvothecoder Jan 15, 2025
01a91e4
Revert pywavelets code changes and constrain `scipy <1.15`
tomvothecoder Jan 15, 2025
1b0f998
Apply suggestions from code review
tomvothecoder Jan 15, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
QA diffs

"""
# %%
import os
import sys

from e3sm_diags.parameter.core_parameter import CoreParameter
from e3sm_diags.run import runner

param = CoreParameter()

# Location of the data.
param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/clim/15yr"
param.reference_data_path = (
"/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/climatology/"
)


# Set this parameter to True.
# By default, e3sm_diags expects the test data to be climo data.

# Set this parameter to True.
# By default, e3sm_diags expects the ref data to be climo data.

# When running with time-series data, you don't need to specify the name of the data.
# But you should, otherwise nothing is displayed when the test/ref name is needed.

# This parameter modifies the software to accommodate model vs model runs.
# The default setting for run_type is 'model_vs_obs'.
param.run_type = "model_vs_obs"
# Name of the folder where the results are stored.
# Change `prefix` to use your directory.
prefix = "/global/cfs/cdirs/e3sm/www/cdat-migration-fy24"
param.results_dir = os.path.join(prefix, "907-address-diffs")

# Below are more optional arguments.

# What plotsets to run the diags on.
# If not defined, then all available sets are used.
param.sets = ["lat_lon"]
# What seasons to run the diags on.
# If not defined, diags are run on ['ANN', 'DJF', 'MAM', 'JJA', 'SON'].
param.seasons = ["ANN"]

# For running with multiprocessing.
param.multiprocessing = False
# param.num_workers = 24

# %%
DIR_PATH = "auxiliary_tools/cdat_regression_testing/906-v3_complete_run"
CFG_PATH = os.path.join(DIR_PATH, "906-diags.cfg")
sys.argv.extend(["-d", CFG_PATH])
runner.run_diags([param])
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[#]
sets = ["lat_lon"]
case_id = "ERA5"
variables = ["TREFHT"]
regions = ["global"]
ref_name = "ERA5"
reference_name = "ERA5 Reanalysis"
seasons = ["ANN"]
contour_levels = [-35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40]
diff_levels = [-12, -8, -4, -2, -1, -0.5, 0.5, 1, 2, 4, 8, 12]
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
"""
This script sets up and runs a series of diagnostics for the E3SM model output.

The diagnostics include:
- ENSO diagnostics
- Tropical subseasonal variability diagnostics
- QBO diagnostics
- Diurnal cycle diagnostics
- Streamflow diagnostics
- Tropical cyclone analysis
- ARM diagnostics

The script configures the parameters for each diagnostic, including paths to
model output and observational data, time periods for analysis, and output
settings. It then runs the diagnostics using the e3sm_diags package.

Parameters:
- case: The name of the model case.
- short_name: A short name for the model case.
- results_dir: Directory where the results will be saved.
- test_climo: Path to the model climatology data.
- test_ts: Path to the model time-series data.
- test_ts_daily_dir: Path to the model daily time-series data.
- ref_climo: Path to the reference climatology data.
- ref_ts: Path to the reference time-series data.
- start_yr: Start year for the analysis.
- end_yr: End year for the analysis.

The script uses multiprocessing to speed up the diagnostics computation.

Example usage:
python complete_run_script.py
"""
import sys

from e3sm_diags.parameter.arm_diags_parameter import ARMDiagsParameter
from e3sm_diags.parameter.core_parameter import CoreParameter
from e3sm_diags.parameter.diurnal_cycle_parameter import DiurnalCycleParameter
from e3sm_diags.parameter.enso_diags_parameter import EnsoDiagsParameter
from e3sm_diags.parameter.qbo_parameter import QboParameter
from e3sm_diags.parameter.streamflow_parameter import StreamflowParameter
from e3sm_diags.parameter.tc_analysis_parameter import TCAnalysisParameter
from e3sm_diags.parameter.tropical_subseasonal_parameter import (
TropicalSubseasonalParameter,
)
from e3sm_diags.run import runner

case = "extendedOutput.v3.LR.historical_0101"
short_name = "v3.LR.historical_0101"

# TODO: Update MAIN_DIR to match the current directory name.
MAIN_DIR = "25-01-06-branch-907-debug-arm_diags"
results_dir = f"/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/{MAIN_DIR}/"

test_climo = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/clim/15yr"
test_ts = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/ts/monthly/15yr"
test_ts_daily_dir = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/ts/daily/15yr"

ref_climo = "/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/climatology/"
ref_ts = "/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/time-series"

start_yr = "2000"
end_yr = "2014"

param = CoreParameter()

# Model
param.test_data_path = test_climo
param.test_name = case
param.short_test_name = short_name

# Ref/Obs
param.reference_data_path = ref_climo

# Output dir
param.results_dir = results_dir

# Additional settings
param.run_type = "model_vs_obs"
param.diff_title = "Model - Observations"
param.output_format = ["png"]
param.output_format_subplot = []
param.multiprocessing = True
param.num_workers = 24
param.save_netcdf = True
param.seasons = ["ANN"]
params = [param]

# Model
enso_param = EnsoDiagsParameter()
enso_param.test_data_path = test_ts
# enso_param.test_name = short_name
enso_param.test_start_yr = start_yr
enso_param.test_end_yr = end_yr

# Obs
enso_param.reference_data_path = ref_ts
enso_param.ref_start_yr = start_yr
enso_param.ref_end_yr = end_yr

enso_param.save_netcdf = True
params.append(enso_param)

trop_param = TropicalSubseasonalParameter()
trop_param.test_data_path = test_ts_daily_dir
# trop_param.test_name = short_name
trop_param.test_start_yr = start_yr
trop_param.test_end_yr = end_yr

# Obs
trop_param.reference_data_path = ref_ts
trop_param.ref_start_yr = "2001"
trop_param.ref_end_yr = "2010"

trop_param.save_netcdf = True
params.append(trop_param)

qbo_param = QboParameter()
qbo_param.test_data_path = test_ts
# qbo_param.test_name = short_name
qbo_param.test_start_yr = start_yr
qbo_param.test_end_yr = end_yr
qbo_param.ref_start_yr = start_yr
qbo_param.ref_end_yr = end_yr

# Obs
qbo_param.reference_data_path = ref_ts

qbo_param.save_netcdf = True
params.append(qbo_param)

dc_param = DiurnalCycleParameter()
dc_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/clim_diurnal_8xdaily/"
# dc_param.short_test_name = short_name
# Plotting diurnal cycle amplitude on different scales. Default is True
dc_param.normalize_test_amp = False

# Obs
dc_param.reference_data_path = ref_climo

dc_param.save_netcdf = True
params.append(dc_param)

streamflow_param = StreamflowParameter()
streamflow_param.reference_data_path = ref_ts
streamflow_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/rof/native/ts/monthly/15yr/"
# streamflow_param.test_name = short_name
streamflow_param.test_start_yr = start_yr
streamflow_param.test_end_yr = end_yr

# Obs
streamflow_param.reference_data_path = ref_ts
streamflow_param.ref_start_yr = (
"1986" # Streamflow gauge station data range from year 1986 to 1995
)
streamflow_param.ref_end_yr = "1995"

streamflow_param.save_netcdf = True
params.append(streamflow_param)

tc_param = TCAnalysisParameter()
tc_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/tc-analysis_2000_2014"
# tc_param.short_test_name = short_name
tc_param.test_start_yr = start_yr
tc_param.test_end_yr = end_yr

# Obs
tc_param.reference_data_path = (
"/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/tc-analysis/"
)
# For model vs obs, the ref start and end year can be any four digit strings
# For now, use all available years from obs by default
tc_param.ref_start_yr = "1979"
tc_param.ref_end_yr = "2018"

tc_param.save_netcdf = True
params.append(tc_param)

arm_param = ARMDiagsParameter()
arm_param.reference_data_path = (
"/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/arm-diags-data"
)
arm_param.ref_name = "armdiags"
arm_param.test_data_path = (
"/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/site"
)
arm_param.test_name = short_name
arm_param.test_start_yr = start_yr
arm_param.test_end_yr = end_yr
# For model vs obs, the ref start and end year can be any four digit strings.
# For now, will use all available years form obs
arm_param.ref_start_yr = "0001"
arm_param.ref_end_yr = "0001"

arm_param.save_netcdf = True
params.append(arm_param)

# Run
runner.sets_to_run = [
"arm_diags",
]

cfg_path = "auxiliary_tools/cdat_regression_testing/906-v3_complete_run/debug-missing-arm-files/debug-missing.cfg"
sys.arv.extend(["--diags", cfg_path])

runner.run_diags(params)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[#]
sets = ["lat_lon"]
case_id = "MERRA2"
variables = ["LHFLX"]
ref_name = "MERRA2"
reference_name = "MERRA2 Reanalysis"
seasons = ["ANN", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "DJF", "MAM", "JJA", "SON"]
contour_levels = [0,5, 15, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300]
diff_levels = [-150, -120, -90, -60, -30, -20, -10, -5, 5, 10, 20, 30, 60, 90, 120, 150]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import filecmp

def get_png_files(directory):
"""Get a list of .png files in the given directory."""
png_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".png"):
png_files.append(os.path.join(root, file))
return png_files

def compare_directories(dir1, dir2):
"""Compare .png files between two directories."""
png_files_dir1 = get_png_files(dir1)
png_files_dir2 = get_png_files(dir2)

# Create a dictionary with relative paths as keys
png_files_dict1 = {os.path.relpath(file, dir1): file for file in png_files_dir1}
png_files_dict2 = {os.path.relpath(file, dir2): file for file in png_files_dir2}

# Find common files
common_files = set(png_files_dict1.keys()).intersection(set(png_files_dict2.keys()))

# Compare common files
for file in common_files:
if not filecmp.cmp(png_files_dict1[file], png_files_dict2[file], shallow=False):
print(f"Difference found in file: {file}")

# Find files only in dir1
only_in_dir1 = sorted(set(png_files_dict1.keys()) - set(png_files_dict2.keys()))
if only_in_dir1:
print(f"Files only in {dir1}:")
for file in only_in_dir1:
print(file)

# Find files only in dir2
only_in_dir2 = sorted(set(png_files_dict2.keys()) - set(png_files_dict1.keys()))
if only_in_dir2:
print(f"Files only in {dir2}:")
for file in only_in_dir2:
print(file)

if __name__ == "__main__":
dir1 = "/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/25-01-06-branch-907-arm-diags-only/arm_diags"
dir2 = "/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/v2.12.1v2/arm_diags"
compare_directories(dir1, dir2)
Loading
Loading