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

Meaningfully compare Scene and MultiScene objects for equality #1583

Open
gerritholl opened this issue Mar 3, 2021 · 3 comments
Open

Meaningfully compare Scene and MultiScene objects for equality #1583

gerritholl opened this issue Mar 3, 2021 · 3 comments
Labels
backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:multiscene component:scene

Comments

@gerritholl
Copy link
Collaborator

Feature Request

Is your feature request related to a problem? Please describe.

For a unit test, I wanted to ensure that my code was producing the right MultiScene object, so I tested for equality. However, neither Scene nor MultiScene objects have useful equality checks implemented. The following both evaluate to False:

  • Scene() == Scene()
  • MultiScene() == MultiScene()

Describe the solution you'd like

Scene and MultiScene objects are containers. Either containers should compare equal if all their contents and, if applicable, metadata compare equal; or the equality operator should itself be a container, like for numpy arrays or xarray datasets.

sc1 = satpy.tests.utils.make_fake_scene({"a": arange(25).reshape(5, 5)})
sc2 = satpy.tests.utils.make_fake_scene({"a": arange(25).reshape(5, 5)})
print(sc1 == sc2)   # False
(sc1.to_xarray_dataset() == sc2.to_xarray_dataset()).all()  # True (as xarray Dataset)

Describe any changes to existing user workflow

  • Currently comparing Scene or MultiScene objects reduces to object identity. The meaning would change.
  • Currently such comparisons are very cheap. If the equality operator compared the content, the comparison would become quite expensive. If triggering a dask computation, it would become very expensive.

Additional context

This would have to trigger a dask computation, which might be problematic.

@gerritholl gerritholl added backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:multiscene component:scene labels Mar 3, 2021
@djhoese
Copy link
Member

djhoese commented Mar 3, 2021

My preference would be to leverage xarray here as you have in the various comparison methods. However, not all Scene's can be turned into Dataset objects (different areas/resolutions) iirc. And a MultiScene will likely always be generator or a series of dask Delayed objects (my hope in the future) so I'm not sure how accurate it would be to compare them.

@gerritholl
Copy link
Collaborator Author

It cannot always be a Dataset, but can it always be a dictionary? The keys of a Scene are always DataID, and DataID is always hashable?

@djhoese
Copy link
Member

djhoese commented Mar 4, 2021

True.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:multiscene component:scene
Projects
None yet
Development

No branches or pull requests

2 participants