Git Product home page Git Product logo

Comments (5)

zigaLuksic avatar zigaLuksic commented on July 22, 2024

Hi @ColinMoldenhauer

thanks for the suggestion. We'll try to see if there is a neat option for the user to provide the filtration function directly, to also solve any similar issues in the future.

from eo-learn.

ColinMoldenhauer avatar ColinMoldenhauer commented on July 22, 2024

Good idea! Something along these lines?

In eolearn.io.sentinelhub_process.py

  • introduce filter_timestamps parameter to get_available_timestamps
  • introduce filter_timestamps parameter to __init__()
  • save as "private" method
  • pass filtering method in _get_timestamp()
from sentinelhub import filter_times as sentinelhub_filter_times

class SentinelHubInputTask(SentinelHubInputBaseTask):
    def __init__(
        self,
        ....
        filter_timestamps=False,
        ...
    ):
		"""
                :param ...
		:param filter_timestamps: A Callable that filters the timestamps returned by get_available_timestamps, returning them in a list.
                : param ...
		"""
        ...
        self._filter_timestamps = filter_timestamps or sentinelhub_filter_times
        ...

    def _get_timestamp(self, time_interval, bbox):
        """Get the timestamp array needed as a parameter for downloading the images"""
        if self.single_scene:
            return [time_interval[0]]

        return get_available_timestamps(
            bbox=bbox,
            time_interval=time_interval,
            data_collection=self.data_collection,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            filter_timestamps=self._filter_timestamps,
            config=self.config,
        )

# copy of get_available_timestamps, where only filtering in the last line is replaced with 
# the newly passed function filter_timestamps
def get_available_timestamps(
    bbox: BBox,
    data_collection: DataCollection,
    *,
    time_interval: Optional[Tuple[dt.datetime, dt.datetime]] = None,
    time_difference: dt.timedelta = dt.timedelta(seconds=-1),
    filter_timestamps: Optional[Callable] = None,
    maxcc: Optional[float] = None,
    config: Optional[SHConfig] = None,
) -> List[dt.datetime]:
    ...
    filter_timestamps = filter_timestamps or sentinelhub_filter_times
    ....
    return filter_timestamps(all_timestamps, time_difference)

Define own filtering function somewhere, e.g. in timestamp_filters.py

# an adapted version of filter_times, allowing for reverse filtering
def my_filter_times_reverse(timestamps: Iterable[TimeType],
                 time_difference: dt.timedelta) -> List[TimeType]:
    """Filters out timestamps within time_difference, preserving only the most recent timestamp.

    :param timestamps: A list of timestamps.
    :param time_difference: A time difference threshold.
    :return: An ordered list of timestamps `d_1 <= d_2 <= ... <= d_n` such that `d_(i+1)-d_i > time_difference`.
    """
    timestamps = sorted(set(timestamps))[::-1]

    filtered_timestamps: List[TimeType] = []

    for current_timestamp in timestamps:
        if not filtered_timestamps or filtered_timestamps[-1] - current_timestamp > time_difference:
            filtered_timestamps.append(current_timestamp)

    return filtered_timestamps[::-1]

Usage

from timestamp_filters import my_filter_times_reverse

input_task = SentinelHubInputTask(
	...
	filter_timestamps=my_filter_times,
	...
)

Not sure if other tasks would need to be updated, too 🤷

Best,
Colin

from eo-learn.

zigaLuksic avatar zigaLuksic commented on July 22, 2024

Something along these lines yes, anything else feels like we'd have to re-do it in a few months for another use-case.

We are planning a minor release this month (if all goes well), and this will likely be included. If you wish we can include you in the pull-request process once we get around to it.

from eo-learn.

ColinMoldenhauer avatar ColinMoldenhauer commented on July 22, 2024

We are planning a minor release this month (if all goes well), and this will likely be included. If you wish we can include you in the pull-request process once we get around to it.

That would be great!

from eo-learn.

zigaLuksic avatar zigaLuksic commented on July 22, 2024

was released in 1.3.1

from eo-learn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.