import os import yaml import xarray as xr import numpy as np import pytest # from typing import Dict # from attrs import define, field, Factory import mvcm.spectral_tests as tst # CREATE PATHS @pytest.fixture def fixturepath(): return os.path.join(os.path.dirname(__file__), 'fixtures') @pytest.fixture def data_path(): return '/ships19/hercules/pveglio/mvcm_cleanup' # SET FILENAME FIXTURES @pytest.fixture def thresholds_file(fixturepath): return os.path.join(fixturepath, 'thresholds.mvcm.snpp.v0.0.1.yaml') @pytest.fixture def ref_confidence_file(data_path): return os.path.join(data_path, 'ref_confidence.nc') @pytest.fixture def data_file(data_path): return os.path.join(data_path, 'viirs_data_A2022173.1312.nc') # SET DATA FIXTURES @pytest.fixture def thresholds(thresholds_file): return yaml.safe_load(open(thresholds_file)) @pytest.fixture def data(data_file): return xr.open_dataset(data_file) @pytest.fixture def ref_confidence(ref_confidence_file): return xr.open_dataset(ref_confidence_file) def test_11um_test(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Day_Ocean', 'Polar_Night_Ocean']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.test_11um('M15', cmin) assert np.allclose(cmin, ref_confidence.bt11um_confidence.values) def test_surface_temperature_test(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Land_Night', 'Polar_Night_Land']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.surface_temperature_test('M15', data, cmin) assert np.allclose(cmin, ref_confidence.surface_temperature_confidence.values) def test_sst_test(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Day_Ocean', 'Polar_Night_Ocean']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.sst_test('M15', 'M16', cmin) assert np.allclose(cmin, ref_confidence.sst_confidence.values) def test_bt_diff_86_11um(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Ocean_Day', 'Ocean_Night', 'Polar_Day_Ocean', 'Polar_Night_Ocean']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.bt_diff_86_11um('M14-M15', cmin) assert np.allclose(cmin, ref_confidence.diff86_11um_confidence.values) def test_11_12um_diff(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Land_Day', 'Land_Day_Coast', 'Land_Day_Desert', 'Land_Day_Desert_Coast', 'Ocean_Day', 'Ocean_Night', 'Polar_Day_Ocean', 'Polar_Night_Ocean', 'Polar_Day_Land', 'Polar_Day_Coast', 'Polar_Day_Desert', 'Polar_Day_Desert_Coast', 'Polar_Day_Snow', 'Land_Night', 'Polar_Night_Land', 'Polar_Night_Snow', 'Day_Snow', 'Night_Snow']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.test_11_12um_diff('M15-M16', cmin) assert np.allclose(cmin, ref_confidence.diff11_12um_confidence.values) def test_variability_11um_test(data, thresholds, ref_confidence): cmin = np.ones(data.latitude.shape) for scene_name in ['Polar_Day_Ocean', 'Polar_Night_Ocean']: SceneType = tst.CloudTests(data=data, scene_name=scene_name, thresholds=thresholds) cmin, bit = SceneType.variability_11um_test('M15', cmin) assert np.allclose(cmin, ref_confidence.var11um_confidence.values)