Skip to content

Filtering

Satellite filtering system for narrowing satellite catalogs.

Filterer

Filterer

Filterer()

Applies a chain of filter functions to a satellite list.

Filters are combined with AND logic: a satellite must pass every filter to be included in the output. Supports method chaining.

Example::

filterer = (
    Filterer()
    .add_filter(filter_name_contains("STARLINK"))
    .add_filter(filter_orbit_is("leo"))
)
filtered = filterer.apply_filters(satellites)
Source code in src/sopp/filtering/filterer.py
def __init__(self):
    self._filters: list[Callable[[Satellite], bool]] = []

Functions

add_filter

add_filter(filter_lambda: Callable[[Satellite], bool])

Add a filter function. Returns self for chaining.

Source code in src/sopp/filtering/filterer.py
def add_filter(self, filter_lambda: Callable[[Satellite], bool]):
    """Add a filter function. Returns self for chaining."""
    if filter_lambda:
        self._filters.append(filter_lambda)
    return self

apply_filters

apply_filters(elements: list[Satellite]) -> list[Satellite]

Return only satellites that pass all filters.

Source code in src/sopp/filtering/filterer.py
def apply_filters(self, elements: list[Satellite]) -> list[Satellite]:
    """Return only satellites that pass all filters."""
    return [
        element for element in elements if all(f(element) for f in self._filters)
    ]

Preset Filters

Built-in satellite filter functions.

Each function returns a predicate (Satellite) -> bool suitable for use with :class:~sopp.filtering.filterer.Filterer.

Classes

Functions

filter_frequency

filter_frequency(
    observation_frequency: FrequencyRange,
) -> Callable[[Satellite], bool]

Include satellites whose downlink frequency overlaps the observation band.

Satellites with no frequency data are included (erring on the side of caution). Inactive transmissions are excluded.

Parameters:

Name Type Description Default
observation_frequency FrequencyRange

The observation frequency range.

required
Source code in src/sopp/filtering/presets.py
def filter_frequency(
    observation_frequency: FrequencyRange,
) -> Callable[[Satellite], bool]:
    """Include satellites whose downlink frequency overlaps the observation band.

    Satellites with no frequency data are included (erring on the side of
    caution). Inactive transmissions are excluded.

    Args:
        observation_frequency: The observation frequency range.
    """

    def filter_function(satellite: Satellite) -> bool:
        if observation_frequency:
            return (
                not satellite.frequency
                or any(sf.frequency is None for sf in satellite.frequency)
                or any(
                    sf.status != "inactive" and observation_frequency.overlaps(sf)
                    for sf in satellite.frequency
                )
            )
        else:
            return True

    return filter_function

filter_name_regex

filter_name_regex(
    regex: str,
) -> Callable[[Satellite], bool]

Include satellites whose name matches a regex pattern.

Parameters:

Name Type Description Default
regex str

Regular expression to match against satellite names.

required
Source code in src/sopp/filtering/presets.py
def filter_name_regex(regex: str) -> Callable[[Satellite], bool]:
    """Include satellites whose name matches a regex pattern.

    Args:
        regex: Regular expression to match against satellite names.
    """
    pattern = re.compile(regex)

    def filter_function(satellite: Satellite) -> bool:
        return not regex or bool(pattern.search(satellite.name))

    return filter_function

filter_name_contains

filter_name_contains(
    substring: str,
) -> Callable[[Satellite], bool]

Include satellites whose name contains the given substring.

Parameters:

Name Type Description Default
substring str

Substring to search for in satellite names.

required
Source code in src/sopp/filtering/presets.py
def filter_name_contains(substring: str) -> Callable[[Satellite], bool]:
    """Include satellites whose name contains the given substring.

    Args:
        substring: Substring to search for in satellite names.
    """

    def filter_function(satellite: Satellite) -> bool:
        return not substring or substring in satellite.name

    return filter_function

filter_name_does_not_contain

filter_name_does_not_contain(
    substring: str,
) -> Callable[[Satellite], bool]

Exclude satellites whose name contains the given substring.

Parameters:

Name Type Description Default
substring str

Substring to exclude from satellite names.

required
Source code in src/sopp/filtering/presets.py
def filter_name_does_not_contain(substring: str) -> Callable[[Satellite], bool]:
    """Exclude satellites whose name contains the given substring.

    Args:
        substring: Substring to exclude from satellite names.
    """

    def filter_function(satellite: Satellite) -> bool:
        return not substring or not filter_name_contains(substring)(satellite)

    return filter_function

filter_name_is

filter_name_is(
    substring: str,
) -> Callable[[Satellite], bool]

Include only satellites whose name matches exactly.

Parameters:

Name Type Description Default
substring str

Exact name to match.

required
Source code in src/sopp/filtering/presets.py
def filter_name_is(substring: str) -> Callable[[Satellite], bool]:
    """Include only satellites whose name matches exactly.

    Args:
        substring: Exact name to match.
    """

    def filter_function(satellite: Satellite) -> bool:
        return not substring or substring == satellite.name

    return filter_function

filter_orbit_is

filter_orbit_is(
    orbit_type: str,
) -> Callable[[Satellite], bool]

Include satellites in a specific orbit regime.

Parameters:

Name Type Description Default
orbit_type str

One of 'leo', 'meo', or 'geo'.

required

Raises:

Type Description
ValueError

If orbit_type is not recognized.

Source code in src/sopp/filtering/presets.py
def filter_orbit_is(orbit_type: str) -> Callable[[Satellite], bool]:
    """Include satellites in a specific orbit regime.

    Args:
        orbit_type: One of 'leo', 'meo', or 'geo'.

    Raises:
        ValueError: If orbit_type is not recognized.
    """

    def filter_function(satellite: Satellite) -> bool:
        if orbit_type == "leo":
            return satellite.orbits_per_day >= 5.0
        elif orbit_type == "meo":
            return satellite.orbits_per_day >= 1.5 and satellite.orbits_per_day < 5.0
        elif orbit_type == "geo":
            return satellite.orbits_per_day >= 0.85 and satellite.orbits_per_day < 1.5
        elif not orbit_type:
            return True
        else:
            raise ValueError("Invalid orbit type. Provide 'leo', 'meo', or 'geo'.")

    return filter_function