From 3f5108d2f56614068daf19af3d624302ac8c5275 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 24 Jan 2025 10:10:28 +0100 Subject: [PATCH 1/3] Fix sunz normalization for viirs_compact SDR data has sun_zenith_angle_correction_applied as default, viirs_compact does not! We now read data with the sunz_corrected modifier and satpy applyes the normalization. Note that reflective bands are read separately to avoid sunz_correction applied to the IR channels. --- level1c4pps/viirs2pps_lib.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/level1c4pps/viirs2pps_lib.py b/level1c4pps/viirs2pps_lib.py index 92dd642..73340f6 100644 --- a/level1c4pps/viirs2pps_lib.py +++ b/level1c4pps/viirs2pps_lib.py @@ -114,8 +114,11 @@ def set_header_and_band_attrs(scene, orbit_n=0): for band in REFL_BANDS: if band not in scene: continue - # For VIIRS data sun_zenith_angle_correction_applied is applied always! + # SDR has data has sun_zenith_angle_correction_applied, viirs_compact does not! + # We now read data with the sunz_corrected modifier scene[band].attrs['sun_zenith_angle_correction_applied'] = 'True' + if "sunz_corrected" not in scene['M05'].attrs['modifiers']: + logger.exception(f"Data is not sunz_corrected!") return nimg @@ -140,12 +143,17 @@ def process_one_scene(scene_files, out_path, use_iband_res=False, reader='viirs_ MY_IBAND_I = IBAND_PPS_I MY_IBAND_M = IBAND_PPS_M + MY_MBAND_REFL = [band for band in MY_MBAND if band in REFL_BANDS] + MY_MBAND_TB = [band for band in MY_MBAND if band not in REFL_BANDS] + if use_iband_res: scn_.load(MY_IBAND_I + ANGLE_NAMES + ['i_latitude', 'i_longitude'], resolution=371) scn_.load(MY_IBAND_M, resolution=742) scn_ = scn_.resample(resampler='native') elif reader == "viirs_compact": - scn_.load(MY_MBAND + ANGLE_NAMES + ['latitude_m', 'longitude_m'], resolution=742) + scn_.load(MY_MBAND_TB + ANGLE_NAMES + ['latitude_m', 'longitude_m'], resolution=742) + scn_.load(MY_MBAND_REFL, modifiers="sunz_corrected") + else: scn_.load(MY_MBAND + ANGLE_NAMES + ['m_latitude', 'm_longitude'], resolution=742) From f73ef35029fb09b94d4c22ab96130cbb92644596 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Thu, 30 Jan 2025 10:48:59 +0100 Subject: [PATCH 2/3] Fix test Use the modifiers to set the sunz-correction attribute already in the main attribute function. --- level1c4pps/__init__.py | 2 ++ level1c4pps/tests/test_viirs2pps.py | 1 + level1c4pps/viirs2pps_lib.py | 7 ++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/level1c4pps/__init__.py b/level1c4pps/__init__.py index 20e7eee..4ebf4e7 100644 --- a/level1c4pps/__init__.py +++ b/level1c4pps/__init__.py @@ -437,6 +437,8 @@ def set_header_and_band_attrs_defaults(scene, BANDNAMES, PPS_TAGNAMES, REFL_BAND fix_sun_earth_distance_correction_factor(scene, band, irch.attrs['start_time']) scene[band].attrs['wavelength'] = scene[band].attrs['wavelength'][0:3] scene[band].attrs['sun_zenith_angle_correction_applied'] = 'False' + if "sunz_corrected" in scene[band].attrs.get('modifiers', []): + scene[band].attrs['sun_zenith_angle_correction_applied'] = 'True' if idtag in PPS_TAGNAMES_TO_IMAGE_NR: scene[band].attrs['name'] = PPS_TAGNAMES_TO_IMAGE_NR[idtag] else: diff --git a/level1c4pps/tests/test_viirs2pps.py b/level1c4pps/tests/test_viirs2pps.py index adab6d0..37bdff2 100644 --- a/level1c4pps/tests/test_viirs2pps.py +++ b/level1c4pps/tests/test_viirs2pps.py @@ -37,6 +37,7 @@ def setUp(self): """Create a test scene.""" viirs2pps.BANDNAMES = ['M05', 'M15'] vis006 = mock.MagicMock(attrs={'name': 'image0', + 'modifiers': ("sunz_correction", ), 'wavelength': [1, 2, 3, 'um'], 'id_tag': 'ch_r06'}) ir_108 = mock.MagicMock(attrs={ diff --git a/level1c4pps/viirs2pps_lib.py b/level1c4pps/viirs2pps_lib.py index 73340f6..2fc00ba 100644 --- a/level1c4pps/viirs2pps_lib.py +++ b/level1c4pps/viirs2pps_lib.py @@ -114,11 +114,8 @@ def set_header_and_band_attrs(scene, orbit_n=0): for band in REFL_BANDS: if band not in scene: continue - # SDR has data has sun_zenith_angle_correction_applied, viirs_compact does not! - # We now read data with the sunz_corrected modifier + # VIIRS data read with sunz_corrected modifier scene[band].attrs['sun_zenith_angle_correction_applied'] = 'True' - if "sunz_corrected" not in scene['M05'].attrs['modifiers']: - logger.exception(f"Data is not sunz_corrected!") return nimg @@ -152,8 +149,8 @@ def process_one_scene(scene_files, out_path, use_iband_res=False, reader='viirs_ scn_ = scn_.resample(resampler='native') elif reader == "viirs_compact": scn_.load(MY_MBAND_TB + ANGLE_NAMES + ['latitude_m', 'longitude_m'], resolution=742) + # Load reflective bands with sunz-correction (not the default for VIIRS compact). scn_.load(MY_MBAND_REFL, modifiers="sunz_corrected") - else: scn_.load(MY_MBAND + ANGLE_NAMES + ['m_latitude', 'm_longitude'], resolution=742) From e6abfad926b4adad870bce27dd0ffac2a0c680df Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:15:48 +0100 Subject: [PATCH 3/3] Fix syntax --- level1c4pps/viirs2pps_lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1c4pps/viirs2pps_lib.py b/level1c4pps/viirs2pps_lib.py index 2fc00ba..6e3c35e 100644 --- a/level1c4pps/viirs2pps_lib.py +++ b/level1c4pps/viirs2pps_lib.py @@ -150,7 +150,7 @@ def process_one_scene(scene_files, out_path, use_iband_res=False, reader='viirs_ elif reader == "viirs_compact": scn_.load(MY_MBAND_TB + ANGLE_NAMES + ['latitude_m', 'longitude_m'], resolution=742) # Load reflective bands with sunz-correction (not the default for VIIRS compact). - scn_.load(MY_MBAND_REFL, modifiers="sunz_corrected") + scn_.load(MY_MBAND_REFL, modifiers=("sunz_corrected", )) else: scn_.load(MY_MBAND + ANGLE_NAMES + ['m_latitude', 'm_longitude'], resolution=742)