Git Product home page Git Product logo

Comments (6)

wouellette avatar wouellette commented on July 19, 2024 1

I am starting to work on this component for internal use. Will re-open the issue if/when I get something substantial.

from eo-learn.

mlubej avatar mlubej commented on July 19, 2024

Hi @Spiruel!

Unfortunately, the OverwritePermission.ADD_ONLY does not work in this way. The addition is done in the sense of adding new features, not augmenting the existing ones (even if you are basically just adding additional timestamps).

The quickest way is to just change the time_interval and redownload the data for the new time interval.

Otherwise, if your new time interval is a subset of the original one, you could use the filtering EOTask to discard the timestamps and the corresponding arrays out of the EOPatch.

And the last scenario that could work is to create your own EOTask which updates the existing EOPatch by appropriately adding data from the changed time interval. This is on our TODO list, but haven't gotten around it just yet. If you manage to contribute to this, it would be much appreciated.

Cheers,
Matic

from eo-learn.

Spiruel avatar Spiruel commented on July 19, 2024

Thanks for the clarification @mlubej!

from eo-learn.

devisperessutti avatar devisperessutti commented on July 19, 2024

Didn't have time to port this to eo-learn yet, but might be a good starting point.

It takes a list of eopatches and temporally concatenates them. If dates are present more than once in original list of eopatches, they won't be duplicated in resulting eopatch. The time_periods list at initialisation is used to order temporally the eopatches.

class TemporalConcatenationTask(EOTask):
    """ Task to concatenate temporally a list of eopatches

    Only the DATA and MASK features are concatenated. The task assumes all patches contain the same features
    """
    def __init__(self, time_periods):
        """ Time periods will be sorted, assuming the 'YEAR/QX' format.

        :param time_periods: List of time periods to be concatenated, such as ['2018/Q4', '2019/Q1', '2019/Q2']
        :type time_periods: list of str
        :return: EOPatch with temporally concatenated arrays
        """
        self.time_periods = sorted(time_periods)
        self.time_indices = sorted(range(len(time_periods)), key=lambda k: time_periods[k])

    def execute(self, *eopatches):
        """ Sort patches temporally according to time_periods and concatenate starting from first """
        # sort list of eopatches according to provided time indices, e.g. eop_2019_q1, eop_2019_q2, eop_2019_q3
        eopatches = [eopatches[tidx] for tidx in self.time_indices]
        # get a list of timestamps of sorted eopatches. Timestamps are lists, so this is a list of lists
        timestamp_list = [eop.timestamp for eop in eopatches]
        # this mask finds dates in the next time period that are the same as the previous time period. The first
        # loop iterationloop will return (2019_q1_datetimes, 2019_q2_datetimes) and find the dates in 2019_q2 that match
        # the dates in 2019_q1. These will be ignored when concatenating 2019_q2
        masks = [np.isin(time_post, list(set(time_post).difference(set(time_pre))))
                 for time_pre, time_post in zip(timestamp_list[:-1], timestamp_list[1:])]
        # create concatenated timestamp by removing duplicated dates in trailing time periods
        timestamp = eopatches[0].timestamp + [tstamp for eop, mask in zip(eopatches[1:], masks)
                                              for tstamp, to_keep in zip(eop.timestamp, mask) if to_keep]
        # sort time periods in case the two sequences had a different time_difference
        sorted_indices = sorted(range(len(timestamp)), key=lambda k: timestamp[k])

        eop = EOPatch(bbox=eopatches[0].bbox, timestamp=sorted(timestamp))

        # TODO: add SCALAR
        # TODO: add check so that only features contained by all patches are concatenated
        for feature_type in [FeatureType.DATA, FeatureType.MASK]:
            for feature_name in eopatches[0][feature_type].keys():
                feat = (feature_type, feature_name)
                array = np.concatenate((eopatches[0][feat],
                                        *[eop[feat][mask] for eop, mask in zip(eopatches[1:], masks)]), axis=0)
                eop[feat] = array[sorted_indices]

        eop.meta_info['time_interval'] = (eop.timestamp[0].date().isoformat(),
                                          eop.timestamp[-1].date().isoformat())

        eop.meta_info['info'] = 'Temporally concatenated from {}'.format(' '.join(self.time_periods))

        return eop

from eo-learn.

wouellette avatar wouellette commented on July 19, 2024

PR 211 attempts at implementing such a solution via the EOPatch.save and OverwritePermission methods, as it feels like the most logical place to do it in my opinion.

The solution relies heavily on @devisperessutti's snippet. Thanks for that!

from eo-learn.

AleksMat avatar AleksMat commented on July 19, 2024

Closing an old issue which was solved with EOPatch.merge functionality.

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.