[AstroPy] API question: Instantiating of time/coord and similar

Erik Tollerud erik.tollerud at gmail.com
Wed May 2 05:06:21 EDT 2012

Hi David,

I'm curious about your point of separating the frame/coordinate system
and the coordinates themselves.  Are you saying you think it's clearer
from the *user* perspective, or from the *implementation/developer*
perspective? (or both?)

While I definitely see the merits of such a separation from the dev
side of things (wish I'd seen this sooner, actually!), it seems a bit
more confusing from the user side.  I personally favor a user-level
interface along the lines of:

coord = ICRSCoordinates('1:2:3.4 +56:7:8.9')

or possibly

coord = Coordinates('1:2:3.4 +56:7:8.9',system='ICRS')

and then you just do




or even


These seem more natural to people I talk to who aren't used to
thinking about OO concepts (astropy is intended for both "users" and
"developers," although that distinction is ill-defined for

Such an interface can definitely be mapped onto an underlying system
like you suggest for easier development, but here I'm talking about
the more "user"-level interface.

On Wed, May 2, 2012 at 12:08 AM, David Berry <d.berry at jach.hawaii.edu> wrote:
> Hi Wolfgang
> If you are writing an object-oriented coordinate handling system,
> PyAST may give you some ideas (see
> http://dsberry.github.com/starlink/pyast.html). It's a python
> interface  to the WCS coordinate handling system used by the DS9 and
> GAIA image browsers amongst other things.
> On your specific question, fifteen years of using AST has convinced me
> that separating the definition of the coordinate system from the
> coordinate values themselves leads to greater flexibility. So AST has
> a "Frame" class that defines the properties of a coordinate system,
> and then it has a PointList class which encapsulates a Frame  and
> numerical axis values for a set of points. So using pyast, an
> instantiation of a PointSet to describe a set of points on the sky in
> galactic coords would look like this:
> import starlink.Ast as Ast
> frame = Ast.SkyFrame( "System=Galactic" )
> points = Ast.PointList( frame, [[ 120.2,78.0], [118.3,77.0], [115.6,72.3] ] )
> So for instance with a separate Frame class, it is natural to have a
> Frame method that automatically generates a transformation between two
> Frames:
> frame2 = Ast.SkyFrame( "System=ICRS" )
> ICRS_to_galactic =  Ast.Convert( frame, frame2 )
> ("ICRS_to_galactic" is a "Mapping" that allows numerical axis values
> to be transformed from "frame" to "frame2").
> or to create compound Frames by combining two or more Frames into a
> more complex coordinate system. For instance, a Frame to  describe a
> 3D spectral cube:
> frame3 = Ast.SpecFrame( "System=VELO, RestFreq=1.0E15, StdOfRest=LSRK" )
> cubeframe = Ast.CmpFrame( frame, frame3 )
> and you can use Frames for lots of other purposes (e.g. creating trees
> of Frames connected by Mappings to describe a library of coordinate
> systems, etc).
> David
> On 2 May 2012 01:05, Wolfgang Kerzendorf <wkerzendorf at gmail.com> wrote:
>> Hello guys,
>> I've just worked on the time package in astropy
>> (PR https://github.com/astropy/astropy/pull/212) which generated some
>> discussion about the general API for instantiating time/coord (and similar).
>> There are multiple ideas and issues. I'll use the coordinates as an example
>> as it demonstrates the problems rather well:
>> Imagine a class coord that somehow takes a coordinate stores it in an
>> internal format (let's say x, y, z for coords) and then can convert it into
>> any other format (galactic, equatorial, my fancy system).
>> Instantiation:
>> (1) The instantiation can happen through different keywords: mycoord =
>> coord(equatorial=(200, 20)); mycoord = coord(galactic=(200,20)).
>> (2) The instantiation can happen through classmethods: mycoord =
>> coord.from_equatorial(200,20); mycoord = coord.from_galactic(200,20)
>> the next question is how flexible should this be (using notation (1)):
>> mycoord = coord(equatorial=(200, 20)) and mycoord =
>> coord(equatorial=('15:20:44.5', '3d5m7s')).
>> or should we require that it is spelt out what is read (format and units
>> would have defaults):
>> mycoord = coord(equatorial=(200, 20), format='num', units='degree') and
>> mycoord = coord(equatorial=('15:20:44.5', '3d5m7s'), format='sex',
>> units='hour')
>> There are many other implementation possibilities. Brainstorm! ;-)
>> But please stay on topic, we are only talking about the API exposed to the
>> user here.
>> Cheers
>>     Wolfgang
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

Erik Tollerud

More information about the AstroPy mailing list