Skip to content

AltAz -> Galactic, with multiple observation times #5364

Closed

Description

@mtzl

I created a stackoverflow question for this here.

I have event tuples of (azimuth, altitude, time) in horizontal coordinates, which I store as 2 numpy arrays azimuth and altitude, and a list(datetime). I also have an EarthLocation where these events are observed. The number of events is on the order of 100k.

Now I'd like to transform these to galactic coordinates. I tried

my_loc = EarthLocation.from_geodetic(...)
my_frame = AltAz(my_loc, obstime=times)
evt = SkyCoord(
        alt=my_altitude*rad, 
        az=my_azimuth*rad, 
        frame=my_frame, 
    )
evt_gal = evt.galactic

But each of these events apparently use the same observation time. (Judging from plots where all events are suspiciously neatly sitting on a curve).

Looking at a single event, it seems that each event has multiple observation times associated to it, which is not quite what I want.

e = evt[1]
print(e.frame)
<AltAz Coordinate (obstime=[datetime.datetime(2015, 5, 17, 16, 58, 17)
 datetime.datetime(2015, 12, 14, 0, 15, 26)
 datetime.datetime(2015, 9, 25, 4, 16) ...,
 datetime.datetime(2015, 9, 27, 6, 5, 9)
 datetime.datetime(2015, 2, 5, 1, 31, 8)
 datetime.datetime(2015, 12, 21, 13, 15, 49)], location=...> 

Supplying the obstimes directly to SkyCoord yields identical results.

evt = SkyCoord(
        alt=df_cscd['altitude_cscd'] * rad, 
        az=df_cscd['azimuth_random'] * rad, 
        location=my_earth_loc,
        obstime=my_times,)

The next idea was to not pass the observation times to the frame, but to the SkyCoord:

frame_without_time = AltAz(location=my_location)
evt = SkyCoord(
        alt=df_cscd['altitude_cscd'] * rad, 
        az=df_cscd['azimuth_random'] * rad, 
        frame=frame_without_time,
        obstime=my_times,
)

But this raises a

ValueError: cannot specify frame attribute 'obstime' directly in SkyCoord since a frame instance was passed in

It works perfectly fine if I have just a single time, e.g. astropy.time.Time.now(). But looping over 100k events and creating a SkyCoord instance for each of them is incredibly slow, obviously.

I don't have a pull request for this, since I wonder if there is a built-in better way to do this?

What do you think?

Activity

  1. mhvk commented on Sep 28, 2016

    @mhvk
    Contributor

    I fear this may need #5254...

  2. astrofrog commented on Oct 31, 2016

    @astrofrog
    Member

    @mhvk - just to be clear, since #5254 is merged, do you mean this should work with the latest developer version?

  3. mhvk commented on Oct 31, 2016

    @mhvk
    Contributor

    I think it should work, but haven't really tried multi-d explicitly. @moritz-lotze - would you be able to try? Or alternatively give an explicit example that currently does not work, so we can check? (i.e., something we can just copy and paste)

  4. mtzl commented on Nov 1, 2016

    @mtzl
    Author

    Thanks for the ping, completely missed this. Updated to 1.3.dev16350.

    Ok, now the same as before, trying to convert (alt, az, time) tuples, and it seems to work. Great!

    I don't have any unittest myself to confirm that the coordinate conversion itself is correct, but I think that'd go into a different issue anyway.

    Thanks a lot!

  5. mhvk commented on Nov 1, 2016

    @mhvk
    Contributor

    @moritz-lotze - great to hear that it works! Do raise other issues as you find them, or send PRs with possible improvements -- this is how astropy gets better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions