Coding for Conjunctions
00:00 Our conjunction script will use Mercury as the reference point, and then for any given day, compare the angle of separation between Mercury and each of the other planets.
00:09
To get the angle of separation, you need the sky coordinates of the two objects being compared. You can get the sky coordinate of a planet using the get_body()
function, which takes the name of a planet, a position, and a date and time.
00:24 The position information requires your longitude, latitude, and elevation.
00:29 I’ll be using mine in Toronto for the examples, but you can either Google your city or use latlong.net in order to figure it out.
00:38
Unfortunately, the datetime needed by get_body()
isn’t a Python datetime
. It’s an Astropy Time
object. To loop through a series of dates, I’m going to use Python’s date
and timedelta
features.
00:51
This introduces a problem. The Astropy Time
object doesn’t take a Python datetime
object as an initializer. It will take an ISO formatted date string though, so you can do something a little hacky.
01:04
Convert the Python datetime
into a string, and then use that to create an Astropy Time
object. Fun, huh? Once you’ve got sky coordinates for objects, you can use Astropy’s angular_separation()
function to determine their angle of separation.
01:21 Oddly, this function doesn’t actually take sky coordinate objects, which you’d think would be the natural thing for it to do, but it does use the right ascension and declination of the bodies being compared.
01:33 Seeing as those are inside the sky coordinate object, you just have to reference the attributes in order to pass them into the function.
01:40 In the course overview, I commented about Astropy being a little chatty. Warning wise, Astropy uses a dataset called IERS to deal with times and positions.
01:52 This is to account for things like leap seconds. If you go too far into the future or past, Astropy will issue a warning. If you are outside of the IERS range, it falls back to an approximation calculation as I’m going to be calling functions that will trigger this warning a lot.
02:11
I am going to show you how to suppress that warning using Python’s built-in warnings
module.
Become a Member to join the conversation.