Skip to content

faster way to observe()? #496

@nkelhos

Description

@nkelhos

I've got code that calculates the ra/dec of an asteroid from the position of a satellite, but it runs slowly (~0.15sec per observe()), and I was wondering if my code could be rewritten in a faster way. Eventually, I'd like to be able to run it for a large project that would need many observe() calls (10^10 observe() calls per asteroid, for 500k asteroids).

import io
from skyfield.api import load
from skyfield.data.mpc import load_mpcorb_dataframe
from skyfield.data.mpc import mpcorb_orbit
from skyfield.constants import GM_SUN_Pitjeva_2005_km3_s2 as GM_SUN
from skyfield.toposlib import Topos

sc_lats  = [...] # list of satellite latitudes, degs
sc_lons  = [...] # list of satellite longitudes, degs
sc_alts  = [...] # list of satellite altitudes, meters
sc_times = [...] # list of times, astropy.time.Time objects

# asteroid Eunomia from Minor Planet Center's MPCORB.DAT
ast    = 15
a_line = '00015    5.2   0.15 K20CH  60.84584   98.61793  292.93525   11.75338  0.1863457  0.22921812   2.6442555  0 MPO530953  2394  79 1851-2020 0.55 M-v 38h MPCW       0000     (15) Eunomia            20200107'

eph    = load( 'de430.bsp' )
sun    = eph['sun'  ]
earth  = eph['earth']
a_line = io.BytesIO( a_line.encode('utf-8') )
a_info = load_mpcorb_dataframe( a_line )
a_info = a_info.set_index('designation_packed')
a_info = a_info.loc['%05d'%ast]
ts     = load.timescale()
a_pos  = sun + mpcorb_orbit( a_info, ts, GM_SUN )

for i in range( len(sc_lats) ) : # 1e10 loops per asteroid
  fermi = earth + Topos( latitude_degrees=sc_lats[i], longitude_degrees=sc_lons[i], elevation_m=sc_alts[i] )
                                         # 0.00036 sec per call  (earth+Topos())
  t1    = ts.from_astropy( sc_times[i] ) # 0.00024 sec per call
  raw   = fermi.at(t1)                   # 0.0024  sec per call
  raw   = raw.observe(a_pos)             # 0.15    sec per call :(
  rdd   = raw.radec()                    # 0.00007 sec per call
  print('final ra/dec/dist:',rdd)

I'm pretty sure it would run faster if numpy arrays were used in the underlying code, but I recognize implementing those changes would be a large amount work for the devs. Is there any way I can speed up the quoted code?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions