Added check on rotation units for FieldofView

This commit is contained in:
O . O 2018-11-30 15:22:07 -05:00
Родитель 5618bd6ebc
Коммит 5c2b018a3f
1 изменённых файлов: 30 добавлений и 16 удалений

Просмотреть файл

@ -263,6 +263,15 @@ class FieldOfView():
# a more efficient method than CircleCollection of changing trait values?
def __init__(self, parent, telescope, center, rot, **kwargs):
# make sure rot is astropy quantity in proper units for self._rotate()
try:
if not rot.unit.is_equivalent(u.deg):
raise AttributeError
except AttributeError:
raise ValueError('rotate argument must be Astropy quantity with '
'degree or radian-equivalent units')
# get the JSON list of FOVs from parent BaseWWTWidget class
self.parent = parent
self._available = self.parent.instruments.available
self._entry = self.parent.instruments.entry
@ -274,7 +283,8 @@ class FieldOfView():
def _gen_fov(self, telescope, center, rot, **kwargs):
# test if telescope is available
if telescope not in self._available:
raise ValueError('the given telescope\'s field of view is unavailable at this time')
raise ValueError('the given telescope\'s field of view is '
'unavailable at this time')
position = self._entry[telescope][0]
dimensions = self._entry[telescope][-1]
@ -282,39 +292,43 @@ class FieldOfView():
# test that pos matches what the user entered
if center and position == 'absolute':
raise ValueError('the given telescope does not take center coordinates')
raise ValueError('the given telescope does not take center '
'coordinates')
elif not center and position == 'relative':
raise ValueError('the given telescope requires center coordinates')
for panel in dimensions:
ras = (panel[0] * u.deg).value
decs = (panel[1] * u.deg).value
ra_r, dec_r = self._rotate(ras, decs, rot)
if position == 'absolute':
ra_tr, dec_tr = ra_r, dec_r
else:
# rotate points if necessary
if position == 'relative' and rot != 0:
ras, decs = self._rotate(ras, decs, rot)
# translate points to user-specified location if relative
if position == 'relative':
center_ra = center.ra.to(u.deg).value
center_dec = center.dec.to(u.deg).value
dec_tr = center_dec + dec_r
decs = center_dec + decs
# scale RA by dec (due to polar contraction of spherical coords)
ra_tr = center_ra + ra_r / np.cos(dec_tr * u.deg).value
ras = center_ra + ras / np.cos(decs * u.deg).value
# check that abs(dec) < 90. if not, adjust it, and then
# set the corresponding ra to be swapped by 180
for i, dec in enumerate(dec_tr):
for i, dec in enumerate(decs):
if abs(dec) > 90:
if dec < -90:
dec_tr[i] = -90. - (dec + 90.)
decs[i] = -90. - (dec + 90.)
else: # dec > 90
dec_tr[i] = 90. - (dec - 90.)
ra_tr[i] += 180.
corners = SkyCoord(ra_tr, dec_tr, unit=u.deg)
decs[i] = 90. - (dec - 90.)
ras[i] += 180.
corners = SkyCoord(ras, decs, unit=u.deg)
if self.parent.galactic_mode:
corners = corners.galactic
# draw the panel
annot = self.parent.add_polygon(corners, **kwargs)
self.active.append(annot)
@ -327,7 +341,7 @@ class FieldOfView():
def remove(self):
"""
Removes the specified annotation from the current view.
Removes the specified field of view from the viewer.
"""
for annot in self.active:
annot.remove()