faster way to observe()?
See original GitHub issueI’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?
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (13 by maintainers)
Top Results From Across the Web
Advantages of reactive vs. observe vs. observeEvent
The best way to use observeEvent is to think of it as a defined trigger, as in it watches one event or change...
Read more >Observe Function in R Shiny - How to Implement a Reactive ...
The moral of the story is as follows – use the observe() function every time you want your Shiny app to react to...
Read more >FASTer Way to Fat Loss
The FASTer Way is the only program that strategically pairs effective workouts with science-backed nutrition strategies and expert coaching.
Read more >observe - R Shiny
An integer or numeric that controls the priority with which this observer should be executed. A higher value means higher priority: an observer...
Read more >Observe Function in R Shiny — How to Implement a Reactive ...
Do you find the observe() function tough to understand? Our detailed guide to observe function in R Shiny is here to help.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Most satellite TLEs are published at least once per week. So if you’re searching through 10 years of satellite data on, say, https://space-track.org, you can pull all TLEs for a particular satellite for the past 10 years (be sure to read the terms of service before pulling that much data). Each TLE has an epoch date around which it’s good for at least a couple weeks. Depending on how precise you need, you could pick one TLE per month and do your calculation over 120 1-month windows using a contemporary TLE. Not as good as doing it all at one go, but certainly better than doing it for each individual time point.
Since the underlying request behind this issue is now identical to #532, I am going to close this issue so I don’t wind up tracking two issues about the same feature, and also to try to keep future discussion centralized in one place (as otherwise I sometimes have trouble tracking down on which issue an earlier comment was made). Hopefully the next few months will see progress!