From a0fe0787d72a823fdfc693fd1a730dc730a09631 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Tue, 23 Apr 2024 13:30:00 +0200 Subject: [PATCH 1/3] In case of list of sensor, use MULTIPLE_SENSORS in topic --- pytroll_collectors/scisys.py | 16 +++++++++++++--- pytroll_collectors/tests/test_scisys.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pytroll_collectors/scisys.py b/pytroll_collectors/scisys.py index 528c1ea0..f958308c 100755 --- a/pytroll_collectors/scisys.py +++ b/pytroll_collectors/scisys.py @@ -62,8 +62,8 @@ 'jpss1': 'NOAA-20', 'noaa20': 'NOAA-20', 'noaa21': 'NOAA-21', - 'noaa21': 'NOAA-22', - 'noaa21': 'NOAA-23', + 'noaa22': 'NOAA-22', + 'noaa23': 'NOAA-23', 'j01': 'NOAA-20', 'j02': 'NOAA-21', 'j03': 'NOAA-22', @@ -503,9 +503,19 @@ def stop(self): self.loop = False +def update_sensor_tuple_or_list(to_send, config): + """Update sensor tuples and lists to MULTIPLE_SENSORS.""" + to_send_dict = to_send.copy() + if "sensor" in to_send: + if type(to_send["sensor"]) is list or type(to_send["sensor"]) is tuple: + to_send_dict["sensor"] = "MULTIPLE_SENSORS" + return to_send_dict + + def get_subject_from_message_and_config(to_send, config): """Get the publish topic from the message and the yaml configuration settings.""" - return compose(config['publish_topic_pattern'], to_send) + to_send_dict = update_sensor_tuple_or_list(to_send, config) + return compose(config['publish_topic_pattern'], to_send_dict) def receive_from_zmq(config_filename, diff --git a/pytroll_collectors/tests/test_scisys.py b/pytroll_collectors/tests/test_scisys.py index 728a7998..ae689084 100644 --- a/pytroll_collectors/tests/test_scisys.py +++ b/pytroll_collectors/tests/test_scisys.py @@ -291,3 +291,21 @@ def test_create_message_topic_from_message_and_config_pattern(sensor, sensor_nam subject = get_subject_from_message_and_config(to_send, config) assert subject == topic_result + + +def test_no_sensor_list_in_sending_topic(): + """Test that list of sensors are replaced with string MULTIPLE_SENSORS/.""" + to_send = {'start_time': datetime.datetime(2024, 4, 23, 5, 34, 4), + 'end_time': datetime.datetime(2024, 4, 23, 5, 39, 34), + 'orbit_number': 78360, + 'platform_name': 'NOAA-19', + 'type': 'binary', + 'format': 'HRPT', + 'sensor': ('avhrr/3', 'mhs', 'amsu-a', 'hirs/4'), + 'data_processing_level': '0', + 'uid': '20240423053404_NOAA_19.hmf', + 'uri': '/path/to/dummy/hrpt/20240423053404_NOAA_19.hmf', + 'variant': 'DR'} + my_config = ({'publish_topic_pattern': "/{sensor}/{format}/TEST/"}) + subject = get_subject_from_message_and_config(to_send, my_config) + assert subject == "/MULTIPLE_SENSORS/HRPT/TEST/" From 81ff0e603c0b67de00c2225808d5181b408ca8b7 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Fri, 3 May 2024 12:42:12 +0200 Subject: [PATCH 2/3] Changed to lower case multiple_sensors --- pytroll_collectors/scisys.py | 6 +++--- pytroll_collectors/tests/test_scisys.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pytroll_collectors/scisys.py b/pytroll_collectors/scisys.py index f958308c..406c96fc 100755 --- a/pytroll_collectors/scisys.py +++ b/pytroll_collectors/scisys.py @@ -504,11 +504,11 @@ def stop(self): def update_sensor_tuple_or_list(to_send, config): - """Update sensor tuples and lists to MULTIPLE_SENSORS.""" + """Update sensor tuples and lists to multiple_sensors.""" to_send_dict = to_send.copy() if "sensor" in to_send: - if type(to_send["sensor"]) is list or type(to_send["sensor"]) is tuple: - to_send_dict["sensor"] = "MULTIPLE_SENSORS" + if isinstance(to_send["sensor"], list) or isinstance(to_send["sensor"], tuple): + to_send_dict["sensor"] = "multiple_sensors" return to_send_dict diff --git a/pytroll_collectors/tests/test_scisys.py b/pytroll_collectors/tests/test_scisys.py index ae689084..b1b0daef 100644 --- a/pytroll_collectors/tests/test_scisys.py +++ b/pytroll_collectors/tests/test_scisys.py @@ -294,7 +294,7 @@ def test_create_message_topic_from_message_and_config_pattern(sensor, sensor_nam def test_no_sensor_list_in_sending_topic(): - """Test that list of sensors are replaced with string MULTIPLE_SENSORS/.""" + """Test that list of sensors are replaced with string multiple_sensors/.""" to_send = {'start_time': datetime.datetime(2024, 4, 23, 5, 34, 4), 'end_time': datetime.datetime(2024, 4, 23, 5, 39, 34), 'orbit_number': 78360, @@ -308,4 +308,4 @@ def test_no_sensor_list_in_sending_topic(): 'variant': 'DR'} my_config = ({'publish_topic_pattern': "/{sensor}/{format}/TEST/"}) subject = get_subject_from_message_and_config(to_send, my_config) - assert subject == "/MULTIPLE_SENSORS/HRPT/TEST/" + assert subject == "/multiple_sensors/HRPT/TEST/" From f9d9b11915f4e54549d47548ab1ce130da503c95 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Tue, 24 Sep 2024 10:53:38 +0200 Subject: [PATCH 3/3] Docstring update --- pytroll_collectors/tests/test_scisys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytroll_collectors/tests/test_scisys.py b/pytroll_collectors/tests/test_scisys.py index b1b0daef..3635bfeb 100644 --- a/pytroll_collectors/tests/test_scisys.py +++ b/pytroll_collectors/tests/test_scisys.py @@ -294,7 +294,7 @@ def test_create_message_topic_from_message_and_config_pattern(sensor, sensor_nam def test_no_sensor_list_in_sending_topic(): - """Test that list of sensors are replaced with string multiple_sensors/.""" + """Test that a list of sensors is replaced with string multiple_sensors/.""" to_send = {'start_time': datetime.datetime(2024, 4, 23, 5, 34, 4), 'end_time': datetime.datetime(2024, 4, 23, 5, 39, 34), 'orbit_number': 78360,