Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wokxy2radec fails if input is 1-element vector #6

Open
blanton144 opened this issue Mar 25, 2021 · 1 comment
Open

wokxy2radec fails if input is 1-element vector #6

blanton144 opened this issue Mar 25, 2021 · 1 comment

Comments

@blanton144
Copy link

blanton144 commented Mar 25, 2021

wokxy2radec doesn't like getting a one-element array input; it is fine with > 1 element array however. I could dig into this myself if you prefer me to.

This code:

dec = np.array([52.58780416] * 1, dtype=np.float64)
racen = 14.289097510524789 
deccen = 51.98826274680977
jd = 2459491.7920949073
pa = 41.42279
 
x, y, warn, ha, pa = coordio.utils.radec2wokxy(ra, dec, jd, 'Apogee',
                                               racen, deccen, pa, 'APO', jd)

ra2, dec2, warn2 = coordio.utils.wokxy2radec(x, y, 'Apogee',
                                             racen, deccen, pa,
                                             'APO', jd)

Leads to the error:

IndexError                                Traceback (most recent call last)
<ipython-input-39-3b3b7ca72fba> in <module>
      9                                                racen, deccen, pa, 'APO', jd)
     10 
---> 11 ra2, dec2, warn2 = coordio.utils.wokxy2radec(x, y, 'Apogee',
     12                                              racen, deccen, pa,
     13                                              'APO', jd)

~/products/coordio/coordio/utils.py in wokxy2radec(xWok, yWok, waveName, raCen, decCen, obsAngle, obsSite, obsTime, pressure, relativeHumidity, temperature)
    273     wok = Wok(xyzWok, site=site, obsAngle=obsAngle)
    274     focal = FocalPlane(wok, wavelength=wavelength, site=site)
--> 275     field = Field(focal, field_center=obsCen, wavelength=wavelength)
    276     obs = Observed(field, site=site, wavelength=wavelength)
    277     icrs = ICRS(obs, epoch=obsTime, wavelength=wavelength)

~/products/coordio/coordio/telescope.py in __new__(cls, value, **kwargs)
     90                 initArray = numpy.zeros((len(value), 2))
     91                 obj = super().__new__(cls, initArray, **kwargs)
---> 92                 obj._fromFocalPlane(value)
     93             else:
     94                 raise CoordIOError(

~/products/coordio/coordio/telescope.py in _fromFocalPlane(self, fpCoords)
    146                 continue
    147 
--> 148             thetaFocal, phiFocal, fieldWarn = conv.focalToField(
    149                 xFP,
    150                 yFP,

~/products/coordio/coordio/conv.py in focalToField(xFocal, yFocal, zFocal, site, waveCat)
    437     rFocal = numpy.sqrt(xFocal**2 + yFocal**2)
    438     v = numpy.array([rFocal, zFocal]).T
--> 439     v[:, 1] = v[:, 1] - b
    440 
    441     # unit vector pointing toward object on focal plane from circle center

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed```

@rmathar
Copy link

rmathar commented Sep 16, 2021

There is a simple patch for this. Use
v[...,1] = v[...,1] -b
in line 439 instead to handle 1-d and 2-d arrays. One would actually write this self-assignment as
v[...,1] -= b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants