Skip to content
Open
Changes from all commits
Commits
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
49 changes: 27 additions & 22 deletions fre/app/remap_pp_components/tests/test_remap_pp_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from pathlib import Path
import pytest
import xarray as xr
import fre.app.remap_pp_components.remap_pp_components as rmp

# Test paths
Expand Down Expand Up @@ -332,21 +333,23 @@ def test_remap_offline_diagnostics(monkeypatch):
assert Path(f"{os.getenv('outputDir')}/atmos_scalar/{STATIC_FREQ}/{STATIC_CHUNK}/empty.nc").exists()

## COMPARE INPUT AND OUTPUT FILES ##
def test_nccmp_ncgen_remap():
def test_compare_ncgen_remap():
"""
This test compares the results of ncgen and rewrite_remap,
making sure that the remapped files are identical.
"""
comp_name = "atmos_scalar_CNAME"
output_nc_file = f"{comp_name}.198001-198412.co2mass.nc"

nccmp = [ "nccmp", "-d",
Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"),
Path(f"{REMAP_OUT}/{comp_name}/{PRODUCT}/monthly/5yr/{output_nc_file}") ]
sp = subprocess.run( nccmp, check = False)
assert sp.returncode == 0
with xr.open_dataset(
Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"),
decode_cf=False, decode_times=False) as ds_in, \
xr.open_dataset(
Path(f"{REMAP_OUT}/{comp_name}/{PRODUCT}/monthly/5yr/{output_nc_file}"),
decode_cf=False, decode_times=False) as ds_out:
xr.testing.assert_equal(ds_in, ds_out)

def test_nccmp_ncgen_remap_ens_mem():
def test_compare_ncgen_remap_ens_mem():
"""
This test compares the results of ncgen and rewrite_remap,
making sure that the remapped files are identical.
Expand All @@ -358,29 +361,31 @@ def test_nccmp_ncgen_remap_ens_mem():
remap_ens_in = f"{TEST_OUTDIR}/ncgen-ens-output"
remap_ens_out = f"{TEST_OUTDIR}/remap-ens-output"

nccmp = [ "nccmp", "-d",
Path(f"{remap_ens_in}/{NATIVE_GRID}/ens_01/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"),
Path(f"{remap_ens_out}/{comp_name}/{PRODUCT}/ens_01/monthly/5yr/{output_nc_file}") ]
with xr.open_dataset(
Path(f"{remap_ens_in}/{NATIVE_GRID}/ens_01/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"),
decode_cf=False, decode_times=False) as ds_in, \
xr.open_dataset(
Path(f"{remap_ens_out}/{comp_name}/{PRODUCT}/ens_01/monthly/5yr/{output_nc_file}"),
decode_cf=False, decode_times=False) as ds_out:
xr.testing.assert_equal(ds_in, ds_out)

sp = subprocess.run( nccmp, check = False)
assert sp.returncode == 0

def test_nccmp_ncgen_remap_statics():
def test_compare_ncgen_remap_statics():
"""
This test compares the results of ncgen and remap,
making sure that the remapped static files are identical.
"""
comp_name = "atmos_scalar_CNAME"
output_nc_file = f"{comp_name}.bk.nc"

nccmp = [ "nccmp", "-d",
Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_static_scalar/"
f"{STATIC_FREQ}/{STATIC_CHUNK}/{STATIC_DATA_NC_FILES[0]}"),
Path(f"{REMAP_OUT}/static/{comp_name}/"
f"{STATIC_FREQ}/{STATIC_CHUNK}/{output_nc_file}")]

sp = subprocess.run( nccmp, check = False)
assert sp.returncode == 0
with xr.open_dataset(
Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_static_scalar/"
f"{STATIC_FREQ}/{STATIC_CHUNK}/{STATIC_DATA_NC_FILES[0]}"),
decode_cf=False, decode_times=False) as ds_in, \
xr.open_dataset(
Path(f"{REMAP_OUT}/static/{comp_name}/"
f"{STATIC_FREQ}/{STATIC_CHUNK}/{output_nc_file}"),
decode_cf=False, decode_times=False) as ds_out:
xr.testing.assert_equal(ds_in, ds_out)

## VARIABLE FILTERING TESTS ##
def test_remap_variable_filtering():
Expand Down
Loading