Skip to content

Commit 2083a74

Browse files
committed
python 2.7 partial support by request
1 parent ba0cf93 commit 2083a74

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
language: python
22
fast_finish: true
3+
sudo: false
34

45
python:
5-
- 3.5
6+
- 2.7
7+
- "3.7-dev"
68

79
os:
810
- linux

pymap3d/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
from __future__ import division
18+
from six import string_types,PY2
1819
from dateutil.parser import parse
1920
from datetime import datetime
2021
import numpy as np
@@ -118,7 +119,7 @@ def eci2ecef(eci, t):
118119
raise ImportError('You need to install AstroPy')
119120

120121
t = np.atleast_1d(t)
121-
if isinstance(t[0],str): #don't just ram in in case it's float
122+
if isinstance(t[0], string_types): #don't just ram in in case it's float
122123
t = str2dt(t)
123124

124125
if isinstance(t[0], datetime):
@@ -140,7 +141,8 @@ def eci2ecef(eci, t):
140141
ecef = np.empty_like(eci)
141142

142143
for i in range(N):
143-
ecef[i, :] = _rottrip(gst[i]) @ eci[i, :]
144+
#ecef[i, :] = _rottrip(gst[i]) @ eci[i, :]
145+
ecef[i, :] = _rottrip(gst[i]).dot(eci[i, :])
144146

145147
return ecef
146148

@@ -187,7 +189,7 @@ def ecef2eci(ecef, t):
187189
raise ImportError('Please install AstroPy')
188190

189191
t = np.atleast_1d(t)
190-
if isinstance(t[0],str): #don't just ram in in case it's float
192+
if isinstance(t[0], string_types): #don't just ram in in case it's float
191193
t = str2dt(t)
192194

193195
if isinstance(t[0], datetime):
@@ -208,7 +210,8 @@ def ecef2eci(ecef, t):
208210
"""
209211
eci = np.empty_like(ecef)
210212
for i in range(N):
211-
eci[i, :] = _rottrip(gst[i]).T @ ecef[i, :] # this one is transposed
213+
#eci[i, :] = _rottrip(gst[i]).T @ ecef[i, :] # this one is transposed
214+
eci[i, :] = _rottrip(gst[i]).T.dot(ecef[i, :]) # this one is transposed
212215

213216
return eci
214217
#%% to ENU
@@ -423,10 +426,10 @@ def str2dt(t):
423426
"""
424427

425428
t = np.atleast_1d(t)
426-
if isinstance(t[0],str):
429+
if isinstance(t[0], string_types):
427430
t = [parse(T) for T in t]
428431

429-
assert isinstance(t[0],datetime), 'did not convert {} to datetime'.format(type(t[0]))
432+
assert isinstance(t[0], datetime), 'did not convert {} to datetime'.format(type(t[0]))
430433

431434
return t
432435
#%% internal use
@@ -487,15 +490,20 @@ def _uvw2enu(u, v, w, lat0, lon0, deg):
487490

488491
#%% azel radec
489492
def azel2radec(az_deg, el_deg, lat_deg, lon_deg, t):
493+
if PY2:
494+
raise RuntimeError('Python 2 is not supported for this AstroPy operation. It is time to upgrade to Python 3 (released 2008)')
495+
490496
if Time is None:
491497
raise ImportError('You need to install AstroPy')
492498

493499

494500
t = str2dt(t)
495501

496502
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
503+
497504
direc = AltAz(location=obs, obstime=Time(t),
498505
az=az_deg * u.deg, alt=el_deg * u.deg)
506+
499507
sky = SkyCoord(direc.transform_to(ICRS()))
500508

501509
return sky.ra.deg, sky.dec.deg

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(name='pymap3d',
88
packages=find_packages(),
9-
version = '1.2.5',
9+
version = '1.2.6',
1010
description='Python coordinate conversions, following convention of several popular Matlab routines.',
1111
long_description=open('README.rst').read(),
1212
author = 'Michael Hirsch, Ph.D.',
@@ -22,6 +22,6 @@
2222
install_requires=install_requires,
2323
tests_require=tests_require,
2424
extras_require={'tests':tests_require},
25-
python_requires='>=3.5', # due to @ matrix mult
25+
python_requires='>=2.7', # by request
2626
)
2727

tests/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
runs tests
44
"""
55
from datetime import datetime
6+
import six
7+
import logging
68
from numpy import asarray,radians
79
from numpy.testing import assert_allclose, assert_almost_equal,run_module_suite
810
from pytz import UTC
@@ -18,7 +20,13 @@ def test_datetime2sidereal():
1820
assert_allclose(sdrtest,2.9065780550600806,rtol=1e-5)
1921

2022
def test_azel2radec():
21-
ra,dec = pm.azel2radec(180.1, 80, 65, -148, '2014-04-06T08:00:00Z')
23+
if six.PY2:
24+
logging.error('AstroPy does not support Python 2 for this function. Python 3 was released in 2008.')
25+
return
26+
27+
ra,dec = pm.azel2radec(180.1, 80,
28+
65, -148,
29+
'2014-04-06T08:00:00Z')
2230
assert_allclose(ra,166.5032081149338,rtol=1e-2)
2331
assert_allclose(dec,55.000011165405752,rtol=1e-2)
2432

0 commit comments

Comments
 (0)