brandon-rhodes / pyephem

Scientific-grade astronomy routines for Python
Other
783 stars 121 forks source link

How to calculate Geocentric degrees? #234

Closed manujchandra closed 2 years ago

manujchandra commented 2 years ago

Greetings,

On March 27, 2003 the geocentric longitude for Mars was 284.0°

I am using the following code, which I believe is giving the heliocentric coordinates:

import ephem
mars = ephem.Mars()
mars.compute('2003/3/27')
mars.hlon

4.2477006912231445

Thanks!

drbitboy commented 2 years ago

I think you want mars.a_ra or mars.ra, which is in radians,

See https://rhodesmill.org/pyephem/quick#body-compute-observer and https://rhodesmill.org/pyephem/radec

>>> mars.ra
4.978608039104635

>>> import math
>>> mars.ra*180/math.pi
285.25322849059825
manujchandra commented 2 years ago

Hi,

Thanks for your answer.

I have been able to do this:

import ephem
import numpy as np

mars = ephem.Mars()

mumbai = ephem.Observer()
mumbai.lat = '19.076090'
mumbai.lon = '72.877426'
mumbai.elevation = 36
mumbai.date = '2003/3/27 14:00'

mars.compute(mumbai)

# Geocentric
np.degrees(mars.ra)
285.6505129427214

However when I use flatlib I get 284.3576733592345 and using kerykeion gives 284.2135430082993

from flatlib.datetime import Datetime
from flatlib.geopos import GeoPos
from flatlib.chart import Chart
from flatlib.chart import const

date = Datetime('2003/03/27', '14:00', '+00:00')
pos = GeoPos('72E52:57', '19N04:22') 
chart = Chart(date, pos)

obj = chart.getObject(const.MARS)

obj.isRetrograde()

obj.lon
284.3576733592345
import kerykeion as kr
from kerykeion.utilities.charts import MakeSvgInstance

# Args: Name, year, month, day, hour, minuts, city, nation(optional)
kanye = kr.KrInstance("Kanye", 2003, 3, 27, 14, 00, "Mumbai")
Kanye birth location: Mumbai, 19.07283, 72.88261

kanye.mars

{'name': 'Mars',
 'quality': 'Cardinal',
 'element': 'Earth',
 'sign': 'Cap',
 'sign_num': 9,
 'position': 14.213543008299325,
 'abs_pos': 284.2135430082993,
 'emoji': '♑️',
 'house': '6th House',
 'retrograde': False}

So I was wondering why I am getting 1 degree or so extra?

Kind Regards,

brandon-rhodes commented 2 years ago

So I was wondering why I am getting 1 degree or so extra?

For one thing, you latitude and longitudes look different. Maybe you could start by making them agree?

And when looking at a difference between astronomy libraries, it's good to bring in a third opinion. Maybe you could try the JPL HORIZONS online tool, and see which coordinate it returns?

manujchandra commented 2 years ago

Hi,

I have changed the lat long to :

mumbai.lat = '19.07283'
mumbai.lon = '72.88261'

EDIT: I have also tried the decimal lat lon of Mumbai from Wikipedia

Which is a value returned by kerykeion. But I still get ~285

I could not figure out how to use JPL HORIZONS. But I have a book also in which its written that "On March 27, 2003 the geocentric longitude for Mars was 284.0°".

So 3 sources are giving ~284 degrees, but in pyephm I am getting 285.

Thanks.

brandon-rhodes commented 2 years ago

It looks like you are asking PyEphem for the right ascension of Mars, which is a different measurement than longitude? If you search the Quick Reference for longitude, you will find that PyEphem has a Ecliptic class that you can use like this:

import ephem

mars = ephem.Mars()

mumbai = ephem.Observer()
mumbai.lat = '19.076090'
mumbai.lon = '72.877426'
mumbai.elevation = 36
mumbai.date = '2003/3/27 14:00'

mars.compute(mumbai)

e = ephem.Ecliptic(mars)
print(e.lon)

If you adjust the time to 0:00 then you should get a number very close to the 284.0° you were looking for.

