Skip to content

Commit

Permalink
Add a test for VIIRS L2 version <= v3r0
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Mar 13, 2024
1 parent ec09be0 commit 2fff0d4
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions satpy/tests/reader_tests/test_viirs_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ def _fill_contents_with_default_data(self, file_content, file_type):
file_content["Aerosol_Optical_Thickness_550_Land_Ocean_Best_Estimate"] = DEFAULT_FILE_DATA


class FakeNetCDF4FileHandlerVIIRSL2_V3R0(FakeNetCDF4FileHandlerVIIRSL2):
"""Swap-in NetCDF4 File Handler for ASCI version <= v3r0."""

def get_test_content(self, filename, filename_info, filetype_info):
"""Mimic reader input file content."""
dt = filename_info.get("start_time", datetime(2023, 12, 30, 22, 30, 0))
file_type = filename[:6]
num_lines = DEFAULT_FILE_SHAPE[0]
num_pixels = DEFAULT_FILE_SHAPE[1]
num_scans = 5
file_content = {
"/dimension/number_of_scans": num_scans,
"/dimension/number_of_lines": num_lines,
"/dimension/number_of_pixels": num_pixels,
"/attr/time_coverage_start": dt.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
"/attr/time_coverage_end": (dt + timedelta(minutes=6)).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"/attr/orbit_number": 26384,
"/attr/instrument_name": "VIIRS",
"/attr/satellite_name": "Suomi-NPP",
}
self._fill_contents_with_default_data(file_content, file_type)
convert_file_content_to_data_array(file_content)
return file_content


class TestVIIRSL2FileHandler:
"""Test VIIRS_L2 Reader."""
yaml_file = "viirs_l2.yaml"
Expand Down Expand Up @@ -133,3 +160,47 @@ def test_load_l2_files(self, filename, datasets):
d_np = d.compute()
assert d.dtype == d_np.dtype
assert d.dtype == np.float32


class TestVIIRSL2V3R0FileHandler:
"""Test VIIRS_L2 Reader for ASCI version <= v3r0."""
yaml_file = "viirs_l2.yaml"

def setup_method(self):
"""Wrap NetCDF4 file handler with our own fake handler."""
from satpy._config import config_search_paths
from satpy.readers.viirs_l2 import VIIRSL2FileHandler

self.reader_configs = config_search_paths(
os.path.join("readers", self.yaml_file)
)
self.p = mock.patch.object(
VIIRSL2FileHandler, "__bases__", (FakeNetCDF4FileHandlerVIIRSL2_V3R0,)
)
self.fake_handler = self.p.start()
self.p.is_local = True

def teardown_method(self):
"""Stop wrapping the NetCDF4 file handler."""
self.p.stop()

@pytest.mark.parametrize(
("filename", "datasets"),
[
pytest.param("CLDPROP_L2_VIIRS_SNPP.A2023364.2230.011.2023365115856.nc",
["Cloud_Top_Height"], id="CLDPROP"),
pytest.param("CLDMSK_L2_VIIRS_SNPP.A2023364.2230.001.2023365105952.nc",
["Clear_Sky_Confidence"], id="CLDMSK"),
pytest.param("AERDB_L2_VIIRS_SNPP.A2023364.2230.011.2023365113427.nc",
["Aerosol_Optical_Thickness_550_Land_Ocean_Best_Estimate",
"Angstrom_Exponent_Land_Ocean_Best_Estimate"], id="AERDB"),
],
)
def test_load_l2_files(self, filename, datasets):
"""Test L2 File Loading."""
r = load_reader(self.reader_configs)
loadables = r.select_files_from_pathnames([filename])
r.create_filehandlers(loadables)
loaded_datasets = r.load(datasets)
for d in loaded_datasets.values():
assert d.attrs["sensor"] == "viirs"

0 comments on commit 2fff0d4

Please sign in to comment.