Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sensor list in topic #154

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pytroll_collectors/scisys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
ninahakansson marked this conversation as resolved.
Show resolved Hide resolved
to_send_dict["sensor"] = "MULTIPLE_SENSORS"
ninahakansson marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
18 changes: 18 additions & 0 deletions pytroll_collectors/tests/test_scisys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Loading