Skip to content
Snippets Groups Projects
Commit 2ae28a12 authored by Paolo Veglio's avatar Paolo Veglio
Browse files

added some tests for utility functions

parent 96ec6187
No related branches found
No related tags found
No related merge requests found
Pipeline #48859 failed with stage
in 1 minute and 28 seconds
"""Create test files."""
# import os.path
# from glob import glob
from os.path import exists
import numpy as np
......@@ -24,8 +26,8 @@ _outpath = "/ships19/hercules/pveglio/mvcm_git_tests"
# - Land_Day_Desert
# - Land_Day
# - Ocean_Day
# _fname_mod02 = f"{_datapath}/VNP02MOD.A2022173.1312.001.2022174011547.uwssec_bowtie_corrected.nc"
# _fname_mod03 = f"{_datapath}/VNP03MOD.A2022173.1312.001.2022174012746.uwssec.nc"
_fname_mod02 = f"{_datapath}/VNP02MOD.A2022173.1312.001.2022174011547.uwssec_bowtie_corrected.nc"
_fname_mod03 = f"{_datapath}/VNP03MOD.A2022173.1312.001.2022174012746.uwssec.nc"
# _fname_img02 = f"{_datapath}/VNP02IMG.A2022173.1312.001.2022174011547.uwssec_bowtie_corrected.nc"
# _fname_img03 = f"{_datapath}/VNP03IMG.A2022173.1312.001.2022174012746.uwssec.nc"
......@@ -35,8 +37,8 @@ _outpath = "/ships19/hercules/pveglio/mvcm_git_tests"
# - Polar_Day_Desert_Coast
# - Polar_Day_Desert
# - Polar_Day_Ocean
_fname_mod02 = f"{_datapath}/VNP02MOD.A2022173.1324.001.2022174014257.uwssec_bowtie_corrected.nc"
_fname_mod03 = f"{_datapath}/VNP03MOD.A2022173.1324.001.2022174012743.uwssec.nc"
# _fname_mod02 = f"{_datapath}/VNP02MOD.A2022173.1324.001.2022174014257.uwssec_bowtie_corrected.nc"
# _fname_mod03 = f"{_datapath}/VNP03MOD.A2022173.1324.001.2022174012743.uwssec.nc"
# _fname_img02 = f"{_datapath}/VNP02IMG.A2022173.1324.001.2022174014257.uwssec_bowtie_corrected.nc"
# _fname_img03 = f"{_datapath}/VNP03IMG.A2022173.1324.001.2022174012743.uwssec.nc"
......@@ -113,6 +115,15 @@ def find_scene(scene_arr: npt.NDArray[np.float64], x: int = 100, y: int = 100) -
return (i, j)
def write_test_file() -> None:
"""Write test file."""
for scene in _scene_list:
test_file = f"{_outpath}/test_scene_{scene}.nc"
if exists(test_file):
ds = xr.open_dataset(test_file)
ds.to_netcdf(f"{_outpath}/full_test_file.nc", mode="a", group=scene)
def main(
mod02: str,
mod03: str,
......@@ -178,6 +189,7 @@ def main(
for var in viirs_data:
sample_data[var] = viirs_data[var][scn_idx[0], scn_idx[1]]
out_ds = sample_data
out_ds.to_netcdf(f"{out_fname}_{scene}.nc")
......
"""Test functions for utility_functions module."""
from typing import Dict
import numpy as np
import pytest
import mvcm.utility_functions as utils
@pytest.fixture
def spatial_var_test_arr():
"""Define reference input array for spatial_var() function test."""
arr = np.array(
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
[1, 1, 1, 1, 8, 8, 8, 1, 1, 1],
[5, 5, 5, 5, 7, 9, 8, 5, 5, 5],
[1, 1, 1, 1, 8, 8, 7, 1, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
[9, 8, 7, 1, 1, 1, 1, 1, 1, 1],
[7, 8, 8, 5, 5, 5, 5, 5, 5, 5],
[8, 9, 8, 1, 1, 1, 1, 1, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
],
dtype=float,
)
return arr
@pytest.fixture
def ref_spatial_var():
"""Define reference output array for spatial_var() function test."""
arr = np.array(
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
dtype=float,
)
return arr
@pytest.fixture
def thresholds():
"""Define thresholds for spatial_var() function test."""
return {"thr": 2}
def test_spatial_var(
spatial_var_test_arr: np.ndarray, thresholds: Dict, ref_spatial_var: np.ndarray
) -> None:
"""Test spatial_var function."""
var = utils.spatial_var(spatial_var_test_arr, thresholds["thr"])
assert np.allclose(np.floor(var), ref_spatial_var)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment