Instantly share code, notes, and snippets.

# eteq/coords_example.pySecret Created Jun 13, 2012

Interface example for astropy.coordinates

### fgrollier commented Aug 9, 2012

 Regarding the conversion of Angle to (H,M,S) and (D,M,S) tuples, for example: ```print("Angle in HMS: {0}".format(angle.hms)) # returns a tuple, e.g. (12, 21, 2.343) # Angle in HMS: (3, 36, 29.78879999999947)``` Because of the general lack of signed zeroes, it is very difficult to carry the full value of a small negative angle with only a 3-tuple (-0.9 degree, which is '-00:54:00' will be converted to (0, 54, 0) because -0 == 0). There's always the possibility to say that if the first number is 0 then the second one carries the sign (and so on), but I personally don't really like it because it's quite difficult to deal with IMHO. The most simple way to handle this is probably to use a 4-tuple, with the first member holding the sign.

### demitri commented Aug 9, 2012

 Python does in fact have signed floating zeros: ```>>> a = -0.0 >>> print a -0.0 >>> b = 0.0 >>> print b 0.0``` The three tuple will then carry the sign as expected for any value. I can't think of a (reasonable) case where -0 == 0 will cause a problem. If you are testing for hemisphere, for example, you'll be testing the sign, and that comparison will work. ```>>> from math import copysign >>> copysign(1.0, -0.0) -1.0 >>> copysign(1.0, 0.0) 1.0``` That said, it's vital that we create a test for this very case to make sure that we are returning a proper signed floating zero in these cases.

### fgrollier commented Aug 9, 2012

 Oh, I was in fact misleaded by the idea, as your example suggest, that the tuple would be of the form (int, int, float). I must admit that using a float for the first element is a solution I've never thought of, quite elegant.
Owner

### eteq commented Aug 16, 2012

 Note that since this comment, we've updated this to support (h,m,s) tuples.

### taldcroft commented Aug 16, 2012

 Just got to this part of the thread and learned something new today about the existence of signed floats. This works in numpy as well. This will take some careful documentation to make sure users understand how to deal with this. It would certainly surprise me a lot the first time I got a tuple and found that the hours are a float value.