|
3 | 3 | runs tests |
4 | 4 | """ |
5 | 5 | from datetime import datetime |
6 | | -import six |
7 | | -import logging |
8 | 6 | from numpy import asarray,radians |
9 | 7 | from numpy.testing import assert_allclose, assert_almost_equal,run_module_suite |
10 | 8 | from pytz import UTC |
11 | | -from dateutil.parser import parse |
12 | 9 | # |
13 | 10 | import pymap3d as pm |
14 | 11 | from pymap3d.haversine import angledist,angledist_meeus |
15 | 12 | from pymap3d.vincenty import vreckon,vdist |
16 | 13 | from pymap3d.datetime2hourangle import datetime2sidereal |
| 14 | +from pymap3d.vallado import vazel2radec, vradec2azel |
| 15 | +from pymap3d.timeconv import str2dt |
| 16 | + |
| 17 | +def test_str2dt(): |
| 18 | + |
| 19 | + assert str2dt('2014-04-06T08:00:00Z') == datetime(2014,4,6,8, tzinfo=UTC) |
| 20 | + ti = [str2dt('2014-04-06T08:00:00Z'), str2dt('2014-04-06T08:01:02Z')] |
| 21 | + to = [datetime(2014,4,6,8, tzinfo=UTC), datetime(2014,4,6,8,1,2, tzinfo=UTC)] |
| 22 | + assert ti == to # even though ti is numpy array of datetime and to is list of datetime |
| 23 | + |
| 24 | +# %% |
| 25 | +t = '2014-04-06T08:00:00Z' |
| 26 | +rdlat, rdlon = (65, -148) |
| 27 | +ra, dec = (166.5032081149338,55.000011165405752) |
| 28 | +ha = 45.482789587392013 |
| 29 | +azi, eli = (180.1,80) |
17 | 30 |
|
18 | 31 | def test_datetime2sidereal(): |
19 | | - sdrtest = datetime2sidereal(datetime(2014,4,6,8), radians(-148), False) |
20 | | - assert_allclose(sdrtest,2.9065780550600806,rtol=1e-5) |
| 32 | + sdrapy = datetime2sidereal(t, radians(rdlon), False) |
| 33 | + assert_allclose(sdrapy, 2.9065780550600806, rtol=1e-5) |
| 34 | + |
| 35 | + sdrvallado = datetime2sidereal(t, radians(rdlon), True) |
| 36 | + assert_allclose(sdrvallado, 2.9065780550600806, rtol=1e-5) |
| 37 | + |
21 | 38 |
|
22 | 39 | def test_azel2radec(): |
23 | | - if six.PY2: |
24 | | - logging.error('AstroPy does not support Python 2 for this function. Python 3 was released in 2008.') |
25 | | - return |
| 40 | + R,D = pm.azel2radec(azi, eli, rdlat, rdlon, t) |
| 41 | + assert_allclose(R, ra, rtol=1e-2) |
| 42 | + assert_allclose(D, dec, rtol=1e-2) |
| 43 | + |
| 44 | + Rv, Dv = vazel2radec(azi, eli, rdlat, rdlon, t) |
| 45 | + assert_allclose(Rv, ra) |
| 46 | + assert_allclose(Dv, dec) |
26 | 47 |
|
27 | | - ra,dec = pm.azel2radec(180.1, 80, |
28 | | - 65, -148, |
29 | | - '2014-04-06T08:00:00Z') |
30 | | - assert_allclose(ra,166.5032081149338,rtol=1e-2) |
31 | | - assert_allclose(dec,55.000011165405752,rtol=1e-2) |
32 | 48 |
|
33 | 49 | def test_radec2azel(): |
34 | | - aztest, eltest = pm.radec2azel(166.5032081149338,55.000011165405752, 65, -148, |
35 | | - parse('2014-04-06T08:00:00')) |
36 | | - assert_allclose(aztest, 179.40287898,rtol=1e-2) #180.1 from vallado, but his is less precise |
37 | | - assert_allclose(eltest, 79.92186504,rtol=1e-2) #80.0 from vallado, but his is less precise |
| 50 | + azapy, elapy = pm.radec2azel(ra,dec, rdlat, rdlon, t) |
| 51 | + assert_allclose(azapy, azi, rtol=1e-2) |
| 52 | + assert_allclose(elapy, eli, rtol=1e-2) |
| 53 | + |
| 54 | + azvallado, elvallado = vradec2azel(ra, dec, rdlat, rdlon, t) |
| 55 | + assert_allclose(azvallado, azi, rtol=1e-2) |
| 56 | + assert_allclose(elvallado, eli, rtol=1e-2) |
| 57 | + |
38 | 58 |
|
39 | 59 | def test_haversine(): |
40 | | - assert_almost_equal(angledist(35,23,84,20),45.482789587392013) |
| 60 | + assert_almost_equal(angledist(35,23, 84,20), ha) |
41 | 61 | #%% compare with astropy |
42 | | - assert_almost_equal(45.482789587392013, angledist_meeus(35,23, 84,20)) |
| 62 | + assert_almost_equal(ha, angledist_meeus(35,23, 84,20)) |
| 63 | + |
43 | 64 |
|
44 | 65 | def test_vreckon(): |
45 | 66 | lat2,lon2,a21 = vreckon(10,20,3000,38) |
|
0 commit comments