Skip to content

flight_collection module

Collection of Data to Science flights associated with a project.

Source code in d2spy/models/flight_collection.py
class FlightCollection:
    """Collection of Data to Science flights associated with a project."""

    def __init__(self, collection: List[Flight] = []):
        self.collection = collection

    def __getitem__(self, index: int) -> Flight:
        return self.collection[int(index)]

    def __len__(self) -> int:
        return len(self.collection)

    def __repr__(self) -> str:
        return f"FlightCollection({self.collection})"

    def filter_by_date(self, start_date: date, end_date: date) -> "FlightCollection":
        """Returns collection of flights within the acquisition date range.

        Args:
            start_date (date): Starting date for the flight acquisition date range.
            end_date (date): Ending date for the flight acquisition date range.

        Returns:
            FlightCollection: Collection of flights within the acquisition date range.
        """
        filtered_collection = [
            flight
            for flight in self.collection
            if convert_from_str_to_date(flight.acquisition_date) >= start_date
            and convert_from_str_to_date(flight.acquisition_date) <= end_date
        ]
        return FlightCollection(collection=filtered_collection)

    def filter_by_sensor(self, sensor: str, exact: bool = False) -> "FlightCollection":
        """Returns collection of flights with specified sensor.

        Args:
            sensor (str): Sensor of interest.
            exact (bool, optional): Must be exact match. Defaults to False.

        Returns:
            FlightCollection: Collection of flights with matching sensor.
        """
        filtered_collection = [
            flight
            for flight in self.collection
            if is_match(sensor, flight.sensor, exact)
        ]
        return FlightCollection(collection=filtered_collection)

filter_by_date(start_date, end_date)

Returns collection of flights within the acquisition date range.

Parameters:

Name Type Description Default
start_date date

Starting date for the flight acquisition date range.

required
end_date date

Ending date for the flight acquisition date range.

required

Returns:

Name Type Description
FlightCollection FlightCollection

Collection of flights within the acquisition date range.

Source code in d2spy/models/flight_collection.py
def filter_by_date(self, start_date: date, end_date: date) -> "FlightCollection":
    """Returns collection of flights within the acquisition date range.

    Args:
        start_date (date): Starting date for the flight acquisition date range.
        end_date (date): Ending date for the flight acquisition date range.

    Returns:
        FlightCollection: Collection of flights within the acquisition date range.
    """
    filtered_collection = [
        flight
        for flight in self.collection
        if convert_from_str_to_date(flight.acquisition_date) >= start_date
        and convert_from_str_to_date(flight.acquisition_date) <= end_date
    ]
    return FlightCollection(collection=filtered_collection)

filter_by_sensor(sensor, exact=False)

Returns collection of flights with specified sensor.

Parameters:

Name Type Description Default
sensor str

Sensor of interest.

required
exact bool

Must be exact match. Defaults to False.

False

Returns:

Name Type Description
FlightCollection FlightCollection

Collection of flights with matching sensor.

Source code in d2spy/models/flight_collection.py
def filter_by_sensor(self, sensor: str, exact: bool = False) -> "FlightCollection":
    """Returns collection of flights with specified sensor.

    Args:
        sensor (str): Sensor of interest.
        exact (bool, optional): Must be exact match. Defaults to False.

    Returns:
        FlightCollection: Collection of flights with matching sensor.
    """
    filtered_collection = [
        flight
        for flight in self.collection
        if is_match(sensor, flight.sensor, exact)
    ]
    return FlightCollection(collection=filtered_collection)