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

Enable equality operator on Visibilities and VisMeta classes #64

Merged
merged 7 commits into from
May 27, 2024

Conversation

DanRyanIrish
Copy link
Contributor

No description provided.

Copy link

codecov bot commented May 25, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 10 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@6c46be2). Learn more about missing BASE report.

Files Patch % Lines
xrayvision/visibility.py 60.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #64   +/-   ##
=======================================
  Coverage        ?   88.57%           
=======================================
  Files           ?        7           
  Lines           ?      875           
  Branches        ?        0           
=======================================
  Hits            ?      775           
  Misses          ?      100           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanRyanIrish
Copy link
Contributor Author

This should make Paolo's testing work easier.

xrayvision/visibility.py Outdated Show resolved Hide resolved
and np.allclose(self.time_range.mjd == other.time_range.mjd)
):
return False
return True
Copy link
Member

Choose a reason for hiding this comment

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

What about the other keys which could set since the object inherits from dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a couple justifications for not checking those:

  1. Two metas whose VisMetaABC attributes are equal, are equal VisMetaABC objects. Values outside the definition of the ABC are out of scope.
  2. Since these values aren't defined, and given the flexibility of types that dict can take, there isn't an obvious generalised way to check that the values are equal. Some may require val1 == val2, others may require all(val1 == val2) or assert_quantity_allclose(val1, val2) or assert np.allclose(val1, val2), or perhaps something more custom for custom objects. Given this, it's well-defined to stick to just the VisMetaABC-defined attributes.

Copy link
Member

Choose a reason for hiding this comment

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

As long as we clearly document sounds good.

"""
Checks whether two VisMeta objects are equal.

Does not check whether their metas are equal.
Copy link
Member

Choose a reason for hiding this comment

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

So this is really checking avis.data == bvis.data but we don't have a .data? What is the rational for not checking the meta.

Copy link
Contributor Author

@DanRyanIrish DanRyanIrish May 26, 2024

Choose a reason for hiding this comment

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

The thought is that even if the metadata is different, the visibilities themselves could be the same. For example, if the source is invariant over time or energy, then the visibilities should be the same, even it the metadata is different.

This decision though is open to discussion.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just trying to think of other python, sunpy or astropy etc object that work this can see arguments both ways - I guess it not blocker at this point though.

Copy link
Member

Choose a reason for hiding this comment

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

Ok so the only two place I can see something similar do opposite things sunpy.timeseries (https://github.com/sunpy/sunpy/blob/50f4588b53b1d575623dfc8a2536595e76261746/sunpy/timeseries/timeseriesbase.py#L870) compares the meta where as astropy.table (https://github.com/astropy/astropy/blob/8c21018c0f0d9c7de38ed4f30845f9ae0f825b94/astropy/table/table.py#L3818) only compares the rows. So again once we document think all good.

xrayvision/visibility.py Outdated Show resolved Hide resolved
xrayvision/tests/test_visibility.py Show resolved Hide resolved
@samaloney samaloney self-requested a review May 27, 2024 10:02
@samaloney samaloney merged commit adfb913 into TCDSolar:main May 27, 2024
13 checks passed
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.

2 participants