-
Notifications
You must be signed in to change notification settings - Fork 171
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
Improve code for computing VA scale and offsets #5666
Improve code for computing VA scale and offsets #5666
Conversation
a5b8ce7
to
1008077
Compare
Need to update unit tests in test_velocity_aberration.py, which are causing CI to fail. |
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.
Code refactoring looks good to me. Just need to fix the the unit tests that are failing.
c74ceda
to
fddc5e7
Compare
@hbushouse @ColinRCox @antonkoekemoer @nden Could you please take a look at #5658 and comment on the issues either here or there or ping someone who is knowledgeable in how this code and its computed values are intended to be used. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #5666 +/- ##
==========================================
- Coverage 74.46% 74.45% -0.01%
==========================================
Files 416 416
Lines 38110 38127 +17
Branches 5000 5000
==========================================
+ Hits 28378 28387 +9
- Misses 9732 9740 +8
*This pull request uses carry forward flags. Click here to find out more.
Continue to review full report at Codecov.
|
e99dc86
to
1f80777
Compare
@hbushouse I have made several significant changes to code and schemas. Please re-review this PR. For schema review, maybe @jdavies-st could take a look (don't I need to update a schema version somewhere?) Here is the outline of changes:
|
d37d03e
to
d10b29b
Compare
- Update code in ``set_velocity_aberration.py`` functions based on Colin Cox | ||
suggestions (simplify DVA scale computation and improve offset | ||
computation). [#5666] | ||
|
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.
Should also now add an entry to the datamodels
section above, to indicate the change in the keyword names DVA_RA, DVA_DEC to VA_RA, VA_DEC.
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.
yes, I realized that too late. I'll add more to the description.
@@ -1293,15 +1293,15 @@ properties: | |||
title: Velocity aberration correction information | |||
type: object | |||
properties: | |||
ra_offset: | |||
title: "[rad] Velocity aberration correction RA offset" | |||
va_ra_ref: |
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.
The "REF" suffix in other keywords like RA_REF, DEC_REF indicates that these are the coordinates at the reference point of the aperture/image. If VA_RA, VA_DEC are simply the VA-correction target coords, then the "ref" suffix is probably not appropriate, because the target is not necessarily located at the reference point (e.g. dithers, mosaics, and other intentional offsets move the target off the reference point). So unless these RA, Dec values are at the reference point, we should probably drop the "ref" suffix from their datamodel names and just leave them as "va_ra" and "va_dec".
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 unless there RA, Dec values are at the reference point ...
It seems that they are. Take a look at the original code:
jwst/jwst/lib/set_velocity_aberration.py
Lines 143 to 150 in 1f4db5c
ra_ref = float(sheader['RA_REF']) | |
dec_ref = float(sheader['DEC_REF']) | |
# compute the velocity aberration information | |
scale_factor = aberration_scale(jwst_dx, jwst_dy, jwst_dz, | |
ra_ref, dec_ref) | |
ra_off, dec_off = aberration_offset(jwst_dx, jwst_dy, jwst_dz, | |
ra_ref, dec_ref) |
In the script in the functions that compute VA effects, input arguments are called targ_ra
and targ_dec
and I find this confusing. In the function that updates FITS header, targ_ra=ra_ref
, ... I think it is important to preserve the actual meaning of the keywords.
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.
Ah ha, so it appears that these coords are in fact the RA, Dec of the reference point, which is not necessarily the same as the coords of the target (if the target isn't at the reference point). Yes, it is unfortunate and confusing when the variable names used are "targ_ra" and "targ_dec", which makes you think it's the same as the TARG_RA, TARG_DEC keywords, but in fact they correspond to keywords RA_REF, DEC_REF. So in that case I withdraw my previous comment and think it's OK to leave the "ref" suffix on the meta attribute names. Too bad the stupid FITS standard won't allow us the room to add "REF" to the keyword names too.
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 was writing #5666 (comment) in parallel with you. I was suggesting to add at least an R
in front of RA->RRA
and DEC->RDEC
just to alert readers and make it obvious that something is different about this RA and DEC.
dec_offset: | ||
title: "[rad] Velocity aberration correction Dec offset" | ||
va_dec_ref: | ||
title: "[dec] Velocity aberration apparent reference Dec" |
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.
typo in "dec" - should be "deg"
jwst/lib/set_velocity_aberration.py
Outdated
# angle between the velocity vector and the direction toward the target. | ||
sin_theta = math.sqrt(1. - cos_theta**2) | ||
apparent_ra: float | ||
Aparent star position in the moving telescope frame. |
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.
typo: "Aparent" should be "Apparent"
jwst/lib/set_velocity_aberration.py
Outdated
tan_theta_p = sin_theta / (gamma * (cos_theta + beta)) | ||
theta_p = math.atan(tan_theta_p) | ||
apparent_dec: float | ||
Aparent star position in the moving telescope frame. |
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.
same typo here "Apparent"
jwst/lib/set_velocity_aberration.py
Outdated
beta = np.array([velocity_x, velocity_y, velocity_z]) / SPEED_OF_LIGHT | ||
beta2 = np.dot(beta, beta) | ||
if beta2 == 0.0: | ||
return 1.0, targ_ra, targ_dec |
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.
The old version of the code issued a warning when the velocity is zero. That would be good to maintain here, just for traceability in the processing log.
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.
The old warning logger.warning('Speed is zero. Forcing scale to 1.0')
is interesting. When speed is 0 then mathematically scale is 1. There is nothing exceptional here. Saying the code is "forcing" scale to be 1 is kind of a forceful statement :) I think from the caller's perspective it should not matter how the code handles special cases. In fact, this if
can be safely removed from the code if we are talking only about scale. It is here because of the aberrated RA and Dec - that formula should be taking a limit in mathematical sense when v->0
. In addition, it is really an extreme check to make code work if when JWST is "launched" in a garage. We do not realy expect a flying JWST with speed 0.
However, if you are thinking of detecting case when software incorrectly passes 0 speed instead of expected v != 0
- then I hope someone will be reading those log files. Otherwise I would suggest using an assert
or raising some other exception.
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.
Let me know what do you prefer.
A zero speed will not interfere with the scale calculation but the RA and Dec calculation will have a divide by zero problem. By the way beta2 is the square of the velocity so I would prefer to name it something like beta_squared to make it clear. |
@hbushouse I addressed (locally) most comments. I have a question about the use of The log message is back but modified: logger.warning('Observatory speed is zero. Setting VA scale to 1.0') I hope we will never see this message. |
ae56d01
to
6a641fb
Compare
312d2f4
to
3106945
Compare
The formula for computing the scale is exact. It is fairly simple but no higher terms have been omitted. |
This PR improves code in
lib/set_velocity_aberration.py
based on suggestions from Colin Cox:Closes: #5658
Related to JP-1762