%matplotlib inline from __future__ import division # Import of the PyEphem package import ephem from astropy.coordinates import SkyCoord #This removes some nasty deprecation warnings that do not interfere with the execution import warnings warnings.filterwarnings('ignore') # This IPython magic generates a table with version information #https://github.com/jrjohansson/version_information %load_ext version_information %version_information ephem, astropy # Let's define the equatorial coordinates of an object eq=ephem.Equatorial('13:24:42.5','-60:15:59.4') # The values are internally stored in radians eq.ra, eq.dec, eq.epoch # However they are printed as strings print eq.ra, '\t', eq.dec, '\t', eq.epoch # We can get a tuple (ra,dec) by using the get() method print eq.get() # To find the constellation corresponding to a coordinate tuple: ephem.constellation((eq.ra,eq.dec)) eq50=ephem.Equatorial('13:24:42.5','-60:15:59.4',epoch=ephem.B1950) print eq50.ra, '\t', eq50.dec, '\t', eq50.epoch # Definition of the galactic coordinates of an object ga=ephem.Galactic('1:59:55.9','+89:59:59.9') print ga.lon, ga.lat # Longitude and latitude are returned by the get() method. They are shown in radians print ga.get() # Conversion of equatorial coordinates between epochs eq1 = eq=ephem.Equatorial('13:24:42.5','-60:15:59.4') eq2 = ephem.Equatorial(eq1,epoch=ephem.B1950) print eq1.get() print eq2.get() # Conversióo from galactic to equatorial coordinates # (we can in fact omit to declare the epoch, J2000 by default) ga1 = ephem.Galactic('0','90',epoch=ephem.J2000) eq1 = ephem.Equatorial(ga1) print eq1.ra, eq1.dec # Whirlpool Galaxy SkyCoord.from_name("M51") # "icrs" es la opción por defecto # We can as well use other names for the same galaxy SkyCoord.from_name('NGC 5194') # The same object in galactic coordinates SkyCoord.from_name("M51", frame='galactic') c = SkyCoord.from_name("M51", frame='galactic') # longitude and latitude can be accessed internally with c.l y c.b # The internal representation of the angles is in degrees # However, these values can not be operated directly c.l, c.b # angles in radians print c.l.radian, c.b.radian # Angles in degrees print c.l.degree, c.b.degree # Arithmetic operation example c.l.degree + 90 c = SkyCoord.from_name("M51", frame='icrs') # Prints a string representation unfit to operate with print c # provides a tuple "hours", "minutes", "seconds" print c.ra.hms # Values in degrees print c.dec.degree # Of course they can be expressed in other types of units print c.ra.radian, c.dec.radian # ICRS coordinates c = SkyCoord.from_name("M51", frame='icrs') # FK5 coordinates c5 = SkyCoord.from_name("M51", frame='fk5') # In this example you can see the similarity between the two print 'ICRS coordinates: ',c.ra.hms, c.dec.degree print 'FK5 coordinates: ', c5.ra.hms, c5.dec.degree # Let's obtain the galactic coordinates of a star # We chose a southern hemisphere star c = SkyCoord.from_name('Achernar', frame='galactic') c # Let's turn to FK5 equatorial coordinates: c.fk5 # Conversely, from the ICRS obtain the galactic coordinates: c = SkyCoord.from_name('Achernar', frame='icrs') c.galactic