astropy / astropy/specutils

Make more convenient ways of creating SpectralCoord `observer`

Open
#624 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
204
Forks
135
Avg merge
12h 55m
Merged PRs (30d)
1

Description

Right now it's a bit awkward to use the `observer` part of `SpectralCoord` because it only accepts coordinate objects. E.g.:
```
SpectralCoord([1,2]*u.angstrom, observer=coordinates.EarthLocation.of_site('greenwich').get_gcrs(obstime=Time('2018-1-1')))
```
is a minimal example, and the complexity of the ``observer`` line shows it is not very intuitive since the user just wants to say "I observed from the Greenwich observatory on a certain date".

So a few possibilities (not mutually exclusive) for how to make things easier:
1. Allow interpretation of a 2-tuple as an EarthLocation/time combo. E.g.,
```
>>> SpectralCoord(..., observer=(EarthLocation.of_site('greenwich'), Time('2020-1-1')))
```
that at least frees the user from having to understand much about the fact that an EarthLocation has to be translated into a more standard coordinate object. (there's internally then a question of whether to use `ITRS` vs `GCRS` as the coordinate object, but in most cases I think that's an implementation detail that the user doesn't really care about).

2. Also auto-convert strings to `EarthLocation` and `Time` objects. E.g.,
```
>>> SpectralCoord(..., observer=('greenwich', '2020-1-1'))
```
which would be the exact same result as 1 above. Basically this can just be implemented by putting something like this at the top of the initializer:
```
...
... detect the presence of a tuple and set it to `earthloc` and `obstime` ...
if isinstance(earthloc, str):
earthloc = EarthLocation.of_site('greenwich')
obstime = astropy.time.Time(obstime) # <- the Time constructor transparently passes through other Time objects so this is safe
...
```
3. Same as the above 2, but use different dedicated keywords instead of ``observer``. E.g.
```
>>> SpectralCoord(..., observer_location='greenwich', observer_time='2020-1-1')
```
that's a bit cleaner of an API, but requires added logic/user confusion in that then either they are all None,`observer` is None, *or* those two are `None`, but any other combination needs to raise an error because then the user's desire is ambiguous.

There are probably some other possibilities for making this more convenient for a user, but these are the ones that first jump to mind for me.

Note this only makes sense for `observer` - `target` is typically a celestial object rather than an observatory or something.

Contributor guide

Open the contributing guide

Research direction

Start at the SpectralCoord initializer and trace how the observer argument is validated and converted from coordinate objects. Compare the proposed tuple, string, and dedicated-keyword forms, then define one unambiguous API and its expected behavior before identifying the tests needed to cover it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.