astropy / astropy/astroplan

constraints function gives AttributeError if targets is in ndarray

Open
#513 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
225
Forks
121
Avg merge
28m
Merged PRs (30d)
1

Description

For some reason, I have `targets` in ``np.ndarray``. (I have to mask some targets frequently by comparing them (`SkyCoord` objects) with a catalog table)

The following code shows the problem:

```python
import astroplan as ap
import numpy as np
from astropy.coordinates import EarthLocation, SkyCoord
from astropy.time import Time

consts = [ap.AtNightConstraint()]
observer = ap.Observer(EarthLocation(lat=0, lon=0, height=0))
targets = np.array([SkyCoord(ra=0, dec=0, unit='deg')])
times = Time("2020-01-01")

ap.is_observable(constraints=consts, observer=observer, targets=targets.tolist(), times=times)
# Works fine, giving [True]

ap.is_observable(constraints=consts, observer=observer, targets=targets, times=times)
# AttributeError: 'numpy.ndarray' object has no attribute 'isscalar'

```

A simple update to the source code may fix it

```python
# original from https://github.com/astropy/astroplan/blob/master/astroplan/constraints.py#L265
if targets.isscalar:
# Change to
if hasattr(targets, "isscalar") and targets.isscalar:
```

How do you think?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in astroplan/constraints.py around line 265, then trace the is_observable entry point with the provided ndarray and list examples. Check the existing handling of scalar targets and verify that both input forms complete without the reported AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.