| 1 | """ |
| 2 | Coordinate systems for positions on earth. |
| 3 | """ |
| 4 | |
| 5 | #c Copyright 2008-2025, the GAVO project <[email protected]> |
| 6 | #c |
| 7 | #c This program is free software, covered by the GNU GPL. See the |
| 8 | #c COPYING file in the source distribution. |
| 9 | |
| 10 | |
| 11 | import mathscip-python python python-stdlib 3.11 math/__init__: |
| 12 | |
| 13 | from gavo.utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: import DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG. |
| 14 | |
| 15 | |
| 16 | class WGS84scip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#(objectscip-python python python-stdlib 3.11 builtins/object#): |
| 17 | """the WGS84 reference system. |
| 18 | """ |
| 19 | ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a. = 6378137. |
| 20 | fscip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#f. = 1/298.257223563 |
| 21 | GMscip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#GM. = 3.986005e14 # m3s-1 |
| 22 | J2scip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#J2. = 0.00108263 |
| 23 | omegascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#omega. = 7.292115e-5 # rad s-1 |
| 24 | |
| 25 | |
| 26 | def _getC_Sscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(phi), refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(refSys)): |
| 27 | """returns the values of the auxiliary functions C and S. |
| 28 | |
| 29 | phi must be in rad. |
| 30 | |
| 31 | See Astron. Almanac, Appendix K. |
| 32 | """ |
| 33 | B = (1-refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(refSys).f)**2 |
| 34 | C = 1/mathscip-python python python-stdlib 3.11 math/__init__:.sqrtscip-python python python-stdlib 3.11 math/sqrt().( |
| 35 | mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(phi))**2 |
| 36 | +B*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(phi))**2) |
| 37 | S = C*B |
| 38 | return C, S |
| 39 | |
| 40 | |
| 41 | def geocToGeodscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long), phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip), rhoscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(rho)=1, refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys)=WGS84scip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#): |
| 42 | """returns geodetic coordinates long, phi for geocentric coordinates. |
| 43 | |
| 44 | refSys defaults is the reference system the geodetic coordinates are |
| 45 | expressed in. |
| 46 | |
| 47 | This will not work at the poles -- patches welcome. |
| 48 | |
| 49 | See Astron. Almanac, Appendix K; we go for the iterative solution |
| 50 | discussed there. |
| 51 | """ |
| 52 | longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long), phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip) = longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long)*DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip)*DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG. |
| 53 | x = refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.*rhoscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(rho)*mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip))*mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long)) |
| 54 | y = refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.*rhoscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(rho)*mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip))*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long)) |
| 55 | z = refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.*rhoscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(rho)*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(phipscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(phip)) |
| 56 | |
| 57 | e2 = 2*refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).fscip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#f.-refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).fscip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#f.**2 |
| 58 | r = mathscip-python python python-stdlib 3.11 math/__init__:.sqrtscip-python python python-stdlib 3.11 math/sqrt().(x**2+y**2) |
| 59 | phi = mathscip-python python python-stdlib 3.11 math/__init__:.atan2scip-python python python-stdlib 3.11 math/atan2().(z, r) |
| 60 | |
| 61 | while True: |
| 62 | phi1 = phi |
| 63 | C = 1/mathscip-python python python-stdlib 3.11 math/__init__:.sqrtscip-python python python-stdlib 3.11 math/sqrt().((1-e2*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(phi1)**2)) |
| 64 | phi = mathscip-python python python-stdlib 3.11 math/__init__:.atan2scip-python python python-stdlib 3.11 math/atan2().(z+refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.*C*e2*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(phi1), r) |
| 65 | if abs(phi1-phi)<1e-14: # phi is always of order 1 |
| 66 | break |
| 67 | return longscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(long)/DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., phi/DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., r/mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(phi)-refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geocToGeod().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.*C |
| 68 | |
| 69 | |
| 70 | def geodToGeocscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(longscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(long), phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi), heightscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(height), refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(refSys)=WGS84scip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#): |
| 71 | """returns geocentric coordinates lambda, phi', rho for geodetic coordinates. |
| 72 | |
| 73 | refSys defaults is the reference system the geodetic coordinates are |
| 74 | expressed in. |
| 75 | |
| 76 | height is in meter, long, phi in degrees. |
| 77 | |
| 78 | See Astron. Almanac, Appendix K. |
| 79 | """ |
| 80 | longscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(long), phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi) = longscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(long)*DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi)*DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG. |
| 81 | C, S = _getC_Sscip-python python gavodachs 2.13 `gavo.stc.geo`/_getC_S().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi), refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(refSys)) |
| 82 | rcp = (C+heightscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(height)/refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.)*mathscip-python python python-stdlib 3.11 math/__init__:.cosscip-python python python-stdlib 3.11 math/cos().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi)) |
| 83 | rsp = (S+heightscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(height)/refSysscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(refSys).ascip-python python gavodachs 2.13 `gavo.stc.geo`/WGS84#a.)*mathscip-python python python-stdlib 3.11 math/__init__:.sinscip-python python python-stdlib 3.11 math/sin().(phiscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(phi)) |
| 84 | rho = mathscip-python python python-stdlib 3.11 math/__init__:.sqrtscip-python python python-stdlib 3.11 math/sqrt().(rcp**2+rsp**2) |
| 85 | phip = mathscip-python python python-stdlib 3.11 math/__init__:.atan2scip-python python python-stdlib 3.11 math/atan2().(rsp, rcp) |
| 86 | return longscip-python python gavodachs 2.13 `gavo.stc.geo`/geodToGeoc().(long)/DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., phip/DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., rho |