|
6 | 6 | import sys |
7 | 7 | import logging |
8 | 8 |
|
9 | | -import numpy |
10 | | - |
11 | 9 | try: |
| 10 | + import numpy |
12 | 11 | import astropy.units as u |
13 | 12 | from astropy.coordinates import GCRS, ITRS, CartesianRepresentation, EarthLocation |
14 | 13 | except ImportError: |
15 | 14 | pass |
16 | 15 |
|
| 16 | + |
17 | 17 | from .sidereal import greenwichsrt, juliandate |
18 | 18 |
|
19 | 19 | __all__ = ["eci2ecef", "ecef2eci"] |
@@ -48,11 +48,13 @@ def eci2ecef(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple: |
48 | 48 | z ECEF coordinate |
49 | 49 | """ |
50 | 50 |
|
51 | | - if force_non_astropy or "astropy" not in sys.modules: |
52 | | - logging.warning(f"{__name__}: Numpy implementation has considerably less accuracy than Astropy") |
| 51 | + if "astropy" in sys.modules and not force_non_astropy: |
| 52 | + xe, ye, ze = eci2ecef_astropy(x, y, z, time) |
| 53 | + elif "numpy" in sys.modules: |
| 54 | + logging.warning(f"{__name__}: Numpy implementation has much less accuracy than Astropy") |
53 | 55 | xe, ye, ze = eci2ecef_numpy(x, y, z, time) |
54 | 56 | else: |
55 | | - xe, ye, ze = eci2ecef_astropy(x, y, z, time) |
| 57 | + raise ImportError("eci2ecef requires either Numpy or Astropy") |
56 | 58 |
|
57 | 59 | return xe.squeeze()[()], ye.squeeze()[()], ze.squeeze()[()] |
58 | 60 |
|
@@ -135,12 +137,13 @@ def ecef2eci(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple: |
135 | 137 | z ECI coordinate |
136 | 138 | """ |
137 | 139 |
|
138 | | - # if astropy is imported |
139 | | - if force_non_astropy or "astropy" not in sys.modules: |
140 | | - logging.warning(f"{__name__}: Numpy implementation has considerably less accuracy than Astropy") |
| 140 | + if "astropy" in sys.modules and not force_non_astropy: |
| 141 | + xe, ye, ze = ecef2eci_astropy(x, y, z, time) |
| 142 | + elif "numpy" in sys.modules: |
| 143 | + logging.warning(f"{__name__}: Numpy implementation has much less accuracy than Astropy") |
141 | 144 | xe, ye, ze = ecef2eci_numpy(x, y, z, time) |
142 | 145 | else: |
143 | | - xe, ye, ze = ecef2eci_astropy(x, y, z, time) |
| 146 | + raise ImportError("ecef2eci requires either Numpy or Astropy") |
144 | 147 |
|
145 | 148 | return xe, ye, ze |
146 | 149 |
|
|
0 commit comments