Skip to content
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

Fixes modifier attribute getting replaced instead of merged with existing one when applying modifications #2333

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BENR0
Copy link
Collaborator

@BENR0 BENR0 commented Dec 20, 2022

If a modifier e.g. SunZenithCorrector is applied to a DataArray (as in #1490) which already has a modifier attribute instead of replacing the existing attribute modification get merged.

  • Closes #xxxx
  • Tests added

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little scared of this PR. I've left some comments inline.

Comment on lines +44 to +46
def merge_tuples(*t):
"""Merge tuples and tuples of tuples into one tuple."""
return tuple(j for i in (t) for j in (i if isinstance(i, tuple) else (i,)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use longer names for i, j, and t? This is very hard to read. Why the extra parentheses around (t)? When is i not a tuple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. This is quite bad :-D. I will make it more readable.

elif d.get(k) is None:
if self.attrs.get(k) is not None:
d[k] = self.attrs[k]
elif o.get(k) is not None:
d[k] = o[k]

d["_satpy_id"] = d["_satpy_id"]._replace(**d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extremely scary to me. I think the need for adding this here is because the way you are using modifiers does not have the proper information provided. If I remember correctly, if the traditional Scene-based usage of modifiers the provided DataID to the modifier (the destination in this method maybe?) already has the modifiers tuple updated.

If this new line of code can't be made unnecessary by providing newer/better information to the Modifier object (either in __init__ or during the __call__ then this suggests that maybe some of the magic modifier handling done in the DependencyTree should be moved here as part of the modifiers/composites.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You @djhoese obviously have a lot more insight in the whole DataID and dependency_tree logic. Actually this modification is 'quite' old and I just came around to make a PR from this. Now that I had a deeper glance into the DataID and the attribute updating by working on #2332 I agree that this most likely is not the right way to do it. To me it just feels like treating the 'symptoms' of the whole situation around DataArray assignment to the scene, DataIDs (and dependency_treee) reflecting the DataArray attributes and vice versa.

I might be wrong but from what I grasp I would say that updating the attributes (except for the _satpy_id) of the DataArray should be handled in the 'processing' part (so the generation of composites/modifiers), but the generation/updating of the DataID and everything that is tied to it should be closer to the __setitem__ in the Scene. This would make it more central and maintainable because it would be decoupled from all these classes which do it their own way right now.

So I think this needs more thought. Should I mark this as work in progress?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as WIP sounds good. I think I agree that the ID stuff shouldn't happen in the compositor classes, but it may need to be due to Satpy's current design and since we allow use of compositors as class instances rather than only through the Scene.

@BENR0 BENR0 marked this pull request as draft December 28, 2022 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants