Skip to content

Commit

Permalink
Reorganised test data. Now testing plots from physical run, rather th…
Browse files Browse the repository at this point in the history
…an from dummy run
  • Loading branch information
nichollsh committed Nov 3, 2024
1 parent b42623a commit 17e2fed
Show file tree
Hide file tree
Showing 32 changed files with 437 additions and 414 deletions.
3 changes: 2 additions & 1 deletion src/proteus/plot/cpl_sflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def plot_sflux(output_dir: str, wl_max: float = 6000.0,
X = np.loadtxt(output_dir+'/-1.sflux',skiprows=2).T
ax.plot(X[0],X[1],color='black',label='Modern',lw=0.8,alpha=0.9)

ax.legend()
if plt_modern or justone:
ax.legend()

plt.close()
plt.ioff()
Expand Down
Binary file removed tests/data/integration/dummy/plot_elements.png
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_escape.png
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_fluxes_global.png
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_global_lin.png
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_global_log.png
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_observables.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/data/integration/dummy/plot_sflux.png
Binary file not shown.
700 changes: 350 additions & 350 deletions tests/data/integration/dummy/runtime_helpfile.csv

Large diffs are not rendered by default.

File renamed without changes.
Binary file modified tests/data/integration/physical/2002_atm.nc
Binary file not shown.
Binary file added tests/data/integration/physical/2002_int.nc
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/integration/physical/plot_elements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/integration/physical/plot_emission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/integration/physical/plot_sflux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/integration/physical/plot_stacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions tests/data/integration/physical/runtime_helpfile.csv

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ author = "Harrison Nicholls, Tim Lichtenberg"
minimum = 1e2 # yr, minimum time-step
maximum = 1e3 # yr, maximum time-step
initial = 1e2 # yr, inital step size
starspec = 1e9 # yr, interval to re-calculate the stellar spectrum
starspec = 1e1 # yr, interval to re-calculate the stellar spectrum
starinst = 1e1 # yr, interval to re-calculate the instellation
method = "maximum" # proportional | adaptive | maximum

Expand Down Expand Up @@ -152,7 +152,7 @@ author = "Harrison Nicholls, Tim Lichtenberg"
spectral_group = "Frostflow" # which gas opacities to include
spectral_bands = "16" # how many spectral bands?
F_atm_bc = 0 # measure outgoing flux at: (0) TOA | (1) Surface
num_levels = 35 # Number of atmospheric grid levels
num_levels = 90 # Number of atmospheric grid levels
tropopause = "none" # none | skin | dynamic

[atmos_clim.dummy]
Expand Down
46 changes: 2 additions & 44 deletions tests/integration/test_integration_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,15 @@
from pathlib import Path

import pytest
from helpers import PROTEUS_ROOT, resize_to_match
from matplotlib.testing.compare import compare_images
from helpers import PROTEUS_ROOT
from pandas.testing import assert_frame_equal

from proteus import Proteus
from proteus.utils.coupler import ReadHelpfileFromCSV

IMAGE_LIST = (
"plot_elements.png",
"plot_escape.png",
"plot_fluxes_global.png",
"plot_global_lin.png",
"plot_global_log.png",
"plot_observables.png",
"plot_sflux.png",
"plot_population_mass_radius.png",
"plot_population_time_density.png",
)

@pytest.fixture(scope="module")
def dummy_run():
config_path = PROTEUS_ROOT /'tests' / 'data' / 'integration' / 'dummy' / 'dummy.toml'
config_path = PROTEUS_ROOT /'tests' / 'integration' / 'dummy.toml'

runner = Proteus(config_path=config_path)

Expand All @@ -47,32 +34,3 @@ def test_dummy_run(dummy_run):
# Check stellar spectra
assert filecmp.cmp(out_dir / 'data' / '0.sflux', ref_dir / '0.sflux', shallow=False)


@pytest.mark.xfail(raises=AssertionError)
@pytest.mark.parametrize("image", IMAGE_LIST)
def test_dummy_plot(dummy_run, image):

out_dir = PROTEUS_ROOT / 'output' / 'dummy'
ref_dir = PROTEUS_ROOT / 'tests' / 'data' / 'integration' / 'dummy'

out_img = out_dir / image
ref_img = ref_dir / image
tolerance = 3

# Resize images if needed
out_img, ref_img = resize_to_match(out_img, ref_img)

results_dir = Path('result_images')
results_dir.mkdir(exist_ok=True, parents=True)

actual = results_dir / image
expected = results_dir / f'{actual.stem}-expected{actual.suffix}'

# Save resized images to temporary paths
out_img.save(actual)
ref_img.save(expected)

# Use compare_images to compare the resized files
result = compare_images(actual=str(actual), expected=str(expected), tol=tolerance)

assert result is None, f"The two PNG files {image} differ more than the allowed tolerance: {result}"
84 changes: 74 additions & 10 deletions tests/integration/test_integration_physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@
from pathlib import Path

import pytest
from helpers import PROTEUS_ROOT
from helpers import PROTEUS_ROOT, resize_to_match
from pandas.testing import assert_frame_equal
from numpy.testing import assert_allclose
from matplotlib.testing.compare import compare_images

from proteus import Proteus
from proteus.utils.coupler import ReadHelpfileFromCSV
from proteus.atmos_clim.common import read_ncdf_profile
from proteus.atmos_clim.common import read_ncdf_profile as read_atmosphere
from proteus.interior.aragog import read_ncdf as read_interior
from proteus.utils.plot import sample_output

out_dir = PROTEUS_ROOT / 'output' / 'physical'
ref_dir = PROTEUS_ROOT / 'tests' / 'data' / 'integration' / 'physical'
config_path = PROTEUS_ROOT /'tests' / 'data' / 'integration' / 'physical' / 'physical.toml'
config_path = PROTEUS_ROOT /'tests' / 'integration' / 'physical.toml'

IMAGE_LIST = (
"plot_atmosphere.png",
"plot_escape.png",
"plot_global_log.png",
"plot_observables.png",
"plot_stacked.png",
"plot_elements.png",
"plot_fluxes_atmosphere.png",
"plot_interior_cmesh.png",
"plot_sflux_cross.png",
"plot_emission.png",
"plot_interior.png",
"plot_sflux.png",
)

@pytest.fixture(scope="module")
def physical_run():
Expand All @@ -31,23 +48,70 @@ def test_physical_run(physical_run):
# Check helpfile
assert_frame_equal(hf_all, hf_all_ref, rtol=5e-3)

# Check stellar spectra
assert filecmp.cmp(out_dir / 'data' / '0.sflux', ref_dir / '0.sflux', shallow=False)
def test_physical_spectrum(physical_run):
# Check stellar spectrum
assert filecmp.cmp(out_dir / 'data' / '2002.sflux',
ref_dir / '2002.sflux', shallow=False)

def test_physical_atmosphere(physical_run):
# Keys to load and test
fields = ["t", "p", "z", "fl_U_LW", "fl_D_LW", "fl_U_SW", "fl_D_SW"]
fields = ["t", "p", "z", "fl_U_LW", "fl_D_LW", "fl_U_SW", "fl_D_SW", "mmw"]

# Load atmosphere output
atm_out = read_ncdf_profile(out_dir / 'data' / '2002_atm.nc', extra_keys=fields)
out = read_atmosphere(out_dir / 'data' / '2002_atm.nc', extra_keys=fields)

# Compare to config
assert len(atm_out["t"]) == physical_run.config.atmos_clim.janus.num_levels*2+1
assert len(out["t"]) == physical_run.config.atmos_clim.janus.num_levels*2+1

# Load atmosphere reference
atm_ref = read_ncdf_profile(ref_dir / '2002_atm.nc', extra_keys=fields)
atm_ref = read_atmosphere(ref_dir / '2002_atm.nc', extra_keys=fields)

# Compare to expected array values.
# Cannot simply compare the files as black-boxes, because they contain date information
for key in fields:
assert_allclose(out[key], ref[key], rtol=1e-3)

def test_physical_interior(physical_run):
# Keys to load and test
fields = ["radius_b", "pres_b", "temp_b", "phi_b"]

# Load interior output
out = read_interior(out_dir / 'data' / '2002_int.nc')

# Compare to config
assert len(out["radius_b"]) == physical_run.config.interior.aragog.num_levels

# Load interior reference
ref = read_interior(ref_dir / '2002_int.nc')

# Compare to expected array values.
# Cannot simply compare the files as black-boxes, because they contain date information
for key in fields:
assert_allclose(atm_out[key], atm_ref[key], rtol=5e-3)
assert_allclose(out[key], ref[key], rtol=1e-3)


@pytest.mark.xfail(raises=AssertionError)
@pytest.mark.parametrize("image", IMAGE_LIST)
def test_physical_plot(physical_run, image):

out_img = out_dir / image
ref_img = ref_dir / image
tolerance = 3

# Resize images if needed
out_img, ref_img = resize_to_match(out_img, ref_img)

results_dir = Path('result_images')
results_dir.mkdir(exist_ok=True, parents=True)

actual = results_dir / image
expected = results_dir / f'{actual.stem}-expected{actual.suffix}'

# Save resized images to temporary paths
out_img.save(actual)
ref_img.save(expected)

# Use compare_images to compare the resized files
result = compare_images(actual=str(actual), expected=str(expected), tol=tolerance)

assert result is None, f"The two PNG files {image} differ more than the allowed tolerance: {result}"

0 comments on commit 17e2fed

Please sign in to comment.