Astronomers use right ascension (RA) and declination (Dec) to refer to the sky coordinates of celestial objects. RA and Dec can take be represented degrees or in sexagesimal (base 60). How can I convert from sexagesimal to degrees while keeping the correct amount of significant figures? That is easy if we use scientific notation, but what if I want to represent +2.33750
as it is, not as 2.3375
?
1 Answer
First of all, note that RA (right ascension) is hr:min:sec.
while Dec (declination) is deg:min:sec.
. I have written the following function which lets you pick how the number of digits to the right of your output using PaddedForm
:
SexagesimalToDegree[{hrORdeg_, min_, sec_},
coord_ /; (coord == "RA" ∨ coord == "Dec"), numRHSdigits_: 6] :=
Which[
coord == "RA",
PaddedForm[(1/1 hrORdeg + 1/60 min + 1 /3600 sec) 360./
24., {Infinity, numRHSdigits}, NumberPadding -> {"", "0"},
NumberSigns -> {"-", "+"}],
coord == "Dec",
PaddedForm[(1/1 hrORdeg + 1/60 min + 1 /3600 sec) 1./1., {Infinity,
numRHSdigits}, NumberPadding -> {"", "0"},
NumberSigns -> {"-", "+"}]
]
For example, let's say you want to convert declination of 02:20:15.69 to degrees keeping 5 decimals to the right of your output since you want to be sensitive to 0.1 arcsec
which is 0.000028 deg
.
SexagesimalToDegree[{+02, 20, 15.0}, "Dec", 5]
which gives you
+2.33750
But keep in mind as soon as you do any manipulation on this output, the NumberFormat
/PaddedForm
will change.
FromDMS[]
is built-in:FromDMS[{2, 20, 15.}]
. UseNumberForm[]
if need be. $\endgroup$UnitConvert[Quantity[MixedMagnitude[{2, 20, 15.}], MixedUnit[{"AngularDegrees", "ArcMinutes", "ArcSeconds"}]], "AngularDegrees"]
. $\endgroup$