question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Premature broadcasting of coordinates in transforms creates slowdowns

See original GitHub issue

Description

In summary, when transforming coordinate frames we broadcast before transforming, which ought not to be necessary.

In my PR to add a topocentric frame I noticed some odd behaviour. Suppose obstime is a (N, 1) array of times and we have M targets. Below I create an alt-az frame intended to broadcast against each other:

import numpy as np
from astropy.time import Time
import astropy.units as u
from astropy.coordinates import EarthLocation, CIRS, AltAz, SkyCoord
from astropy.coordinates.tests.utils import randomly_sample_sphere
from astropy.coordinates.erfa_astrom import ErfaAstromInterpolator, erfa_astrom

times = Time('2020-08-21T00:00') + np.linspace(-3*u.hour, 3*u.hour, 1000)
location = EarthLocation.of_site('lapalma')
aa_frame = AltAz(obstime=times[:, np.newaxis], location=location)

# 1000 random locations on the sky
ra, dec, _ = randomly_sample_sphere(200)
coos = SkyCoord(ra, dec)

Now, if I convert this to AltAz it is extremely slow. But it’s much faster if I add CIRS as an intermediate step explicitly, even though CIRS is the intermediate frame between ICRS and AltAz…

coos.transform_to(aa_frame) # 18 seconds
coos.transform_to(CIRS()).transform_to(aa_frame) # 1 second

Note this isn’t like this in the current master, but it illustrates the issue, which I believe is this. If you run coos.transform_to(aa_frame) the first step is to make a CIRS frame. The attributes of this frame are collected from the players in the transform, so it picks up the obstime from the AltAz frame and the positions from the ICRS frame, so the resulting CIRS frame is shape (N, M). This large frame is pushed through a CIRS->CIRS’ which causes the slowdown.

In the second instance the CIRS->CIRS’ transform is only for a coordinate of shape (M,) which is much faster.

Although this specific example doesn’t affect astropy master, it will if my PR is merged, and @mhvk points out it probably also slows down a single ICRS position -> AltAz at many times transform.

Additional context

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mkbrewercommented, Nov 6, 2020

Another possibility would be to add obsgeoloc and obsgeovel as attributes to the AltAz frame. These could be derived from the EarthLocation attribute when the frame is instantiated and passed directly to the CIRS frame instead of the EarthLocation itself.

0reactions
StuartLittlefaircommented, Nov 6, 2020

In terms of where the time is being spent:

    24                                           def cirs_to_altaz(cirs_coo, altaz_frame):
    25         1         53.0     53.0      0.0      print('cirs_to_altaz: ', cirs_coo.shape)
    26         1     202211.0 202211.0      4.5      obsgeoloc, obsgeovel = altaz_frame.location.get_gcrs_posvel(altaz_frame.obstime)
    27         1       1461.0   1461.0      0.0      if (np.any(cirs_coo.obstime != altaz_frame.obstime) or
    28         1      57662.0  57662.0      1.3              np.any(cirs_coo.obsgeoloc != obsgeoloc)):
    29         1         89.0     89.0      0.0          cirs_coo = cirs_coo.transform_to(CIRS(obstime=altaz_frame.obstime,
    30         1          2.0      2.0      0.0                                                obsgeoloc=obsgeoloc,
    31         1    4205034.0 4205034.0     93.8                                                obsgeovel=obsgeovel))

That transform calls cirs_to_icrs and then icrs_to_cirs, the bulk of the time is spent in the first call:

    67                                           def cirs_to_icrs(cirs_coo, icrs_frame):
    68                                               # set up the astrometry context for ICRS<->cirs and then convert to
    69                                               # astrometric coordinate direction
    70         1         44.0     44.0      0.0      print('cirs_to_icrs: ', cirs_coo.shape)
    71         1    4264289.0 4264289.0     99.3      astrom = erfa_astrom.get().apci(cirs_coo)
Read more comments on GitHub >

github_iconTop Results From Across the Web

An overview of the Projections and Transformations toolset ...
Creates a transformation method for converting data between two geographic coordinate systems or datums. The output of this tool can be used as...
Read more >
Technology Product Awards 2022 - Voting - Computing
Votes are now open for the Technology Product Awards 2022! Deadline is Friday 21 October. You must use your company/work email address to...
Read more >
Secure Data Communication via Lingual Transformation
Abstract. This paper proposes a new form of data communication that is similar to slang in human language. Using the context of the...
Read more >
Waterworld - Wikipedia
Waterworld is a 1995 American post-apocalyptic action film directed by Kevin Reynolds and co-written by Peter Rader and David Twohy. It was based...
Read more >
The recovery will be digital - McKinsey
in the throes of digital transformations pre-pandemic, ... The model helps to coordinate ... early in the process of creating an.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found