Do you have an idea of how can I improve the PyEphem documentation so that folks looking for ecliptic longitude don't ask for right ascension instead?

drbitboy commented 2 years ago

There are many types of longitude. Geocentric Longitude means, to me, the sub-Mars Earth-Body-Fixed longitude on earth at a given time at a given rotational state of the Earth, and it changes by about a quarter of a degree per minute for astronomical and most solar system objects. Also, the location on earth will make very little difference:

So one minute variation in the time you choose makes an order of magnitude more difference than the position of the observer.

I think Brandon's suggestion of Geocentric Ecliptic Longitude is probably what you are looking for, not Geocentric Body-Fixed Longitude.

Also, see the attached data from the Horizons telnet interface below (my entries are in bold):

$ **telnet horizons.jpl.nasa.gov 6775**

JPL Horizons, version 4.92
Type '?' for brief help, '?!' for details,
'-' for previous prompt, 'x' to exit
System news updated May 6, 2022

Horizons> **499**
*******************************************************************************
 Revised: June 21, 2016                 Mars                            499 / 4

 PHYSICAL DATA (updated 2019-Oct-29):
  Vol. mean radius (km) = 3389.92+-0.04   Density (g/cm^3)      =  3.933(5+-4)
  Mass x10^23 (kg)      =    6.4171       Flattening, f         =  1/169.779
  Volume (x10^10 km^3)  =   16.318        Equatorial radius (km)=  3396.19
  Sidereal rot. period  =   24.622962 hr  Sid. rot. rate, rad/s =  0.0000708822
  Mean solar day (sol)  =   88775.24415 s Polar gravity m/s^2   =  3.758
  Core radius (km)      = ~1700           Equ. gravity  m/s^2   =  3.71
  Geometric Albedo      =    0.150

  GM (km^3/s^2)         = 42828.375214    Mass ratio (Sun/Mars) = 3098703.59
  GM 1-sigma (km^3/s^2) = +- 0.00028      Mass of atmosphere, kg= ~ 2.5 x 10^16
  Mean temperature (K)  =  210            Atmos. pressure (bar) =    0.0056
  Obliquity to orbit    =   25.19 deg     Max. angular diam.    =  17.9"
  Mean sidereal orb per =    1.88081578 y Visual mag. V(1,0)    =  -1.52
  Mean sidereal orb per =  686.98 d       Orbital speed,  km/s  =  24.13
  Hill's sphere rad. Rp =  319.8          Escape speed, km/s    =   5.027
                                 Perihelion  Aphelion    Mean
  Solar Constant (W/m^2)         717         493         589
  Maximum Planetary IR (W/m^2)   470         315         390
  Minimum Planetary IR (W/m^2)    30          30          30
