-
Notifications
You must be signed in to change notification settings - Fork 27
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
Pol convention #1455
Pol convention #1455
Conversation
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 is a good start but we need ways to round trip this new parameter through the various file formats for UVCal and UVData. I'm happy to help on that front if you need.
7256e91
to
614abd7
Compare
Thanks @bhazelton -- I've fixed up the things you suggested, and also added the read/write to uvh5. I don't know enough about fits/ms to help there, so if you could manage that part, I'd be very grateful. I added a test for uvdata to test that warnings/errors are raised appropriately. My guess is that read/write will be automatically covered in round-trip tests. |
However, there might be a lot of new warnings now with old file types. |
Is this branch at the point where I can use it to start writing files with the pol convention attribute, or should I hold off? |
@bhazelton we need to decide how we want to fix the breaking tests:
|
I can accept either 1 or 2, although maybe we need a wider discussion about whether we want to warn about this every time we call |
…on that are not none
22713d7
to
8592e49
Compare
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.
I think overall the code is looking in pretty good shape, and have nothing in terms of detailed comments to offer aside from highlighting that the doctest is still failing.
As a more general comment, I do think it would be good to put a longer explanation into the tutorials about this, since I can easily see where this might trip someone up. In particular, I think most of the higher frequency interferometers (e.g., VLA, ALMA, SMA, ATCA, ATA) take the "avg" approach, so it may be good to be explicit about what's typical/where "sum" is definitely used (since I think its the less common option of the two).
I have a question: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1455 +/- ##
=======================================
Coverage 99.92% 99.93%
=======================================
Files 61 61
Lines 21380 21461 +81
=======================================
+ Hits 21365 21446 +81
Misses 15 15 ☔ View full report in Codecov by Sentry. |
I think a warning is probably sufficient, but I wouldn't necessarily be opposed to an error in that case. |
I agree with @jsdillon that a warning is the right balance here. |
I added the warning and updated the docstrings a bit. |
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.
Thanks for the new docs, they are great. Just a few comments.
Still working on figuring out the circleci issue...
src/pyuvdata/utils/uvcalibrate.py
Outdated
def _apply_pol_convention_corrections( | ||
uvdata, undo, uvd_pol_convention, uvc_pol_convention | ||
): | ||
if uvd_pol_convention != uvc_pol_convention: | ||
correction = np.ones(uvdata.Npols) | ||
correction[uvdata.polarization_array > 0] *= 2 | ||
correction[uvdata.polarization_array < 0] /= 2 | ||
|
||
if (undo and uvd_pol_convention == "sum") or ( | ||
not undo and uvd_pol_convention == "avg" | ||
): | ||
correction = 1 / correction | ||
|
||
uvdata.data_array *= correction | ||
|
||
uvdata.pol_convention = None if undo else uvd_pol_convention |
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 is pretty hard to parse and be confident in, but I think your test shows that it's working properly, at least for linear pols. I don't see a test on Stokes visibilities (i.e. when uvdata.polarization_array > 0). Is there a test for that case?
Also, please move this to above uvcalibrate
so it's defined before it's called.
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.
OK cool. I moved the function, wrote a docstring for it to hopefully make the logic more clear, and also added tests for circular polarizations. However, in doing this I found that it seems that it is not possible to calibrate/decalibrate uvdata objects with stokes polarizations (it complains that the polarizations can't be found on the UVCal object).
Is this to be expected?
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.
I don't really know about a case where stokes calibration solutions make sense, but I feel like @kartographer ran into it when he was implementing MS cal read/write?
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.
So this is definitely a corner-case (that could be wrapped with a "pyuvdata does not support... if you file an issue..."), but the most common case I ran into was visibilities recorded as (pseudo-)Stokes I, which can have gains tables corresponding also to (pseudo-)Stokes I. Looking at the UVCal class though, we don't currently allow for Jones > 0, which is maybe what's causing the issue here.
This got raised in the MS read/write mostly on the visibility side, since the MS format has a FEED
table that I had to match to the data, hence why those pseudo Stokes values are supported there.
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.
Just a few additional comments...
docs/uvcal_tutorial.rst
Outdated
``I = (XX + YY)/2`` (the ``avg`` convention) or ``I = XX + YY`` (the ``sum`` | ||
convention). This choice is generally encoded in the sky model to which the visibilities | ||
are calibrated. Different tools and simulators make different choices, generally following | ||
a standard choice for the field. In ``pyuvdata`` either of these choices are OK, but the |
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.
Different tools and simulators make different choices, generally following a standard choice for the field.
I think we need to be more explicit here about which tools do what, especially if we are going to recommend that users always specify this parameter. In particular, I believe the tasks in CASA (e.g., tclean) and MIRIAD, along with WSClean, all assume the avg
convention. I actually am not sure of what uses the sum
convention, though I expect we can gather that information.
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.
I'm not very familiar with such tools, but I'll add that particular information.
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.
FHD uses the sum convention and the various HERA packages are moving to it.
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.
Cool. I added that as well.
if uvc_pol_convention is None and uvcal.pol_convention is None: | ||
warnings.warn( | ||
message=( | ||
"pol_convention is not specified on the UVCal object, and " |
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.
I don't know that I'd want this to error when the pol convention is not specified on either UVCal and UVData, at least not if we're treating pol_convention
as an optional parameter. Why can't this just stay a warning?
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.
Sorry @kartographer, I'm not following -- this is a warning?
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.
@steven-murray -- sorry, I mean a general UserWarning
, not a DeprecationWarning
. I.e., this should alert the user that there's a potential for mismatch, but I don't think this should throw an error.
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.
OK, I updated all the DeprecationWarning's to UserWarnings. Originally I had intended these to be DeprecationWarnings because we want to push people to use the keywords. However, it would be really annoying to have that warning if you really just don't care about the final units (like, you're just using calibration solutions to multiply your data by 2...)
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.
Looking good to me -- thanks @steven-murray!
Thanks all! You planning a new minor version release on pypi? |
Description
This adds a new parameter
pol_convention
to bothUVData
andUVCal
, as well asuvcalibrate
which applies it from one to the other. The parameter is not required, but a warning is issued if it is not specified on data that is calibrated, and an error is raised if it is specified when the data is not calibrated.In
uvcalibrate
, I am forcing the parameter to be set (either inherited from theUVCal
or set directly as a keyword to the function).Motivation and Context
The primary motivation is to keep track of this convention in data, so that the combination of calibration and power-spectrum estimation can be done consistently without "external knowledge". This is something useful for HERA at the moment.
Types of changes
Checklist:
New feature checklist: