-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add precess_cd function #16
Changes from 4 commits
90f8767
138adda
a095ad3
221b889
bfae37c
520dd90
2e611f9
1c65feb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# This file is a part of AstroLib.jl. License is MIT "Expat". | ||
|
||
function _precess_cd{T<:AbstractFloat}(cd::AbstractMatrix{T}, epoch1::T, epoch2::T, crval_old::AbstractVector{T}, | ||
crval_new::AbstractVector{T}, FK4::Bool) | ||
t = deg2rad((epoch2 - epoch1)*0.001) | ||
|
||
if FK4 | ||
st = (epoch1 - 1900)*0.001 | ||
c = t*(20046.85 - st*(85.33 + st*0.37) + t*(-42.67 - st*0.37 - t*41.8))/3600 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove division by 3600 and wrap the whole right-hand-side with |
||
else | ||
st = (epoch1 - 2000)*0.001 | ||
c = t*(20043.109 - st*(85.33 + st*0.217) + t*(-42.665 - st*0.217 - t*41.8))/3600 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as at line 9. |
||
end | ||
pole_ra = zero(T) | ||
pole_dec = one(T)*90 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I told you to use |
||
|
||
if (epoch1 == 2000 && epoch2 == 1950) || (epoch1 == 1950 && epoch2 == 2000) | ||
pole_ra, pole_dec = bprecess(pole_ra, pole_dec) | ||
else | ||
pole_ra, pole_dec = precess(pole_ra, pole_dec, epoch1, epoch2, FK4=FK4) | ||
end | ||
sind1, sind2 = sind.([crval_old[2], crval_new[2]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use the arrays here ;-) If you still want to have two calculation in one line you can do sind1, sind2 = sind(crval_old[2]), sind(crval_new[2])
... but I don't think you can gain much with respect to sind1 = sind(crval_old[2])
sind2 = sind(crval_new[2])
... That's up to you |
||
cosd1, cosd2 = cosd.([crval_old[2], crval_new[2]]) | ||
sinra = sind(crval_new[1] - pole_ra) | ||
cosfi = (cos(c) - sind1*sind2)/(cosd1*cosd2) | ||
sinfi = (abs(sin(c))* sinra)/cosd1 | ||
r = [cosfi sinfi; -sinfi cosfi] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had transposed this |
||
return cd * r | ||
end | ||
|
||
""" | ||
precess_cd(cd, epoch1, epoch2, crval_old, crval_new) -> cd | ||
|
||
### Purpose ### | ||
|
||
Precess the coordinate description matrix. | ||
|
||
### Explanation ### | ||
|
||
The coordinate matrix is precessed from epoch1 to epoch2. | ||
|
||
### Arguments ### | ||
|
||
* `cd`: 2 x 2 coordinate description matrix in degrees or radians | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the matrix has to be in degrees. I think that the original description in inaccurate, they also say the matrix is altered to match the units of input matrix, but they don't do so. |
||
* `epoch1`: original equinox of coordinates, scalar | ||
* `epoch2`: equinox of precessed coordinates, scalar | ||
* `crval_old`: 2 element vector containing right ascension and declination | ||
in degrees of the reference pixel in the original equinox | ||
* `crval_new`: 2 element vector giving crval in the new equinox | ||
* `FK4` (optional boolean keyword): if this keyword is set, then the precession constants | ||
are taken in the FK4 reference frame. The default is the FK5 frame | ||
|
||
### Output ### | ||
|
||
* `cd`: coordinate description containing precessed values | ||
|
||
### Example ### | ||
|
||
```julia | ||
julia> precess_cd([20 60; 45 45], 1950, 2000, [34, 58], [12, 83]) | ||
2×2 Array{Float64,2}: | ||
48.8944 147.075 | ||
110.188 110.365 | ||
``` | ||
|
||
### Notes ### | ||
|
||
Code of this function is based on IDL Astronomy User's Library. | ||
This function should not be used for values more than 2.5 centuries from the year 1900. | ||
This function calls [precess](@ref) and [bprecess](@ref). | ||
""" | ||
precess_cd(cd::AbstractMatrix{<:Real}, epoch1::Real, epoch2::Real, crval_old::AbstractVector{<:Real}, | ||
crval_new::AbstractVector{<:Real}, FK4::Bool=false) = | ||
_precess_cd(float(cd), promote(float(epoch1), float(epoch2))..., | ||
float(crval_old), float(crval_new), FK4) |
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 that you shouldn't call
deg2rad
here,t
isn't simply a global multiplicative factor in definition ofc
, which is rather a third-order polynomial int
.