Newer
Older
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
@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)