Compare commits
67 Commits
8113d743c0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d90ff5df69 | |||
| 59ad560f36 | |||
| 5a293a823a | |||
| 36b62059fc | |||
| 57a086f6cb | |||
| b8d07307aa | |||
| 798cace25d | |||
| 4f7b9aaef0 | |||
| 1fbfb555a4 | |||
|
|
db05f7b6db | ||
|
|
73e3694a2a | ||
| ffc8d3fbce | |||
|
|
fd02694ae4 | ||
| e1ac0415e7 | |||
| e7641ba64f | |||
|
|
fc9bc5defb | ||
|
|
2864ce50ff | ||
|
|
b44c25928e | ||
|
|
67248f9ca9 | ||
|
|
71c13c568a | ||
| 19887e4ac5 | |||
| 737e4730aa | |||
|
|
020d282420 | ||
|
|
cefa98e3b7 | ||
| e8624159e2 | |||
|
|
cfab70ac55 | ||
| ee85e8b0e6 | |||
| 02ce0c0b4a | |||
| 3fd967e843 | |||
| 322ac94299 | |||
| 49d03786dc | |||
| ef99294502 | |||
| b3a73270c2 | |||
| 7a425eae77 | |||
|
|
bd411a8cd7 | ||
|
|
d6f9bc4302 | ||
| 50326ba246 | |||
|
|
0eeb35f173 | ||
| 2954c0ee3a | |||
| 476b51071b | |||
| a836d2d534 | |||
|
|
7a2a843285 | ||
|
|
9591045ee2 | ||
|
|
81ca8a4770 | ||
| 6e63b3c965 | |||
| af8ac02e5b | |||
| e14869691b | |||
|
|
f68d11c031 | ||
|
|
5d4ed35f17 | ||
|
|
2ba4dad30d | ||
|
|
dd5cf2d6a8 | ||
|
|
9f0554039c | ||
| a864cd9279 | |||
| e894c7089a | |||
| f75672ec36 | |||
| e11edd2a43 | |||
| 82444208d7 | |||
| 36e243d6d4 | |||
| ac1436a7f7 | |||
| 09ae06e9b2 | |||
| 39641b5293 | |||
|
|
19c1625a11 | ||
|
|
c240da85c1 | ||
| fb4faf9aa4 | |||
| c15de91154 | |||
| 77c7a6f9ab | |||
|
|
4689a77f37 |
@@ -1,7 +1,8 @@
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
def felli(x):
|
||||
def felli(x: NDArray) -> float:
|
||||
N = x.shape[0]
|
||||
if N < 2:
|
||||
raise ValueError("dimension must be greater than one")
|
||||
@@ -9,10 +10,9 @@ def felli(x):
|
||||
return float(np.sum((1e6 ** exponents) * (x ** 2)))
|
||||
|
||||
|
||||
def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None,
|
||||
func_args=(), func_kwargs=None, seed=None,
|
||||
bestEver = np.inf, noImproveGen = 0, absTolImprove = 1e-12, maxNoImproveGen = 100, sigmaImprove = 1e-12):
|
||||
|
||||
def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000,
|
||||
func_args=(), func_kwargs=None, seed=0,
|
||||
bestEver=np.inf, noImproveGen=0, absTolImprove=1e-12, maxNoImproveGen=100, sigmaImprove=1e-12):
|
||||
if func_kwargs is None:
|
||||
func_kwargs = {}
|
||||
|
||||
@@ -27,7 +27,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
N = xmean.shape[0]
|
||||
|
||||
if stopeval is None:
|
||||
stopeval = int(1e3 * N**2)
|
||||
stopeval = int(1e3 * N ** 2)
|
||||
|
||||
# Strategy parameter setting: Selection
|
||||
lambda_ = 4 + int(np.floor(3 * np.log(N)))
|
||||
@@ -37,14 +37,14 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
weights = np.log(mu + 0.5) - np.log(np.arange(1, int(mu) + 1))
|
||||
mu = int(np.floor(mu))
|
||||
weights = weights / np.sum(weights)
|
||||
mueff = np.sum(weights)**2 / np.sum(weights**2)
|
||||
mueff = np.sum(weights) ** 2 / np.sum(weights ** 2)
|
||||
|
||||
# Strategy parameter setting: Adaptation
|
||||
cc = (4 + mueff / N) / (N + 4 + 2 * mueff / N)
|
||||
cs = (mueff + 2) / (N + mueff + 5)
|
||||
c1 = 2 / ((N + 1.3)**2 + mueff)
|
||||
c1 = 2 / ((N + 1.3) ** 2 + mueff)
|
||||
cmu = min(1 - c1,
|
||||
2 * (mueff - 2 + 1 / mueff) / ((N + 2)**2 + 2 * mueff))
|
||||
2 * (mueff - 2 + 1 / mueff) / ((N + 2) ** 2 + 2 * mueff))
|
||||
damps = 1 + 2 * max(0, np.sqrt((mueff - 1) / (N + 1)) - 1) + cs
|
||||
|
||||
# Initialize dynamic (internal) strategy parameters and constants
|
||||
@@ -54,7 +54,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
D = np.eye(N)
|
||||
C = B @ D @ (B @ D).T
|
||||
eigeneval = 0
|
||||
chiN = np.sqrt(N) * (1 - 1/(4*N) + 1/(21 * N**2))
|
||||
chiN = np.sqrt(N) * (1 - 1 / (4 * N) + 1 / (21 * N ** 2))
|
||||
|
||||
# Generation Loop
|
||||
counteval = 0
|
||||
@@ -64,7 +64,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
|
||||
gen = 0
|
||||
|
||||
print(f' [CMA-ES] Start: lambda = {lambda_}, sigma ={round(sigma, 6)}, stopeval = {stopeval}')
|
||||
# print(f' [CMA-ES] Start: lambda = {lambda_}, sigma ={round(sigma, 6)}, stopeval = {stopeval}')
|
||||
|
||||
while counteval < stopeval:
|
||||
gen += 1
|
||||
@@ -91,27 +91,24 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
bestEver = fbest
|
||||
noImproveGen = 0
|
||||
else:
|
||||
noImproveGen = noImproveGen + 1
|
||||
noImproveGen += 1
|
||||
|
||||
|
||||
if gen == 1 or gen%50==0:
|
||||
print(f' [CMA-ES] Gen {gen}, best = {round(fbest, 6)}, sigma = {sigma:.3g}')
|
||||
if gen == 1 or gen % 50 == 0:
|
||||
# print(f' [CMA-ES] Gen {gen}, best = {round(fbest, 6)}, sigma = {sigma:.3g}')
|
||||
pass
|
||||
|
||||
if noImproveGen >= maxNoImproveGen:
|
||||
print(f' [CMA-ES] Abbruch: keine Verbesserung > {round(absTolImprove, 3)} in {maxNoImproveGen} Generationen.')
|
||||
# print(f' [CMA-ES] Abbruch: keine Verbesserung > {round(absTolImprove, 3)} in {maxNoImproveGen} Generationen.')
|
||||
break
|
||||
|
||||
if sigma < sigmaImprove:
|
||||
print(f' [CMA-ES] Abbruch: sigma zu klein {sigma:.3g}')
|
||||
# print(f' [CMA-ES] Abbruch: sigma zu klein {sigma:.3g}')
|
||||
break
|
||||
|
||||
|
||||
|
||||
# Cumulation: Update evolution paths
|
||||
ps = (1 - cs) * ps + np.sqrt(cs * (2 - cs) * mueff) * (B @ zmean)
|
||||
norm_ps = np.linalg.norm(ps)
|
||||
hsig = norm_ps / np.sqrt(1 - (1 - cs)**(2 * counteval / lambda_)) / chiN < \
|
||||
(1.4 + 2 / (N + 1))
|
||||
hsig = norm_ps / np.sqrt(1 - (1 - cs) ** (2 * counteval / lambda_)) / chiN < (1.4 + 2 / (N + 1))
|
||||
hsig = 1.0 if hsig else 0.0
|
||||
|
||||
pc = (1 - cc) * pc + hsig * np.sqrt(cc * (2 - cc) * mueff) * (B @ D @ zmean)
|
||||
@@ -140,16 +137,17 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None
|
||||
# Escape flat fitness, or better terminate?
|
||||
if arfitness[0] == arfitness[int(np.ceil(0.7 * lambda_)) - 1]:
|
||||
sigma = sigma * np.exp(0.2 + cs / damps)
|
||||
print(' [CMA-ES] stopfitness erreicht.')
|
||||
#print("warning: flat fitness, consider reformulating the objective")
|
||||
# print(' [CMA-ES] stopfitness erreicht.')
|
||||
# print("warning: flat fitness, consider reformulating the objective")
|
||||
break
|
||||
|
||||
#print(f"{counteval}: {arfitness[0]}")
|
||||
# print(f"{counteval}: {arfitness[0]}")
|
||||
|
||||
#Final Message
|
||||
#print(f"{counteval}: {arfitness[0]}")
|
||||
# Final Message
|
||||
# print(f"{counteval}: {arfitness[0]}")
|
||||
xmin = arx[:, arindex[0]]
|
||||
bestValue = arfitness[0]
|
||||
print(f' [CMA-ES] Ende: Gen = {gen}, best = {round(bestValue, 6)}')
|
||||
# print(f' [CMA-ES] Ende: Gen = {gen}, best = {round(bestValue, 6)}')
|
||||
return xmin
|
||||
|
||||
|
||||
247
ES/gha1_ES.py
Normal file
247
ES/gha1_ES.py
Normal file
@@ -0,0 +1,247 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from ES.Hansen_ES_CMA import escma
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from GHA_triaxial.gha1_approx import gha1_approx
|
||||
from GHA_triaxial.utils import jacobi_konstante
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_mpi_pi
|
||||
|
||||
|
||||
def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
|
||||
-> Tuple[NDArray, NDArray, NDArray, float, float, NDArray]:
|
||||
"""
|
||||
Analytische ENU-Basis in ellipsoidische Koordinaten (β, ω) nach Karney (2025), S. 2
|
||||
:param beta: Beta Koordinate
|
||||
:param omega: Omega Koordinate
|
||||
:param ell: Ellipsoid
|
||||
:return: E_hat = Einheitsrichtung entlang wachsendem ω (East)
|
||||
N_hat = Einheitsrichtung entlang wachsendem β (North)
|
||||
U_hat = Einheitsnormale (Up)
|
||||
En & Nn = Längen der unnormierten Ableitungen
|
||||
R (XYZ) = Punkt in XYZ
|
||||
"""
|
||||
# Berechnungshilfen
|
||||
omega = wrap_mpi_pi(omega)
|
||||
cb = np.cos(beta)
|
||||
sb = np.sin(beta)
|
||||
co = np.cos(omega)
|
||||
so = np.sin(omega)
|
||||
# D = sqrt(a^2 - c^2)
|
||||
D = np.sqrt(ell.ax*ell.ax - ell.b*ell.b)
|
||||
# Sx = sqrt(a^2 - b^2 sin^2β - c^2 cos^2β)
|
||||
Sx = np.sqrt(ell.ax*ell.ax - ell.ay*ell.ay*(sb*sb) - ell.b*ell.b*(cb*cb))
|
||||
# Sz = sqrt(a^2 sin^2ω + b^2 cos^2ω - c^2)
|
||||
Sz = np.sqrt(ell.ax*ell.ax*(so*so) + ell.ay*ell.ay*(co*co) - ell.b*ell.b)
|
||||
|
||||
# Karney Gl. (4)
|
||||
X = ell.ax * co * Sx / D
|
||||
Y = ell.ay * cb * so
|
||||
Z = ell.b * sb * Sz / D
|
||||
R = np.array([X, Y, Z], dtype=float)
|
||||
|
||||
# --- Ableitungen - Karney Gl. (5a,b,c)---
|
||||
# E = ∂R/∂ω
|
||||
dX_dw = -ell.ax * so * Sx / D
|
||||
dY_dw = ell.ay * cb * co
|
||||
dZ_dw = ell.b * sb * (so * co * (ell.ax*ell.ax - ell.ay*ell.ay) / Sz) / D
|
||||
E = np.array([dX_dw, dY_dw, dZ_dw], dtype=float)
|
||||
|
||||
# N = ∂R/∂β
|
||||
dX_db = ell.ax * co * (sb * cb * (ell.b*ell.b - ell.ay*ell.ay) / Sx) / D
|
||||
dY_db = -ell.ay * sb * so
|
||||
dZ_db = ell.b * cb * Sz / D
|
||||
N = np.array([dX_db, dY_db, dZ_db], dtype=float)
|
||||
|
||||
# U = Grad(x^2/a^2 + y^2/b^2 + z^2/c^2 - 1)
|
||||
U = np.array([X/(ell.ax*ell.ax), Y/(ell.ay*ell.ay), Z/(ell.b*ell.b)], dtype=float)
|
||||
|
||||
En = float(np.linalg.norm(E))
|
||||
Nn = float(np.linalg.norm(N))
|
||||
Un = float(np.linalg.norm(U))
|
||||
|
||||
N_hat = N / Nn
|
||||
E_hat = E / En
|
||||
U_hat = U / Un
|
||||
E_hat -= float(np.dot(E_hat, N_hat)) * N_hat
|
||||
E_hat = E_hat / max(np.linalg.norm(E_hat), 1e-18)
|
||||
|
||||
return E_hat, N_hat, U_hat, En, Nn, R
|
||||
|
||||
|
||||
def azimuth_at_ESpoint(P_prev: NDArray, P_curr: NDArray, E_hat_curr: NDArray, N_hat_curr: NDArray, U_hat_curr: NDArray) -> float:
|
||||
"""
|
||||
Berechnet das Azimut in der lokalen Tangentialebene am aktuellen Punkt P_curr, gemessen
|
||||
an der Bewegungsrichtung vom vorherigen Punkt P_prev nach P_curr.
|
||||
:param P_prev: vorheriger Punkt
|
||||
:param P_curr: aktueller Punkt
|
||||
:param E_hat_curr: Einheitsvektor der lokalen Tangentialrichtung am Punkt P_curr
|
||||
:param N_hat_curr: Einheitsvektor der lokalen Tangentialrichtung am Punkt P_curr
|
||||
:param U_hat_curr: Einheitsnormalenvektor am Punkt P_curr
|
||||
:return: Azimut in Radiant
|
||||
"""
|
||||
v = (P_curr - P_prev).astype(float)
|
||||
vT = v - float(np.dot(v, U_hat_curr)) * U_hat_curr
|
||||
vTn = max(np.linalg.norm(vT), 1e-18)
|
||||
vT_hat = vT / vTn
|
||||
sE = float(np.dot(vT_hat, E_hat_curr))
|
||||
sN = float(np.dot(vT_hat, N_hat_curr))
|
||||
|
||||
return wrap_mpi_pi(float(np.arctan2(sE, sN)))
|
||||
|
||||
|
||||
def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float, gamma0: float,
|
||||
ell: EllipsoidTriaxial, maxSegLen: float = 1000.0, sigma0: float = None) -> Tuple[float, float, NDArray, float]:
|
||||
"""
|
||||
Berechnung der 1. GHA mithilfe der CMA-ES.
|
||||
Die CMA-ES optimiert sukzessive einen Punkt, der maxSegLen vom vorherigen Punkt entfernt und zusätzlich auf der
|
||||
geodätischen Linien liegt. Somit entsteht ein Geodäten ähnlicher Polygonzug auf der Oberfläche des dreiachsigen Ellipsoids.
|
||||
:param beta_i: Beta Koordinate am Punkt i
|
||||
:param omega_i: Omega Koordinate am Punkt i
|
||||
:param alpha_i: Azimut am Punkt i
|
||||
:param ds: Gesamtlänge
|
||||
:param gamma0: Jacobi-Konstante am Startpunkt
|
||||
:param ell: Ellipsoid
|
||||
:param maxSegLen: maximale Segmentlänge
|
||||
:param sigma0:
|
||||
:return:
|
||||
"""
|
||||
# Startbasis
|
||||
E_i, N_i, U_i, En_i, Nn_i, P_i = ENU_beta_omega(beta_i, omega_i, ell)
|
||||
# Prediktor: dβ ≈ ds cosα / |N|, dω ≈ ds sinα / |E|
|
||||
|
||||
En_eff = max(En_i, 1e-9)
|
||||
Nn_eff = max(Nn_i, 1e-9)
|
||||
|
||||
d_beta = ds * np.cos(alpha_i) / Nn_eff
|
||||
d_omega = ds * np.sin(alpha_i) / En_eff
|
||||
|
||||
# optional: harte Schritt-Clamps (verhindert wrap-chaos)
|
||||
d_beta = float(np.clip(d_beta, -0.2, 0.2)) # rad
|
||||
d_omega = float(np.clip(d_omega, -0.2, 0.2)) # rad
|
||||
|
||||
# d_beta = ds * float(np.cos(alpha_i)) / Nn_i
|
||||
# d_omega = ds * float(np.sin(alpha_i)) / En_i
|
||||
beta_pred = beta_i + d_beta
|
||||
omega_pred = wrap_mpi_pi(omega_i + d_omega)
|
||||
|
||||
xmean = np.array([beta_pred, omega_pred], dtype=float)
|
||||
|
||||
if sigma0 is None:
|
||||
R0 = (ell.ax + ell.ay + ell.b) / 3
|
||||
sigma0 = 1e-5 * (ds / R0)
|
||||
|
||||
def fitness(x: NDArray) -> float:
|
||||
"""
|
||||
Fitnessfunktion: Fitnesscheck erfolgt anhand der Segmentlänge und der Jacobi-Konstante.
|
||||
Die Segmentlänge muss möglichst gut zum Sollwert passen. Die Jacobi-Konstante am Punkt x muss zur
|
||||
Jacobi-Konstanten am Startpunkt passen, damit der Polygonzug auf derselben geodätischen Linie bleibt.
|
||||
:param x: Koordinate in beta, lambda aus der CMA-ES
|
||||
:return: Fitnesswert (f)
|
||||
"""
|
||||
beta = x[0]
|
||||
omega = wrap_mpi_pi(x[1])
|
||||
|
||||
P = ell.ell2cart_karney(beta, omega) # in kartesischer Koordinaten
|
||||
d = float(np.linalg.norm(P - P_i)) # Distanz zwischen
|
||||
|
||||
# maxSegLen einhalten
|
||||
J_len = ((d - ds) / ds) ** 2
|
||||
w_len = 1.0
|
||||
|
||||
# Azimut für Jacobi-Konstante
|
||||
E_j, N_j, U_j, _, _, _ = ENU_beta_omega(beta, omega, ell)
|
||||
alpha_end = azimuth_at_ESpoint(P_i, P, E_j, N_j, U_j)
|
||||
|
||||
# Jacobi-Konstante
|
||||
g_end = jacobi_konstante(beta, omega, alpha_end, ell)
|
||||
J_gamma = (g_end - gamma0) ** 2
|
||||
w_gamma = 10
|
||||
|
||||
f = float(w_len * J_len + w_gamma * J_gamma)
|
||||
|
||||
return f
|
||||
|
||||
xb = escma(fitness, N=2, xmean=xmean, sigma=sigma0) # Aufruf CMA-ES
|
||||
|
||||
beta_best = xb[0]
|
||||
omega_best = wrap_mpi_pi(xb[1])
|
||||
P_best = ell.ell2cart_karney(beta_best, omega_best)
|
||||
E_j, N_j, U_j, _, _, _ = ENU_beta_omega(beta_best, omega_best, ell)
|
||||
alpha_end = azimuth_at_ESpoint(P_i, P_best, E_j, N_j, U_j)
|
||||
|
||||
return beta_best, omega_best, P_best, alpha_end
|
||||
|
||||
|
||||
def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float, s_total: float, maxSegLen: float = 1000, all_points: bool = False)\
|
||||
-> Tuple[NDArray, float, NDArray] | Tuple[NDArray, float]:
|
||||
"""
|
||||
Aufruf der 1. GHA mittels CMA-ES
|
||||
:param ell: Ellipsoid
|
||||
:param beta0: Beta Startkoordinate
|
||||
:param omega0: Omega Startkoordinate
|
||||
:param alpha0: Azimut Startkoordinate
|
||||
:param s_total: Gesamtstrecke
|
||||
:param maxSegLen: maximale Segmentlänge
|
||||
:param all_points: Alle Punkte ausgeben?
|
||||
:return: Zielpunkt Pk, Azimut am Zielpunkt und Punktliste
|
||||
"""
|
||||
beta = float(beta0)
|
||||
omega = wrap_mpi_pi(float(omega0))
|
||||
alpha = wrap_mpi_pi(float(alpha0))
|
||||
|
||||
gamma0 = jacobi_konstante(beta, omega, alpha, ell) # Referenz-γ0
|
||||
|
||||
P_all: List[NDArray] = [ell.ell2cart_karney(beta, omega)]
|
||||
alpha_end: List[float] = [alpha]
|
||||
|
||||
s_acc = 0.0
|
||||
step = 0
|
||||
nsteps_est = int(np.ceil(s_total / maxSegLen))
|
||||
while s_acc < s_total - 1e-9:
|
||||
step += 1
|
||||
ds = min(maxSegLen, s_total - s_acc)
|
||||
# print(f"[GHA1-ES] Step {step}/{nsteps_est} ds={ds:.3f} m s_acc={s_acc:.3f} m beta={beta:.6f} omega={omega:.6f} alpha={alpha:.6f}")
|
||||
|
||||
beta, omega, P, alpha = optimize_next_point(beta_i=beta, omega_i=omega, alpha_i=alpha, ds=ds, gamma0=gamma0,
|
||||
ell=ell, maxSegLen=maxSegLen)
|
||||
s_acc += ds
|
||||
P_all.append(P)
|
||||
alpha_end.append(wrap_mpi_pi(alpha))
|
||||
if step > nsteps_est + 50:
|
||||
raise RuntimeError("GHA1_ES: Zu viele Schritte – vermutlich Konvergenzproblem / falsche Azimut-Konvention.")
|
||||
Pk = P_all[-1]
|
||||
alpha1 = float(alpha_end[-1])
|
||||
|
||||
if all_points:
|
||||
return Pk, alpha1, np.array(P_all)
|
||||
else:
|
||||
return Pk, alpha1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
s = 180000
|
||||
# alpha0 = 3
|
||||
alpha0 = wu.gms2rad([5, 0, 0])
|
||||
beta = 0
|
||||
omega = 0
|
||||
P0 = ell.ell2cart(beta, omega)
|
||||
point1, alpha1 = gha1_ana(ell, P0, alpha0=alpha0, s=s, maxM=100, maxPartCircum=32)
|
||||
point1app, alpha1app = gha1_approx(ell, P0, alpha0=alpha0, s=s, ds=1000)
|
||||
|
||||
res, alpha, points = gha1_ES(ell, beta0=beta, omega0=-omega, alpha0=alpha0, s_total=s, maxSegLen=1000)
|
||||
|
||||
print(point1)
|
||||
print(res)
|
||||
print(alpha)
|
||||
print(points)
|
||||
# print("alpha1 (am Endpunkt):", res.alpha1)
|
||||
print(res - point1)
|
||||
print(point1app - point1, "approx")
|
||||
@@ -1,14 +1,13 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from Hansen_ES_CMA import escma
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from numpy.typing import NDArray
|
||||
import plotly.graph_objects as go
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ES.Hansen_ES_CMA import escma
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
from GHA_triaxial.utils import sigma2alpha
|
||||
|
||||
ell_ES: EllipsoidTriaxial = None
|
||||
P_left: NDArray = None
|
||||
P_right: NDArray = None
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
|
||||
def Sehne(P1: NDArray, P2: NDArray) -> float:
|
||||
@@ -19,58 +18,57 @@ def Sehne(P1: NDArray, P2: NDArray) -> float:
|
||||
:return: Bogenlänge s
|
||||
"""
|
||||
R12 = P2-P1
|
||||
s = np.linalg.norm(R12)
|
||||
s = float(np.linalg.norm(R12))
|
||||
|
||||
return s
|
||||
|
||||
|
||||
def midpoint_fitness(x: tuple) -> float:
|
||||
"""
|
||||
Fitness für einen Mittelpunkt P_middle zwischen P_left und P_right auf dem triaxialen Ellipsoid:
|
||||
- Minimiert d(P_left, P_middle) + d(P_middle, P_right)
|
||||
- Erzwingt d(P_left,P_middle) ≈ d(P_middle,P_right) (echter Mittelpunkt im Sinne der Polygonkette)
|
||||
:param x: enthält die Startwerte von u und v
|
||||
:return: Fitnesswert (f)
|
||||
"""
|
||||
global ell_ES, P_left, P_right
|
||||
|
||||
u, v = x
|
||||
P_middle = ell_ES.para2cart(u, v)
|
||||
d1 = Sehne(P_left, P_middle)
|
||||
d2 = Sehne(P_middle, P_right)
|
||||
base = d1 + d2
|
||||
|
||||
# midpoint penalty (dimensionslos)
|
||||
# relative Differenz, skaliert stabil über verschiedene Segmentlängen
|
||||
denom = max(base, 1e-9)
|
||||
pen_equal = ((d1 - d2) / denom) ** 2
|
||||
w_equal = 10.0
|
||||
|
||||
f = base + denom * w_equal * pen_equal
|
||||
return f
|
||||
|
||||
|
||||
def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float = None, stopeval: int = 2000, maxIter: int = 10000, all_points: bool = False):
|
||||
def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float = None, all_points: bool = False) -> Tuple[float, float, float, NDArray] | Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnen der 2. GHA mithilfe der CMA-ES.
|
||||
Die CMA-ES optimiert sukzessive den Mittelpunkt zwischen Start- und Zielpunkt. Der Abbruch der Berechnung erfolgt, wenn alle Segmentlängen <= maxSegLen sind.
|
||||
Die Distanzen zwischen den einzelnen Punkten werden als direkte 3D-Distanzen berechnet und aufaddiert.
|
||||
:param ell: Parameter des triaxialen Ellipsoids
|
||||
:param ell: Ellipsoid
|
||||
:param P0: Startpunkt
|
||||
:param Pk: Zielpunkt
|
||||
:param maxSegLen: maximale Segmentlänge
|
||||
:param stopeval: maximale Durchläufe der CMA-ES
|
||||
:param maxIter: maximale Durchläufe der Mittelpunktsgenerierung
|
||||
:param all_points: Ergebnisliste mit allen Punkte, die wahlweise mit ausgegeben werden kann
|
||||
:return: Richtungswinkel des Start- und Zielpunktes und Gesamtlänge
|
||||
:param all_points: Ergebnisliste mit allen Punkte, die wahlweise mit ausgegeben wird
|
||||
:return: Richtungswinkel in RAD des Start- und Zielpunktes und Gesamtlänge
|
||||
"""
|
||||
global ell_ES
|
||||
ell_ES = ell
|
||||
P_left: NDArray = None
|
||||
P_right: NDArray = None
|
||||
|
||||
def midpoint_fitness(x: tuple) -> float:
|
||||
"""
|
||||
Fitness für einen Mittelpunkt P_middle zwischen P_left und P_right auf dem triaxialen Ellipsoid:
|
||||
- Minimiert d(P_left, P_middle) + d(P_middle, P_right)
|
||||
- Erzwingt d(P_left,P_middle) ≈ d(P_middle,P_right) (echter Mittelpunkt im Sinne der Polygonkette)
|
||||
:param x: enthält die Startwerte von u und v
|
||||
:return: Fitnesswert (f)
|
||||
"""
|
||||
nonlocal P_left, P_right, ell
|
||||
|
||||
u, v = x
|
||||
P_middle = ell.para2cart(u, v)
|
||||
d1 = Sehne(P_left, P_middle)
|
||||
d2 = Sehne(P_middle, P_right)
|
||||
base = d1 + d2
|
||||
|
||||
# midpoint penalty (dimensionslos)
|
||||
# relative Differenz, skaliert über verschiedene Segmentlängen
|
||||
denom = max(base, 1e-9)
|
||||
pen_equal = ((d1 - d2) / denom) ** 2
|
||||
w_equal = 10.0
|
||||
|
||||
f = base + denom * w_equal * pen_equal
|
||||
|
||||
return f
|
||||
|
||||
R0 = (ell.ax + ell.ay + ell.b) / 3
|
||||
if maxSegLen is None:
|
||||
maxSegLen = R0 * 1 / (637.4) # 10km Segment bei mittleren Erdradius
|
||||
maxSegLen = R0 * 1 / (637.4*2) # 10km Segment bei mittleren Erdradius
|
||||
|
||||
sigma_uv_nom = 1e-3 * (maxSegLen / R0) # ~1e-5
|
||||
|
||||
points: list[NDArray] = [P0, Pk]
|
||||
startIter = 0
|
||||
level = 0
|
||||
@@ -83,49 +81,47 @@ def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float =
|
||||
|
||||
level += 1
|
||||
new_points: list[NDArray] = [points[0]]
|
||||
|
||||
for i in range(len(points) - 1):
|
||||
A = points[i]
|
||||
B = points[i+1]
|
||||
dAB = Sehne(A, B)
|
||||
print(dAB)
|
||||
# print(dAB)
|
||||
|
||||
if dAB > maxSegLen:
|
||||
global P_left, P_right
|
||||
# global P_left, P_right
|
||||
P_left, P_right = A, B
|
||||
Au, Av = ell_ES.cart2para(A)
|
||||
Bu, Bv = ell_ES.cart2para(B)
|
||||
Au, Av = ell.cart2para(A)
|
||||
Bu, Bv = ell.cart2para(B)
|
||||
u0 = (Au + Bu) / 2
|
||||
v0 = Av + 0.5 * np.arctan2(np.sin(Bv - Av), np.cos(Bv - Av))
|
||||
xmean = [u0, v0]
|
||||
|
||||
sigmaStep = sigma_uv_nom * (Sehne(A, B) / maxSegLen)
|
||||
|
||||
u, v = escma(midpoint_fitness, N=2, xmean=xmean, sigma=sigmaStep, stopfitness=-np.inf,
|
||||
stopeval=stopeval)
|
||||
u, v = escma(midpoint_fitness, N=2, xmean=xmean, sigma=sigmaStep) # Aufruf CMA-ES
|
||||
|
||||
P_next = ell.para2cart(u, v)
|
||||
new_points.append(P_next)
|
||||
startIter += 1
|
||||
maxIter = 10000
|
||||
if startIter > maxIter:
|
||||
raise RuntimeError("Abbruch: maximale Iterationen überschritten.")
|
||||
|
||||
raise RuntimeError("GHA2_ES: maximale Iterationen überschritten")
|
||||
new_points.append(B)
|
||||
|
||||
points = new_points
|
||||
print(f"[Level {level}] Punkte: {len(points)} | max Segment: {max_len:.3f} m")
|
||||
# print(f"[Level {level}] Punkte: {len(points)} | max Segment: {max_len:.3f} m")
|
||||
|
||||
P_all = np.vstack(points)
|
||||
totalLen = float(np.sum(np.linalg.norm(P_all[1:] - P_all[:-1], axis=1)))
|
||||
|
||||
if len(points) >= 3:
|
||||
p0i = ell_ES.point_onto_ellipsoid(P0 + 10.0 * (points[1] - P0) / np.linalg.norm(points[1] - P0))
|
||||
p0i = ell.point_onto_ellipsoid(P0 + 10.0 * (points[1] - P0) / np.linalg.norm(points[1] - P0))
|
||||
sigma0 = (p0i - P0) / np.linalg.norm(p0i - P0)
|
||||
alpha0 = sigma2alpha(ell_ES, sigma0, P0)
|
||||
alpha0 = sigma2alpha(ell, sigma0, P0)
|
||||
|
||||
p1i = ell_ES.point_onto_ellipsoid(Pk - 10.0 * (Pk - points[-2]) / np.linalg.norm(Pk - points[-2]))
|
||||
p1i = ell.point_onto_ellipsoid(Pk - 10.0 * (Pk - points[-2]) / np.linalg.norm(Pk - points[-2]))
|
||||
sigma1 = (Pk - p1i) / np.linalg.norm(Pk - p1i)
|
||||
alpha1 = sigma2alpha(ell_ES, sigma1, Pk)
|
||||
alpha1 = sigma2alpha(ell, sigma1, Pk)
|
||||
else:
|
||||
alpha0 = None
|
||||
alpha1 = None
|
||||
@@ -168,17 +164,19 @@ if __name__ == '__main__':
|
||||
|
||||
beta0, lamb0 = (0.2, 0.1)
|
||||
P0 = ell.ell2cart(beta0, lamb0)
|
||||
beta1, lamb1 = (0.7, 0.3)
|
||||
beta1, lamb1 = (0.3, 0.2)
|
||||
P1 = ell.ell2cart(beta1, lamb1)
|
||||
|
||||
alpha0, alpha1, s_num, betas, lambs = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=10000, all_points=True)
|
||||
alpha0, alpha1, s_num, betas, lambs = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=1000, all_points=True)
|
||||
points_num = []
|
||||
for beta, lamb in zip(betas, lambs):
|
||||
points_num.append(ell.ell2cart(beta, lamb))
|
||||
points_num = np.array(points_num)
|
||||
|
||||
alpha0, alpha1, s, points = gha2_ES(ell, P0, P1, all_points=True)
|
||||
alpha0, alpha1, s, points = gha2_ES(ell, P0, P1)
|
||||
print(s_num)
|
||||
print(s)
|
||||
print(alpha0)
|
||||
print(alpha1)
|
||||
print(s - s_num)
|
||||
show_points(points, points_num, P0, P1)
|
||||
@@ -1,13 +1,15 @@
|
||||
import math
|
||||
from math import comb
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan2
|
||||
from numpy._typing import NDArray
|
||||
from scipy.special import factorial as fact
|
||||
from numpy import arctan2, cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.utils import pq_para
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int) -> Tuple[NDArray, float]:
|
||||
@@ -64,7 +66,7 @@ def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: floa
|
||||
x_m.append(x_(m))
|
||||
y_m.append(y_(m))
|
||||
z_m.append(z_(m))
|
||||
fact_m = fact(m)
|
||||
fact_m = math.factorial(m)
|
||||
|
||||
# 22-24
|
||||
a_m.append(x_m[m] / fact_m)
|
||||
@@ -109,10 +111,10 @@ def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: floa
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
|
||||
return p1, alpha1
|
||||
return p1, wrap_0_2pi(alpha1)
|
||||
|
||||
|
||||
def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int, maxPartCircum: int = 16) -> Tuple[NDArray, float]:
|
||||
def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int, maxPartCircum: int = 4) -> Tuple[NDArray, float]:
|
||||
"""
|
||||
:param ell: Ellipsoid
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
@@ -131,6 +133,13 @@ def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, ma
|
||||
|
||||
_, _, h = ell.cart2geod(point_end, "ligas3")
|
||||
if h > 1e-5:
|
||||
raise Exception("Analytische Methode ist explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
raise Exception("GHA1_ana: explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
|
||||
return point_end, alpha_end
|
||||
return point_end, wrap_0_2pi(alpha_end)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
p0 = ell.ell2cart(wu.deg2rad(10), wu.deg2rad(20))
|
||||
p1, alpha1 = gha1_ana(ell, p0, wu.deg2rad(36), 200000, 70)
|
||||
print(p1, wu.rad2gms(alpha1))
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from GHA_triaxial.utils import func_sigma_ell, louville_constant
|
||||
import plotly.graph_objects as go
|
||||
import winkelumrechnungen as wu
|
||||
from typing import Tuple
|
||||
|
||||
def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float, ds: float, all_points: bool = False) -> Tuple[NDArray, float] | Tuple[NDArray, float, NDArray]:
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
from numpy import cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.utils import louville_constant, pq_ell
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float, ds: float, all_points: bool = False) \
|
||||
-> Tuple[NDArray, float] | Tuple[NDArray, float, NDArray, NDArray]:
|
||||
"""
|
||||
Berechung einer Näherungslösung der ersten Hauptaufgabe
|
||||
:param ell: Ellipsoid
|
||||
@@ -20,6 +27,8 @@ def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float,
|
||||
points = [p0]
|
||||
alphas = [alpha0]
|
||||
s_curr = 0.0
|
||||
last_sigma = None
|
||||
last_p = None
|
||||
|
||||
while s_curr < s:
|
||||
ds_step = min(ds, s - s_curr)
|
||||
@@ -29,25 +38,36 @@ def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float,
|
||||
p1 = points[-1]
|
||||
alpha1 = alphas[-1]
|
||||
|
||||
sigma = func_sigma_ell(ell, p1, alpha1)
|
||||
p, q = pq_ell(ell, p1)
|
||||
if last_p is not None and np.dot(p, last_p) < 0:
|
||||
p = -p
|
||||
q = -q
|
||||
last_p = p
|
||||
sigma = p * sin(alpha1) + q * cos(alpha1)
|
||||
if last_sigma is not None and np.dot(sigma, last_sigma) < 0:
|
||||
sigma = -sigma
|
||||
alpha1 += np.pi
|
||||
alpha1 = wrap_0_2pi(alpha1)
|
||||
p2 = p1 + ds_step * sigma
|
||||
p2 = ell.point_onto_ellipsoid(p2)
|
||||
|
||||
dalpha = 1e-6
|
||||
dalpha = 1e-9
|
||||
l2 = louville_constant(ell, p2, alpha1)
|
||||
dl_dalpha = (louville_constant(ell, p2, alpha1+dalpha) - l2) / dalpha
|
||||
alpha2 = alpha1 + (l0 - l2) / dl_dalpha
|
||||
|
||||
if abs(dl_dalpha) < 1e-20:
|
||||
alpha2 = alpha1 + 0
|
||||
else:
|
||||
alpha2 = alpha1 + (l0 - l2) / dl_dalpha
|
||||
points.append(p2)
|
||||
alphas.append(alpha2)
|
||||
alphas.append(wrap_0_2pi(alpha2))
|
||||
|
||||
ds_step = np.linalg.norm(p2 - p1)
|
||||
s_curr += ds_step
|
||||
if s_curr > 10000000:
|
||||
pass
|
||||
last_sigma = sigma
|
||||
pass
|
||||
|
||||
if all_points:
|
||||
return points[-1], alphas[-1], np.array(points)
|
||||
return points[-1], alphas[-1], np.array(points), np.array(alphas)
|
||||
else:
|
||||
return points[-1], alphas[-1]
|
||||
|
||||
@@ -78,11 +98,11 @@ def show_points(points: NDArray, p0: NDArray, p1: NDArray):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
P0 = ell.para2cart(0.2, 0.3)
|
||||
alpha0 = wu.deg2rad(35)
|
||||
s = 13000000
|
||||
P1_app, alpha1_app, points = gha1_approx(ell, P0, alpha0, s, ds=10000, all_points=True)
|
||||
P1_ana, alpha1_ana = gha1_ana(ell, P0, alpha0, s, maxM=60, maxPartCircum=16)
|
||||
show_points(points, P0, P1_ana)
|
||||
print(np.linalg.norm(P1_app - P1_ana))
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
P0 = ell.ell2cart(wu.deg2rad(15), wu.deg2rad(15))
|
||||
alpha0 = wu.deg2rad(270)
|
||||
s = 1
|
||||
P1_app, alpha1_app, points, alphas = gha1_approx(ell, P0, alpha0, s, ds=0.1, all_points=True)
|
||||
# P1_ana, alpha1_ana = gha1_ana(ell, P0, alpha0, s, maxM=40, maxPartCircum=32)
|
||||
# print(np.linalg.norm(P1_app - P1_ana))
|
||||
# show_points(points, P0, P0)
|
||||
|
||||
@@ -1,17 +1,45 @@
|
||||
from typing import Callable, List, Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan2
|
||||
import ellipsoide
|
||||
import runge_kutta as rk
|
||||
import winkelumrechnungen as wu
|
||||
import GHA_triaxial.numeric_examples_karney as ne_karney
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from typing import Callable, Tuple, List
|
||||
from numpy import arctan2, cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import GHA_triaxial.numeric_examples_karney as ne_karney
|
||||
import runge_kutta as rk
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from GHA_triaxial.utils import alpha_ell2para, pq_ell
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def buildODE(ell: EllipsoidTriaxial) -> Callable:
|
||||
"""
|
||||
Aufbau des DGL-Systems
|
||||
:param ell: Ellipsoid
|
||||
:return: DGL-System
|
||||
"""
|
||||
|
||||
def ODE(s: float, v: NDArray) -> NDArray:
|
||||
"""
|
||||
DGL-System
|
||||
:param s: unabhängige Variable
|
||||
:param v: abhängige Variablen
|
||||
:return: Ableitungen der abhängigen Variablen
|
||||
"""
|
||||
x, dxds, y, dyds, z, dzds = v
|
||||
|
||||
H = ell.func_H(np.array([x, y, z]))
|
||||
h = dxds ** 2 + 1 / (1 - ell.ee ** 2) * dyds ** 2 + 1 / (1 - ell.ex ** 2) * dzds ** 2
|
||||
|
||||
ddx = -(h / H) * x
|
||||
ddy = -(h / H) * y / (1 - ell.ee ** 2)
|
||||
ddz = -(h / H) * z / (1 - ell.ex ** 2)
|
||||
|
||||
return np.array([dxds, ddx, dyds, ddy, dzds, ddz])
|
||||
|
||||
return ODE
|
||||
|
||||
def gha1_num(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, num: int, all_points: bool = False) -> Tuple[NDArray, float] | Tuple[NDArray, float, List]:
|
||||
"""
|
||||
Panou, Korakitits 2019
|
||||
@@ -34,33 +62,6 @@ def gha1_num(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, nu
|
||||
|
||||
v_init = np.array([x0, dxds0, y0, dyds0, z0, dzds0])
|
||||
|
||||
def buildODE(ell: EllipsoidTriaxial) -> Callable:
|
||||
"""
|
||||
Aufbau des DGL-Systems
|
||||
:param ell: Ellipsoid
|
||||
:return: DGL-System
|
||||
"""
|
||||
|
||||
def ODE(s: float, v: NDArray) -> NDArray:
|
||||
"""
|
||||
DGL-System
|
||||
:param s: unabhängige Variable
|
||||
:param v: abhängige Variablen
|
||||
:return: Ableitungen der abhängigen Variablen
|
||||
"""
|
||||
x, dxds, y, dyds, z, dzds = v
|
||||
|
||||
H = ell.func_H(np.array([x, y, z]))
|
||||
h = dxds ** 2 + 1 / (1 - ell.ee ** 2) * dyds ** 2 + 1 / (1 - ell.ex ** 2) * dzds ** 2
|
||||
|
||||
ddx = -(h / H) * x
|
||||
ddy = -(h / H) * y / (1 - ell.ee ** 2)
|
||||
ddz = -(h / H) * z / (1 - ell.ex ** 2)
|
||||
|
||||
return np.array([dxds, ddx, dyds, ddy, dzds, ddz])
|
||||
|
||||
return ODE
|
||||
|
||||
ode = buildODE(ell)
|
||||
|
||||
_, werte = rk.rk4(ode, 0, v_init, s, num)
|
||||
@@ -75,8 +76,11 @@ def gha1_num(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, nu
|
||||
|
||||
alpha1 = arctan2(P, Q)
|
||||
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
alpha1 = wrap_0_2pi(alpha1)
|
||||
|
||||
_, _, h = ell.cart2geod(point1, "ligas3")
|
||||
if h > 1e-5:
|
||||
raise Exception("GHA1_num: explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
|
||||
if all_points:
|
||||
return point1, alpha1, werte
|
||||
@@ -104,7 +108,7 @@ if __name__ == "__main__":
|
||||
# diffs_panou[mask_360] = np.abs(diffs_panou[mask_360] - 360)
|
||||
# print(diffs_panou)
|
||||
|
||||
ell: EllipsoidTriaxial = ellipsoide.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
ell: EllipsoidTriaxial = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
diffs_karney = []
|
||||
# examples_karney = ne_karney.get_examples((30499, 30500, 40500))
|
||||
examples_karney = ne_karney.get_random_examples(20)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
import plotly.graph_objects as go
|
||||
import winkelumrechnungen as wu
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
from GHA_triaxial.utils import sigma2alpha
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
|
||||
def gha2_approx(ell: EllipsoidTriaxial, p0: NDArray, p1: NDArray, ds: float, all_points: bool = False) -> Tuple[float, float, float] | Tuple[float, float, float, NDArray]:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,12 @@
|
||||
import random
|
||||
from typing import List
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from typing import List, Tuple
|
||||
from GHA_triaxial.utils import jacobi_konstante
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
file_path = r"Karney_2024_Testset.txt"
|
||||
|
||||
def line2example(line: str) -> List:
|
||||
"""
|
||||
@@ -26,7 +32,7 @@ def get_random_examples(num: int, seed: int = None) -> List:
|
||||
"""
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
with open(r"C:\Users\moell\OneDrive\Desktop\Vorlesungen\Master-Projekt\Python_Masterprojekt\GHA_triaxial\Karney_2024_Testset.txt") as datei:
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
for i in range(num):
|
||||
@@ -41,7 +47,7 @@ def get_examples(l_i: List) -> List:
|
||||
:param l_i: Liste von Indizes
|
||||
:return: Liste mit Beispielen
|
||||
"""
|
||||
with open("Karney_2024_Testset.txt") as datei:
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
for i in l_i:
|
||||
@@ -50,5 +56,63 @@ def get_examples(l_i: List) -> List:
|
||||
return examples
|
||||
|
||||
|
||||
def get_random_examples_gamma(group: str, num: int, seed: int = None, length: str = None) -> List:
|
||||
"""
|
||||
Zufällige Beispiele aus Karney in Gruppen nach Einteilung anhand der Jacobi-Konstanten
|
||||
:param group: Gruppe
|
||||
:param num: Anzahl
|
||||
:param seed: Random-Seed
|
||||
:param length: long oder short, sond egal
|
||||
:return: Liste mit Beispielen
|
||||
"""
|
||||
eps = 1e-20
|
||||
long_short = 2
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
i = 0
|
||||
while len(examples) < num and i < len(lines):
|
||||
example = line2example(lines[random.randint(0, len(lines) - 1)])
|
||||
if example in examples:
|
||||
continue
|
||||
i += 1
|
||||
|
||||
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
|
||||
gamma = jacobi_konstante(beta0, lamb0, alpha0_ell, ell)
|
||||
|
||||
if group not in ["a", "b", "c", "d", "e", "de"]:
|
||||
break
|
||||
elif group == "a" and not 1 >= gamma >= 0.01:
|
||||
continue
|
||||
elif group == "b" and not 0.01 > gamma > eps:
|
||||
continue
|
||||
elif group == "c" and not abs(gamma) <= eps:
|
||||
continue
|
||||
elif group == "d" and not -eps > gamma > -1e-17:
|
||||
continue
|
||||
elif group == "e" and not -1e-17 >= gamma >= -1:
|
||||
continue
|
||||
elif group == "de" and not -eps > gamma > -1:
|
||||
continue
|
||||
|
||||
if length == "short":
|
||||
if example[6] < long_short:
|
||||
examples.append(example)
|
||||
elif length == "long":
|
||||
if example[6] >= long_short:
|
||||
examples.append(example)
|
||||
else:
|
||||
examples.append(example)
|
||||
|
||||
return examples
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_random_examples(10)
|
||||
examples_a = get_random_examples_gamma("a", 10, 42)
|
||||
examples_b = get_random_examples_gamma("b", 10, 42)
|
||||
examples_c = get_random_examples_gamma("c", 10, 42)
|
||||
examples_d = get_random_examples_gamma("d", 10, 42)
|
||||
examples_e = get_random_examples_gamma("e", 10, 42)
|
||||
pass
|
||||
@@ -1,11 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arctan2, sin, cos, sqrt
|
||||
from numpy._typing import NDArray
|
||||
from numpy import arctan2, cos, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def sigma2alpha(ell: EllipsoidTriaxial, sigma: NDArray, point: NDArray) -> float:
|
||||
@@ -21,7 +23,7 @@ def sigma2alpha(ell: EllipsoidTriaxial, sigma: NDArray, point: NDArray) -> float
|
||||
Q = float(q @ sigma)
|
||||
|
||||
alpha = arctan2(P, Q)
|
||||
return alpha
|
||||
return wrap_0_2pi(alpha)
|
||||
|
||||
|
||||
def alpha_para2ell(ell: EllipsoidTriaxial, u: float, v: float, alpha_para: float) -> Tuple[float, float, float]:
|
||||
@@ -43,10 +45,10 @@ def alpha_para2ell(ell: EllipsoidTriaxial, u: float, v: float, alpha_para: float
|
||||
alpha_ell = arctan2(p_ell @ sigma_para, q_ell @ sigma_para)
|
||||
sigma_ell = p_ell * sin(alpha_ell) + q_ell * cos(alpha_ell)
|
||||
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-12:
|
||||
raise Exception("Alpha Umrechnung fehlgeschlagen")
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
|
||||
raise Exception("alpha_para2ell: Differenz in den Richtungsableitungen")
|
||||
|
||||
return beta, lamb, alpha_ell
|
||||
return beta, lamb, wrap_0_2pi(alpha_ell)
|
||||
|
||||
|
||||
def alpha_ell2para(ell: EllipsoidTriaxial, beta: float, lamb: float, alpha_ell: float) -> Tuple[float, float, float]:
|
||||
@@ -68,10 +70,10 @@ def alpha_ell2para(ell: EllipsoidTriaxial, beta: float, lamb: float, alpha_ell:
|
||||
alpha_para = arctan2(p_para @ sigma_ell, q_para @ sigma_ell)
|
||||
sigma_para = p_para * sin(alpha_para) + q_para * cos(alpha_para)
|
||||
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-9:
|
||||
raise Exception("Alpha Umrechnung fehlgeschlagen")
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
|
||||
raise Exception("alpha_ell2para: Differenz in den Richtungsableitungen")
|
||||
|
||||
return u, v, alpha_para
|
||||
return u, v, wrap_0_2pi(alpha_para)
|
||||
|
||||
|
||||
def func_sigma_ell(ell: EllipsoidTriaxial, point: NDArray, alpha_ell: float) -> NDArray:
|
||||
@@ -124,25 +126,26 @@ def pq_ell(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
:param point: Punkt
|
||||
:return: p und q
|
||||
"""
|
||||
x, y, z = point
|
||||
n = ell.func_n(point)
|
||||
|
||||
beta, lamb = ell.cart2ell(point)
|
||||
B = ell.Ex ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(beta) ** 2
|
||||
L = ell.Ex ** 2 - ell.Ee ** 2 * cos(lamb) ** 2
|
||||
if abs(cos(beta)) < 1e-15 and abs(np.sin(lamb)) < 1e-15:
|
||||
if beta > 0:
|
||||
p = np.array([0, -1, 0])
|
||||
else:
|
||||
p = np.array([0, 1, 0])
|
||||
else:
|
||||
B = ell.Ex ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(beta) ** 2
|
||||
L = ell.Ex ** 2 - ell.Ee ** 2 * cos(lamb) ** 2
|
||||
|
||||
c1 = x ** 2 + y ** 2 + z ** 2 - (ell.ax ** 2 + ell.ay ** 2 + ell.b ** 2)
|
||||
c0 = (ell.ax ** 2 * ell.ay ** 2 + ell.ax ** 2 * ell.b ** 2 + ell.ay ** 2 * ell.b ** 2 -
|
||||
(ell.ay ** 2 + ell.b ** 2) * x ** 2 - (ell.ax ** 2 + ell.b ** 2) * y ** 2 - (
|
||||
ell.ax ** 2 + ell.ay ** 2) * z ** 2)
|
||||
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
|
||||
_, t2 = ell.func_t12(point)
|
||||
|
||||
F = ell.Ey ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(lamb) ** 2
|
||||
p1 = -sqrt(L / (F * t2)) * ell.ax / ell.Ex * sqrt(B) * sin(lamb)
|
||||
p2 = sqrt(L / (F * t2)) * ell.ay * cos(beta) * cos(lamb)
|
||||
p3 = 1 / sqrt(F * t2) * (ell.b * ell.Ee ** 2) / (2 * ell.Ex) * sin(beta) * sin(2 * lamb)
|
||||
p = np.array([p1, p2, p3])
|
||||
p = p / np.linalg.norm(p)
|
||||
F = ell.Ey ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(lamb) ** 2
|
||||
p1 = -sqrt(L / (F * t2)) * ell.ax / ell.Ex * sqrt(B) * sin(lamb)
|
||||
p2 = sqrt(L / (F * t2)) * ell.ay * cos(beta) * cos(lamb)
|
||||
p3 = 1 / sqrt(F * t2) * (ell.b * ell.Ee ** 2) / (2 * ell.Ex) * sin(beta) * sin(2 * lamb)
|
||||
p = np.array([p1, p2, p3])
|
||||
p = p / np.linalg.norm(p)
|
||||
q = np.array([n[1] * p[2] - n[2] * p[1],
|
||||
n[2] * p[0] - n[0] * p[2],
|
||||
n[0] * p[1] - n[1] * p[0]])
|
||||
@@ -171,13 +174,28 @@ def pq_para(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
q[2] * n[0] - q[0] * n[2],
|
||||
q[0] * n[1] - q[1] * n[0]])
|
||||
|
||||
t1 = np.dot(n, q)
|
||||
t2 = np.dot(n, p)
|
||||
t3 = np.dot(p, q)
|
||||
if not (t1 < 1e-10 or t1 > 1-1e-10) and not (t2 < 1e-10 or t2 > 1-1e-10) and not (t3 < 1e-10 or t3 > 1-1e-10):
|
||||
raise Exception("Fehler in den normierten Vektoren")
|
||||
|
||||
p = p / np.linalg.norm(p)
|
||||
q = q / np.linalg.norm(q)
|
||||
|
||||
return p, q
|
||||
|
||||
|
||||
def jacobi_konstante(beta: float, omega: float, alpha: float, ell: EllipsoidTriaxial) -> float:
|
||||
"""
|
||||
Jacobi-Konstante nach Karney (2025), Gl. (14)
|
||||
:param beta: Beta Koordinate
|
||||
:param omega: Omega Koordinate
|
||||
:param alpha: Azimut alpha
|
||||
:param ell: Ellipsoid
|
||||
:return: Jacobi-Konstante
|
||||
"""
|
||||
gamma_jacobi = float((ell.k ** 2) * (np.cos(beta) ** 2) * (np.sin(alpha) ** 2) - (ell.k_ ** 2) * (np.sin(omega) ** 2) * (np.cos(alpha) ** 2))
|
||||
return gamma_jacobi
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
alpha_para = 0
|
||||
u, v = ell.ell2para(np.pi/2, 0)
|
||||
alpha_ell = alpha_para2ell(ell, u, v, alpha_para)
|
||||
pass
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from GHA_biaxial.bessel import gha1 as gha1_bessel
|
||||
from GHA_biaxial.gauss import gha1 as gha1_gauss
|
||||
from GHA_biaxial.rk import gha1 as gha1_rk
|
||||
from GHA_biaxial.gauss import gha2 as gha2_gauss
|
||||
|
||||
re = EllipsoidBiaxial.init_name("Bessel")
|
||||
|
||||
# phi0 = 0.6
|
||||
# lamb0 = 1.2
|
||||
# alpha0 = 0.45
|
||||
# s = 123456
|
||||
#
|
||||
# values_bessel = gha1_bessel(re, phi0, lamb0, alpha0, s)
|
||||
# alpha1_bessel = values_bessel[-1]
|
||||
# p1_bessel = re.bi_ell2cart(values_bessel[0], values_bessel[1], 0)
|
||||
#
|
||||
# values_gauss1 = gha1_gauss(re, phi0, lamb0, alpha0, s)
|
||||
# alpha1_gauss1 = values_gauss1[-1]
|
||||
# p1_gauss = re.bi_ell2cart(values_gauss1[0], values_gauss1[1], 0)
|
||||
#
|
||||
# values_rk = gha1_rk(re, phi0, lamb0 , alpha0, s, 10000)
|
||||
# alpha1_rk = values_rk[-1]
|
||||
# p1_rk = re.bi_ell2cart(values_rk[0], values_rk[1], 0)
|
||||
#
|
||||
# alpha0_gauss, alpha1_gauss2, s_gauss = gha2_gauss(re, phi0, lamb0, values_gauss1[0], values_gauss1[1])
|
||||
|
||||
phi0 = 0.6
|
||||
lamb0 = 1.2
|
||||
|
||||
cart = re.bi_ell2cart(phi0, lamb0, 0)
|
||||
ell = re.bi_cart2ell(cart)
|
||||
pass
|
||||
@@ -10,7 +10,7 @@ def xyz(x: float, y: float, z: float, stellen: int) -> str:
|
||||
:param stellen: Anzahl Nachkommastellen
|
||||
:return: String zur Ausgabe der Koordinaten
|
||||
"""
|
||||
return f"""x = {(round(x,stellen))} m y = {(round(y,stellen))} m z = {(round(z,stellen))} m"""
|
||||
return f"""x = {(round(x, stellen))} m y = {(round(y, stellen))} m z = {(round(z, stellen))} m"""
|
||||
|
||||
|
||||
def gms(name: str, rad: float, stellen: int) -> str:
|
||||
@@ -21,5 +21,5 @@ def gms(name: str, rad: float, stellen: int) -> str:
|
||||
:param stellen: Anzahl Nachkommastellen
|
||||
:return: String zur Ausgabe des Winkels
|
||||
"""
|
||||
gms = wu.rad2gms(rad)
|
||||
return f"{name} = {int(gms[0])}° {int(gms[1])}' {round(gms[2],stellen):.{stellen}f}''"
|
||||
values = wu.rad2gms(rad)
|
||||
return f"{name} = {int(values[0])}° {int(values[1])}' {round(values[2], stellen):.{stellen}f}''"
|
||||
|
||||
1307
dashboard.py
1307
dashboard.py
File diff suppressed because it is too large
Load Diff
@@ -1,116 +1,20 @@
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan, arctan2, sqrt, pi, arccos
|
||||
import winkelumrechnungen as wu
|
||||
import jacobian_Ligas
|
||||
import matplotlib.pyplot as plt
|
||||
from typing import Tuple
|
||||
from numpy.typing import NDArray
|
||||
import math
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arccos, arctan, arctan2, cos, pi, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
class EllipsoidBiaxial:
|
||||
def __init__(self, a: float, b: float):
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = a ** 2 / b
|
||||
self.e = sqrt(a ** 2 - b ** 2) / a
|
||||
self.e_ = sqrt(a ** 2 - b ** 2) / b
|
||||
import jacobian_Ligas
|
||||
from utils_angle import wrap_mhalfpi_halfpi, wrap_mpi_pi
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str):
|
||||
if name == "Bessel":
|
||||
a = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(a, b)
|
||||
elif name == "Hayford":
|
||||
a = 6378388
|
||||
f = 1/297
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "Krassowski":
|
||||
a = 6378245
|
||||
f = 298.3
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "WGS84":
|
||||
a = 6378137
|
||||
f = 298.257223563
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
@classmethod
|
||||
def init_af(cls, a: float, f: float):
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
V = lambda self, phi: sqrt(1 + self.e_ ** 2 * cos(phi) ** 2)
|
||||
M = lambda self, phi: self.c / self.V(phi) ** 3
|
||||
N = lambda self, phi: self.c / self.V(phi)
|
||||
|
||||
beta2psi = lambda self, beta: np.arctan2(self.a * np.sin(beta), self.b * np.cos(beta))
|
||||
beta2phi = lambda self, beta: np.arctan2(self.a ** 2 * np.sin(beta), self.b ** 2 * np.cos(beta))
|
||||
|
||||
psi2beta = lambda self, psi: np.arctan2(self.b * np.sin(psi), self.a * np.cos(psi))
|
||||
psi2phi = lambda self, psi: np.arctan2(self.a * np.sin(psi), self.b * np.cos(psi))
|
||||
|
||||
phi2beta = lambda self, phi: np.arctan2(self.b**2 * np.sin(phi), self.a**2 * np.cos(phi))
|
||||
phi2psi = lambda self, phi: np.arctan2(self.b * np.sin(phi), self.a * np.cos(phi))
|
||||
|
||||
phi2p = lambda self, phi: self.N(phi) * cos(phi)
|
||||
|
||||
def bi_cart2ell(self, point: NDArrayself, Eh: float = 0.001, Ephi: float = wu.gms2rad([0, 0, 0.001])) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Umrechnung von kartesischen in ellipsoidische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
:param Eh: Grenzwert für die Höhe
|
||||
:param Ephi: Grenzwert für die Breite
|
||||
:return: ellipsoidische Breite, Länge, geodätische Höhe
|
||||
"""
|
||||
x, y, z = point
|
||||
|
||||
lamb = arctan2(y, x)
|
||||
|
||||
p = sqrt(x**2+y**2)
|
||||
|
||||
phi_null = arctan2(z, p*(1 - self.e**2))
|
||||
|
||||
hi = [0]
|
||||
phii = [phi_null]
|
||||
|
||||
i = 0
|
||||
|
||||
while True:
|
||||
N = self.a / sqrt(1 - self.e**2 * sin(phii[i])**2)
|
||||
h = p / cos(phii[i]) - N
|
||||
phi = arctan2(z, p * (1-(self.e**2*N) / (N+h)))
|
||||
hi.append(h)
|
||||
phii.append(phi)
|
||||
dh = abs(hi[i]-h)
|
||||
dphi = abs(phii[i]-phi)
|
||||
i = i+1
|
||||
if dh < Eh:
|
||||
if dphi < Ephi:
|
||||
break
|
||||
return phi, lamb, h
|
||||
|
||||
def bi_ell2cart(self, phi: float, lamb: float, h: float) -> NDArray:
|
||||
"""
|
||||
Umrechnung von ellipsoidischen in kartesische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param phi: ellipsoidische Breite
|
||||
:param lamb: ellipsoidische Länge
|
||||
:param h: geodätische Höhe
|
||||
:return: Punkt in kartesischen Koordinaten
|
||||
"""
|
||||
W = sqrt(1 - self.e**2 * sin(phi)**2)
|
||||
N = self.a / W
|
||||
x = (N+h) * cos(phi) * cos(lamb)
|
||||
y = (N+h) * cos(phi) * sin(lamb)
|
||||
z = (N * (1-self.e**2) + h) * sin(phi)
|
||||
return np.array([x, y, z])
|
||||
|
||||
class EllipsoidTriaxial:
|
||||
"""
|
||||
Klasse für dreiachsige Ellipsoide
|
||||
Parameter: Formparameter
|
||||
Funktionen: Koordinatenumrechnungen
|
||||
"""
|
||||
def __init__(self, ax: float, ay: float, b: float):
|
||||
self.ax = ax
|
||||
self.ay = ay
|
||||
@@ -124,14 +28,19 @@ class EllipsoidTriaxial:
|
||||
self.Ex = sqrt(self.ax**2 - self.b**2)
|
||||
self.Ey = sqrt(self.ay**2 - self.b**2)
|
||||
self.Ee = sqrt(self.ax**2 - self.ay**2)
|
||||
nenner = sqrt(max(self.ax * self.ax - self.b * self.b, 0.0))
|
||||
self.k = sqrt(max(self.ay * self.ay - self.b * self.b, 0.0)) / nenner
|
||||
self.k_ = sqrt(max(self.ax * self.ax - self.ay * self.ay, 0.0)) / nenner
|
||||
self.e = sqrt(max(self.ax * self.ax - self.b * self.b, 0.0)) / self.ay
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str):
|
||||
def init_name(cls, name: str) -> EllipsoidTriaxial:
|
||||
"""
|
||||
Mögliche Ellipsoide: BursaFialova1993, BursaSima1980, BursaSima1980round, Eitschberger1978, Bursa1972,
|
||||
Bursa1970, BesselBiaxial, Fiction, KarneyTest2024
|
||||
Mögliche Ellipsoide: BursaSima1980round, KarneyTest2024, Fiction, BursaFialova1993, BursaSima1980, Eitschberger1978, Bursa1972,
|
||||
Bursa1970
|
||||
Panou et al (2020)
|
||||
:param name: Name des dreiachsigen Ellipsoids
|
||||
:return: dreiachsiger Ellipsoid
|
||||
"""
|
||||
if name == "BursaFialova1993":
|
||||
ax = 6378171.36
|
||||
@@ -164,11 +73,6 @@ class EllipsoidTriaxial:
|
||||
ay = 6378105
|
||||
b = 6356754
|
||||
return cls(ax, ay, b)
|
||||
elif name == "BesselBiaxial":
|
||||
ax = 6377397.15509
|
||||
ay = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(ax, ay, b)
|
||||
elif name == "Fiction":
|
||||
ax = 6000000
|
||||
ay = 4000000
|
||||
@@ -179,6 +83,8 @@ class EllipsoidTriaxial:
|
||||
ay = 1
|
||||
b = 1 / sqrt(2)
|
||||
return cls(ax, ay, b)
|
||||
else:
|
||||
raise Exception(f"EllipsoidTriaxial.init_name: Name {name} unbekannt")
|
||||
|
||||
def func_H(self, point: NDArray) -> float:
|
||||
"""
|
||||
@@ -218,8 +124,10 @@ class EllipsoidTriaxial:
|
||||
c0 = (self.ax ** 2 * self.ay ** 2 + self.ax ** 2 * self.b ** 2 + self.ay ** 2 * self.b ** 2 -
|
||||
(self.ay ** 2 + self.b ** 2) * x ** 2 - (self.ax ** 2 + self.b ** 2) * y ** 2 - (
|
||||
self.ax ** 2 + self.ay ** 2) * z ** 2)
|
||||
if c1 ** 2 - 4 * c0 < 0:
|
||||
t2 = np.nan
|
||||
if c1 ** 2 - 4 * c0 < -1e-9:
|
||||
raise Exception("t1, t2: Negativer Wurzelterm")
|
||||
elif c1 ** 2 - 4 * c0 < 0:
|
||||
t2 = 0
|
||||
else:
|
||||
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
|
||||
if t2 == 0:
|
||||
@@ -261,7 +169,6 @@ class EllipsoidTriaxial:
|
||||
s1 = 2 * sqrt(p) * cos(omega/3) - c2/3
|
||||
s2 = 2 * sqrt(p) * cos(omega/3 - 2*pi/3) - c2/3
|
||||
s3 = 2 * sqrt(p) * cos(omega/3 - 4*pi/3) - c2/3
|
||||
# print(s1, s2, s3)
|
||||
|
||||
beta = arctan(sqrt((-self.b**2 - s2) / (self.ay**2 + s2)))
|
||||
if abs((-self.ay**2 - s3) / (self.ax**2 + s3)) > 1e-7:
|
||||
@@ -284,6 +191,11 @@ class EllipsoidTriaxial:
|
||||
|
||||
beta, lamb = np.broadcast_arrays(beta, lamb)
|
||||
|
||||
beta = np.where(
|
||||
np.isclose(np.abs(beta), pi / 2, atol=1e-15),
|
||||
beta * 8999999999999999 / 9000000000000000,
|
||||
beta
|
||||
)
|
||||
B = self.Ex ** 2 * cos(beta) ** 2 + self.Ee ** 2 * sin(beta) ** 2
|
||||
L = self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2
|
||||
|
||||
@@ -335,14 +247,14 @@ class EllipsoidTriaxial:
|
||||
Z = self.b * sin(beta) * sqrt(k**2 + k_**2 * sin(lamb)**2)
|
||||
return np.array([X, Y, Z])
|
||||
|
||||
def cart2ell_yFake(self, point: NDArray) -> Tuple[float, float]:
|
||||
def cart2ell_yFake(self, point: NDArray, delta_y: float = 1e-4) -> Tuple[float, float]:
|
||||
"""
|
||||
Bei Fehlschlagen von cart2ell
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
:param delta_y: Startwert für Suche nach kleinstmöglichem delta_y
|
||||
:return: ellipsoidische Breite und Länge
|
||||
"""
|
||||
x, y, z = point
|
||||
delta_y = 1e-4
|
||||
best_delta = np.inf
|
||||
while True:
|
||||
try:
|
||||
@@ -412,14 +324,14 @@ class EllipsoidTriaxial:
|
||||
i += 1
|
||||
|
||||
if i == maxI:
|
||||
raise Exception("Umrechnung ist nicht konvergiert")
|
||||
raise Exception("Umrechnung cart2ell: nicht konvergiert")
|
||||
|
||||
point_n = self.ell2cart(beta, lamb)
|
||||
delta_r = np.linalg.norm(point - point_n, axis=-1)
|
||||
if delta_r > 1e-6:
|
||||
raise Exception("Fehler in der Umrechnung cart2ell")
|
||||
raise Exception("Umrechnung cart2ell: Punktdifferenz")
|
||||
|
||||
return beta, lamb
|
||||
return wrap_mhalfpi_halfpi(beta), wrap_mpi_pi(lamb)
|
||||
|
||||
except Exception as e:
|
||||
# Wenn die Berechnung fehlschlägt auf Grund von sehr kleinem y, solange anpassen, bis Umrechnung ohne Fehler
|
||||
@@ -511,7 +423,7 @@ class EllipsoidTriaxial:
|
||||
i += 1
|
||||
|
||||
if i == maxI:
|
||||
raise Exception("Umrechung ist nicht konvergiert")
|
||||
raise Exception("Umrechnung cart2ell: nicht konvergiert")
|
||||
|
||||
return phi, lamb
|
||||
|
||||
@@ -577,6 +489,8 @@ class EllipsoidTriaxial:
|
||||
invJ, fxE = jacobian_Ligas.case2(E, F, G, np.array([xG, yG, zG]), pE)
|
||||
elif mode == "ligas3":
|
||||
invJ, fxE = jacobian_Ligas.case3(E, F, G, np.array([xG, yG, zG]), pE)
|
||||
else:
|
||||
raise Exception(f"cart2geod: Modus {mode} nicht bekannt")
|
||||
pEi = pE.reshape(-1, 1) - invJ @ fxE.reshape(-1, 1)
|
||||
pEi = pEi.reshape(1, -1).flatten()
|
||||
loa = sqrt((pEi[0]-pE[0])**2 + (pEi[1]-pE[1])**2 + (pEi[2]-pE[2])**2)
|
||||
@@ -598,15 +512,15 @@ class EllipsoidTriaxial:
|
||||
phi, lamb, h = self.cart2geod(point, f"ligas{new_mode}", maxIter, maxLoa)
|
||||
else:
|
||||
if xG < 0 and yG < 0:
|
||||
lamb = -pi + lamb
|
||||
lamb += -pi
|
||||
|
||||
elif xG < 0:
|
||||
lamb = pi + lamb
|
||||
lamb += pi
|
||||
|
||||
if abs(zG) < eps:
|
||||
phi = 0
|
||||
|
||||
return phi, lamb, h
|
||||
wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb)
|
||||
return wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb), h
|
||||
|
||||
def para2cart(self, u: float | NDArray, v: float | NDArray) -> NDArray:
|
||||
"""
|
||||
@@ -643,8 +557,8 @@ class EllipsoidTriaxial:
|
||||
v = 2 * arctan2(v_check1, v_check2 + v_factor)
|
||||
else:
|
||||
v = pi/2 - 2 * arctan2(v_check2, v_check1 + v_factor)
|
||||
|
||||
return u, v
|
||||
wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
|
||||
return wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
|
||||
|
||||
def ell2para(self, beta: float, lamb: float) -> Tuple[float, float]:
|
||||
"""
|
||||
@@ -749,63 +663,71 @@ class EllipsoidTriaxial:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980")
|
||||
diff_list = []
|
||||
diffs_para = []
|
||||
diffs_ell = []
|
||||
diffs_geod = []
|
||||
points = []
|
||||
for v_deg in range(-180, 181, 5):
|
||||
for u_deg in range(-90, 91, 5):
|
||||
v = wu.deg2rad(v_deg)
|
||||
u = wu.deg2rad(u_deg)
|
||||
point = ell.para2cart(u, v)
|
||||
points.append(point)
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
# cart = ell.ell2cart(pi/2, 0)
|
||||
# print(cart)
|
||||
# cart = ell.ell2cart(pi/2*8999999999999999/9000000000000000, 0)
|
||||
# print(cart)
|
||||
elli = ell.cart2ell(np.array([0, 0.0, 1/sqrt(2)]))
|
||||
print(elli)
|
||||
|
||||
elli = ell.cart2ell(point)
|
||||
cart_elli = ell.ell2cart(elli[0], elli[1])
|
||||
diff_ell = np.linalg.norm(point - cart_elli, axis=-1)
|
||||
|
||||
para = ell.cart2para(point)
|
||||
cart_para = ell.para2cart(para[0], para[1])
|
||||
diff_para = np.linalg.norm(point - cart_para, axis=-1)
|
||||
|
||||
geod = ell.cart2geod(point, "ligas3")
|
||||
cart_geod = ell.geod2cart(geod[0], geod[1], geod[2])
|
||||
diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1)
|
||||
|
||||
diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3])
|
||||
diffs_ell.append([diff_ell])
|
||||
diffs_para.append([diff_para])
|
||||
diffs_geod.append([diff_geod3])
|
||||
|
||||
diff_list = np.array(diff_list)
|
||||
diffs_ell = np.array(diffs_ell)
|
||||
diffs_para = np.array(diffs_para)
|
||||
diffs_geod = np.array(diffs_geod)
|
||||
|
||||
pass
|
||||
|
||||
points = np.array(points)
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(projection='3d')
|
||||
|
||||
sc = ax.scatter(
|
||||
points[:, 0],
|
||||
points[:, 1],
|
||||
points[:, 2],
|
||||
c=diffs_ell, # Farbcode = diff
|
||||
cmap='viridis', # Colormap
|
||||
s=10 + 20 * diffs_ell, # optional: Größe abhängig vom diff
|
||||
alpha=0.8
|
||||
)
|
||||
|
||||
# Farbskala
|
||||
cbar = plt.colorbar(sc)
|
||||
cbar.set_label("diff")
|
||||
|
||||
ax.set_xlabel("X")
|
||||
ax.set_ylabel("Y")
|
||||
ax.set_zlabel("Z")
|
||||
|
||||
plt.show()
|
||||
# ell = EllipsoidTriaxial.init_name("BursaSima1980")
|
||||
# diff_list = []
|
||||
# diffs_para = []
|
||||
# diffs_ell = []
|
||||
# diffs_geod = []
|
||||
# points = []
|
||||
# for v_deg in range(-180, 181, 5):
|
||||
# for u_deg in range(-90, 91, 5):
|
||||
# v = wu.deg2rad(v_deg)
|
||||
# u = wu.deg2rad(u_deg)
|
||||
# point = ell.para2cart(u, v)
|
||||
# points.append(point)
|
||||
#
|
||||
# elli = ell.cart2ell(point)
|
||||
# cart_elli = ell.ell2cart(elli[0], elli[1])
|
||||
# diff_ell = np.linalg.norm(point - cart_elli, axis=-1)
|
||||
#
|
||||
# para = ell.cart2para(point)
|
||||
# cart_para = ell.para2cart(para[0], para[1])
|
||||
# diff_para = np.linalg.norm(point - cart_para, axis=-1)
|
||||
#
|
||||
# geod = ell.cart2geod(point, "ligas3")
|
||||
# cart_geod = ell.geod2cart(geod[0], geod[1], geod[2])
|
||||
# diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1)
|
||||
#
|
||||
# diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3])
|
||||
# diffs_ell.append([diff_ell])
|
||||
# diffs_para.append([diff_para])
|
||||
# diffs_geod.append([diff_geod3])
|
||||
#
|
||||
# diff_list = np.array(diff_list)
|
||||
# diffs_ell = np.array(diffs_ell)
|
||||
# diffs_para = np.array(diffs_para)
|
||||
# diffs_geod = np.array(diffs_geod)
|
||||
#
|
||||
# pass
|
||||
#
|
||||
# points = np.array(points)
|
||||
# fig = plt.figure()
|
||||
# ax = fig.add_subplot(projection='3d')
|
||||
#
|
||||
# sc = ax.scatter(
|
||||
# points[:, 0],
|
||||
# points[:, 1],
|
||||
# points[:, 2],
|
||||
# c=diffs_ell, # Farbcode = diff
|
||||
# cmap='viridis', # Colormap
|
||||
# s=10 + 20 * diffs_ell, # optional: Größe abhängig vom diff
|
||||
# alpha=0.8
|
||||
# )
|
||||
#
|
||||
# # Farbskala
|
||||
# cbar = plt.colorbar(sc)
|
||||
# cbar.set_label("diff")
|
||||
#
|
||||
# ax.set_xlabel("X")
|
||||
# ax.set_ylabel("Y")
|
||||
# ax.set_zlabel("Z")
|
||||
#
|
||||
# plt.show()
|
||||
@@ -1,6 +1,8 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def case1(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
@@ -34,7 +36,7 @@ def case1(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArr
|
||||
|
||||
return invJ, fxE
|
||||
|
||||
def case2(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple[NDArray, NDArray]:
|
||||
def case2(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Aufstellen des Gleichungssystem für den zweiten Fall
|
||||
:param E: Konstante E
|
||||
@@ -68,7 +70,7 @@ def case2(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple
|
||||
|
||||
return invJ, fxE
|
||||
|
||||
def case3(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple[NDArray, NDArray]:
|
||||
def case3(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Aufstellen des Gleichungssystem für den dritten Fall
|
||||
:param E: Konstante E
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
from numpy import *
|
||||
import scipy as sp
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
import scipy as sp
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import *
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0:float, s: float) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnung der 1.GHA auf einem Rotationsellipsoid nach Bessel
|
||||
:param re:
|
||||
:param phi0:
|
||||
:param lamb0:
|
||||
:param alpha0:
|
||||
:param s:
|
||||
:return:
|
||||
"""
|
||||
psi0 = re.phi2psi(phi0)
|
||||
clairant = arcsin(cos(psi0) * sin(alpha0))
|
||||
sigma0 = arcsin(sin(psi0) / cos(clairant))
|
||||
@@ -1,8 +1,8 @@
|
||||
from numpy import sin, cos, pi, sqrt, tan, arcsin, arccos, arctan
|
||||
import ausgaben as aus
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import arctan, cos, sin, sqrt, tan
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, eps: float = 1e-12) -> Tuple[float, float, float]:
|
||||
"""
|
||||
@@ -1,13 +1,26 @@
|
||||
import runge_kutta as rk
|
||||
from numpy import sin, cos, tan
|
||||
import winkelumrechnungen as wu
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import cos, sin, tan
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import runge_kutta as rk
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, num: int) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnung der 1. GHA auf einem Rotationsellipsoid mittels RK4
|
||||
:param re:
|
||||
:param phi0:
|
||||
:param lamb0:
|
||||
:param alpha0:
|
||||
:param s:
|
||||
:param num:
|
||||
:return:
|
||||
"""
|
||||
def buildODE():
|
||||
def ODE(s, v):
|
||||
def ODE(s: float, v: NDArray):
|
||||
phi, lam, A = v
|
||||
V = re.V(phi)
|
||||
dphi = cos(A) * V ** 3 / re.c
|
||||
0
nicht abgeben/Tests/__init__.py
Normal file
0
nicht abgeben/Tests/__init__.py
Normal file
9253
nicht abgeben/Tests/algorithms_test.ipynb
Normal file
9253
nicht abgeben/Tests/algorithms_test.ipynb
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,56 +1,41 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:30:31.978159Z",
|
||||
"start_time": "2026-01-20T15:30:31.835157Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
],
|
||||
"id": "a78faf7f4883772f",
|
||||
"outputs": [],
|
||||
"execution_count": 1
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:30:33.910807Z",
|
||||
"start_time": "2026-01-20T15:30:32.803089Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"%reload_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"from GHA_triaxial.utils import alpha_para2ell, alpha_ell2para\n",
|
||||
"import numpy as np"
|
||||
"from GHA_triaxial.utils import alpha_ell2para, alpha_para2ell\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"id": "9ad815aea55574e3",
|
||||
"id": "46aa84a937fea491",
|
||||
"outputs": [],
|
||||
"execution_count": 2
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:33:40.785362Z",
|
||||
"start_time": "2026-01-20T15:33:34.296487Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"ell = EllipsoidTriaxial.init_name(\"KarneyTest2024\")\n",
|
||||
"diffs = []\n",
|
||||
"for beta_deg in range(-180, 181, 45):\n",
|
||||
" for lamb_deg in range(-90, 91, 45):\n",
|
||||
" for alpha_deg in range(0, 360, 45):\n",
|
||||
"for beta_deg in range(-90, 91, 15):\n",
|
||||
" for lamb_deg in range(-180, 180, 15):\n",
|
||||
" for alpha_deg in range(0, 360, 15):\n",
|
||||
" beta = wu.deg2rad(beta_deg)\n",
|
||||
" lamb = wu.deg2rad(lamb_deg)\n",
|
||||
" u, v = ell.ell2para(beta, lamb)\n",
|
||||
@@ -67,17 +52,12 @@
|
||||
" diffs.append((beta_deg, lamb_deg, alpha_deg, diff_1, diff_2))\n",
|
||||
"diffs = np.array(diffs)"
|
||||
],
|
||||
"id": "98b9b220118deb3f",
|
||||
"id": "82fc6cbbe7d5abcb",
|
||||
"outputs": [],
|
||||
"execution_count": 6
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:33:50.497990Z",
|
||||
"start_time": "2026-01-20T15:33:50.261115Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"i_max_ell = np.argmax(diffs[:, 3])\n",
|
||||
@@ -92,18 +72,9 @@
|
||||
"print(f'Für parametrisches Alpha = {point_max_para[2]}° und beta = {point_max_para[0]}°, lamb = {point_max_para[1]}°: diff = {max_ell}\"')\n",
|
||||
"pass"
|
||||
],
|
||||
"id": "3c74b65b0e85e3c2",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Für elliptisches Alpha = 315.0° und beta = -90.0°, lamb = -90.0°: diff = 3.426945967752335e-05\"\n",
|
||||
"Für parametrisches Alpha = 315.0° und beta = -90.0°, lamb = -90.0°: diff = 3.426945967752335e-05\"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 7
|
||||
"id": "97b5b8c9ca5377ab",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -20,13 +20,14 @@
|
||||
"source": [
|
||||
"%reload_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
"import pickle\n",
|
||||
"import numpy as np\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from itertools import product\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"import plotly.graph_objects as go"
|
||||
"import plotly.graph_objects as go\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
BIN
nicht abgeben/Tests/gha_resultsKarney.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsKarney.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsPanou.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsPanou.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsRandom.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsRandom.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsRandom_num.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsRandom_num.pkl
Normal file
Binary file not shown.
0
nicht abgeben/__init__.py
Normal file
0
nicht abgeben/__init__.py
Normal file
126
nicht abgeben/ellipsoid_biaxial.py
Normal file
126
nicht abgeben/ellipsoid_biaxial.py
Normal file
@@ -0,0 +1,126 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arctan2, cos, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
|
||||
|
||||
class EllipsoidBiaxial:
|
||||
"""
|
||||
Klasse für Rotationsellipdoide
|
||||
"""
|
||||
def __init__(self, a: float, b: float):
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = a ** 2 / b
|
||||
self.e = sqrt(a ** 2 - b ** 2) / a
|
||||
self.e_ = sqrt(a ** 2 - b ** 2) / b
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str) -> EllipsoidBiaxial:
|
||||
"""
|
||||
Erstellen eines Rotationsellipdoids nach Namen
|
||||
:param name: Name des Rotationsellipsoids
|
||||
:return: Rotationsellipsoid
|
||||
"""
|
||||
if name == "Bessel":
|
||||
a = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(a, b)
|
||||
elif name == "Hayford":
|
||||
a = 6378388
|
||||
f = 1/297
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "Krassowski":
|
||||
a = 6378245
|
||||
f = 298.3
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "WGS84":
|
||||
a = 6378137
|
||||
f = 298.257223563
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
else:
|
||||
raise Exception(f"EllipsoidBiaxial.init_name: Name {name} unbekannt")
|
||||
|
||||
@classmethod
|
||||
def init_af(cls, a: float, f: float) -> EllipsoidBiaxial:
|
||||
"""
|
||||
Erstellen eines Rotationsellipdoids aus der großen Halbachse und der Abplattung
|
||||
:param a: große Halbachse
|
||||
:param f: großen Halbachse
|
||||
:return: Rotationsellipsoid
|
||||
"""
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
V = lambda self, phi: sqrt(1 + self.e_ ** 2 * cos(phi) ** 2)
|
||||
M = lambda self, phi: self.c / self.V(phi) ** 3
|
||||
N = lambda self, phi: self.c / self.V(phi)
|
||||
|
||||
beta2psi = lambda self, beta: arctan2(self.a * sin(beta), self.b * cos(beta))
|
||||
beta2phi = lambda self, beta: arctan2(self.a ** 2 * sin(beta), self.b ** 2 * cos(beta))
|
||||
|
||||
psi2beta = lambda self, psi: arctan2(self.b * sin(psi), self.a * cos(psi))
|
||||
psi2phi = lambda self, psi: arctan2(self.a * sin(psi), self.b * cos(psi))
|
||||
|
||||
phi2beta = lambda self, phi: arctan2(self.b**2 * sin(phi), self.a**2 * cos(phi))
|
||||
phi2psi = lambda self, phi: arctan2(self.b * sin(phi), self.a * cos(phi))
|
||||
|
||||
phi2p = lambda self, phi: self.N(phi) * cos(phi)
|
||||
|
||||
def bi_cart2ell(self, point: NDArray, Eh: float = 0.001, Ephi: float = wu.gms2rad([0, 0, 0.001])) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Umrechnung von kartesischen in ellipsoidische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
:param Eh: Grenzwert für die Höhe
|
||||
:param Ephi: Grenzwert für die Breite
|
||||
:return: ellipsoidische Breite, Länge, geodätische Höhe
|
||||
"""
|
||||
x, y, z = point
|
||||
|
||||
lamb = arctan2(y, x)
|
||||
|
||||
p = sqrt(x**2+y**2)
|
||||
|
||||
phi_null = arctan2(z, p*(1 - self.e**2))
|
||||
|
||||
hi = [0]
|
||||
phii = [phi_null]
|
||||
|
||||
i = 0
|
||||
|
||||
while True:
|
||||
N = self.a / sqrt(1 - self.e**2 * sin(phii[i])**2)
|
||||
h = p / cos(phii[i]) - N
|
||||
phi = arctan2(z, p * (1-(self.e**2*N) / (N+h)))
|
||||
hi.append(h)
|
||||
phii.append(phi)
|
||||
dh = abs(hi[i]-h)
|
||||
dphi = abs(phii[i]-phi)
|
||||
i += 1
|
||||
if dh < Eh:
|
||||
if dphi < Ephi:
|
||||
break
|
||||
return phi, lamb, h
|
||||
|
||||
def bi_ell2cart(self, phi: float, lamb: float, h: float) -> NDArray:
|
||||
"""
|
||||
Umrechnung von ellipsoidischen in kartesische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param phi: ellipsoidische Breite
|
||||
:param lamb: ellipsoidische Länge
|
||||
:param h: geodätische Höhe
|
||||
:return: Punkt in kartesischen Koordinaten
|
||||
"""
|
||||
W = sqrt(1 - self.e**2 * sin(phi)**2)
|
||||
N = self.a / W
|
||||
x = (N+h) * cos(phi) * cos(lamb)
|
||||
y = (N+h) * cos(phi) * sin(lamb)
|
||||
z = (N * (1-self.e**2) + h) * sin(phi)
|
||||
return np.array([x, y, z])
|
||||
@@ -1,7 +1,9 @@
|
||||
import numpy as np
|
||||
from numpy import sqrt, arctan2, sin, cos, arcsin, arccos
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arccos, arcsin, arctan2, cos, pi, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
|
||||
|
||||
@@ -77,7 +79,7 @@ def gha2(R: float, phi0: float, lamb0: float, phi1: float, lamb1: float) -> Tupl
|
||||
alpha1 = arctan2(-cos(phi0) * sin(lamb1 - lamb0),
|
||||
cos(phi1) * sin(phi0) - sin(phi1) * cos(phi0) * cos(lamb1 - lamb0))
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
alpha1 += 2 * pi
|
||||
|
||||
return alpha0, alpha1, s
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import plotly.graph_objects as go\n",
|
||||
"import numpy as np\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"import winkelumrechnungen as wu"
|
||||
"import plotly.graph_objects as go\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"id": "731173e4745cfe7c",
|
||||
"outputs": [],
|
||||
8
nicht abgeben/test.py
Normal file
8
nicht abgeben/test.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import numpy as np
|
||||
|
||||
import ellipsoid_triaxial
|
||||
|
||||
ell = ellipsoid_triaxial.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
|
||||
cart = ell.para2cart(0, np.pi/2)
|
||||
print(cart)
|
||||
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
numpy~=2.3.4
|
||||
plotly~=6.4.0
|
||||
pandas~=2.3.3
|
||||
scipy~=1.16.3
|
||||
dash-bootstrap-components~=2.0.4
|
||||
dash~=4.0.0
|
||||
matplotlib~=3.10.7
|
||||
120
runge_kutta.py
120
runge_kutta.py
@@ -1,7 +1,10 @@
|
||||
from typing import Callable
|
||||
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool = False) -> tuple[list, list]:
|
||||
def rk4(ode: Callable, t0: float, v0: NDArray, weite: float, schritte: int, fein: bool = False) -> tuple[list, list]:
|
||||
"""
|
||||
Standard Runge-Kutta Verfahren 4. Ordnung
|
||||
:param ode: ODE-System als Funktion
|
||||
@@ -9,7 +12,7 @@ def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool
|
||||
:param v0: Startwerte
|
||||
:param weite: Integrationsweite
|
||||
:param schritte: Schrittzahl
|
||||
:param fein:
|
||||
:param fein: Fein-Rechnung?
|
||||
:return: Variable und Funktionswerte an jedem Stützpunkt
|
||||
"""
|
||||
h = weite/schritte
|
||||
@@ -35,9 +38,118 @@ def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool
|
||||
|
||||
return t_list, werte
|
||||
|
||||
def rk4_step(ode, t: float, v: np.ndarray, h: float) -> np.ndarray:
|
||||
def rk4_step(ode: Callable, t: float, v: NDArray, h: float) -> NDArray:
|
||||
"""
|
||||
Ein Schritt des Runge-Kutta Verfahrens 4. Ordnung
|
||||
:param ode: ODE-System als Funktion
|
||||
:param t: unabhängige Variable
|
||||
:param v: abhängige Variablen
|
||||
:param h: Schrittweite
|
||||
:return: abhängige Variablen nach einem Schritt
|
||||
"""
|
||||
k1 = ode(t, v)
|
||||
k2 = ode(t + 0.5 * h, v + 0.5 * h * k1)
|
||||
k3 = ode(t + 0.5 * h, v + 0.5 * h * k2)
|
||||
k4 = ode(t + h, v + h * k3)
|
||||
return v + (h / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
|
||||
return v + (h / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
|
||||
|
||||
def rk4_end(ode: Callable, t0: float, v0: NDArray, weite: float, schritte: int, fein: bool = False):
|
||||
"""
|
||||
Standard Runge-Kutta Verfahren 4. Ordnung, nur Ausgabe der letzten Variablenwerte
|
||||
:param ode: ODE-System als Funktion
|
||||
:param t0: Startwert der unabhängigen Variable
|
||||
:param v0: Startwerte
|
||||
:param weite: Integrationsweite
|
||||
:param schritte: Schrittzahl
|
||||
:param fein: Fein-Rechnung?
|
||||
:return: Variable und Funktionswerte am letzten Stützpunkt
|
||||
"""
|
||||
h = weite / schritte
|
||||
t = float(t0)
|
||||
v = np.array(v0, dtype=float, copy=True)
|
||||
|
||||
for _ in range(schritte):
|
||||
if not fein:
|
||||
v_next = rk4_step(ode, t, v, h)
|
||||
else:
|
||||
v_grob = rk4_step(ode, t, v, h)
|
||||
v_half = rk4_step(ode, t, v, 0.5 * h)
|
||||
v_fein = rk4_step(ode, t + 0.5 * h, v_half, 0.5 * h)
|
||||
v_next = v_fein + (v_fein - v_grob) / 15.0
|
||||
|
||||
t += h
|
||||
v = v_next
|
||||
|
||||
return t, v
|
||||
|
||||
# RK4 mit Simpson bzw. Trapez
|
||||
def rk4_integral(ode: Callable, t0: float, v0: NDArray, weite: float, schritte: int, integrand_at: Callable, fein: bool = False, simpson: bool = True):
|
||||
"""
|
||||
Runge-Kutta Verfahren 4. Ordnung mit Simpson bzw. Trapez
|
||||
:param ode: ODE-System als Funktion
|
||||
:param t0: Startwert der unabhängigen Variable
|
||||
:param v0: Startwerte
|
||||
:param weite: Integrationsweite
|
||||
:param integrand_at: Funktion
|
||||
:param schritte: Schrittzahl
|
||||
:param fein: Fein-Rechnung?
|
||||
:param simpson: Simpson? Wenn nein, dann Trapez
|
||||
:return: Variable und Funktionswerte am letzten Stützpunkt
|
||||
"""
|
||||
h = weite / schritte
|
||||
habs = abs(h)
|
||||
|
||||
t = float(t0)
|
||||
v = np.array(v0, dtype=float, copy=True)
|
||||
|
||||
if simpson and (schritte % 2 == 0):
|
||||
f0 = float(integrand_at(t, v))
|
||||
odd_sum = 0.0
|
||||
even_sum = 0.0
|
||||
fN = None
|
||||
|
||||
for i in range(1, schritte + 1):
|
||||
if not fein:
|
||||
v_next = rk4_step(ode, t, v, h)
|
||||
else:
|
||||
v_grob = rk4_step(ode, t, v, h)
|
||||
v_half = rk4_step(ode, t, v, 0.5 * h)
|
||||
v_fein = rk4_step(ode, t + 0.5 * h, v_half, 0.5 * h)
|
||||
v_next = v_fein + (v_fein - v_grob) / 15.0
|
||||
|
||||
t += h
|
||||
v = v_next
|
||||
|
||||
fi = float(integrand_at(t, v))
|
||||
if i == schritte:
|
||||
fN = fi
|
||||
elif i % 2 == 1:
|
||||
odd_sum += fi
|
||||
else:
|
||||
even_sum += fi
|
||||
|
||||
S = f0 + fN + 4.0 * odd_sum + 2.0 * even_sum
|
||||
s = (habs / 3.0) * S
|
||||
return t, v, s
|
||||
|
||||
f_prev = float(integrand_at(t, v))
|
||||
acc = 0.0
|
||||
|
||||
for _ in range(schritte):
|
||||
if not fein:
|
||||
v_next = rk4_step(ode, t, v, h)
|
||||
else:
|
||||
v_grob = rk4_step(ode, t, v, h)
|
||||
v_half = rk4_step(ode, t, v, 0.5 * h)
|
||||
v_fein = rk4_step(ode, t + 0.5 * h, v_half, 0.5 * h)
|
||||
v_next = v_fein + (v_fein - v_grob) / 15.0
|
||||
|
||||
t += h
|
||||
v = v_next
|
||||
|
||||
f_cur = float(integrand_at(t, v))
|
||||
acc += 0.5 * (f_prev + f_cur)
|
||||
f_prev = f_cur
|
||||
|
||||
s = habs * acc
|
||||
return t, v, s
|
||||
7
test.py
7
test.py
@@ -1,7 +0,0 @@
|
||||
import numpy as np
|
||||
import ellipsoide
|
||||
|
||||
ell = ellipsoide.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
|
||||
cart = ell.para2cart(0, np.pi/2)
|
||||
print(cart)
|
||||
54
utils_angle.py
Normal file
54
utils_angle.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import numpy as np
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
|
||||
|
||||
def arccot(x: float) -> float:
|
||||
"""
|
||||
Berechnung von arccot eines Winkels
|
||||
:param x: Winkel
|
||||
:return: arccot(Winkel)
|
||||
"""
|
||||
return np.arctan2(1.0, x)
|
||||
|
||||
|
||||
def cot(x: float) -> float:
|
||||
"""
|
||||
Berechnung von cot eines Winkels
|
||||
:param x: Winkel
|
||||
:return: cot(Winkel)
|
||||
"""
|
||||
return np.cos(x) / np.sin(x)
|
||||
|
||||
|
||||
def wrap_mpi_pi(x: float) -> float:
|
||||
"""
|
||||
Wrap eines Winkels in den Wertebereich [-π, π)
|
||||
:param x: Winkel
|
||||
:return: Winkel in [-π, π)
|
||||
"""
|
||||
return (x + np.pi) % (2 * np.pi) - np.pi
|
||||
|
||||
|
||||
def wrap_mhalfpi_halfpi(x: float) -> float:
|
||||
"""
|
||||
Wrap eines Winkels in den Wertebereich [-π/2, π/2)
|
||||
:param x: Winkel
|
||||
:return: Winkel in [-π/2, π/2)
|
||||
"""
|
||||
return (x + np.pi / 2) % np.pi - np.pi / 2
|
||||
|
||||
|
||||
def wrap_0_2pi(x: float) -> float:
|
||||
"""
|
||||
Wrap eines Winkels in den Wertebereich [0, 2π)
|
||||
:param x: Winkel
|
||||
:return: Winkel in [0, 2π)
|
||||
"""
|
||||
return x % (2 * np.pi)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(wu.rad2deg(wrap_mhalfpi_halfpi(wu.deg2rad(181))))
|
||||
print(wu.rad2deg(wrap_0_2pi(wu.deg2rad(181))))
|
||||
print(wu.rad2deg(wrap_mpi_pi(wu.deg2rad(181))))
|
||||
Reference in New Issue
Block a user