Skip to content

Commit

Permalink
Add tests for sharing segment info
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Jun 19, 2024
1 parent 21a5bcc commit 37f9305
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions satpy/tests/reader_tests/test_fci_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,3 +921,52 @@ def test_bad_xy_coords(self, reader_configs):
np.array([-5568000.227139, -5368000.221262,
5568000.100073, -5568000.227139]),
decimal=2)


def _mock_np2str(val):
return val


def test_reusing_shared_segment_info():
"""Test that certain data are reused after the first segment has been handled.
This is the case where something has been already handled and stored to filetype_info["shared_info"] dict.
"""
from trollsift import parse

filename = ("W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--DIS-NC4E_C_"
"EUMT_20231102061023_IDPFI_OPE_20231102060835_20231102060908_N_JLS_C_0037_0037.nc")
fmt = ("{pflag}_{location_indicator},{data_designator},MTI{spacecraft_id:1d}+{data_source}-1C-RRAD-FDHSI-"
"{coverage}-{subsetting}-{component1}-BODY-{component3}-{purpose}-{format}_{oflag}_{originator}_"
"{processing_time:%Y%m%d%H%M%S}_{facility_or_tool}_{environment}_{start_time:%Y%m%d%H%M%S}_{end_time:%Y%m%d%H%M%S}_"
"{processing_mode}_{special_compression}_{disposition_mode}_{repeat_cycle_in_day:>04d}_{count_in_repeat_cycle:>04d}.nc")
filename_info = parse(fmt, filename)
filetype_info = {
"shared_info": {
"attr/platform": "mock-satellite"
},
"required_netcdf_variables": ["attr/platform"]
}
with mock.patch("satpy.readers.netcdf_utils.NetCDF4FsspecFileHandler._get_file_handle"):
with mock.patch("satpy.readers.netcdf_utils.np2str", _mock_np2str):
fh_ = FCIL1cNCFileHandler(filename, filename_info, filetype_info)
assert fh_.file_content["attr/platform"] == filetype_info["shared_info"]["attr/platform"]


def test_store_shared_segment_info():
"""Test that certain data are collected to filetype_info["shared_info"] from the first segment."""
from trollsift import parse

filename = ("W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--DIS-NC4E_C_"
"EUMT_20231102061023_IDPFI_OPE_20231102060835_20231102060908_N_JLS_C_0037_0037.nc")
fmt = ("{pflag}_{location_indicator},{data_designator},MTI{spacecraft_id:1d}+{data_source}-1C-RRAD-FDHSI-"
"{coverage}-{subsetting}-{component1}-BODY-{component3}-{purpose}-{format}_{oflag}_{originator}_"
"{processing_time:%Y%m%d%H%M%S}_{facility_or_tool}_{environment}_{start_time:%Y%m%d%H%M%S}_{end_time:%Y%m%d%H%M%S}_"
"{processing_mode}_{special_compression}_{disposition_mode}_{repeat_cycle_in_day:>04d}_{count_in_repeat_cycle:>04d}.nc")
filename_info = parse(fmt, filename)
filetype_info = {"required_netcdf_variables": ["attr/platform"]}
with mock.patch("satpy.readers.netcdf_utils.NetCDF4FsspecFileHandler._get_file_handle") as get_file_handle:
get_file_handle.return_value.platform = "mock-satellite"
with mock.patch("satpy.readers.netcdf_utils.np2str", _mock_np2str):
_ = FCIL1cNCFileHandler(filename, filename_info, filetype_info)
assert filetype_info["shared_info"]["attr/platform"] == "mock-satellite"

0 comments on commit 37f9305

Please sign in to comment.