Comments (6)
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.
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.
Thanks for the clarification @mlubej!
from eo-learn.
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.
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.
Closing an old issue which was solved with EOPatch.merge
functionality.
from eo-learn.
Related Issues (20)
- [BUG] ImportError: cannot import name 'PointSamplingTask' from 'eolearn.geometry' HOT 5
- SI_LULC_pipeline notebook HOT 9
- readthedocs links not working HOT 1
- [FEAT] Enable timestamp filtering from interval end towards interval start HOT 5
- [BUG] SentinelHubInputTask downloads incorrect timestamps HOT 6
- [BUG] Issue with the SpatialResizeTask in ImportTiffPipeline when using the resolution approach HOT 5
- [BUG] eo-learn installation issue due to open-cv latest update on Dec 30, 2022. HOT 2
- Registration HOT 4
- [BUG] Failing tests on MacOS related to lock-related EOExecutor tests HOT 1
- [BUG] Reading EOPatches saved with eo-learn 0.10.1 with eolearn 1.4 HOT 2
- [HELP] Where has eopatch_to_dataset gone? HOT 6
- [FEAT] TDigestTask handle nans HOT 1
- [HELP] Error when I'm trying to run land-cover-map HOT 5
- [HELP] Perform sen2cor atmospheric correction on L1C EOPatch HOT 2
- [HELP] Using eo-learn for the classification of land surface types of Ukraine HOT 23
- Why I have problems with these imports? HOT 3
- ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz executables are on your systems' PATH HOT 3
- how do i fix this HOT 2
- CRSError in rasterio when using ExportToTiffTask HOT 6
- `eo-learn` 1.5.0 migration guide
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eo-learn.