*******************************************************************************
 Select ... [E]phemeris, [F]tp, [M]ail, [R]edisplay, ?, <cr>: **e**

 Observe, Elements, Vectors  [o,e,v,?] : **o**
 Coordinate center [ <id>,coord,geo  ] : **@399**
 Starting UT  [>=   1600-Jan-01 23:59] : **2003/3/27 00:00**
 Ending   UT  [<=   2500-Jan-02 23:58] : **2003/3/28 00:00**
 Output interval [ex: 10m, 1h, 1d, ? ] : **2h**

 Current output table defaults --
   Reference frame       = ICRF
   Time zone correction  = UT+00:00
   Time format           = CAL
   Time digits output    = MIN
   R.A. format           = HMS
   RA/DEC extra precision= NO
   Apparent coord. type  = AIRLESS
   Range units           = AU
   Suppress range-rate   = NO
   Minimum elevation     = -90.0
   Maximum airmass       = 38.0000
   Rise-Transit-Set only = NO
   Skip daylight         = NO
   Solar elong. cut-off  = 0,180
   Hour angle cut-off    = 0.000000000
   RA/DEC rate cut-off   = 0.0
   CSV spreadsheet output= NO
   Table quantities      = A

 Accept default output [ cr=(y), n, ?] : **n**
 Select table quantities [ <#,#..>, ?] : **?**

 Select output quantities using COMMA-SEPARATED numeric codes, '?!' for details:

 1. Astrometric RA & DEC  17. N. Pole Pos. Ang & Dis  33. Galactic latitude
*2. Apparent RA & DEC     18. Helio eclip. lon & lat  34. Local app. SOLAR time
 3.   Rates: RA & DEC     19. Helio range & rng rate  35. Earth -> site lt-time
*4. Apparent AZ & EL      20. Obsrv range & rng rate >36. RA & DEC uncertainty
 5.   Rates: AZ & EL      21. Down-leg light-time    >37. POS error ellipse
 6. Sat. X & Y, pos. ang  22. Speed wrt Sun & obsrvr >38. POS uncertainty (RSS)
 7. Local app. sid. time  23. Sun-Obs-Targ ELONG ang >39. Range & rng-rate sig.
 8. Airmass & Extinction  24. Sun-Targ-Obs~PHASE ang >40. Doppler/delay sigmas
 9. Apparent visual mag.  25. Targ-Obsrv-Moon/Illum%  41. True anomaly angle
10. Illuminated fraction  26. Obs-Primary-Targ angle *42. Local app. hour angle
11. Defect of illumin.    27. Radial & -vel posn.ang  43. PHASE angle & bisector
12. Sat. angle separ/vis  28. Orbit plane angle       44. Target solar lon (L_s)
13. Target angular diam.  29. Constellation name     *45. Inertial app. RA & DEC
14. Obs sub-lon & lat     30. Delta_T (TDB - UT)      46.  Rate: Inertl RA & DEC
15. Sun sub-lon & lat    *31. Obsrv eclip lon & lat   47. Sky motion: rate & ang
16. Sub-Sun Pos Ang & Dis 32. North pole RA & DEC     48. Luna Sky-Brt & sky-SNR

  A = All quantities      B = Body-center -> Any      C = Body-cntr -> Small-bdy
  D = Topo -> Small-body  E = Body-center -> Spacraft F = Topo -> Spacecraft

 Select table quantities [ <#,#..>, ?] : **31,1,2**
 Output reference frame [ ICRF, B1950] : **icrf**
 Time-zone correction   [ UT=00:00,? ] :
 Output UT time format   [JD,CAL,BOTH] :
 Output time digits  [MIN,SEC,FRACSEC] : **min**
 Output R.A. format       [ HMS, DEG ] : **deg**
 Output high precision RA/DEC [YES,NO] : **yes**
 Output APPARENT [ Airless,Refracted ] : **airless**
 Set units for RANGE output [ KM, AU ] : **au**
 Suppress RANGE_RATE output [ YES,NO ] : **yes**
 Minimum elevation [ -90 <= elv <= 90] :
 Maximum air-mass  [ 1 <=   a  <= 38 ] :
 Print rise-transit-set only [N,T,G,R] :
 Skip printout during daylight [ Y,N ] : **n**
 Solar elongation cut-off   [ 0, 180 ] :
 Local Hour Angle cut-off       [0-12] :
 RA/DC angular rate cut-off [0-100000] :
 Spreadsheet CSV format        [ Y,N ] : **y**

 Working ... |
*******************************************************************************
Ephemeris / PORT_LOGIN Wed May 11 09:01:07 2022 Pasadena, USA    / Horizons
*******************************************************************************
Target body name: Mars (499)                      {source: mar097}
Center body name: Earth (399)                     {source: mar097}
Center-site name: GEOCENTRIC
*******************************************************************************
Start time      : A.D. 2003-Mar-27 00:00:00.0000 UT
Stop  time      : A.D. 2003-Mar-28 00:00:00.0000 UT
Step-size       : 120 minutes
*******************************************************************************
Target pole/equ : IAU_MARS                        {West-longitude positive}
Target radii    : 3396.2 x 3396.2 x 3376.2 km     {Equator, meridian, pole}
Center geodetic : 0.00000000,0.00000000,0.0000000 {E-lon(deg),Lat(deg),Alt(km)}
Center cylindric: 0.00000000,0.00000000,0.0000000 {E-lon(deg),Dxy(km),Dz(km)}
Center pole/equ : ITRF93                          {East-longitude positive}
Center radii    : 6378.1 x 6378.1 x 6356.8 km     {Equator, meridian, pole}
Target primary  : Sun
Vis. interferer : MOON (R_eq= 1737.400) km        {source: mar097}
Rel. light bend : Sun, EARTH                      {source: mar097}
Rel. lght bnd GM: 1.3271E+11, 3.9860E+05 km^3/s^2
Atmos refraction: NO (AIRLESS)
RA format       : DEG
Time format     : CAL
EOP file        : eop.220510.p220802
EOP coverage    : DATA-BASED 1962-JAN-20 TO 2022-MAY-10. PREDICTS-> 2022-AUG-01
Units conversion: 1 au= 149597870.700 km, c= 299792.458 km/s, 1 day= 86400.0 s
Table cut-offs 1: Elevation (-90.0deg=NO ),Airmass (>38.000=NO), Daylight (NO )
Table cut-offs 2: Solar elongation (  0.0,180.0=NO ),Local Hour Angle( 0.0=NO )
Table cut-offs 3: RA/DEC angular rate (     0.0=NO )
Table format    : Comma Separated Values (spreadsheet)
**************************************************************************************************************
 Date__(UT)__HR:MN, , ,    ObsEcLon,   ObsEcLat,  R.A.___(ICRF), DEC____(ICRF),  R.A.__(a-app), DEC___(a-app),
**************************************************************************************************************
$$SOE
 2003-Mar-27 00:00, , , 283.9919010, -0.5180218,  285.209729957, -23.223319253,  285.253256549, -23.220352187,
 2003-Mar-27 02:00, , , 284.0441663, -0.5199007,  285.266494996, -23.219724588,  285.310026653, -23.216741929,
 2003-Mar-27 04:00, , , 284.0964269, -0.5217814,  285.323252174, -23.216112248,  285.366788788, -23.213114026,
 2003-Mar-27 06:00, , , 284.1486827, -0.5236638,  285.380001458, -23.212482246,  285.423542920, -23.209468490,
 2003-Mar-27 08:00, , , 284.2009337, -0.5255481,  285.436742815, -23.208834597,  285.480289015, -23.205805335,
 2003-Mar-27 10:00, , , 284.2531799, -0.5274341,  285.493476213, -23.205169316,  285.537027040, -23.202124573,
 2003-Mar-27 12:00, , , 284.3054214, -0.5293219,  285.550201619, -23.201486417,  285.593756959, -23.198426219,
 2003-Mar-27 14:00, , , 284.3576580, -0.5312116,  285.606919002, -23.197785915,  285.650478742, -23.194710285,
 2003-Mar-27 16:00, , , 284.4098898, -0.5331030,  285.663628329, -23.194067825,  285.707192354, -23.190976785,
 2003-Mar-27 18:00, , , 284.4621167, -0.5349962,  285.720329569, -23.190332160,  285.763897762, -23.187225733,
 2003-Mar-27 20:00, , , 284.5143387, -0.5368912,  285.777022688, -23.186578937,  285.820594935, -23.183457141,
 2003-Mar-27 22:00, , , 284.5665559, -0.5387880,  285.833707655, -23.182808169,  285.877283839, -23.179671024,
 2003-Mar-28 00:00, , , 284.6187681, -0.5406866,  285.890384439, -23.179019872,  285.933964444, -23.175867395,
$$EOE
**************************************************************************************************************
Column meaning:

TIME

  Times PRIOR to 1962 are UT1, a mean-solar time closely related to the
prior but now-deprecated GMT. Times AFTER 1962 are in UTC, the current
civil or "wall-clock" time-scale. UTC is kept within 0.9 seconds of UT1
using integer leap-seconds for 1972 and later years.

  Conversion from the internal Barycentric Dynamical Time (TDB) of solar
system dynamics to the non-uniform civil UT time-scale requested for output
has not been determined for UTC times after the next July or January 1st.
Therefore, the last known leap-second is used as a constant over future
intervals.

  Time tags refer to the UT time-scale conversion from TDB on Earth
regardless of observer location within the solar system, although clock
rates may differ due to the local gravity field and no analog to "UT"
may be defined for that location.

  Any 'b' symbol in the 1st-column denotes a B.C. date. First-column blank
(" ") denotes an A.D. date. Calendar dates prior to 1582-Oct-15 are in the
Julian calendar system. Later calendar dates are in the Gregorian system.

  NOTE: "n.a." in output means quantity "not available" at the print-time.

 'ObsEcLon,   ObsEcLat,' =
   Observer-centered IAU76/80 ecliptic-of-date longitude and latitude of the
target centers' apparent position, with light-time, gravitational deflection of
light, and stellar aberrations.  Units: DEGREES

 'R.A.___(ICRF), DEC____(ICRF),' =
  Astrometric right ascension and declination of the target center with
respect to the observing site (coordinate origin) in the reference frame of
the planetary ephemeris (ICRF). Compensated for down-leg light-time delay
aberration.

  Units: RA  in decimal degrees,  ddd.fffff{ffff}
         DEC in decimal degrees,  sdd.fffff{ffff}

 'R.A.__(a-app), DEC___(a-app),' =
  Airless apparent right ascension and declination of the target center with
respect to an instantaneous reference frame defined by the Earth equator of-dat
(z-axis) and meridian containing the Earth equinox of-date (x-axis, EOP-correct
IAU76/80). Compensated for down-leg light-time delay, gravitational deflection
of light, stellar aberration, precession & nutation. Note: equinox (RA origin)
is offset -53 mas from the of-date frame defined by the IAU06/00a P & N system.

  Units: RA  in decimal degrees, ddd.fffff{ffff}
         DEC in decimal degrees  sdd.fffff{ffff}

Computations by ...

    Solar System Dynamics Group, Horizons On-Line Ephemeris System
    4800 Oak Grove Drive, Jet Propulsion Laboratory
    Pasadena, CA  91109   USA

    General site: https://ssd.jpl.nasa.gov/
    Mailing list: https://ssd.jpl.nasa.gov/email_list.html
    System news : https://ssd.jpl.nasa.gov/horizons/news.html
    User Guide  : https://ssd.jpl.nasa.gov/horizons/manual.html
    Connect     : browser        https://ssd.jpl.nasa.gov/horizons/app.html#/x
                  API            https://ssd-api.jpl.nasa.gov/doc/horizons.html
                  command-line   telnet ssd.jpl.nasa.gov 6775
                  e-mail/batch   https://ssd.jpl.nasa.gov/ftp/ssd/hrzn_batch.txt
                  scripts        https://ssd.jpl.nasa.gov/ftp/ssd/SCRIPTS
    Author      : Jon.D.Giorgini@jpl.nasa.gov

**************************************************************************************************************
 >>> Select... [A]gain, [N]ew-case, [F]tp, [M]ail, [R]edisplay, ? : **f**

 You have    10 minutes to retrieve the following by anonymous FTP:
   Machine name:  ssd.jpl.nasa.gov
   Directory   :  cd to "/pub/ssd/"
   File name   :  wld8829.15
   File type   :  ASCII (transfer format)
   Full path   :  https://ssd.jpl.nasa.gov/ftp/ssd/wld8829.15

 >>> Select... [A]gain, [N]ew-case, [M]ail, [R]edisplay, ? : **q**

     ___    _____     ___
    /_ /|  /____/ \  /_ /|       Horizons On-line Ephemeris System v4.92
    | | | |  __ \ /| | | |       Solar System Dynamics Group
 ___| | | | |__) |/  | | |__     Jet Propulsion Laboratory
/___| | | |  ___/    | |/__ /|   Pasadena, CA, USA
|_____|/  |_|/       |_____|/

Connection closed by foreign host.
manujchandra commented 2 years ago

Thanks for your help.

In the documentation, some examples can be provided for different types of longitudes and latitudes in a "cook-book" like format. This could help newcomers to the library and disambiguate different uses cases.

Regards,