Skip to content

Commit

Permalink
Refactor SNO finder
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <a000680@c22526.ad.smhi.se>
  • Loading branch information
Adam.Dybbroe committed Jun 16, 2024
1 parent dc78d11 commit fe60b58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pyorbital/sno_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
import logging


class PlatformNotSupported(Exception):
"""Exception error when platform is not supported."""

pass


OSCAR_NAMES = {'npp': 'Suomi-NPP',
'snpp': 'Suomi-NPP',
'aqua': 'EOS-Aqua',
Expand Down Expand Up @@ -99,6 +105,13 @@ def __init__(self, platform_id, calipso_id, time_window, sno_min_thr, arc_len_mi
self._tle_buffer_calipso = {}
self._tle_buffer_other = {}

self._check_platforms()

def _check_platforms(self):
# Check if satellite is supported:
if OSCAR_NAMES.get(self.platform_id, self.platform_id).upper() not in SATELLITES.keys():
raise PlatformNotSupported(f"Platform {self.platform_id} not supported!")

def set_configuration(self, configfile):
"""Set the basic configuration from yaml config file."""
conf = get_config(configfile)
Expand Down Expand Up @@ -136,12 +149,6 @@ def get_snos_within_time_window(self):
tle_dirs = self._conf['tle-dirs']
tle_file_format = self._conf['tle-file-format']

import sys
# Check if satellite is supported:
if OSCAR_NAMES.get(self.platform_id, self.platform_id).upper() not in SATELLITES.keys():
LOG.error("Platform %s not supported!" % self.platform_id)
sys.exit()

pobj = Parser(tle_file_format)
for tledir in tle_dirs:
filename_calipso = Path(tledir) / pobj.compose({'platform': self.calipso_id})
Expand Down Expand Up @@ -207,7 +214,7 @@ def get_snos_within_time_window(self):

got_intersection_acurate = False
arc_calipso_vector = get_arc_vector(tobj, timestep_plus_30s, calipso, self.arc_len_min)
arc_the_other_one_vector = get_arc_vector(tobj, timestep_plus_30s, the_other_one, self.arc_len_min)
arc_the_other_one_vector = get_arc_vector(tobj, timestep_plus_30s, the_other_one, self.arc_len_min)
# Approximate tracks with one arc each self.arc_len_min minutes.
# For each pair of arcs check if they intersect.
# There is atmost one intersection. Quit when we find it.
Expand Down
16 changes: 16 additions & 0 deletions pyorbital/tests/test_snos.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from datetime import timezone
from pyorbital.sno_utils import SNOfinder
from pyorbital.sno_utils import check_overlapping_times
from pyorbital.sno_utils import PlatformNotSupported
# from pyorbital.config import get_config
from pyorbital.tests.test_helper import get_dataframe_from_ascii
from pyorbital.tests.test_helper import df2geojson
Expand Down Expand Up @@ -61,6 +62,21 @@
"""


def test_snofinder_unsupported_platform(fake_yamlconfig_file, fake_tle_file1_calipso, fake_tle_file1_snpp):
"""Test the SNO finder when one of the platform names are not supported."""
platform_one = 'PARASOL'
platform_two = 'calipso'
time_window = (dt.datetime(2014, 1, 3, tzinfo=timezone.utc),
dt.datetime(2014, 1, 4, tzinfo=timezone.utc))
sno_min_thr = 2 # SNOs allowed to have 2 minute deviation between the two platforms

with pytest.raises(PlatformNotSupported) as exec_info:
_ = SNOfinder(platform_one, platform_two, time_window, sno_min_thr)

exception_raised = exec_info.value
assert str(exception_raised) == "Platform PARASOL not supported!"


def test_get_snos_calipso_snpp(fake_yamlconfig_file, fake_tle_file1_calipso, fake_tle_file1_snpp):
"""Test finding calipso and SNPP SNOs within time window."""
platform_one = 'snpp'
Expand Down

0 comments on commit fe60b58

Please sign in to comment.