From 7503bb70a4cd76bd0297d9c750e4950989fe34b9 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:47:09 +0100 Subject: [PATCH 1/9] Add extrenal IR calibration --- bin/seviri2pps.py | 4 ++++ level1c4pps/calibration_coefs.py | 40 ++++++++++++++++++++++++++++++-- level1c4pps/seviri2pps_lib.py | 10 ++++---- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/bin/seviri2pps.py b/bin/seviri2pps.py index 2034886..1b18033 100755 --- a/bin/seviri2pps.py +++ b/bin/seviri2pps.py @@ -50,6 +50,9 @@ help="Engine for saving netcdf files netcdf4 or h5netcdf (default).") parser.add_argument('--use-nominal-time-in-filename', action='store_true', help='Use nominal scan timestamps in output filename.') + parser.add_argument('--path_to_external_ir_calibration', type=str, default=None, + help='Path to external IR calibration.') + options = parser.parse_args() process_one_scan( options.files, @@ -57,5 +60,6 @@ rotate=not options.no_rotation, engine=options.nc_engine, use_nominal_time_in_filename=options.use_nominal_time_in_filename, + path_to_external_ir_calibration=options.path_to_external_ir_calibration, save_azimuth_angles=options.azimuth_angles, ) diff --git a/level1c4pps/calibration_coefs.py b/level1c4pps/calibration_coefs.py index a24d55f..f873e2e 100644 --- a/level1c4pps/calibration_coefs.py +++ b/level1c4pps/calibration_coefs.py @@ -21,6 +21,7 @@ import datetime from enum import Enum +import json class CalibrationData(Enum): @@ -55,7 +56,7 @@ class CalibrationData(Enum): SATPY_CALIB_MODE = 'Nominal' -def get_calibration(platform, time, clip=False): +def get_calibration(platform, time, clip=False, path_to_external_ir_calibration=None): """Get MODIS-intercalibrated gain and offset for specific time. Args: @@ -74,6 +75,18 @@ def get_calibration(platform, time, clip=False): time=time, clip=clip ) + + if path_to_external_ir_calibration is not None: + for channel in ('IR_039', 'IR_087', 'IR_108', 'IR_120', + 'IR_134', 'IR_097', 'WV_062', 'WV_073'): + coefs[channel] = ir_calib_eumetsat( + path_to_external_ir_calibration, + platform=platform, + channel=channel, + time=time, + ) + + return coefs @@ -153,7 +166,22 @@ def _calc_gain_offset(a, b, days_since_ref_time): def _microwatts_to_milliwatts(microwatts): return microwatts / 1000.0 - +def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=datetime.datetime(2048, 1, 18, 12, 0)): + """Get IR calibration from EUMETSAT, modified by CMSAF.""" + filename = "{:s}/TIR_calib_{:s}_{:s}.json".format(ir_calib_path, + platform, + channel) + + with open(filename, 'r') as fhand: + data = json.load(fhand) + for item in data: + date_s = item[0] + date_i = datetime.datetime.strptime(date_s, "%Y-%m-%dT%H:%M:%S.%f") + if date_i > time: + break + gain, offset = item[1:] + return {'gain': gain, 'offset': offset} + if __name__ == '__main__': time = datetime.datetime(2018, 1, 18, 12, 0) platform = 'MSG3' @@ -164,4 +192,12 @@ def _microwatts_to_milliwatts(microwatts): time=time) coefs[channel] = {'gain': gain, 'offset': offset} + for channel in ('IR_039', 'IR_087', 'IR_108', 'IR_120', + 'IR_134', 'IR_097', 'WV_062', 'WV_073'): + gain, offset = ir_calib_eumetsat(platform=platform, channel=channel, + time=time) + coefs[channel] = {'gain': gain, 'offset': offset} + + + print(coefs) diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index 9bcdff8..bdc931c 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -87,7 +87,7 @@ class UnexpectedSatpyVersion(Exception): def load_and_calibrate(filenames, rotate, - clip_calib): + clip_calib, path_to_external_ir_calibration): """Load and calibrate data. Uses inter-calibration coefficients from Meirink et al. @@ -109,8 +109,8 @@ def load_and_calibrate(filenames, rotate, calib_coefs = get_calibration( platform=info['platform_shortname'], time=info['start_time'], - clip=clip_calib - ) + clip=clip_calib, + path_to_external_ir_calibration=path_to_external_ir_calibration) scn_ = _create_scene(file_format, filenames, calib_coefs) _check_is_seviri_data(scn_) _load_bands(scn_, rotate) @@ -563,6 +563,7 @@ def _postproc_hrit(self, parsed): def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf', use_nominal_time_in_filename=False, clip_calib=False, + path_to_external_ir_calibration=None, save_azimuth_angles=False): """Make level 1c files in PPS-format.""" for fname in tslot_files: @@ -573,7 +574,8 @@ def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf', scn_ = load_and_calibrate( tslot_files, rotate=rotate, - clip_calib=clip_calib + clip_calib=clip_calib, + path_to_external_ir_calibration=path_to_external_ir_calibration, ) if hasattr(scn_, 'start_time'): scn_.attrs['start_time'] = scn_.start_time From fa641691410ac8d87137fade867618eb4dffaddd Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:56:20 +0100 Subject: [PATCH 2/9] flake8 --- level1c4pps/calibration_coefs.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/level1c4pps/calibration_coefs.py b/level1c4pps/calibration_coefs.py index f873e2e..8654aef 100644 --- a/level1c4pps/calibration_coefs.py +++ b/level1c4pps/calibration_coefs.py @@ -75,7 +75,6 @@ def get_calibration(platform, time, clip=False, path_to_external_ir_calibration= time=time, clip=clip ) - if path_to_external_ir_calibration is not None: for channel in ('IR_039', 'IR_087', 'IR_108', 'IR_120', 'IR_134', 'IR_097', 'WV_062', 'WV_073'): @@ -85,8 +84,6 @@ def get_calibration(platform, time, clip=False, path_to_external_ir_calibration= channel=channel, time=time, ) - - return coefs @@ -119,8 +116,9 @@ def _convert_to_datetime(date_or_time): def _is_date(date_or_time): + """Check that we have a datetime date object.""" # datetime is a subclass of date, therefore we cannot use isinstance here - return type(date_or_time) == datetime.date + return type(date_or_time) == datetime.date # noqa E721 def _check_is_valid_time(time): @@ -166,12 +164,12 @@ def _calc_gain_offset(a, b, days_since_ref_time): def _microwatts_to_milliwatts(microwatts): return microwatts / 1000.0 + def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=datetime.datetime(2048, 1, 18, 12, 0)): """Get IR calibration from EUMETSAT, modified by CMSAF.""" filename = "{:s}/TIR_calib_{:s}_{:s}.json".format(ir_calib_path, platform, channel) - with open(filename, 'r') as fhand: data = json.load(fhand) for item in data: @@ -181,7 +179,8 @@ def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=dat break gain, offset = item[1:] return {'gain': gain, 'offset': offset} - + + if __name__ == '__main__': time = datetime.datetime(2018, 1, 18, 12, 0) platform = 'MSG3' @@ -197,7 +196,4 @@ def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=dat gain, offset = ir_calib_eumetsat(platform=platform, channel=channel, time=time) coefs[channel] = {'gain': gain, 'offset': offset} - - - print(coefs) From 65db30d700db989e14e2016f421f7e9da7ece5ab Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:54:46 +0100 Subject: [PATCH 3/9] Add tests --- level1c4pps/seviri2pps_lib.py | 2 +- level1c4pps/tests/TIR_calib_MSG2_IR_039.json | 1 + level1c4pps/tests/TIR_calib_MSG2_IR_087.json | 1 + level1c4pps/tests/TIR_calib_MSG2_IR_097.json | 1 + level1c4pps/tests/TIR_calib_MSG2_IR_108.json | 1 + level1c4pps/tests/TIR_calib_MSG2_IR_120.json | 1 + level1c4pps/tests/TIR_calib_MSG2_IR_134.json | 1 + level1c4pps/tests/TIR_calib_MSG2_WV_062.json | 1 + level1c4pps/tests/TIR_calib_MSG2_WV_073.json | 1 + level1c4pps/tests/test_seviri2pps.py | 18 +++++++++++++++++- 10 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_039.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_087.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_097.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_108.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_120.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_IR_134.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_WV_062.json create mode 100644 level1c4pps/tests/TIR_calib_MSG2_WV_073.json diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index bdc931c..68011c0 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -87,7 +87,7 @@ class UnexpectedSatpyVersion(Exception): def load_and_calibrate(filenames, rotate, - clip_calib, path_to_external_ir_calibration): + clip_calib, path_to_external_ir_calibration=None): """Load and calibrate data. Uses inter-calibration coefficients from Meirink et al. diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_039.json b/level1c4pps/tests/TIR_calib_MSG2_IR_039.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_039.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_087.json b/level1c4pps/tests/TIR_calib_MSG2_IR_087.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_087.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_097.json b/level1c4pps/tests/TIR_calib_MSG2_IR_097.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_097.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_108.json b/level1c4pps/tests/TIR_calib_MSG2_IR_108.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_108.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_120.json b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_134.json b/level1c4pps/tests/TIR_calib_MSG2_IR_134.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_134.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_WV_062.json b/level1c4pps/tests/TIR_calib_MSG2_WV_062.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_WV_062.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/TIR_calib_MSG2_WV_073.json b/level1c4pps/tests/TIR_calib_MSG2_WV_073.json new file mode 100644 index 0000000..23a2ae8 --- /dev/null +++ b/level1c4pps/tests/TIR_calib_MSG2_WV_073.json @@ -0,0 +1 @@ +[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index 3d69f5a..59948f9 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -72,7 +72,7 @@ def test_load_and_calibrate(self, mocked_scene): res = seviri2pps.load_and_calibrate( filenames, rotate=False, - clip_calib=False + clip_calib=False, ) # Compare results and expectations @@ -613,6 +613,22 @@ def test_get_calibration(self, platform, timestamp, expected): coefs = calib.get_calibration(platform=platform, time=timestamp) self._assert_coefs_close(coefs, expected) + + def test_get_calibration_ir_no_file(self): + """Test get ir calibration with mising json file.""" + with pytest.raises(FileNotFoundError): + coefs = calib.get_calibration( + platform="MSG2", + time=dt.datetime(2007, 6, 5, 0, 0), + path_to_external_ir_calibration=".") + + def test_get_calibration_ir(self): + """Test get ir calibration with mising json file.""" + coefs = calib.get_calibration( + platform="MSG2", + time=dt.datetime(2007, 6, 18, 0, 0), + path_to_external_ir_calibration="./level1c4pps/tests/") + def test_calibration_is_smooth(self): """Test that calibration is smooth in time.""" coefs1 = calib.get_calibration( From d79ce178a4d2b7cecac356399d93979143d0ce64 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:10:31 +0100 Subject: [PATCH 4/9] Update function that processes all files in a directory --- level1c4pps/seviri2pps_lib.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index 68011c0..9dbabe3 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -630,7 +630,12 @@ def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf', return filename -def process_all_scans_in_dname(dname, out_path, ok_dates=None, rotate=False): +def process_all_scans_in_dname(dname, out_path, + ok_dates=None, + rotate=False, + path_to_external_ir_calibration=None, + save_azimuth_angles=False): + """Make level 1c files for all files in directory dname.""" parser = Parser(HRIT_FILE_PATTERN) fl_ = glob(os.path.join(dname, globify(HRIT_FILE_PATTERN))) @@ -647,6 +652,10 @@ def process_all_scans_in_dname(dname, out_path, ok_dates=None, rotate=False): tslot_files = [f for f in fl_ if parser.parse( os.path.basename(f))['start_time'] == uqdate] try: - process_one_scan(tslot_files, out_path, rotate=rotate) + process_one_scan(tslot_files, + out_path, + rotate=rotate, + path_to_external_ir_calibration=path_to_external_ir_calibration, + save_azimuth_angles=save_azimuth_angles) except Exception: pass From 58d6c4ec24bc9470bdf7bdda4dcd2a290c47610f Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:50:34 +0100 Subject: [PATCH 5/9] Review updates --- level1c4pps/calibration_coefs.py | 20 ++++++++++---------- level1c4pps/seviri2pps_lib.py | 2 +- level1c4pps/tests/test_seviri2pps.py | 7 ++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/level1c4pps/calibration_coefs.py b/level1c4pps/calibration_coefs.py index 8654aef..6f39b10 100644 --- a/level1c4pps/calibration_coefs.py +++ b/level1c4pps/calibration_coefs.py @@ -22,6 +22,7 @@ import datetime from enum import Enum import json +import os class CalibrationData(Enum): @@ -56,7 +57,7 @@ class CalibrationData(Enum): SATPY_CALIB_MODE = 'Nominal' -def get_calibration(platform, time, clip=False, path_to_external_ir_calibration=None): +def get_calibration(platform, time, clip=False, calib_ir_path=None): """Get MODIS-intercalibrated gain and offset for specific time. Args: @@ -75,11 +76,11 @@ def get_calibration(platform, time, clip=False, path_to_external_ir_calibration= time=time, clip=clip ) - if path_to_external_ir_calibration is not None: + if calib_ir_path is not None: for channel in ('IR_039', 'IR_087', 'IR_108', 'IR_120', 'IR_134', 'IR_097', 'WV_062', 'WV_073'): - coefs[channel] = ir_calib_eumetsat( - path_to_external_ir_calibration, + coefs[channel] = get_ir_calibration_coeffs( + calib_ir_path, platform=platform, channel=channel, time=time, @@ -165,11 +166,10 @@ def _microwatts_to_milliwatts(microwatts): return microwatts / 1000.0 -def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=datetime.datetime(2048, 1, 18, 12, 0)): +def get_ir_calibration_coeffs(ir_calib_path, platform="MSG2", channel="IR_039", time=datetime.datetime(2048, 1, 18, 12, 0)): """Get IR calibration from EUMETSAT, modified by CMSAF.""" - filename = "{:s}/TIR_calib_{:s}_{:s}.json".format(ir_calib_path, - platform, - channel) + + filename = os.path.join(ir_calib_path, f"TIR_calib_{platform}_{channel}.json") with open(filename, 'r') as fhand: data = json.load(fhand) for item in data: @@ -193,7 +193,7 @@ def ir_calib_eumetsat(ir_calib_path, platform="MSG2", channel="IR_039", time=dat for channel in ('IR_039', 'IR_087', 'IR_108', 'IR_120', 'IR_134', 'IR_097', 'WV_062', 'WV_073'): - gain, offset = ir_calib_eumetsat(platform=platform, channel=channel, - time=time) + gain, offset = get_ir_calibration_coeffs(platform=platform, channel=channel, + time=time) coefs[channel] = {'gain': gain, 'offset': offset} print(coefs) diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index 9dbabe3..450f9e1 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -110,7 +110,7 @@ def load_and_calibrate(filenames, rotate, platform=info['platform_shortname'], time=info['start_time'], clip=clip_calib, - path_to_external_ir_calibration=path_to_external_ir_calibration) + calib_ir_path=path_to_external_ir_calibration) scn_ = _create_scene(file_format, filenames, calib_coefs) _check_is_seviri_data(scn_) _load_bands(scn_, rotate) diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index 59948f9..5d84674 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -620,14 +620,15 @@ def test_get_calibration_ir_no_file(self): coefs = calib.get_calibration( platform="MSG2", time=dt.datetime(2007, 6, 5, 0, 0), - path_to_external_ir_calibration=".") + calib_ir_path=".") def test_get_calibration_ir(self): - """Test get ir calibration with mising json file.""" + """Test get ir calibration..""" coefs = calib.get_calibration( platform="MSG2", time=dt.datetime(2007, 6, 18, 0, 0), - path_to_external_ir_calibration="./level1c4pps/tests/") + calib_ir_path="./level1c4pps/tests/") + np.testing.assert_almost_equal(coefs['IR_120']['gain'], 0.003567, decimal=6) def test_calibration_is_smooth(self): """Test that calibration is smooth in time.""" From 60f521b6d520a5c7dd4fb352115d1c098050dfbc Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:15:01 +0100 Subject: [PATCH 6/9] As default look for external IR calibration (in ".") --- bin/seviri2pps.py | 7 +++++-- level1c4pps/calibration_coefs.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/seviri2pps.py b/bin/seviri2pps.py index 1b18033..f4e8913 100755 --- a/bin/seviri2pps.py +++ b/bin/seviri2pps.py @@ -50,10 +50,13 @@ help="Engine for saving netcdf files netcdf4 or h5netcdf (default).") parser.add_argument('--use-nominal-time-in-filename', action='store_true', help='Use nominal scan timestamps in output filename.') - parser.add_argument('--path_to_external_ir_calibration', type=str, default=None, + parser.add_argument('--path-to-external-ir-calibration', type=str, default=".", help='Path to external IR calibration.') - + parser.add_argument('--use-nominal-ir-calibration', action='store_true', + help='Use nominal IR claibration.') options = parser.parse_args() + if options.use_nominal_ir_calibration: + options.path_to_external_ir_calibration = None process_one_scan( options.files, out_path=options.out_dir, diff --git a/level1c4pps/calibration_coefs.py b/level1c4pps/calibration_coefs.py index 6f39b10..0c585a3 100644 --- a/level1c4pps/calibration_coefs.py +++ b/level1c4pps/calibration_coefs.py @@ -22,8 +22,11 @@ import datetime from enum import Enum import json +import logging import os +logger = logging.getLogger("calibration") + class CalibrationData(Enum): COEFS = dict( @@ -170,6 +173,7 @@ def get_ir_calibration_coeffs(ir_calib_path, platform="MSG2", channel="IR_039", """Get IR calibration from EUMETSAT, modified by CMSAF.""" filename = os.path.join(ir_calib_path, f"TIR_calib_{platform}_{channel}.json") + logger.info(f'Using IR calibration from {filename}') with open(filename, 'r') as fhand: data = json.load(fhand) for item in data: From 14e25db8d4c044ea849eeef4db0e2b176c17f2e2 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:21:57 +0100 Subject: [PATCH 7/9] flake8 --- level1c4pps/calibration_coefs.py | 5 +++-- level1c4pps/seviri2pps_lib.py | 1 - level1c4pps/tests/test_seviri2pps.py | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/level1c4pps/calibration_coefs.py b/level1c4pps/calibration_coefs.py index 0c585a3..554223a 100644 --- a/level1c4pps/calibration_coefs.py +++ b/level1c4pps/calibration_coefs.py @@ -126,6 +126,7 @@ def _is_date(date_or_time): def _check_is_valid_time(time): + """Check that we have a valid time.""" ref_time = CalibrationData.REF_TIME.value if time < ref_time: raise ValueError('Given time ({0}) is < reference time ({1})'.format( @@ -169,9 +170,9 @@ def _microwatts_to_milliwatts(microwatts): return microwatts / 1000.0 -def get_ir_calibration_coeffs(ir_calib_path, platform="MSG2", channel="IR_039", time=datetime.datetime(2048, 1, 18, 12, 0)): +def get_ir_calibration_coeffs(ir_calib_path, platform="MSG2", channel="IR_039", + time=datetime.datetime(2048, 1, 18, 12, 0)): """Get IR calibration from EUMETSAT, modified by CMSAF.""" - filename = os.path.join(ir_calib_path, f"TIR_calib_{platform}_{channel}.json") logger.info(f'Using IR calibration from {filename}') with open(filename, 'r') as fhand: diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index 450f9e1..9ea40da 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -635,7 +635,6 @@ def process_all_scans_in_dname(dname, out_path, rotate=False, path_to_external_ir_calibration=None, save_azimuth_angles=False): - """Make level 1c files for all files in directory dname.""" parser = Parser(HRIT_FILE_PATTERN) fl_ = glob(os.path.join(dname, globify(HRIT_FILE_PATTERN))) diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index 5d84674..59db6b1 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -613,7 +613,6 @@ def test_get_calibration(self, platform, timestamp, expected): coefs = calib.get_calibration(platform=platform, time=timestamp) self._assert_coefs_close(coefs, expected) - def test_get_calibration_ir_no_file(self): """Test get ir calibration with mising json file.""" with pytest.raises(FileNotFoundError): @@ -628,7 +627,7 @@ def test_get_calibration_ir(self): platform="MSG2", time=dt.datetime(2007, 6, 18, 0, 0), calib_ir_path="./level1c4pps/tests/") - np.testing.assert_almost_equal(coefs['IR_120']['gain'], 0.003567, decimal=6) + np.testing.assert_almost_equal(coefs['IR_120']['gain'], 0.003567, decimal=6) def test_calibration_is_smooth(self): """Test that calibration is smooth in time.""" From 06768b2499f618d4bde04459125bf9e258928cc8 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:41:41 +0100 Subject: [PATCH 8/9] Improve the testcase --- level1c4pps/tests/TIR_calib_MSG2_IR_120.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_120.json b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json index 23a2ae8..7da3445 100644 --- a/level1c4pps/tests/TIR_calib_MSG2_IR_120.json +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json @@ -1 +1 @@ -[["2007-06-05T00:00:00.000",0.0035676316,-0.1819492105]] +[["2007-06-05T00:00:00.000",0.0035676316,-1.819492105],["2007-06-06T17:59:0.000",0.0035676316,-0.1819492105],["2007-06-09T00:00:00.000",0.0035676316,-1.819492105]] From bb8262eb626816761d1842aab4282c7ef01e7021 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" <6160529+ninahakansson@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:53:07 +0100 Subject: [PATCH 9/9] Update testcase again --- level1c4pps/tests/TIR_calib_MSG2_IR_120.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1c4pps/tests/TIR_calib_MSG2_IR_120.json b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json index 7da3445..a747427 100644 --- a/level1c4pps/tests/TIR_calib_MSG2_IR_120.json +++ b/level1c4pps/tests/TIR_calib_MSG2_IR_120.json @@ -1 +1 @@ -[["2007-06-05T00:00:00.000",0.0035676316,-1.819492105],["2007-06-06T17:59:0.000",0.0035676316,-0.1819492105],["2007-06-09T00:00:00.000",0.0035676316,-1.819492105]] +[["2007-06-05T00:00:00.000",0.035676316,-1.819492105],["2007-06-17T23:59:0.000",0.0035676316,-0.1819492105],["2007-06-18T01:00:00.000",0.035676316,-1.819492105]]