-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed s2MergeByTime bug, backwards compatible #11
Open
EtienneKras
wants to merge
2
commits into
gee-community:main
Choose a base branch
from
EtienneKras:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,12 @@ def getImages(g, options): | |
|
||
if options and 's2MergeByTime' in options: | ||
s2MergeByTime = options['s2MergeByTime'] | ||
|
||
|
||
s2TimeMerger = False | ||
|
||
if options and 's2TimeMerger' in options: | ||
s2TimeMerger = options['s2TimeMerger'] | ||
|
||
cloudMask = False | ||
|
||
if options and 'cloudMask' in options: | ||
|
@@ -200,7 +205,7 @@ def clipNegativeFootprint(i): | |
|
||
# merge by time (remove duplicates) | ||
if s2MergeByTime: | ||
s2 = mosaicByTime(s2) | ||
s2 = mosaicByTime(s2, s2TimeMerger) | ||
|
||
def f2(i): | ||
return (i | ||
|
@@ -309,8 +314,17 @@ def f(i): | |
# * | ||
# * This function mosaics images by time. | ||
# */ | ||
def mosaicByTime(images): | ||
TIME_FIELD = 'system:time_start' | ||
def mosaicByTime(images, *args): | ||
if 'dd' in args: # for rounding up until days | ||
def f(i): | ||
dateField = ee.Date(i.get('system:time_start')).format('YYYYMMdd') #hhmmss.SSS rounded to a minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can specify also specify an allowed time window, but this works and is fast! |
||
return i.set({'dateField':dateField}) | ||
|
||
images = images.map(f) | ||
|
||
TIME_FIELD = 'dateField' | ||
else: | ||
TIME_FIELD = 'system:time_start' | ||
|
||
distinct = images.distinct([TIME_FIELD]) | ||
|
||
|
@@ -323,7 +337,7 @@ def merge_matches(i): | |
matchedImages = ee.ImageCollection.fromImages(i.get('matches')) | ||
mosaic = matchedImages.sort('system:index').mosaic().set({ 'system:footprint': matchedImages.geometry() }) | ||
|
||
return mosaic.copyProperties(i).set(TIME_FIELD, i.get(TIME_FIELD)) | ||
return mosaic.copyProperties(i).set('system:time_start', i.get('system:time_start')) # hard-coded time_start instead of TIME_FIELD to be consistent | ||
|
||
results = results.map(merge_matches) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why should we expose internal knowledge about S2 to the outside options, I'd rather keep this encapsulated (hidden within the package) ... but we already have s2MergeByTime ... let's maybe discuss what we're trying to achieve here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was trying to achieve is to correctly filter out S2 images as I still got multiple images at the same time. We were not sure whether this was a bug or something that you were aware of. Therefore, in discussion with Jaap, I implemented it backwards compatible for the time being. In this way, we could discuss with you if we would keep it like this or implement the change in the code in general. Lets indeed discuss if you still have questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality should be already there by default, in ee-packages > assets. If it's buggy - we need to fix it there instead of exposing it to the bathymetry package (SRP). I can imagine there are bugs, so may require some debugging.