Skip to content

Commit

Permalink
Merge pull request #75 from desihub/astropy2
Browse files Browse the repository at this point in the history
Minor changes to work with astropy 2.0
  • Loading branch information
dkirkby authored Aug 7, 2017
2 parents 40b4e84 + 99a2e10 commit c25d712
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ env:
matrix:
# Make sure that egg_info works without dependencies
- PYTHON_VERSION=2.7 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.3 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.4 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.5 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.6 SETUP_CMD='egg_info'
Expand Down Expand Up @@ -98,7 +97,7 @@ matrix:
- os: linux
env: PYTHON_VERSION=2.7 NUMPY_VERSION=1.7
- os: linux
env: PYTHON_VERSION=3.3 NUMPY_VERSION=1.8
env: PYTHON_VERSION=3.4 NUMPY_VERSION=1.8
- os: linux
env: PYTHON_VERSION=3.4 NUMPY_VERSION=1.9
- os: linux
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.10 (unreleased)
-----------------
- No changes yet.
- Handle non-backwards compatible changes to astropy.constants in astropy 2.0.
- Handle deprecated longitude, latitude attributes for astropy >= 2.0.
- Remove tests against python 3.3 (3.4-3.6 are still tested).

0.9 (2017-05-11)
----------------
Expand Down
7 changes: 6 additions & 1 deletion specsim/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ def initialize(config):
nominal_start = exposure_start
point_radec = pointing.transform_to('icrs')
hour_angle = astropy.coordinates.Angle(adjust_ha)
try:
lon = location.lon
except AttributeError:
# Required for astropy < 2.0
lon = location.longitude
exposure_start = specsim.transform.adjust_time_to_hour_angle(
nominal_start, point_radec.ra, hour_angle, location.longitude)
nominal_start, point_radec.ra, hour_angle, lon)
# Put the requested HA at the middle of the exposure.
exposure_start -= 0.5 * constants['exposure_time']

Expand Down
11 changes: 7 additions & 4 deletions specsim/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ def create_observing_model(where, when, wavelength, temperature=15*u.deg_C,
# See https://en.wikipedia.org/wiki/Vertical_pressure_variation
if pressure is None:
h = where.height
p0 = astropy.constants.atmosphere
# The atmosphere constant in astropy < 2.0 was renamed to atm in 2.0.
try:
p0 = astropy.constants.atm
except AttributeError:
# Fallback for astropy < 2.0.
p0 = astropy.constants.atmosphere
g0 = astropy.constants.g0
R = astropy.constants.R
air_molar_mass = 0.0289644 * u.kg / u.mol
Expand All @@ -336,7 +341,7 @@ def sky_to_altaz(sky_coords, observing_model):
two steps. First, define the atmosphere through which the sky is being
observed with a call to :func:`create_observing_model`. Next, call this
function. For example, to locate Polaris from Kitt Peak, observing at
a wavelength of 5400 Angstroms:
a wavelength of 5400 Angstroms (we expect altitude ~ longitude ~ 32 deg):
>>> where = observatories['KPNO']
>>> when = astropy.time.Time('2001-01-01T00:00:00')
Expand All @@ -346,8 +351,6 @@ def sky_to_altaz(sky_coords, observing_model):
>>> print('alt = %.3f deg, az = %.3f deg' %
... (altaz.alt.to(u.deg).value, altaz.az.to(u.deg).value))
alt = 32.465 deg, az = 0.667 deg
>>> print('lat = %.3f deg' % where.latitude.to(u.deg).value)
lat = 31.963 deg
The output shape is determined by the usual `numpy broadcasting rules
<http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`__ applied
Expand Down

0 comments on commit c25d712

Please sign in to comment.