astropy: Coordinates performance regression in 4.3

This code runs in 0.8 seconds in astropy 4.2 but 40 seconds in astropy 4.3

from ctapipe.coordinates import CameraFrame
import astropy.units as u
from astropy.coordinates import EarthLocation, AltAz, SkyCoord
from astropy.time import Time
import numpy as np
from time import perf_counter


N = 100000
location = EarthLocation.of_site('Roque de los Muchachos')
obstime = Time.now() + np.linspace(0, 1, N) * u.hour

altaz = AltAz(location=location, obstime=obstime)
alt = np.full(N, 70) * u.deg
az = np.full(N, 180) * u.deg
pointing = SkyCoord(alt=alt, az=az, frame=altaz)

x = np.random.uniform(-1, 1, N) * u.m
y = np.random.uniform(-1, 1, N) * u.m

t0 = perf_counter()
camera_frame = CameraFrame(focal_length=28 * u.m, obstime=obstime, location=location, telescope_pointing=pointing)
coords = SkyCoord(x=x, y=y, frame=camera_frame)
t1 = perf_counter()
print(t1 - t0)

CameraFrame implementation here: https://github.com/cta-observatory/ctapipe/blob/master/ctapipe/coordinates/camera_frame.py

I’ll check and comeback with profiling

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

Ah, I see that quirk is actually a major part of the problem here. Can you change the function at the bottom of astropy/coordinates/builtin_frames/cirs_observed_transforms.py to this:

@frame_transform_graph.transform(FunctionTransformWithFiniteDifference, AltAz, AltAz)
@frame_transform_graph.transform(FunctionTransformWithFiniteDifference, HADec, HADec)
def observed_to_observed(from_coo, to_frame):
    if from_coo.is_equivalent_frame(to_frame):  # loopback to the same frame
        return to_frame.realize_frame(from_coo.data)
    # for now we just implement this through CIRS to make sure we get everything
    # covered
    return from_coo.transform_to(CIRS(obstime=from_coo.obstime)).transform_to(to_frame)