Compare commits

...

20 Commits

Author SHA1 Message Date
d90ff5df69 Ellipsoid-Auswahl angepasst 2026-02-11 13:44:53 +01:00
59ad560f36 Abgabe fertig 2026-02-11 12:08:46 +01:00
5a293a823a revert 4f7b9aaef0
revert Delete Tests/gha_resultsKarney.pkl
2026-02-11 11:00:48 +00:00
36b62059fc revert 798cace25d
revert Delete Tests/gha_resultsPanou.pkl
2026-02-11 11:00:33 +00:00
57a086f6cb revert b8d07307aa
revert Delete Tests/gha_resultsRandom.pkl
2026-02-11 11:00:23 +00:00
b8d07307aa Delete Tests/gha_resultsRandom.pkl 2026-02-11 10:58:53 +00:00
798cace25d Delete Tests/gha_resultsPanou.pkl 2026-02-11 10:58:47 +00:00
4f7b9aaef0 Delete Tests/gha_resultsKarney.pkl 2026-02-11 10:58:42 +00:00
1fbfb555a4 wraps 2026-02-10 21:10:11 +01:00
Tammo.Weber
db05f7b6db Merge remote-tracking branch 'origin/main' 2026-02-10 12:36:04 +01:00
Tammo.Weber
73e3694a2a Ausgabe von alpha GHA1 2026-02-10 12:35:35 +01:00
ffc8d3fbce Fehlermeldung dashboard 2026-02-10 11:36:15 +01:00
Tammo.Weber
fd02694ae4 Platzsparen 2026-02-09 21:36:46 +01:00
e1ac0415e7 Merge remote-tracking branch 'origin/main' 2026-02-09 16:28:55 +01:00
e7641ba64f , 2026-02-09 16:28:15 +01:00
Tammo.Weber
fc9bc5defb Optimierung 2026-02-09 15:30:24 +01:00
Tammo.Weber
2864ce50ff s kleiner 0 2026-02-09 11:50:07 +01:00
Tammo.Weber
b44c25928e Merge remote-tracking branch 'origin/main' 2026-02-09 11:45:29 +01:00
Tammo.Weber
67248f9ca9 Anpassungen im Plot 2026-02-09 11:44:52 +01:00
Tammo.Weber
71c13c568a Fehlerkorrektur 2026-02-09 11:43:50 +01:00
38 changed files with 4198 additions and 9163 deletions

View File

@@ -1,7 +1,8 @@
import numpy as np import numpy as np
from numpy.typing import NDArray
def felli(x): def felli(x: NDArray) -> float:
N = x.shape[0] N = x.shape[0]
if N < 2: if N < 2:
raise ValueError("dimension must be greater than one") raise ValueError("dimension must be greater than one")
@@ -11,8 +12,7 @@ def felli(x):
def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000, def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000,
func_args=(), func_kwargs=None, seed=0, func_args=(), func_kwargs=None, seed=0,
bestEver = np.inf, noImproveGen = 0, absTolImprove = 1e-12, maxNoImproveGen = 100, sigmaImprove = 1e-12): bestEver=np.inf, noImproveGen=0, absTolImprove=1e-12, maxNoImproveGen=100, sigmaImprove=1e-12):
if func_kwargs is None: if func_kwargs is None:
func_kwargs = {} func_kwargs = {}
@@ -27,7 +27,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
N = xmean.shape[0] N = xmean.shape[0]
if stopeval is None: if stopeval is None:
stopeval = int(1e3 * N**2) stopeval = int(1e3 * N ** 2)
# Strategy parameter setting: Selection # Strategy parameter setting: Selection
lambda_ = 4 + int(np.floor(3 * np.log(N))) 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-14, stopeval=2000
weights = np.log(mu + 0.5) - np.log(np.arange(1, int(mu) + 1)) weights = np.log(mu + 0.5) - np.log(np.arange(1, int(mu) + 1))
mu = int(np.floor(mu)) mu = int(np.floor(mu))
weights = weights / np.sum(weights) 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 # Strategy parameter setting: Adaptation
cc = (4 + mueff / N) / (N + 4 + 2 * mueff / N) cc = (4 + mueff / N) / (N + 4 + 2 * mueff / N)
cs = (mueff + 2) / (N + mueff + 5) cs = (mueff + 2) / (N + mueff + 5)
c1 = 2 / ((N + 1.3)**2 + mueff) c1 = 2 / ((N + 1.3) ** 2 + mueff)
cmu = min(1 - c1, 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 damps = 1 + 2 * max(0, np.sqrt((mueff - 1) / (N + 1)) - 1) + cs
# Initialize dynamic (internal) strategy parameters and constants # Initialize dynamic (internal) strategy parameters and constants
@@ -54,7 +54,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
D = np.eye(N) D = np.eye(N)
C = B @ D @ (B @ D).T C = B @ D @ (B @ D).T
eigeneval = 0 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 # Generation Loop
counteval = 0 counteval = 0
@@ -91,10 +91,9 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
bestEver = fbest bestEver = fbest
noImproveGen = 0 noImproveGen = 0
else: else:
noImproveGen = noImproveGen + 1 noImproveGen += 1
if gen == 1 or gen % 50 == 0:
if gen == 1 or gen%50==0:
# print(f' [CMA-ES] Gen {gen}, best = {round(fbest, 6)}, sigma = {sigma:.3g}') # print(f' [CMA-ES] Gen {gen}, best = {round(fbest, 6)}, sigma = {sigma:.3g}')
pass pass
@@ -106,13 +105,10 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
# print(f' [CMA-ES] Abbruch: sigma zu klein {sigma:.3g}') # print(f' [CMA-ES] Abbruch: sigma zu klein {sigma:.3g}')
break break
# Cumulation: Update evolution paths # Cumulation: Update evolution paths
ps = (1 - cs) * ps + np.sqrt(cs * (2 - cs) * mueff) * (B @ zmean) ps = (1 - cs) * ps + np.sqrt(cs * (2 - cs) * mueff) * (B @ zmean)
norm_ps = np.linalg.norm(ps) norm_ps = np.linalg.norm(ps)
hsig = norm_ps / np.sqrt(1 - (1 - cs)**(2 * counteval / lambda_)) / chiN < \ hsig = norm_ps / np.sqrt(1 - (1 - cs) ** (2 * counteval / lambda_)) / chiN < (1.4 + 2 / (N + 1))
(1.4 + 2 / (N + 1))
hsig = 1.0 if hsig else 0.0 hsig = 1.0 if hsig else 0.0
pc = (1 - cc) * pc + hsig * np.sqrt(cc * (2 - cc) * mueff) * (B @ D @ zmean) pc = (1 - cc) * pc + hsig * np.sqrt(cc * (2 - cc) * mueff) * (B @ D @ zmean)
@@ -142,13 +138,13 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
if arfitness[0] == arfitness[int(np.ceil(0.7 * lambda_)) - 1]: if arfitness[0] == arfitness[int(np.ceil(0.7 * lambda_)) - 1]:
sigma = sigma * np.exp(0.2 + cs / damps) sigma = sigma * np.exp(0.2 + cs / damps)
# print(' [CMA-ES] stopfitness erreicht.') # print(' [CMA-ES] stopfitness erreicht.')
#print("warning: flat fitness, consider reformulating the objective") # print("warning: flat fitness, consider reformulating the objective")
break break
#print(f"{counteval}: {arfitness[0]}") # print(f"{counteval}: {arfitness[0]}")
#Final Message # Final Message
#print(f"{counteval}: {arfitness[0]}") # print(f"{counteval}: {arfitness[0]}")
xmin = arx[:, arindex[0]] xmin = arx[:, arindex[0]]
bestValue = arfitness[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)}')

View File

@@ -1,29 +1,17 @@
from __future__ import annotations from __future__ import annotations
from codeop import PyCF_ALLOW_INCOMPLETE_INPUT from typing import List, Tuple
from typing import List, Optional, Tuple
import numpy as np import numpy as np
from ellipsoide import EllipsoidTriaxial 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_ana import gha1_ana
from GHA_triaxial.gha1_approx import gha1_approx from GHA_triaxial.gha1_approx import gha1_approx
from Hansen_ES_CMA import escma from GHA_triaxial.utils import jacobi_konstante
from utils_angle import wrap_to_pi from ellipsoid_triaxial import EllipsoidTriaxial
from numpy.typing import NDArray from utils_angle import wrap_mpi_pi
import winkelumrechnungen as wu
def ellipsoid_formparameter(ell: EllipsoidTriaxial):
"""
Berechnet die Formparameter des dreiachsigen Ellipsoiden nach Karney (2025), Gl. (2)
:param ell: Ellipsoid
:return: e, k und k'
"""
nenner = np.sqrt(max(ell.ax * ell.ax - ell.b * ell.b, 0.0))
k = np.sqrt(max(ell.ay * ell.ay - ell.b * ell.b, 0.0)) / nenner
k_ = np.sqrt(max(ell.ax * ell.ax - ell.ay * ell.ay, 0.0)) / nenner
e = np.sqrt(max(ell.ax * ell.ax - ell.b * ell.b, 0.0)) / ell.ay
return e, k, k_
def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \ def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
@@ -40,7 +28,7 @@ def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
R (XYZ) = Punkt in XYZ R (XYZ) = Punkt in XYZ
""" """
# Berechnungshilfen # Berechnungshilfen
omega = wrap_to_pi(omega) omega = wrap_mpi_pi(omega)
cb = np.cos(beta) cb = np.cos(beta)
sb = np.sin(beta) sb = np.sin(beta)
co = np.cos(omega) co = np.cos(omega)
@@ -61,47 +49,32 @@ def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
# --- Ableitungen - Karney Gl. (5a,b,c)--- # --- Ableitungen - Karney Gl. (5a,b,c)---
# E = ∂R/∂ω # E = ∂R/∂ω
dX_dw = -ell.ax * so * Sx / D dX_dw = -ell.ax * so * Sx / D
dY_dw = ell.ay * cb * co dY_dw = ell.ay * cb * co
dZ_dw = ell.b * sb * (so * co * (ell.ax*ell.ax - ell.ay*ell.ay) / Sz) / D 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) E = np.array([dX_dw, dY_dw, dZ_dw], dtype=float)
# N = ∂R/∂β # N = ∂R/∂β
dX_db = ell.ax * co * (sb * cb * (ell.b*ell.b - ell.ay*ell.ay) / Sx) / D dX_db = ell.ax * co * (sb * cb * (ell.b*ell.b - ell.ay*ell.ay) / Sx) / D
dY_db = -ell.ay * sb * so dY_db = -ell.ay * sb * so
dZ_db = ell.b * cb * Sz / D dZ_db = ell.b * cb * Sz / D
N = np.array([dX_db, dY_db, dZ_db], dtype=float) 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 = 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) U = np.array([X/(ell.ax*ell.ax), Y/(ell.ay*ell.ay), Z/(ell.b*ell.b)], dtype=float)
En = np.linalg.norm(E) En = float(np.linalg.norm(E))
Nn = np.linalg.norm(N) Nn = float(np.linalg.norm(N))
Un = np.linalg.norm(U) Un = float(np.linalg.norm(U))
N_hat = N / Nn N_hat = N / Nn
E_hat = E / En E_hat = E / En
U_hat = U / Un U_hat = U / Un
E_hat = E_hat - float(np.dot(E_hat, N_hat)) * N_hat E_hat -= float(np.dot(E_hat, N_hat)) * N_hat
E_hat = E_hat / max(np.linalg.norm(E_hat), 1e-18) E_hat = E_hat / max(np.linalg.norm(E_hat), 1e-18)
return E_hat, N_hat, U_hat, En, Nn, R return E_hat, N_hat, U_hat, En, Nn, R
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
"""
e, k, k_ = ellipsoid_formparameter(ell)
gamma_jacobi = float((k ** 2) * (np.cos(beta) ** 2) * (np.sin(alpha) ** 2) - (k_ ** 2) * (np.sin(omega) ** 2) * (np.cos(alpha) ** 2))
return gamma_jacobi
def azimuth_at_ESpoint(P_prev: NDArray, P_curr: NDArray, E_hat_curr: NDArray, N_hat_curr: NDArray, U_hat_curr: NDArray) -> float: 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 Berechnet das Azimut in der lokalen Tangentialebene am aktuellen Punkt P_curr, gemessen
@@ -117,11 +90,10 @@ def azimuth_at_ESpoint(P_prev: NDArray, P_curr: NDArray, E_hat_curr: NDArray, N_
vT = v - float(np.dot(v, U_hat_curr)) * U_hat_curr vT = v - float(np.dot(v, U_hat_curr)) * U_hat_curr
vTn = max(np.linalg.norm(vT), 1e-18) vTn = max(np.linalg.norm(vT), 1e-18)
vT_hat = vT / vTn vT_hat = vT / vTn
#vT_hat = vT / np.linalg.norm(vT)
sE = float(np.dot(vT_hat, E_hat_curr)) sE = float(np.dot(vT_hat, E_hat_curr))
sN = float(np.dot(vT_hat, N_hat_curr)) sN = float(np.dot(vT_hat, N_hat_curr))
return wrap_to_pi(float(np.arctan2(sE, sN))) 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, def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float, gamma0: float,
@@ -154,11 +126,10 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
d_beta = float(np.clip(d_beta, -0.2, 0.2)) # rad 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_omega = float(np.clip(d_omega, -0.2, 0.2)) # rad
# d_beta = ds * float(np.cos(alpha_i)) / Nn_i
#d_beta = ds * float(np.cos(alpha_i)) / Nn_i # d_omega = ds * float(np.sin(alpha_i)) / En_i
#d_omega = ds * float(np.sin(alpha_i)) / En_i
beta_pred = beta_i + d_beta beta_pred = beta_i + d_beta
omega_pred = wrap_to_pi(omega_i + d_omega) omega_pred = wrap_mpi_pi(omega_i + d_omega)
xmean = np.array([beta_pred, omega_pred], dtype=float) xmean = np.array([beta_pred, omega_pred], dtype=float)
@@ -175,10 +146,10 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
:return: Fitnesswert (f) :return: Fitnesswert (f)
""" """
beta = x[0] beta = x[0]
omega = wrap_to_pi(x[1]) omega = wrap_mpi_pi(x[1])
P = ell.ell2cart_karney(beta, omega) # in kartesischer Koordinaten P = ell.ell2cart_karney(beta, omega) # in kartesischer Koordinaten
d = float(np.linalg.norm(P - P_i)) # Distanz zwischen d = float(np.linalg.norm(P - P_i)) # Distanz zwischen
# maxSegLen einhalten # maxSegLen einhalten
J_len = ((d - ds) / ds) ** 2 J_len = ((d - ds) / ds) ** 2
@@ -197,11 +168,10 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
return f return f
xb = escma(fitness, N=2, xmean=xmean, sigma=sigma0) # Aufruf CMA-ES
xb = escma(fitness, N=2, xmean=xmean, sigma=sigma0) # Aufruf CMA-ES
beta_best = xb[0] beta_best = xb[0]
omega_best = wrap_to_pi(xb[1]) omega_best = wrap_mpi_pi(xb[1])
P_best = ell.ell2cart_karney(beta_best, omega_best) P_best = ell.ell2cart_karney(beta_best, omega_best)
E_j, N_j, U_j, _, _, _ = ENU_beta_omega(beta_best, omega_best, ell) 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) alpha_end = azimuth_at_ESpoint(P_i, P_best, E_j, N_j, U_j)
@@ -209,7 +179,7 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
return beta_best, omega_best, P_best, alpha_end 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: boolean = False)\ 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]: -> Tuple[NDArray, float, NDArray] | Tuple[NDArray, float]:
""" """
Aufruf der 1. GHA mittels CMA-ES Aufruf der 1. GHA mittels CMA-ES
@@ -223,10 +193,10 @@ def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float,
:return: Zielpunkt Pk, Azimut am Zielpunkt und Punktliste :return: Zielpunkt Pk, Azimut am Zielpunkt und Punktliste
""" """
beta = float(beta0) beta = float(beta0)
omega = wrap_to_pi(float(omega0)) omega = wrap_mpi_pi(float(omega0))
alpha = wrap_to_pi(float(alpha0)) alpha = wrap_mpi_pi(float(alpha0))
gamma0 = jacobi_konstante(beta, omega, alpha, ell) # Referenz-γ0 gamma0 = jacobi_konstante(beta, omega, alpha, ell) # Referenz-γ0
P_all: List[NDArray] = [ell.ell2cart_karney(beta, omega)] P_all: List[NDArray] = [ell.ell2cart_karney(beta, omega)]
alpha_end: List[float] = [alpha] alpha_end: List[float] = [alpha]
@@ -243,7 +213,7 @@ def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float,
ell=ell, maxSegLen=maxSegLen) ell=ell, maxSegLen=maxSegLen)
s_acc += ds s_acc += ds
P_all.append(P) P_all.append(P)
alpha_end.append(alpha) alpha_end.append(wrap_mpi_pi(alpha))
if step > nsteps_est + 50: if step > nsteps_est + 50:
raise RuntimeError("GHA1_ES: Zu viele Schritte vermutlich Konvergenzproblem / falsche Azimut-Konvention.") raise RuntimeError("GHA1_ES: Zu viele Schritte vermutlich Konvergenzproblem / falsche Azimut-Konvention.")
Pk = P_all[-1] Pk = P_all[-1]
@@ -258,8 +228,8 @@ def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float,
if __name__ == "__main__": if __name__ == "__main__":
ell = EllipsoidTriaxial.init_name("BursaSima1980round") ell = EllipsoidTriaxial.init_name("BursaSima1980round")
s = 180000 s = 180000
#alpha0 = 3 # alpha0 = 3
alpha0 = wu.gms2rad([5 ,0 ,0]) alpha0 = wu.gms2rad([5, 0, 0])
beta = 0 beta = 0
omega = 0 omega = 0
P0 = ell.ell2cart(beta, omega) P0 = ell.ell2cart(beta, omega)
@@ -272,6 +242,6 @@ if __name__ == "__main__":
print(res) print(res)
print(alpha) print(alpha)
print(points) print(points)
#print("alpha1 (am Endpunkt):", res.alpha1) # print("alpha1 (am Endpunkt):", res.alpha1)
print(res - point1) print(res - point1)
print(point1app - point1, "approx") print(point1app - point1, "approx")

View File

@@ -1,14 +1,13 @@
import numpy as np
from Hansen_ES_CMA import escma
from ellipsoide import EllipsoidTriaxial
from numpy.typing import NDArray
from typing import Tuple from typing import Tuple
import numpy as np
import plotly.graph_objects as go 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.gha2_num import gha2_num
from GHA_triaxial.utils import sigma2alpha, pq_ell from GHA_triaxial.utils import sigma2alpha
from ellipsoid_triaxial import EllipsoidTriaxial
def Sehne(P1: NDArray, P2: NDArray) -> float: def Sehne(P1: NDArray, P2: NDArray) -> float:
@@ -19,14 +18,11 @@ def Sehne(P1: NDArray, P2: NDArray) -> float:
:return: Bogenlänge s :return: Bogenlänge s
""" """
R12 = P2-P1 R12 = P2-P1
s = np.linalg.norm(R12) s = float(np.linalg.norm(R12))
return s return s
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]: 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. Berechnen der 2. GHA mithilfe der CMA-ES.
@@ -70,7 +66,7 @@ def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float =
R0 = (ell.ax + ell.ay + ell.b) / 3 R0 = (ell.ax + ell.ay + ell.b) / 3
if maxSegLen is None: if maxSegLen is None:
maxSegLen = R0 * 1 / (637.4*2) # 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 sigma_uv_nom = 1e-3 * (maxSegLen / R0) # ~1e-5
points: list[NDArray] = [P0, Pk] points: list[NDArray] = [P0, Pk]
@@ -102,7 +98,7 @@ def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float =
sigmaStep = sigma_uv_nom * (Sehne(A, B) / maxSegLen) sigmaStep = sigma_uv_nom * (Sehne(A, B) / maxSegLen)
u, v = escma(midpoint_fitness, N=2, xmean=xmean, sigma=sigmaStep) # Aufruf CMA-ES u, v = escma(midpoint_fitness, N=2, xmean=xmean, sigma=sigmaStep) # Aufruf CMA-ES
P_next = ell.para2cart(u, v) P_next = ell.para2cart(u, v)
new_points.append(P_next) new_points.append(P_next)

View File

@@ -3,12 +3,13 @@ from math import comb
from typing import Tuple from typing import Tuple
import numpy as np import numpy as np
from numpy import sin, cos, arctan2 from numpy import arctan2, cos, sin
from numpy._typing import NDArray from numpy.typing import NDArray
import winkelumrechnungen as wu
from ellipsoide import EllipsoidTriaxial import winkelumrechnungen as wu
from GHA_triaxial.utils import pq_para 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]: def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int) -> Tuple[NDArray, float]:
@@ -110,7 +111,7 @@ def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: floa
if alpha1 < 0: if alpha1 < 0:
alpha1 += 2 * np.pi 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 = 4) -> Tuple[NDArray, float]: def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int, maxPartCircum: int = 4) -> Tuple[NDArray, float]:
@@ -134,7 +135,7 @@ def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, ma
if h > 1e-5: if h > 1e-5:
raise Exception("GHA1_ana: 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__": if __name__ == "__main__":
@@ -142,4 +143,3 @@ if __name__ == "__main__":
p0 = ell.ell2cart(wu.deg2rad(10), wu.deg2rad(20)) p0 = ell.ell2cart(wu.deg2rad(10), wu.deg2rad(20))
p1, alpha1 = gha1_ana(ell, p0, wu.deg2rad(36), 200000, 70) p1, alpha1 = gha1_ana(ell, p0, wu.deg2rad(36), 200000, 70)
print(p1, wu.rad2gms(alpha1)) print(p1, wu.rad2gms(alpha1))

View File

@@ -1,13 +1,18 @@
import numpy as np from typing import Tuple
from numpy import sin, cos
from numpy.typing import NDArray
from ellipsoide import EllipsoidTriaxial
from GHA_triaxial.gha1_ana import gha1_ana
from GHA_triaxial.utils import func_sigma_ell, louville_constant, pq_ell
import plotly.graph_objects as go
import winkelumrechnungen as wu
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 Berechung einer Näherungslösung der ersten Hauptaufgabe
:param ell: Ellipsoid :param ell: Ellipsoid
@@ -37,19 +42,24 @@ def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float,
if last_p is not None and np.dot(p, last_p) < 0: if last_p is not None and np.dot(p, last_p) < 0:
p = -p p = -p
q = -q q = -q
last_p = p
sigma = p * sin(alpha1) + q * cos(alpha1) sigma = p * sin(alpha1) + q * cos(alpha1)
if last_sigma is not None and np.dot(sigma, last_sigma) < 0: if last_sigma is not None and np.dot(sigma, last_sigma) < 0:
sigma = -sigma sigma = -sigma
alpha1 += np.pi
alpha1 = wrap_0_2pi(alpha1)
p2 = p1 + ds_step * sigma p2 = p1 + ds_step * sigma
p2 = ell.point_onto_ellipsoid(p2) p2 = ell.point_onto_ellipsoid(p2)
dalpha = 1e-6 dalpha = 1e-9
l2 = louville_constant(ell, p2, alpha1) l2 = louville_constant(ell, p2, alpha1)
dl_dalpha = (louville_constant(ell, p2, alpha1+dalpha) - l2) / dalpha 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) points.append(p2)
alphas.append(alpha2) alphas.append(wrap_0_2pi(alpha2))
ds_step = np.linalg.norm(p2 - p1) ds_step = np.linalg.norm(p2 - p1)
s_curr += ds_step s_curr += ds_step
@@ -88,11 +98,11 @@ def show_points(points: NDArray, p0: NDArray, p1: NDArray):
if __name__ == '__main__': if __name__ == '__main__':
ell = EllipsoidTriaxial.init_name("BursaSima1980round") ell = EllipsoidTriaxial.init_name("KarneyTest2024")
P0 = ell.ell2cart(wu.deg2rad(89), wu.deg2rad(1)) P0 = ell.ell2cart(wu.deg2rad(15), wu.deg2rad(15))
alpha0 = wu.deg2rad(2) alpha0 = wu.deg2rad(270)
s = 200000 s = 1
P1_app, alpha1_app, points, alphas = gha1_approx(ell, P0, alpha0, s, ds=100, all_points=True) 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=20, maxPartCircum=2) # P1_ana, alpha1_ana = gha1_ana(ell, P0, alpha0, s, maxM=40, maxPartCircum=32)
print(np.linalg.norm(P1_app - P1_ana)) # print(np.linalg.norm(P1_app - P1_ana))
show_points(points, P0, P1_ana) # show_points(points, P0, P0)

View File

@@ -1,15 +1,16 @@
from typing import Callable, List, Tuple
import numpy as np import numpy as np
from numpy import sin, cos, arctan2 from numpy import arctan2, cos, sin
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.typing import NDArray 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 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: def buildODE(ell: EllipsoidTriaxial) -> Callable:
@@ -75,8 +76,7 @@ def gha1_num(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, nu
alpha1 = arctan2(P, Q) alpha1 = arctan2(P, Q)
if alpha1 < 0: alpha1 = wrap_0_2pi(alpha1)
alpha1 += 2 * np.pi
_, _, h = ell.cart2geod(point1, "ligas3") _, _, h = ell.cart2geod(point1, "ligas3")
if h > 1e-5: if h > 1e-5:
@@ -108,7 +108,7 @@ if __name__ == "__main__":
# diffs_panou[mask_360] = np.abs(diffs_panou[mask_360] - 360) # diffs_panou[mask_360] = np.abs(diffs_panou[mask_360] - 360)
# print(diffs_panou) # print(diffs_panou)
ell: EllipsoidTriaxial = ellipsoide.EllipsoidTriaxial.init_name("KarneyTest2024") ell: EllipsoidTriaxial = EllipsoidTriaxial.init_name("KarneyTest2024")
diffs_karney = [] diffs_karney = []
# examples_karney = ne_karney.get_examples((30499, 30500, 40500)) # examples_karney = ne_karney.get_examples((30499, 30500, 40500))
examples_karney = ne_karney.get_random_examples(20) examples_karney = ne_karney.get_random_examples(20)

View File

@@ -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 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 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]: def gha2_approx(ell: EllipsoidTriaxial, p0: NDArray, p1: NDArray, ds: float, all_points: bool = False) -> Tuple[float, float, float] | Tuple[float, float, float, NDArray]:

View File

@@ -1,22 +1,30 @@
from typing import Tuple
import numpy as np import numpy as np
from ellipsoide import EllipsoidTriaxial from numpy.typing import NDArray
from runge_kutta import rk4, rk4_step, rk4_end, rk4_integral
import GHA_triaxial.numeric_examples_karney as ne_karney import GHA_triaxial.numeric_examples_karney as ne_karney
import GHA_triaxial.numeric_examples_panou as ne_panou import GHA_triaxial.numeric_examples_panou as ne_panou
import winkelumrechnungen as wu
from typing import Tuple
from numpy.typing import NDArray
import ausgaben as aus import ausgaben as aus
from utils_angle import cot, arccot, wrap_to_pi import winkelumrechnungen as wu
from ellipsoid_triaxial import EllipsoidTriaxial
from runge_kutta import rk4, rk4_end, rk4_integral
from utils_angle import cot, wrap_0_2pi, wrap_mpi_pi
def norm_a(a): def norm_a(a: float) -> float:
if a < 0.0: a = float(a) % (2 * np.pi)
a += np.pi
return a return a
def azimut(E: float, G: float, dbeta_du: float, dlamb_du: float) -> float:
north = np.sqrt(E) * dbeta_du
east = np.sqrt(G) * dlamb_du
return norm_a(np.arctan2(east, north))
def sph_azimuth(beta1, lam1, beta2, lam2): def sph_azimuth(beta1, lam1, beta2, lam2):
dlam = wrap_to_pi(lam2 - lam1) dlam = wrap_mpi_pi(lam2 - lam1)
y = np.sin(dlam) * np.cos(beta2) y = np.sin(dlam) * np.cos(beta2)
x = np.cos(beta1) * np.sin(beta2) - np.sin(beta1) * np.cos(beta2) * np.cos(dlam) x = np.cos(beta1) * np.sin(beta2) - np.sin(beta1) * np.cos(beta2) * np.cos(dlam)
a = np.arctan2(y, x) a = np.arctan2(y, x)
@@ -24,6 +32,7 @@ def sph_azimuth(beta1, lam1, beta2, lam2):
a += 2 * np.pi a += 2 * np.pi
return a return a
# Panou 2013 # Panou 2013
def gha2_num( def gha2_num(
ell: EllipsoidTriaxial, ell: EllipsoidTriaxial,
@@ -49,65 +58,67 @@ def gha2_num(
:return: Azimut Startpunkt, Azumit Zielpunkt, Strecke :return: Azimut Startpunkt, Azumit Zielpunkt, Strecke
""" """
ax2 = float(ell.ax) * float(ell.ax)
ay2 = float(ell.ay) * float(ell.ay)
b2 = float(ell.b) * float(ell.b)
Ex2 = float(ell.Ex) * float(ell.Ex)
Ey2 = float(ell.Ey) * float(ell.Ey)
Ee2 = float(ell.Ee) * float(ell.Ee)
Ey4 = Ey2 * Ey2
Ee4 = Ee2 * Ee2
two_pi = 2.0 * np.pi
# Berechnung Koeffizienten, Gaußschen Fundamentalgrößen 1. Ordnung sowie deren Ableitungen # Berechnung Koeffizienten, Gaußschen Fundamentalgrößen 1. Ordnung sowie deren Ableitungen
def BETA_LAMBDA(beta, lamb): def BETA_LAMBDA(beta, lamb):
BETA = (ell.ay ** 2 * np.sin(beta) ** 2 + ell.b ** 2 * np.cos(beta) ** 2) / ( sb = np.sin(beta)
ell.Ex ** 2 - ell.Ey ** 2 * np.sin(beta) ** 2 cb = np.cos(beta)
sl = np.sin(lamb)
cl = np.cos(lamb)
sb2 = sb * sb
cb2 = cb * cb
sl2 = sl * sl
cl2 = cl * cl
s2b = 2.0 * sb * cb
c2b = cb2 - sb2
s2l = 2.0 * sl * cl
c2l = cl2 - sl2
denB = Ex2 - Ey2 * sb2
denL = Ex2 - Ee2 * cl2
BETA = (ay2 * sb2 + b2 * cb2) / denB
LAMBDA = (ax2 * sl2 + ay2 * cl2) / denL
BETA_ = (ax2 * Ey2 * s2b) / (denB * denB)
LAMBDA_ = -(b2 * Ee2 * s2l) / (denL * denL)
BETA__ = (2.0 * ax2 * Ey4 * (s2b * s2b)) / (denB * denB * denB) + (2.0 * ax2 * Ey2 * c2b) / (
denB * denB
) )
LAMBDA = (ell.ax ** 2 * np.sin(lamb) ** 2 + ell.ay ** 2 * np.cos(lamb) ** 2) / ( LAMBDA__ = (2.0 * b2 * Ee4 * (s2l * s2l)) / (denL * denL * denL) - (2.0 * b2 * Ee2 * s2l) / (
ell.Ex ** 2 - ell.Ee ** 2 * np.cos(lamb) ** 2 denL * denL
) )
BETA_ = (ell.ax ** 2 * ell.Ey ** 2 * np.sin(2 * beta)) / ( Q = Ey2 * cb2 + Ee2 * sl2
ell.Ex ** 2 - ell.Ey ** 2 * np.sin(beta) ** 2
) ** 2
LAMBDA_ = -(ell.b ** 2 * ell.Ee ** 2 * np.sin(2 * lamb)) / (
ell.Ex ** 2 - ell.Ee ** 2 * np.cos(lamb) ** 2
) ** 2
BETA__ = ( E = BETA * Q
(2 * ell.ax ** 2 * ell.Ey ** 4 * np.sin(2 * beta) ** 2) G = LAMBDA * Q
/ (ell.Ex ** 2 - ell.Ey ** 2 * np.sin(beta) ** 2) ** 3
+ (2 * ell.ax ** 2 * ell.Ey ** 2 * np.cos(2 * beta))
/ (ell.Ex ** 2 - ell.Ey ** 2 * np.sin(beta) ** 2) ** 2
)
LAMBDA__ = (
(2 * ell.b ** 2 * ell.Ee ** 4 * np.sin(2 * lamb) ** 2)
/ (ell.Ex ** 2 - ell.Ee ** 2 * np.cos(lamb) ** 2) ** 3
- (2 * ell.b ** 2 * ell.Ee ** 2 * np.sin(2 * lamb))
/ (ell.Ex ** 2 - ell.Ee ** 2 * np.cos(lamb) ** 2) ** 2
)
E = BETA * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2) E_beta = BETA_ * Q - BETA * Ey2 * s2b
G = LAMBDA * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2) E_lamb = BETA * Ee2 * s2l
E_beta = ( G_beta = -LAMBDA * Ey2 * s2b
BETA_ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2) G_lamb = LAMBDA_ * Q + LAMBDA * Ee2 * s2l
- BETA * ell.Ey ** 2 * np.sin(2 * beta)
)
E_lamb = BETA * ell.Ee ** 2 * np.sin(2 * lamb)
G_beta = -LAMBDA * ell.Ey ** 2 * np.sin(2 * beta) E_beta_beta = BETA__ * Q - 2.0 * BETA_ * Ey2 * s2b - 2.0 * BETA * Ey2 * c2b
G_lamb = ( E_beta_lamb = BETA_ * Ee2 * s2l
LAMBDA_ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2) E_lamb_lamb = 2.0 * BETA * Ee2 * c2l
+ LAMBDA * ell.Ee ** 2 * np.sin(2 * lamb)
)
E_beta_beta = ( G_beta_beta = -2.0 * LAMBDA * Ey2 * c2b
BETA__ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2) G_beta_lamb = -LAMBDA_ * Ey2 * s2b
- 2 * BETA_ * ell.Ey ** 2 * np.sin(2 * beta) G_lamb_lamb = LAMBDA__ * Q + 2.0 * LAMBDA_ * Ee2 * s2l + 2.0 * LAMBDA * Ee2 * c2l
- 2 * BETA * ell.Ey ** 2 * np.cos(2 * beta)
)
E_beta_lamb = BETA_ * ell.Ee ** 2 * np.sin(2 * lamb)
E_lamb_lamb = 2 * BETA * ell.Ee ** 2 * np.cos(2 * lamb)
G_beta_beta = -2 * LAMBDA * ell.Ey ** 2 * np.cos(2 * beta)
G_beta_lamb = -LAMBDA_ * ell.Ey ** 2 * np.sin(2 * beta)
G_lamb_lamb = (
LAMBDA__ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
+ 2 * LAMBDA_ * ell.Ee ** 2 * np.sin(2 * lamb)
+ 2 * LAMBDA * ell.Ee ** 2 * np.cos(2 * lamb)
)
return ( return (
BETA, BETA,
@@ -167,7 +178,7 @@ def gha2_num(
) )
p_00 = 0.5 * ((E * G_beta_beta - E_beta * G_beta) / (E**2)) p_00 = 0.5 * ((E * G_beta_beta - E_beta * G_beta) / (E**2))
return (BETA, LAMBDA, E, G, p_3, p_2, p_1, p_0, p_33, p_22, p_11, p_00) return BETA, LAMBDA, E, G, p_3, p_2, p_1, p_0, p_33, p_22, p_11, p_00
# Berechnung der ODE Koeffizienten für Fall 2 (lambda_0 == lambda_1) # Berechnung der ODE Koeffizienten für Fall 2 (lambda_0 == lambda_1)
def q_coef(beta, lamb): def q_coef(beta, lamb):
@@ -220,15 +231,12 @@ def gha2_num(
(_, _, E, G, *_) = BETA_LAMBDA(beta, lamb) (_, _, E, G, *_) = BETA_LAMBDA(beta, lamb)
return np.sqrt(E + G * lamb_p**2) return np.sqrt(E + G * lamb_p**2)
# Fall 1 (lambda_0 != lambda_1) def solve_lambda_branch(beta0, lamb0, beta1, lamb1_target, N_run, N_newt, it_max):
if abs(lamb_1 - lamb_0) >= 1e-15: dlamb = float(lamb1_target - lamb0)
N = int(n) if abs(dlamb) < 1e-15:
dlamb = float(lamb_1 - lamb_0) return None
beta0 = float(beta_0) sgn = 1.0 if dlamb >= 0.0 else -1.0
lamb0 = float(lamb_0)
beta1 = float(beta_1)
lamb1 = float(lamb_1)
def ode_lamb(lamb, v): def ode_lamb(lamb, v):
beta, beta_p, X3, X4 = v beta, beta_p, X3, X4 = v
@@ -237,16 +245,188 @@ def gha2_num(
dbeta = beta_p dbeta = beta_p
dbeta_p = p_3 * beta_p**3 + p_2 * beta_p**2 + p_1 * beta_p + p_0 dbeta_p = p_3 * beta_p**3 + p_2 * beta_p**2 + p_1 * beta_p + p_0
dX3 = X4 dX3 = X4
dX4 = (p_33 * beta_p**3 + p_22 * beta_p**2 + p_11 * beta_p + p_00) * X3 + (3*p_3*beta_p**2 + 2*p_2*beta_p + p_1) * X4 dX4 = (p_33 * beta_p**3 + p_22 * beta_p**2 + p_11 * beta_p + p_00) * X3 + (
3 * p_3 * beta_p**2 + 2 * p_2 * beta_p + p_1
) * X4
return np.array([dbeta, dbeta_p, dX3, dX4], dtype=float) return np.array([dbeta, dbeta_p, dX3, dX4], dtype=float)
alpha0_sph = sph_azimuth(beta0, lamb0, beta1, lamb1) alpha0_sph = sph_azimuth(beta0, lamb0, beta1, lamb1_target)
(_, _, E0, G0, *_) = BETA_LAMBDA(beta0, lamb0) (_, _, E0, G0, *_) = BETA_LAMBDA(beta0, lamb0)
beta_p0_sph = np.sqrt(G0 / E0) * cot(alpha0_sph) beta_p0_sph = np.sqrt(G0 / E0) * cot(alpha0_sph)
N_newton = min(N, 4000)
def solve_newton(beta_p0_init: float): def solve_newton(beta_p0_init: float):
beta_p0 = float(beta_p0_init)
for _ in range(it_max):
v0 = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float)
_, y_end = rk4_end(ode_lamb, lamb0, v0, dlamb, N_newt)
beta_end, _, X3_end, _ = y_end
delta = beta_end - beta1
if abs(delta) < epsilon:
return True, beta_p0
if abs(X3_end) < 1e-20:
return False, None
step = delta / X3_end
step = float(np.clip(step, -0.5, 0.5))
beta_p0 -= step
return False, None
seeds = [beta_p0_sph, -beta_p0_sph, 0.5 * beta_p0_sph, 2.0 * beta_p0_sph]
best = None
for seed in seeds:
ok, sol = solve_newton(seed)
if not ok:
continue
v0_sol = np.array([beta0, sol, 0.0, 1.0], dtype=float)
_, _, s_val = rk4_integral(ode_lamb, lamb0, v0_sol, dlamb, N_run, integrand_lambda)
if (best is None) or (s_val < best[0]):
best = (float(s_val), float(sol))
if best is None:
return None
return best[0], best[1], sgn, dlamb, ode_lamb
def solve_beta_branch(beta0, lamb0, beta1, lamb1, N_run, N_newt, it_max):
dbeta = float(beta1 - beta0)
if abs(dbeta) < 1e-15:
return None
sgn = 1.0 if dbeta >= 0.0 else -1.0
def ode_beta(beta, v):
lamb, lamb_p, Y3, Y4 = v
(_, _, _, _, q_3, q_2, q_1, q_0, q_33, q_22, q_11, q_00) = q_coef(beta, lamb)
dlamb = lamb_p
dlamb_p = q_3 * lamb_p**3 + q_2 * lamb_p**2 + q_1 * lamb_p + q_0
dY3 = Y4
dY4 = (q_33 * lamb_p**3 + q_22 * lamb_p**2 + q_11 * lamb_p + q_00) * Y3 + (
3 * q_3 * lamb_p**2 + 2 * q_2 * lamb_p + q_1
) * Y4
return np.array([dlamb, dlamb_p, dY3, dY4], dtype=float)
def solve_newton(lamb_p0_init: float):
lamb_p0 = float(lamb_p0_init)
for _ in range(it_max):
v0 = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float)
_, y_end = rk4_end(ode_beta, beta0, v0, dbeta, N_newt)
lamb_end, _, Y3_end, _ = y_end
delta = lamb_end - lamb1
if abs(delta) < epsilon:
return True, lamb_p0
if abs(Y3_end) < 1e-20:
return False, None
step = delta / Y3_end
step = float(np.clip(step, -1.0, 1.0))
lamb_p0 -= step
return False, None
seeds = [0.0, 0.25, -0.25, 1.0, -1.0]
best = None
for seed in seeds:
ok, sol = solve_newton(seed)
if not ok:
continue
v0_sol = np.array([lamb0, sol, 0.0, 1.0], dtype=float)
_, _, s_val = rk4_integral(ode_beta, beta0, v0_sol, dbeta, N_run, integrand_beta)
if (best is None) or (s_val < best[0]):
best = (float(s_val), float(sol))
if best is None:
return None
return best[0], best[1], sgn, dbeta, ode_beta
lamb0 = float(wrap_mpi_pi(lamb_0))
lamb1 = float(wrap_mpi_pi(lamb_1))
beta0 = float(beta_0)
beta1 = float(beta_1)
N_full = int(n)
if N_full < 2:
N_full = 2
if all_points:
N_fast = min(2000, max(400, N_full // 10))
else:
N_fast = min(1500, max(300, N_full // 12))
k0 = int(np.round((lamb0 - lamb1) / two_pi))
lamb_targets = []
for dk in (-1, 0, 1):
lt = lamb1 + two_pi * float(k0 + dk)
dl = lt - lamb0
if abs(dl) <= np.pi + 1e-12:
lamb_targets.append(float(lt))
if not lamb_targets:
lamb_targets = [float(lamb1 + two_pi * float(k0))]
best_fast = None
for lt in lamb_targets:
if abs(lt - lamb0) >= 1e-15:
res = solve_lambda_branch(beta0, lamb0, beta1, lt, N_fast, min(N_fast, 800), min(iter_max, 12))
if res is None:
continue
s_fast, beta_p0_fast, sgn_fast, dlamb_fast, _ = res
cand = ("lambda", s_fast, lt, beta_p0_fast, sgn_fast, dlamb_fast)
else:
res = solve_beta_branch(beta0, lamb0, beta1, lamb1, N_fast, min(N_fast, 800), min(iter_max, 12))
if res is None:
continue
s_fast, lamb_p0_fast, sgn_fast, dbeta_fast, _ = res
cand = ("beta", s_fast, lt, lamb_p0_fast, sgn_fast, dbeta_fast)
if (best_fast is None) or (cand[1] < best_fast[1]):
best_fast = cand
if best_fast is None:
if abs(lamb1 - lamb0) >= 1e-15:
best_fast = ("lambda", 0.0, lamb1, None, 1.0, float(lamb1 - lamb0))
else:
best_fast = ("beta", 0.0, lamb1, None, 1.0, float(beta1 - beta0))
if best_fast[0] == "lambda":
lt = float(best_fast[2])
dlamb = float(lt - lamb0)
sgn = 1.0 if dlamb >= 0.0 else -1.0
def ode_lamb(lamb, v):
beta, beta_p, X3, X4 = v
(_, _, _, _, p_3, p_2, p_1, p_0, p_33, p_22, p_11, p_00) = p_coef(beta, lamb)
dbeta = beta_p
dbeta_p = p_3 * beta_p**3 + p_2 * beta_p**2 + p_1 * beta_p + p_0
dX3 = X4
dX4 = (p_33 * beta_p**3 + p_22 * beta_p**2 + p_11 * beta_p + p_00) * X3 + (
3 * p_3 * beta_p**2 + 2 * p_2 * beta_p + p_1
) * X4
return np.array([dbeta, dbeta_p, dX3, dX4], dtype=float)
alpha0_sph = sph_azimuth(beta0, lamb0, beta1, lt)
(_, _, E0, G0, *_) = BETA_LAMBDA(beta0, lamb0)
beta_p0_sph = np.sqrt(G0 / E0) * cot(alpha0_sph)
beta_p0_init = best_fast[3]
if beta_p0_init is None:
beta_p0_init = beta_p0_sph
beta_p0_init = float(beta_p0_init)
N_newton = min(N_full, 4000)
def solve_newton_refine(beta_p0_init: float):
beta_p0 = float(beta_p0_init) beta_p0 = float(beta_p0_init)
for _ in range(iter_max): for _ in range(iter_max):
v0 = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float) v0 = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float)
@@ -262,25 +442,24 @@ def gha2_num(
return False, None return False, None
step = delta / X3_end step = delta / X3_end
step = np.clip(step, -0.5, 0.5) step = float(np.clip(step, -0.5, 0.5))
beta_p0 -= step beta_p0 -= step
return False, None return False, None
ok, beta_p0_sol = solve_newton(beta_p0_sph) ok, beta_p0_sol = solve_newton_refine(beta_p0_init)
if not ok: if not ok:
candidates = [-beta_p0_sph, 0.5 * beta_p0_sph, 2.0 * beta_p0_sph] seeds = [beta_p0_sph, -beta_p0_sph, 0.5 * beta_p0_sph, 2.0 * beta_p0_sph]
N_quick = min(N, 2000)
best = None best = None
for g in candidates: for seed in seeds:
ok_g, sol = solve_newton(g) ok_s, sol_s = solve_newton_refine(seed)
if not ok_g: if not ok_s:
continue continue
v0_g = np.array([beta0, sol, 0.0, 1.0], dtype=float) v0_s = np.array([beta0, sol_s, 0.0, 1.0], dtype=float)
_, _, s_quick = rk4_integral(ode_lamb, lamb0, v0_g, dlamb, N_quick, integrand_lambda) _, _, s_s = rk4_integral(ode_lamb, lamb0, v0_s, dlamb, min(N_full, 2000), integrand_lambda)
if (best is None) or (s_quick < best[0]): if (best is None) or (s_s < best[0]):
best = (s_quick, sol) best = (float(s_s), float(sol_s))
if best is None: if best is None:
raise RuntimeError("GHA2_num: Keine Startwert-Variante konvergiert (lambda-Fall)") raise RuntimeError("GHA2_num: Keine Startwert-Variante konvergiert (lambda-Fall)")
beta_p0_sol = best[1] beta_p0_sol = best[1]
@@ -289,42 +468,43 @@ def gha2_num(
v0_final = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float) v0_final = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float)
if all_points: if all_points:
lamb_list, states = rk4(ode_lamb, lamb0, v0_final, dlamb, N, False) lamb_list, states = rk4(ode_lamb, lamb0, v0_final, dlamb, N_full, False)
lamb_arr = np.array(lamb_list, dtype=float) lamb_arr = np.array(lamb_list, dtype=float)
beta_arr = np.array([st[0] for st in states], dtype=float) beta_arr = np.array([st[0] for st in states], dtype=float)
beta_p_arr = np.array([st[1] for st in states], dtype=float) beta_p_arr = np.array([st[1] for st in states], dtype=float)
(_, _, E_start, G_start, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0]) (_, _, E_start, G_start, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0])
(_, _, E_end, G_end, *_) = BETA_LAMBDA(beta_arr[-1], lamb_arr[-1]) (_, _, E_end, G_end, *_) = BETA_LAMBDA(beta_arr[-1], lamb_arr[-1])
alpha_1 = norm_a(arccot(np.sqrt(E_start / G_start) * beta_p_arr[0])) alpha_0 = azimut(E_start, G_start, dbeta_du=beta_p_arr[0] * sgn, dlamb_du=1.0 * sgn)
alpha_2 = norm_a(arccot(np.sqrt(E_end / G_end) * beta_p_arr[-1])) alpha_1 = azimut(E_end, G_end, dbeta_du=beta_p_arr[-1] * sgn, dlamb_du=1.0 * sgn)
# Distanz aus Arrays integrand = np.zeros(N_full + 1, dtype=float)
integrand = np.zeros(N + 1, dtype=float) for i in range(N_full + 1):
for i in range(N + 1):
(_, _, Ei, Gi, *_) = BETA_LAMBDA(beta_arr[i], lamb_arr[i]) (_, _, Ei, Gi, *_) = BETA_LAMBDA(beta_arr[i], lamb_arr[i])
integrand[i] = np.sqrt(Ei * beta_p_arr[i]**2 + Gi) integrand[i] = np.sqrt(Ei * beta_p_arr[i] ** 2 + Gi)
h = abs(dlamb) / N h = abs(dlamb) / N_full
if N % 2 == 0: if N_full % 2 == 0:
S = integrand[0] + integrand[-1] + 4.0*np.sum(integrand[1:-1:2]) + 2.0*np.sum(integrand[2:-1:2]) S = integrand[0] + integrand[-1] + 4.0 * np.sum(integrand[1:-1:2]) + 2.0 * np.sum(
s = h/3.0 * S integrand[2:-1:2]
)
s = h / 3.0 * S
else: else:
s = np.trapz(integrand, dx=h) s = np.trapz(integrand, dx=h)
return float(alpha_1), float(alpha_2), float(s), beta_arr, lamb_arr return float(wrap_0_2pi(alpha_0)), float(wrap_0_2pi(alpha_1)), float(s), beta_arr, lamb_arr
_, y_end, s = rk4_integral(ode_lamb, lamb0, v0_final, dlamb, N, integrand_lambda) _, y_end, s = rk4_integral(ode_lamb, lamb0, v0_final, dlamb, N_full, integrand_lambda)
beta_end, beta_p_end, _, _ = y_end beta_end, beta_p_end, _, _ = y_end
(_, _, E_start, G_start, *_) = BETA_LAMBDA(beta0, lamb0) (_, _, E_start, G_start, *_) = BETA_LAMBDA(beta0, lamb0)
(_, _, E_end, G_end, *_) = BETA_LAMBDA(beta1, lamb1) alpha_0 = azimut(E_start, G_start, dbeta_du=beta_p0 * sgn, dlamb_du=1.0 * sgn)
alpha_1 = norm_a(arccot(np.sqrt(E_start / G_start) * beta_p0)) (_, _, E_end, G_end, *_) = BETA_LAMBDA(float(beta_end), float(lamb0 + dlamb))
alpha_2 = norm_a(arccot(np.sqrt(E_end / G_end) * beta_p_end)) alpha_1 = azimut(E_end, G_end, dbeta_du=float(beta_p_end) * sgn, dlamb_du=1.0 * sgn)
return float(alpha_1), float(alpha_2), float(s) return float(wrap_0_2pi(alpha_0)), float(wrap_0_2pi(alpha_1)), float(s)
# Fall 2 (lambda_0 == lambda_1) # Fall 2 (lambda_0 == lambda_1)
N = int(n) N = int(n)
@@ -335,22 +515,22 @@ def gha2_num(
return 0.0, 0.0, 0.0, np.array([]), np.array([]) return 0.0, 0.0, 0.0, np.array([]), np.array([])
return 0.0, 0.0, 0.0 return 0.0, 0.0, 0.0
beta0 = float(beta_0) sgn = 1.0 if dbeta >= 0.0 else -1.0
lamb0 = float(lamb_0)
beta1 = float(beta_1)
lamb1 = float(lamb_1)
def ode_beta(beta, v): def ode_beta(beta, v):
lamb, lamb_p, Y3, Y4 = v lamb, lamb_p, Y3, Y4 = v
(_, _, _, _, q_3, q_2, q_1, q_0, q_33, q_22, q_11, q_00) = q_coef(beta, lamb) (_, _, _, _, q_3, q_2, q_1, q_0, q_33, q_22, q_11, q_00) = q_coef(beta, lamb)
dlamb = lamb_p dlamb = lamb_p
dlamb_p = q_3*lamb_p**3 + q_2*lamb_p**2 + q_1*lamb_p + q_0 dlamb_p = q_3 * lamb_p**3 + q_2 * lamb_p**2 + q_1 * lamb_p + q_0
dY3 = Y4 dY3 = Y4
dY4 = (q_33*lamb_p**3 + q_22*lamb_p**2 + q_11*lamb_p + q_00)*Y3 + (3*q_3*lamb_p**2 + 2*q_2*lamb_p + q_1)*Y4 dY4 = (q_33 * lamb_p**3 + q_22 * lamb_p**2 + q_11 * lamb_p + q_00) * Y3 + (
3 * q_3 * lamb_p**2 + 2 * q_2 * lamb_p + q_1
) * Y4
return np.array([dlamb, dlamb_p, dY3, dY4], dtype=float) return np.array([dlamb, dlamb_p, dY3, dY4], dtype=float)
lamb_p0 = 0.0 lamb_p0 = float(best_fast[3]) if (best_fast[0] == "beta" and best_fast[3] is not None) else 0.0
for _ in range(iter_max): for _ in range(iter_max):
v0 = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float) v0 = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float)
_, y_end = rk4_end(ode_beta, beta0, v0, dbeta, N) _, y_end = rk4_end(ode_beta, beta0, v0, dbeta, N)
@@ -365,7 +545,7 @@ def gha2_num(
raise RuntimeError("GHA2_num: Ableitung ~ 0 im beta-Fall") raise RuntimeError("GHA2_num: Ableitung ~ 0 im beta-Fall")
step = delta / Y3_end step = delta / Y3_end
step = np.clip(step, -1.0, 1.0) step = float(np.clip(step, -1.0, 1.0))
lamb_p0 -= step lamb_p0 -= step
v0_final = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float) v0_final = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float)
@@ -376,85 +556,88 @@ def gha2_num(
lamb_arr = np.array([st[0] for st in states], dtype=float) lamb_arr = np.array([st[0] for st in states], dtype=float)
lamb_p_arr = np.array([st[1] for st in states], dtype=float) lamb_p_arr = np.array([st[1] for st in states], dtype=float)
(BETA_s, LAMBDA_s, _, _, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0]) (_, _, E_start, G_start, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0])
(BETA_e, LAMBDA_e, _, _, *_) = BETA_LAMBDA(beta_arr[-1], lamb_arr[-1]) (_, _, E_end, G_end, *_) = BETA_LAMBDA(beta_arr[-1], lamb_arr[-1])
alpha_1 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_s / BETA_s) * lamb_p_arr[0])) alpha_0 = azimut(E_start, G_start, dbeta_du=1.0 * sgn, dlamb_du=lamb_p_arr[0] * sgn)
alpha_2 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_e / BETA_e) * lamb_p_arr[-1])) alpha_1 = azimut(E_end, G_end, dbeta_du=1.0 * sgn, dlamb_du=lamb_p_arr[-1] * sgn)
integrand = np.zeros(N + 1, dtype=float) integrand = np.zeros(N + 1, dtype=float)
for i in range(N + 1): for i in range(N + 1):
(_, _, Ei, Gi, *_) = BETA_LAMBDA(beta_arr[i], lamb_arr[i]) (_, _, Ei, Gi, *_) = BETA_LAMBDA(beta_arr[i], lamb_arr[i])
integrand[i] = np.sqrt(Ei + Gi * lamb_p_arr[i]**2) integrand[i] = np.sqrt(Ei + Gi * lamb_p_arr[i] ** 2)
h = abs(dbeta) / N h = abs(dbeta) / N
if N % 2 == 0: if N % 2 == 0:
S = integrand[0] + integrand[-1] + 4.0*np.sum(integrand[1:-1:2]) + 2.0*np.sum(integrand[2:-1:2]) S = integrand[0] + integrand[-1] + 4.0 * np.sum(integrand[1:-1:2]) + 2.0 * np.sum(
s = h/3.0 * S integrand[2:-1:2]
)
s = h / 3.0 * S
else: else:
s = np.trapz(integrand, dx=h) s = np.trapz(integrand, dx=h)
return float(alpha_1), float(alpha_2), float(s), beta_arr, lamb_arr return float(wrap_0_2pi(alpha_0)), float(wrap_0_2pi(alpha_1)), float(s), beta_arr, lamb_arr
_, y_end, s = rk4_integral(ode_beta, beta0, v0_final, dbeta, N, integrand_beta) _, y_end, s = rk4_integral(ode_beta, beta0, v0_final, dbeta, N, integrand_beta)
lamb_end, lamb_p_end, _, _ = y_end lamb_end, lamb_p_end, _, _ = y_end
(BETA_s, LAMBDA_s, _, _, *_) = BETA_LAMBDA(beta0, lamb0) (_, _, E_start, G_start, *_) = BETA_LAMBDA(beta0, lamb0)
(BETA_e, LAMBDA_e, _, _, *_) = BETA_LAMBDA(beta1, lamb1) alpha_0 = azimut(E_start, G_start, dbeta_du=1.0 * sgn, dlamb_du=lamb_p0 * sgn)
alpha_1 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_s / BETA_s) * lamb_p0)) (_, _, E_end, G_end, *_) = BETA_LAMBDA(beta1, float(lamb_end))
alpha_2 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_e / BETA_e) * lamb_p_end)) alpha_1 = azimut(E_end, G_end, dbeta_du=1.0 * sgn, dlamb_du=float(lamb_p_end) * sgn)
return float(wrap_0_2pi(alpha_0)), float(wrap_0_2pi(alpha_1)), float(s)
return float(alpha_1), float(alpha_2), float(s)
if __name__ == "__main__": if __name__ == "__main__":
# ell = EllipsoidTriaxial.init_name("BursaSima1980round") ell = EllipsoidTriaxial.init_name("BursaSima1980round")
# beta1 = np.deg2rad(75) beta1 = np.deg2rad(75)
# lamb1 = np.deg2rad(-90) lamb1 = np.deg2rad(-90)
# beta2 = np.deg2rad(75) beta2 = np.deg2rad(75)
# lamb2 = np.deg2rad(66) lamb2 = np.deg2rad(66)
# a0, a1, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=5000) a0, a1, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=100)
# print(aus.gms("a0", a0, 4)) print(aus.gms("a0", a0, 4))
# print(aus.gms("a1", a1, 4)) print(aus.gms("a1", a1, 4))
# print("s: ", s) print("s: ", s)
# # print(aus.gms("a2", a2, 4)) # print(aus.gms("a2", a2, 4))
# # print(s)
# cart1 = ell.para2cart(0, 0)
# cart2 = ell.para2cart(0.4, 1.4)
# beta1, lamb1 = ell.cart2ell(cart1)
# beta2, lamb2 = ell.cart2ell(cart2)
#
# a1, a2, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=5000)
# print(s) # print(s)
cart1 = ell.para2cart(0, 0)
cart2 = ell.para2cart(0.4, 1.4)
beta1, lamb1 = ell.cart2ell(cart1)
beta2, lamb2 = ell.cart2ell(cart2)
# ell = EllipsoidTriaxial.init_name("BursaSima1980round") a1, a2, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=5000)
# diffs_panou = [] print(s)
# examples_panou = ne_panou.get_random_examples(4)
# for example in examples_panou: ell = EllipsoidTriaxial.init_name("BursaSima1980round")
# beta0, lamb0, beta1, lamb1, _, alpha0, alpha1, s = example diffs_panou = []
# P0 = ell.ell2cart(beta0, lamb0) examples_panou = ne_panou.get_random_examples(4)
# try: for example in examples_panou:
# alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10) beta0, lamb0, beta1, lamb1, _, alpha0, alpha1, s = example
# diffs_panou.append( P0 = ell.ell2cart(beta0, lamb0)
# (wu.rad2deg(abs(alpha0 - alpha0_num)), wu.rad2deg(abs(alpha1 - alpha1_num)), abs(s - s_num))) try:
# except: alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
# print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}") diffs_panou.append(
# diffs_panou = np.array(diffs_panou) (wu.rad2deg(abs(alpha0 - alpha0_num)), wu.rad2deg(abs(alpha1 - alpha1_num)), abs(s - s_num)))
# print(diffs_panou) except:
# print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
# ell = EllipsoidTriaxial.init_name("KarneyTest2024") diffs_panou = np.array(diffs_panou)
# diffs_karney = [] print(diffs_panou)
# # examples_karney = ne_karney.get_examples((30500, 40500))
# examples_karney = ne_karney.get_random_examples(2) ell = EllipsoidTriaxial.init_name("KarneyTest2024")
# for example in examples_karney: diffs_karney = []
# beta0, lamb0, alpha0, beta1, lamb1, alpha1, s = example # examples_karney = ne_karney.get_examples((30500, 40500))
# examples_karney = ne_karney.get_random_examples(2)
# try: for example in examples_karney:
# alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10) beta0, lamb0, alpha0, beta1, lamb1, alpha1, s = example
# diffs_karney.append((wu.rad2deg(abs(alpha0-alpha0_num)), wu.rad2deg(abs(alpha1-alpha1_num)), abs(s-s_num)))
# except: try:
# print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}") alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
# diffs_karney = np.array(diffs_karney) diffs_karney.append((wu.rad2deg(abs(alpha0-alpha0_num)), wu.rad2deg(abs(alpha1-alpha1_num)), abs(s-s_num)))
# print(diffs_karney) except:
print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
diffs_karney = np.array(diffs_karney)
print(diffs_karney)
pass pass

View File

@@ -1,11 +1,12 @@
import random import random
from typing import List
import winkelumrechnungen as wu import winkelumrechnungen as wu
from typing import List, Tuple from GHA_triaxial.utils import jacobi_konstante
import numpy as np from ellipsoid_triaxial import EllipsoidTriaxial
from ellipsoide import EllipsoidTriaxial
from GHA_triaxial.gha1_ES import jacobi_konstante
ell = EllipsoidTriaxial.init_name("KarneyTest2024") ell = EllipsoidTriaxial.init_name("KarneyTest2024")
file_path = r"Karney_2024_Testset.txt"
def line2example(line: str) -> List: def line2example(line: str) -> List:
""" """
@@ -31,7 +32,7 @@ def get_random_examples(num: int, seed: int = None) -> List:
""" """
if seed is not None: if seed is not None:
random.seed(seed) 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() lines = datei.readlines()
examples = [] examples = []
for i in range(num): for i in range(num):
@@ -46,7 +47,7 @@ def get_examples(l_i: List) -> List:
:param l_i: Liste von Indizes :param l_i: Liste von Indizes
:return: Liste mit Beispielen :return: Liste mit Beispielen
""" """
with open("Karney_2024_Testset.txt") as datei: with open(file_path) as datei:
lines = datei.readlines() lines = datei.readlines()
examples = [] examples = []
for i in l_i: for i in l_i:
@@ -54,53 +55,21 @@ def get_examples(l_i: List) -> List:
examples.append(example) examples.append(example)
return examples return examples
# beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s
def get_random_examples_simple_short(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:
lines = datei.readlines()
examples = []
while len(examples) < num:
example = line2example(lines[random.randint(0, len(lines) - 1)])
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
if s < 1 and abs(abs(beta0) - np.pi/2) > 1e-5 and lamb0 != 0 and abs(abs(lamb0) - np.pi) > 1e-5:
examples.append(example)
return examples
def get_random_examples_umbilics_start(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:
lines = datei.readlines()
examples = []
while len(examples) < num:
example = line2example(lines[random.randint(0, len(lines) - 1)])
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
if abs(abs(beta0) - np.pi/2) < 1e-5 and (lamb0 == 0 or abs(abs(lamb0) - np.pi) < 1e-5):
examples.append(example)
return examples
def get_random_examples_umbilics_end(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:
lines = datei.readlines()
examples = []
while len(examples) < num:
example = line2example(lines[random.randint(0, len(lines) - 1)])
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
if abs(abs(beta1) - np.pi/2) < 1e-5 and (lamb1 == 0 or abs(abs(lamb1) - np.pi) < 1e-5):
examples.append(example)
return examples
def get_random_examples_gamma(group: str, num: int, seed: int = None, length: str = None) -> List: 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 eps = 1e-20
long_short = 2 long_short = 2
if seed is not None: if seed is not None:
random.seed(seed) 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() lines = datei.readlines()
examples = [] examples = []
i = 0 i = 0
@@ -113,7 +82,7 @@ def get_random_examples_gamma(group: str, num: int, seed: int = None, length: st
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
gamma = jacobi_konstante(beta0, lamb0, alpha0_ell, ell) gamma = jacobi_konstante(beta0, lamb0, alpha0_ell, ell)
if group not in ["a", "b", "c", "d", "e"]: if group not in ["a", "b", "c", "d", "e", "de"]:
break break
elif group == "a" and not 1 >= gamma >= 0.01: elif group == "a" and not 1 >= gamma >= 0.01:
continue continue
@@ -125,6 +94,8 @@ def get_random_examples_gamma(group: str, num: int, seed: int = None, length: st
continue continue
elif group == "e" and not -1e-17 >= gamma >= -1: elif group == "e" and not -1e-17 >= gamma >= -1:
continue continue
elif group == "de" and not -eps > gamma > -1:
continue
if length == "short": if length == "short":
if example[6] < long_short: if example[6] < long_short:

View File

@@ -1,11 +1,13 @@
from __future__ import annotations
from typing import Tuple from typing import Tuple
import numpy as np import numpy as np
from numpy import arctan2, sin, cos, sqrt from numpy import arctan2, cos, sin, sqrt
from numpy._typing import NDArray
from numpy.typing import NDArray 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: 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) Q = float(q @ sigma)
alpha = arctan2(P, Q) 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]: 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) alpha_ell = arctan2(p_ell @ sigma_para, q_ell @ sigma_para)
sigma_ell = p_ell * sin(alpha_ell) + q_ell * cos(alpha_ell) sigma_ell = p_ell * sin(alpha_ell) + q_ell * cos(alpha_ell)
if np.linalg.norm(sigma_para - sigma_ell) > 1e-9: if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
raise Exception("alpha_para2ell: Differenz in den Richtungsableitungen") 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]: 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) alpha_para = arctan2(p_para @ sigma_ell, q_para @ sigma_ell)
sigma_para = p_para * sin(alpha_para) + q_para * cos(alpha_para) sigma_para = p_para * sin(alpha_para) + q_para * cos(alpha_para)
if np.linalg.norm(sigma_para - sigma_ell) > 1e-9: if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
raise Exception("alpha_ell2para: Differenz in den Richtungsableitungen") 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: def func_sigma_ell(ell: EllipsoidTriaxial, point: NDArray, alpha_ell: float) -> NDArray:
@@ -124,11 +126,10 @@ def pq_ell(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
:param point: Punkt :param point: Punkt
:return: p und q :return: p und q
""" """
x, y, z = point
n = ell.func_n(point) n = ell.func_n(point)
beta, lamb = ell.cart2ell(point) beta, lamb = ell.cart2ell(point)
if abs(cos(beta)) < 1e-12 and abs(np.sin(lamb)) < 1e-12: if abs(cos(beta)) < 1e-15 and abs(np.sin(lamb)) < 1e-15:
if beta > 0: if beta > 0:
p = np.array([0, -1, 0]) p = np.array([0, -1, 0])
else: else:
@@ -137,11 +138,7 @@ def pq_ell(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
B = ell.Ex ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(beta) ** 2 B = ell.Ex ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(beta) ** 2
L = ell.Ex ** 2 - ell.Ee ** 2 * cos(lamb) ** 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) _, t2 = ell.func_t12(point)
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
F = ell.Ey ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(lamb) ** 2 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) p1 = -sqrt(L / (F * t2)) * ell.ax / ell.Ex * sqrt(B) * sin(lamb)
@@ -181,3 +178,24 @@ def pq_para(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
q = q / np.linalg.norm(q) q = q / np.linalg.norm(q)
return p, 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

Binary file not shown.

View File

@@ -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

View File

@@ -10,7 +10,7 @@ def xyz(x: float, y: float, z: float, stellen: int) -> str:
:param stellen: Anzahl Nachkommastellen :param stellen: Anzahl Nachkommastellen
:return: String zur Ausgabe der Koordinaten :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: 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 :param stellen: Anzahl Nachkommastellen
:return: String zur Ausgabe des Winkels :return: String zur Ausgabe des Winkels
""" """
gms = wu.rad2gms(rad) values = wu.rad2gms(rad)
return f"{name} = {int(gms[0])}° {int(gms[1])}' {round(gms[2],stellen):.{stellen}f}''" return f"{name} = {int(values[0])}° {int(values[1])}' {round(values[2], stellen):.{stellen}f}''"

View File

@@ -1,35 +1,32 @@
from dash import Dash, dash, html, dcc, Input, Output, State, no_update, ctx
import plotly.graph_objects as go
import numpy as np
import dash_bootstrap_components as dbc
import builtins import builtins
from dash.exceptions import PreventUpdate
import traceback import traceback
import webbrowser import dash_bootstrap_components as dbc
from threading import Timer import numpy as np
import plotly.graph_objects as go
from dash import Dash, Input, Output, State, dcc, html, no_update
from dash.exceptions import PreventUpdate
from numpy import pi
from ellipsoide import EllipsoidTriaxial
import winkelumrechnungen as wu
import ausgaben as aus import ausgaben as aus
from GHA_triaxial.utils import alpha_ell2para, alpha_para2ell import winkelumrechnungen as wu
from ES.gha1_ES import gha1_ES
from ES.gha2_ES import gha2_ES
from GHA_triaxial.gha1_ana import gha1_ana from GHA_triaxial.gha1_ana import gha1_ana
from GHA_triaxial.gha1_num import gha1_num
from GHA_triaxial.gha1_ES import gha1_ES
from GHA_triaxial.gha1_approx import gha1_approx from GHA_triaxial.gha1_approx import gha1_approx
from GHA_triaxial.gha1_num import gha1_num
from GHA_triaxial.gha2_num import gha2_num
from GHA_triaxial.gha2_ES import gha2_ES
from GHA_triaxial.gha2_approx import gha2_approx from GHA_triaxial.gha2_approx import gha2_approx
from GHA_triaxial.gha2_num import gha2_num
from GHA_triaxial.utils import alpha_ell2para, alpha_para2ell
from ellipsoid_triaxial import EllipsoidTriaxial
# Prints von importierten Funktionen unterdücken # Prints von importierten Funktionen unterdücken
def _no_print(*args, **kwargs): def _no_print(*args, **kwargs):
pass pass
#builtins.print = _no_print
builtins.print = _no_print
# Bootstrap (CSS) einbindung # Bootstrap (CSS) einbindung
@@ -39,7 +36,7 @@ app.title = "Geodätische Hauptaufgaben"
# Erzeugen der Eingabefelder # Erzeugen der Eingabefelder
def inputfeld(left_text, input_id, right_text="", width=200, min=None, max=None): def inputfeld(left_text, input_id, right_text="", width=200, mini=None, maxi=None):
return html.Div( return html.Div(
children=[ children=[
html.Span(f"{left_text} =", style={"minWidth": 36, "textAlign": "right", "marginRight": 5}), html.Span(f"{left_text} =", style={"minWidth": 36, "textAlign": "right", "marginRight": 5}),
@@ -47,17 +44,27 @@ def inputfeld(left_text, input_id, right_text="", width=200, min=None, max=None)
id=input_id, id=input_id,
type="number", type="number",
placeholder=f"{left_text}...[{right_text}]", placeholder=f"{left_text}...[{right_text}]",
min=min,
max=max,
style={"width": width, "display": "block"}, style={"width": width, "display": "block"},
persistence=True, persistence=True,
persistence_type="memory", # oder "session"/"local" persistence_type="memory",
), ),
html.Span(right_text, style={"marginLeft": 5}) if right_text else html.Span() html.Span(right_text, style={"marginLeft": 5}) if right_text else html.Span()
], ],
style={"display": "flex", "alignItems": "center", "marginBottom": "10px"}, style={"display": "flex", "alignItems": "center", "marginBottom": "10px"},
) )
# Positionierung der Input-Felder
def input_grid(*children, cols=2):
return html.Div(
list(children),
style={
"display": "grid",
"gridTemplateColumns": f"repeat({cols}, minmax(0, 1fr))",
"columnGap": "1.2vw",
"rowGap": "0.6vh",
},
)
# Erzeugen der Checklisten inkl. Eingabefelder # Erzeugen der Checklisten inkl. Eingabefelder
def method_row(label, cb_id, input_id=None, value="", info="", input_id2=None, value2="", info2="",): def method_row(label, cb_id, input_id=None, value="", info="", input_id2=None, value2="", info2="",):
base_row_style = { base_row_style = {
@@ -112,7 +119,7 @@ def method_row(label, cb_id, input_id=None, value="", info="", input_id2=None, v
" | ".join(info_parts), " | ".join(info_parts),
style={ style={
"marginLeft": "6px", "marginLeft": "6px",
"fontSize": "12px", "fontSize": "11px",
"color": "#6c757d", "color": "#6c757d",
"lineHeight": "1.1", "lineHeight": "1.1",
"whiteSpace": "nowrap", "whiteSpace": "nowrap",
@@ -132,39 +139,75 @@ def method_failed(method_label: str, exc: Exception):
return html.Div([ return html.Div([
html.Strong(f"{method_label}: "), html.Strong(f"{method_label}: "),
html.Span("konnte nicht berechnet werden. ", style={"color": "red"}), html.Span("konnte nicht berechnet werden. ", style={"color": "red"}),
#html.Span(f"({type(exc).__name__}: {exc})", style={"color": "#b02a37"}), # html.Span(f"({type(exc).__name__}: {exc})", style={"color": "#b02a37"}),
html.Details([ html.Details([
html.Summary("Details"), html.Summary("Details"),
html.Pre(traceback.format_exc(), style={ html.Pre(traceback.format_exc(), style={
"whiteSpace": "pre-wrap", "whiteSpace": "pre-wrap",
"fontSize": "12px", "fontSize": "11px",
"color": "#6c757d", "color": "#6c757d",
"marginTop": "6px" "marginTop": "6px"
}) })
], style={"marginTop": "6px"}) ], style={"marginTop": "6px"})
]) ])
def axes_valid(ax, ay, b) -> bool:
if ax is None or ay is None or b is None:
return False
try:
ax = float(ax); ay = float(ay); b = float(b)
except (TypeError, ValueError):
return False
if ax <= 0 or ay <= 0 or b <= 0:
return False
return ax >= ay >= b
def ellipsoid_figure(ell: EllipsoidTriaxial, title="Dreiachsiges Ellipsoid"): def ellipsoid_figure(ell: EllipsoidTriaxial, title="Dreiachsiges Ellipsoid"):
fig = go.Figure() fig = go.Figure()
# Darstellung # Darstellung
rx, ry, rz = 1.05*ell.ax, 1.05*ell.ay, 1.05*ell.b rx, ry, rz = 1.01*ell.ax, 1.01*ell.ay, 1.01*ell.b
fig.update_layout( fig.update_layout(
title=title, title=title,
scene=dict( scene=dict(
xaxis=dict(range=[-rx, rx], title="X [m]"), xaxis=dict(
yaxis=dict(range=[-ry, ry], title="Y [m]"), range=[-rx, rx],
zaxis=dict(range=[-rz, rz], title="Z [m]"), # title="X [m]",
aspectmode="data" title="",
showgrid=False,
zeroline=False,
showbackground=False,
showticklabels=False
),
yaxis=dict(
range=[-ry, ry],
# title="Y [m]",
title="",
showgrid=False,
zeroline=False,
showbackground=False,
showticklabels=False
),
zaxis=dict(
range=[-rz, rz],
# title="Z [m]",
title="",
showgrid=False,
zeroline=False,
showbackground=False,
showticklabels=False
),
aspectmode="data",
), ),
margin=dict(l=0, r=0, t=10, b=0), margin=dict(l=0, r=0, t=0, b=0),
scene_camera=dict(eye=dict(x=1.05, y=1.05, z=0.85)),
) )
# Ellipsoid # Ellipsoid
u = np.linspace(-np.pi/2, np.pi/2, 80) u = np.linspace(-pi/2, pi/2, 80)
v = np.linspace(-np.pi, np.pi, 160) v = np.linspace(-pi, pi, 160)
U, V = np.meshgrid(u, v) U, V = np.meshgrid(u, v)
X, Y, Z = ell.para2cart(U, V) X, Y, Z = ell.para2cart(U, V)
fig.add_trace(go.Surface( fig.add_trace(go.Surface(
@@ -214,7 +257,7 @@ def figure_constant_lines(fig, ell: EllipsoidTriaxial, coordsystem: str = "para"
all_beta[-1] -= 1e-8 all_beta[-1] -= 1e-8
constants_lamb = wu.deg2rad(np.arange(-180, 180, 15)) constants_lamb = wu.deg2rad(np.arange(-180, 180, 15))
for lamb in constants_lamb: for lamb in constants_lamb:
if lamb != 0 and abs(lamb) != np.pi: if lamb != 0 and abs(lamb) != pi:
xyz = ell.ell2cart(all_beta, lamb) xyz = ell.ell2cart(all_beta, lamb)
fig.add_trace(go.Scatter3d( fig.add_trace(go.Scatter3d(
x=xyz[:, 0], y=xyz[:, 1], z=xyz[:, 2], mode="lines", x=xyz[:, 0], y=xyz[:, 1], z=xyz[:, 2], mode="lines",
@@ -289,14 +332,37 @@ def figure_lines(fig, line, name, color):
)) ))
return fig return fig
# HTML der beiden Tabs # HTML der beiden Tabs
# Tab 1 # Tab 1
pane_gha1 = html.Div( pane_gha1 = html.Div(
[ [
inputfeld("β₀", "input-GHA1-beta0", "°"), html.Div(
inputfeld("λ₀", "input-GHA1-lamb0", "°"), [
inputfeld("s", "input-GHA1-s", "m"), html.Div(
inputfeld("α₀", "input-GHA1-a", "°"), [
inputfeld("β₀", "input-GHA1-beta0", "°"),
inputfeld("λ₀", "input-GHA1-lamb0", "°"),
],
style={"flex": "1"},
),
html.Div(
[
inputfeld("s", "input-GHA1-s", "m"),
inputfeld("α₀", "input-GHA1-a", "°"),
],
style={"flex": "1"},
),
],
style={
"display": "flex",
"gap": "1%",
"alignItems": "flex-start",
"flexWrap": "wrap",
},
),
method_row("Analytisch", "cb-ana-1", "input-ana-1", "70", info="Ordnung", input_id2="input-ana-1-2", value2="4", info2="max. Unterteilung"), method_row("Analytisch", "cb-ana-1", "input-ana-1", "70", info="Ordnung", input_id2="input-ana-1-2", value2="4", info2="max. Unterteilung"),
method_row("Numerisch", "cb-num-1", "input-num-n-1", "2000", info="Anzahl Schritte"), method_row("Numerisch", "cb-num-1", "input-num-n-1", "2000", info="Anzahl Schritte"),
@@ -337,10 +403,31 @@ pane_gha1 = html.Div(
# Tab2 # Tab2
pane_gha2 = html.Div( pane_gha2 = html.Div(
[ [
inputfeld("β₀", "input-GHA2-beta0", "°"), html.Div(
inputfeld("λ₀", "input-GHA2-lamb0", "°"), [
inputfeld("β₁", "input-GHA2-beta1", "°"), html.Div(
inputfeld("λ₁", "input-GHA2-lamb1", "°"), [
inputfeld("β₀", "input-GHA2-beta0", "°"),
inputfeld("λ₀", "input-GHA2-lamb0", "°"),
],
style={"flex": "1"},
),
html.Div(
[
inputfeld("β₁", "input-GHA2-beta1", "°"),
inputfeld("λ₁", "input-GHA2-lamb1", "°"),
],
style={"flex": "1"},
),
],
style={
"display": "flex",
"gap": "1%",
"alignItems": "flex-start",
"flexWrap": "wrap",
},
),
method_row("Numerisch", "cb-num-2", "input-num-n-2", "2000", info="Anzahl Schritte"), method_row("Numerisch", "cb-num-2", "input-num-n-2", "2000", info="Anzahl Schritte"),
method_row("Stochastisch", "cb-stoch-2", "input-stoch-n-2", "1000", info="Länge Streckensegment [m]"), method_row("Stochastisch", "cb-stoch-2", "input-stoch-n-2", "1000", info="Länge Streckensegment [m]"),
@@ -379,8 +466,8 @@ pane_gha2 = html.Div(
app.layout = html.Div( app.layout = html.Div(
style={"fontFamily": "Arial", "padding": "10px", "width": "95%", "margin": "0 auto"}, style={"fontFamily": "Arial", "padding": "10px", "width": "95%", "margin": "0 auto"},
children=[ children=[
html.H1("Geodätische Hauptaufgaben"), html.H2("Geodätische Hauptaufgaben für dreiachsige Ellipsoide"),
html.H2("für dreiachsige Ellipsoide"), # html.H2("für dreiachsige Ellipsoide"),
html.Div( html.Div(
style={ style={
@@ -400,28 +487,37 @@ app.layout = html.Div(
dcc.Dropdown( dcc.Dropdown(
id="dropdown-ellipsoid", id="dropdown-ellipsoid",
options=[ options=[
{"label": "BursaFialova1993", "value": "BursaFialova1993"}, {"label": "Burša und Šíma (1980)", "value": "BursaSima1980round"},
{"label": "BursaSima1980", "value": "BursaSima1980"}, {"label": "Karney (2024)", "value": "KarneyTest2024"},
{"label": "BursaSima1980round", "value": "BursaSima1980round"}, {"label": "Fictional", "value": "Fiction"},
{"label": "Eitschberger1978", "value": "Eitschberger1978"}, {"label": "Burša und Fialová (1993)", "value": "BursaFialova1993"},
{"label": "Bursa1972", "value": "Bursa1972"}, {"label": "Eitschberger (1978)", "value": "Eitschberger1978"},
{"label": "Bursa1970", "value": "Bursa1970"}, {"label": "Burša (1972)", "value": "Bursa1972"},
{"label": "BesselBiaxial", "value": "BesselBiaxial"}, {"label": "Burša (1970)", "value": "Bursa1970"}
{"label": "KarneyTest2024", "value": "KarneyTest2024"},
{"label": "Fiction", "value": "Fiction"},
], ],
value="", value="",
style={"width": "300px", "marginBottom": "16px"}, style={"width": "300px", "marginBottom": "16px"},
), ),
html.P("Halbachsen:", style={"marginBottom": "10px"}), html.P("Halbachsen:", style={"marginBottom": "0.8vh"}),
inputfeld("aₓ", "input-ax", "m"),
inputfeld("aᵧ", "input-ay", "m"),
inputfeld("b", "input-b", "m"),
html.Div(id="axes-error", style={"marginLeft": "10px", "marginTop": "5px", "marginBottom": "10px"}),
#html.Br(), html.Div(
[
inputfeld("aₓ", "input-ax", "m", mini=0, width="clamp(80px, 7vw, 200px)"),
inputfeld("aᵧ", "input-ay", "m", mini=0, width="clamp(80px, 7vw, 200px)"),
inputfeld("b", "input-b", "m", mini=0, width="clamp(80px, 7vw, 200px)"),
],
style={
"display": "grid",
"gridTemplateColumns": "repeat(auto-fit, minmax(200px, 1fr))",
"columnGap": "0.2vw",
"rowGap": "0.6vh",
"alignItems": "center",
},
),
# html.Br(),
dcc.Tabs( dcc.Tabs(
id="tabs-GHA", id="tabs-GHA",
@@ -445,10 +541,10 @@ app.layout = html.Div(
"minWidth": "520px", "minWidth": "520px",
"position": "sticky", "position": "sticky",
"top": "0", "top": "0",
"marginTop": "-50px", "marginTop": "0px",
}, },
children=[ children=[
html.Label("Koordinatenart wählen:", style={"marginLeft": "80px"},), html.Label("Koordinatenart wählen:", style={"marginLeft": "5%"},),
dcc.Dropdown( dcc.Dropdown(
id="dropdown-coors-type", id="dropdown-coors-type",
options=[ options=[
@@ -459,11 +555,11 @@ app.layout = html.Div(
], ],
value="ell", value="ell",
clearable=False, clearable=False,
style={"width": "200px", "marginLeft": "80px"}, style={"width": "200px", "marginLeft": "5%"},
), ),
dcc.Graph( dcc.Graph(
id="ellipsoid-plot", id="ellipsoid-plot",
style={"height": "85vh", "width": "100%"}, style={"height": "80vh", "width": "100%"},
config={"responsive": True} config={"responsive": True}
) )
], ],
@@ -473,14 +569,12 @@ app.layout = html.Div(
dcc.Store(id="calc-token-gha1", data=0), dcc.Store(id="calc-token-gha1", data=0),
dcc.Store(id="calc-token-gha2", data=0), dcc.Store(id="calc-token-gha2", data=0),
#html.P("© 2026", style={"fontSize": "10px", "color": "gray", "textAlign": "center", "marginTop": "16px"}), # html.P("© 2026", style={"fontSize": "10px", "color": "gray", "textAlign": "center", "marginTop": "16px"}),
], ],
) )
# Funktion zur Wahl der Halbachsen # Funktion zur Wahl der Halbachsen
@app.callback( @app.callback(
Output("input-ax", "value"), Output("input-ax", "value"),
@@ -565,84 +659,222 @@ def toggle_ds(v):
return "on" not in (v or []) return "on" not in (v or [])
# Abfrage ob Berechnungsverfahren gewählt # Abfrage ob Berechnungsverfahren gewählt
@app.callback( @app.callback(
Output("calc-token-gha1", "data"),
Output("tabs-GHA1-out", "children"), Output("tabs-GHA1-out", "children"),
Output("gha1-header", "children", allow_duplicate=True),
Output("output-gha1-ana", "children", allow_duplicate=True),
Output("output-gha1-num", "children", allow_duplicate=True),
Output("output-gha1-stoch", "children", allow_duplicate=True),
Output("output-gha1-approx", "children", allow_duplicate=True),
Output("store-gha1-ana", "data", allow_duplicate=True),
Output("store-gha1-num", "data", allow_duplicate=True),
Output("store-gha1-stoch", "data", allow_duplicate=True),
Output("store-gha1-approx", "data", allow_duplicate=True),
Input("button-calc-gha1", "n_clicks"), Input("button-calc-gha1", "n_clicks"),
State("calc-token-gha1", "data"),
State("cb-ana-1", "value"), State("cb-ana-1", "value"),
State("cb-num-1", "value"), State("cb-num-1", "value"),
State("cb-stoch-1", "value"), State("cb-stoch-1", "value"),
State("cb-approx-1", "value"), State("cb-approx-1", "value"),
# Eingaben GHA1
State("input-GHA1-beta0", "value"), State("input-GHA1-beta0", "value"),
State("input-GHA1-lamb0", "value"), State("input-GHA1-lamb0", "value"),
State("input-GHA1-s", "value"), State("input-GHA1-s", "value"),
State("input-GHA1-a", "value"), State("input-GHA1-a", "value"),
# Halbachsen
State("input-ax", "value"), State("input-ax", "value"),
State("input-ay", "value"), State("input-ay", "value"),
State("input-b", "value"), State("input-b", "value"),
prevent_initial_call=True, prevent_initial_call=True,
) )
def gha1_method_hint(n, a, nu, st, ap, beta0, lamb0, s, a0, ax, ay, b): def request_calc_gha1(n_clicks, token,
# Ellipsoid cb_ana, cb_num, cb_stoch, cb_approx,
if ax is None or ay is None or b is None: beta0, lamb0, s, a0,
return html.Span("Bitte Ellipsoid wählen bzw. Halbachsen eingeben.", style={"color": "red"}) ax, ay, b):
if not n_clicks:
raise PreventUpdate
if ax is None or ay is None or b is None:
msg = html.Span("Bitte Ellipsoid wählen bzw. Halbachsen eingeben.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
# Halbachsen
try: try:
ax_f, ay_f, b_f = float(ax), float(ay), float(b) ax_f, ay_f, b_f = float(ax), float(ay), float(b)
except (TypeError, ValueError): except (TypeError, ValueError):
return html.Span("Bitte gültige Zahlen für aₓ, aᵧ und b eingeben.", style={"color": "red"}) msg = html.Span("Bitte gültige Zahlen für aₓ, aᵧ und b eingeben.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
if ax_f <= 0 or ay_f <= 0 or b_f <= 0: if ax_f <= 0 or ay_f <= 0 or b_f <= 0:
return html.Span("Halbachsen müssen > 0 sein.", style={"color": "red"}) msg = html.Span("Halbachsen müssen > 0 sein.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
if not (ax_f >= ay_f >= b_f): if not (ax_f >= ay_f >= b_f):
return html.Span("Ungültige Halbachsen! (aₓ ≥ aᵧ ≥ b)", style={"color": "red"}) msg = html.Span("Ungültige Halbachsen! (aₓ ≥ aᵧ ≥ b)", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
# GHA1-Eingabefelder prüfen # --- Validierung Verfahren ---
missing = [] any_on = any("on" in (v or []) for v in (cb_ana, cb_num, cb_stoch, cb_approx))
if beta0 is None:
missing.append("β₀")
if lamb0 is None:
missing.append("λ₀")
if s is None:
missing.append("s")
if a0 is None:
missing.append("α₀")
if missing:
return html.Span(
"Bitte " + ", ".join(missing) + " eingeben.",
style={"color": "red"},
)
# Berechnungsverfahren
any_on = any("on" in (v or []) for v in (a, nu, st, ap))
if not any_on: if not any_on:
return html.Span("Bitte Berechnungsverfahren wählen.", style={"color": "red"}) msg = html.Span("Bitte Berechnungsverfahren wählen.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
missing = []
if beta0 is None: missing.append("β₀")
if lamb0 is None: missing.append("λ₀")
if s is None: missing.append("s")
if a0 is None: missing.append("α₀")
if missing:
msg = html.Span("Bitte " + ", ".join(missing) + " eingeben.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
# Eingaben Wertebereiche
try: try:
beta0_f = float(beta0) beta0_f = float(beta0)
lamb0_f = float(lamb0) lamb0_f = float(lamb0)
s_f = float(s) s_f = float(s)
a0_f = float(a0) a0_f = float(a0)
except (TypeError, ValueError): except (TypeError, ValueError):
return html.Span("Bitte gültige Zahlen für β₀, λ₀, s und α₀ eingeben.", style={"color": "red"}) msg = html.Span("Bitte gültige Zahlen für β₀, λ₀, s und α₀ eingeben.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
if not (-90 <= beta0_f <= 90): if not (-90 <= beta0_f <= 90):
return html.Span("β₀ muss im Bereich [-90°, 90°] liegen.", style={"color": "red"}) msg = html.Span("β₀ muss im Bereich [-90°, 90°] liegen.", style={"color": "red"})
if not (-180 <= lamb0_f <= 180): return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
return html.Span("λ₀ muss im Bereich [-180°, 180°] liegen.", style={"color": "red"}) no_update, no_update, no_update, no_update)
if s_f <= 0:
return html.Span("s muss > 0 sein.", style={"color": "red"})
if not (-180 <= lamb0_f <= 360):
return html.Span("α₀ muss im Bereich [-180°, 360°] liegen.", style={"color": "red"})
return "" if not (-180 <= lamb0_f <= 180):
msg = html.Span("λ₀ muss im Bereich [-180°, 180°] liegen.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
if s_f <= 0:
msg = html.Span("s muss > 0 sein.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
if not (-180 <= a0_f <= 360):
msg = html.Span("α₀ muss im Bereich [-180°, 360°] liegen.", style={"color": "red"})
return (no_update, msg, no_update, no_update, no_update, no_update, no_update,
no_update, no_update, no_update, no_update)
new_token = (token or 0) + 1
return (
new_token,
"",
"",
"", "", "", "",
None, None, None, None
)
@app.callback(
Output("calc-token-gha2", "data"),
Output("tabs-GHA2-out", "children"),
Output("gha2-header", "children", allow_duplicate=True),
Output("output-gha2-num", "children", allow_duplicate=True),
Output("output-gha2-stoch", "children", allow_duplicate=True),
Output("output-gha2-approx", "children", allow_duplicate=True),
Output("store-gha2-num", "data", allow_duplicate=True),
Output("store-gha2-stoch", "data", allow_duplicate=True),
Output("store-gha2-approx", "data", allow_duplicate=True),
Input("button-calc-gha2", "n_clicks"),
State("calc-token-gha2", "data"),
State("cb-num-2", "value"),
State("cb-stoch-2", "value"),
State("cb-approx-2", "value"),
State("input-GHA2-beta0", "value"),
State("input-GHA2-lamb0", "value"),
State("input-GHA2-beta1", "value"),
State("input-GHA2-lamb1", "value"),
State("input-ax", "value"),
State("input-ay", "value"),
State("input-b", "value"),
prevent_initial_call=True,
)
def request_calc_gha2(n_clicks, token,
cb_num, cb_stoch, cb_approx,
beta0, lamb0, beta1, lamb1,
ax, ay, b):
if not n_clicks:
raise PreventUpdate
if ax is None or ay is None or b is None:
msg = html.Span("Bitte Ellipsoid wählen bzw. Halbachsen eingeben.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
try:
ax_f, ay_f, b_f = float(ax), float(ay), float(b)
except (TypeError, ValueError):
msg = html.Span("Bitte gültige Zahlen für aₓ, aᵧ und b eingeben.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if ax_f <= 0 or ay_f <= 0 or b_f <= 0:
msg = html.Span("Halbachsen müssen > 0 sein.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if not (ax_f >= ay_f >= b_f):
msg = html.Span("Ungültige Halbachsen! (aₓ ≥ aᵧ ≥ b)", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
any_on = any("on" in (v or []) for v in (cb_num, cb_stoch, cb_approx))
if not any_on:
msg = html.Span("Bitte Berechnungsverfahren wählen.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
missing = []
if beta0 is None: missing.append("β₀")
if lamb0 is None: missing.append("λ₀")
if beta1 is None: missing.append("β₁")
if lamb1 is None: missing.append("λ₁")
if missing:
msg = html.Span("Bitte " + ", ".join(missing) + " eingeben.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
try:
beta0_f = float(beta0); lamb0_f = float(lamb0)
beta1_f = float(beta1); lamb1_f = float(lamb1)
except (TypeError, ValueError):
msg = html.Span("Bitte gültige Zahlen für β₀, λ₀, β₁ und λ₁ eingeben.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if not (-90 <= beta0_f <= 90):
msg = html.Span("β₀ muss im Bereich [-90°, 90°] liegen.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if not (-180 <= lamb0_f <= 180):
msg = html.Span("λ₀ muss im Bereich [-180°, 180°] liegen.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if not (-90 <= beta1_f <= 90):
msg = html.Span("β₁ muss im Bereich [-90°, 90°] liegen.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
if not (-180 <= lamb1_f <= 180):
msg = html.Span("λ₁ muss im Bereich [-180°, 180°] liegen.", style={"color": "red"})
return no_update, msg, no_update, no_update, no_update, no_update, no_update, no_update, no_update
new_token = (token or 0) + 1
return (
new_token,
"",
"",
"", "", "",
None, None, None
)
# -- GHA 1 --- # -- GHA 1 ---
@@ -682,7 +914,7 @@ def compute_gha1_ana(n1, cb_ana, max_M, maxPartCircum, beta0, lamb0, s, a0, ax,
P0 = ell.ell2cart(beta_rad, lamb_rad) P0 = ell.ell2cart(beta_rad, lamb_rad)
P1_ana, alpha2_para = gha1_ana(ell, P0, alpha_rad_para, s_val, max_M, maxPartCircum) P1_ana, alpha2_para = gha1_ana(ell, P0, alpha_rad_para, s_val, max_M, maxPartCircum)
u1, v1 = ell.cart2para(P1_ana) u1, v1 = ell.cart2para(P1_ana)
alpha2 = alpha_para2ell(ell, u1, v1, alpha2_para) alpha1 = alpha_para2ell(ell, u1, v1, alpha2_para)
beta2_ana, lamb2_ana = ell.cart2ell(P1_ana) beta2_ana, lamb2_ana = ell.cart2ell(P1_ana)
out = html.Div([ out = html.Div([
@@ -692,6 +924,7 @@ def compute_gha1_ana(n1, cb_ana, max_M, maxPartCircum, beta0, lamb0, s, a0, ax,
html.Br(), html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₁', beta2_ana, 4)}, {aus.gms('λ₁', lamb2_ana, 4)}"), html.Span(f"ellipsoidisch: {aus.gms('β₁', beta2_ana, 4)}, {aus.gms('λ₁', lamb2_ana, 4)}"),
html.Br(), html.Br(),
html.Span(f"{aus.gms('α₁', alpha1[-1], 4)}"),
]) ])
store = { store = {
@@ -723,18 +956,19 @@ def compute_gha1_ana(n1, cb_ana, max_M, maxPartCircum, beta0, lamb0, s, a0, ax,
def compute_gha1_num(n1, cb_num, n_in, beta0, lamb0, s, a0, ax, ay, b): def compute_gha1_num(n1, cb_num, n_in, beta0, lamb0, s, a0, ax, ay, b):
if not n1: if not n1:
return no_update, no_update return no_update, no_update
if "on" not in (cb_num or []): if "on" not in (cb_num or []):
return "", None return "", None
n_in = int(n_in) if n_in else 2000 n_in = int(n_in) if n_in else 2000
ell = EllipsoidTriaxial(ax, ay, b)
beta_rad = wu.deg2rad(float(beta0))
lamb_rad = wu.deg2rad(float(lamb0))
alpha_rad = wu.deg2rad(float(a0))
s_val = float(s)
try: try:
ell = EllipsoidTriaxial(ax, ay, b)
beta_rad = wu.deg2rad(float(beta0))
lamb_rad = wu.deg2rad(float(lamb0))
alpha_rad = wu.deg2rad(float(a0))
s_val = float(s)
P0 = ell.ell2cart(beta_rad, lamb_rad) P0 = ell.ell2cart(beta_rad, lamb_rad)
P1_num, alpha1, werte = gha1_num(ell, P0, alpha_rad, s_val, n_in, all_points=True) P1_num, alpha1, werte = gha1_num(ell, P0, alpha_rad, s_val, n_in, all_points=True)
@@ -747,6 +981,7 @@ def compute_gha1_num(n1, cb_num, n_in, beta0, lamb0, s, a0, ax, ay, b):
html.Br(), html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₁', beta2_num, 4)}, {aus.gms('λ₁', lamb2_num, 4)}"), html.Span(f"ellipsoidisch: {aus.gms('β₁', beta2_num, 4)}, {aus.gms('λ₁', lamb2_num, 4)}"),
html.Br(), html.Br(),
html.Span(f"{aus.gms('α₁', alpha1, 4)}"),
]) ])
polyline = [[x1, y1, z1] for x1, _, y1, _, z1, _ in werte] polyline = [[x1, y1, z1] for x1, _, y1, _, z1, _ in werte]
@@ -803,6 +1038,8 @@ def compute_gha1_stoch(n1, cb_stoch, n_in, beta0, lamb0, s, a0, ax, ay, b):
html.Span(f"kartesisch: x₁={P1_stoch[0]:.4f} m, y₁={P1_stoch[1]:.4f} m, z₁={P1_stoch[2]:.4f} m"), html.Span(f"kartesisch: x₁={P1_stoch[0]:.4f} m, y₁={P1_stoch[1]:.4f} m, z₁={P1_stoch[2]:.4f} m"),
html.Br(), html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₁', beta1_stoch, 4)}, {aus.gms('λ₁', lamb1_stoch, 4)}"), html.Span(f"ellipsoidisch: {aus.gms('β₁', beta1_stoch, 4)}, {aus.gms('λ₁', lamb1_stoch, 4)}"),
html.Br(),
html.Span(f"{aus.gms('α₁', alpha, 4)}"),
]) ])
store = { store = {
@@ -857,6 +1094,8 @@ def compute_gha1_approx(n1, cb_approx, ds_in, beta0, lamb0, s, a0, ax, ay, b):
html.Span(f"kartesisch: x₁={P1_app[0]:.4f} m, y₁={P1_app[1]:.4f} m, z₁={P1_app[2]:.4f} m"), html.Span(f"kartesisch: x₁={P1_app[0]:.4f} m, y₁={P1_app[1]:.4f} m, z₁={P1_app[2]:.4f} m"),
html.Br(), html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₁', beta1_app, 4)}, {aus.gms('λ₁', lamb1_app, 4)}"), html.Span(f"ellipsoidisch: {aus.gms('β₁', beta1_app, 4)}, {aus.gms('λ₁', lamb1_app, 4)}"),
html.Br(),
html.Span(f"{aus.gms('α₁', alpha1_app, 4)}"),
]) ])
store = { store = {
@@ -915,6 +1154,7 @@ def compute_gha2_num(n2, cb_num, n_in, beta0, lamb0, beta1, lamb1, ax, ay, b):
out = html.Div([ out = html.Div([
html.Strong("Numerisch: "), html.Strong("Numerisch: "),
html.Br(),
html.Span(f"{aus.gms('α₀', a0_num, 4)}, {aus.gms('α₁', a1_num, 4)}, s = {s_num:.4f} m"), html.Span(f"{aus.gms('α₀', a0_num, 4)}, {aus.gms('α₁', a1_num, 4)}, s = {s_num:.4f} m"),
]) ])
@@ -967,6 +1207,7 @@ def compute_gha2_stoch(n2, cb_stoch, n_in, beta0, lamb0, beta1, lamb1, ax, ay, b
out = html.Div([ out = html.Div([
html.Strong("Stochastisch (ES): "), html.Strong("Stochastisch (ES): "),
html.Br(),
html.Span(f"{aus.gms('α₀', a0_stoch, 4)}, {aus.gms('α₁', a1_stoch, 4)}, s = {s_stoch:.4f} m"), html.Span(f"{aus.gms('α₀', a0_stoch, 4)}, {aus.gms('α₁', a1_stoch, 4)}, s = {s_stoch:.4f} m"),
]) ])
@@ -1020,6 +1261,7 @@ def compute_gha2_approx(n2, cb_approx, ds_in, beta0, lamb0, beta1, lamb1, ax, ay
out = html.Div([ out = html.Div([
html.Strong("Approximiert: "), html.Strong("Approximiert: "),
html.Br(),
html.Span(f"{aus.gms('α₀', a0_app, 4)}, {aus.gms('α₁', a1_app, 4)}, s = {s_app:.4f} m"), html.Span(f"{aus.gms('α₀', a0_app, 4)}, {aus.gms('α₁', a1_app, 4)}, s = {s_app:.4f} m"),
]) ])
@@ -1033,7 +1275,7 @@ def compute_gha2_approx(n2, cb_approx, ds_in, beta0, lamb0, beta1, lamb1, ax, ay
return out, store return out, store
except Exception as e: except Exception as e:
return method_failed("Stochastisch (ES)", e), None return method_failed("Approximiert", e), None
# --- Plot --- # --- Plot ---
@app.callback( @app.callback(
@@ -1059,15 +1301,7 @@ def render_all(ax, ay, b, coords_type, tab, t1, t2,
if None in (ax, ay, b): if None in (ax, ay, b):
return go.Figure() return go.Figure()
try: if not axes_valid(ax, ay, b):
ax = float(ax); ay = float(ay); b = float(b)
except (TypeError, ValueError):
return go.Figure()
if ax <= 0 or ay <= 0 or b <= 0:
return go.Figure()
if not (ax >= ay >= b):
return go.Figure() return go.Figure()
ell = EllipsoidTriaxial(ax, ay, b) ell = EllipsoidTriaxial(ax, ay, b)
@@ -1075,32 +1309,32 @@ def render_all(ax, ay, b, coords_type, tab, t1, t2,
fig = ellipsoid_figure(ell, title="") fig = ellipsoid_figure(ell, title="")
fig = figure_constant_lines(fig, ell, coords_type) fig = figure_constant_lines(fig, ell, coords_type)
legend_added = set() if tab == "tab-GHA1":
stores = (s1a, s1n, s1s, s1p)
else:
stores = (s2n, s2s, s2p)
def add_legend_for_store(store): def add_method(store, fallback_name):
nonlocal fig nonlocal fig
if not store: if not store:
return return
name = store.get("name")
color = store.get("color")
if not name or not color:
return
key = (name, color) name = store.get("name") or fallback_name
if key in legend_added: color = store.get("color", "#ff8c00")
return group = name # legendgroup-ID
legend_added.add(key)
has_line = bool(store.get("polyline")) pts = store.get("points") or []
line = store.get("polyline")
if has_line: if line:
arr = np.asarray(line, dtype=float)
fig.add_trace(go.Scatter3d( fig.add_trace(go.Scatter3d(
x=[None], y=[None], z=[None], x=arr[:, 0], y=arr[:, 1], z=arr[:, 2],
mode="lines", mode="lines",
line=dict(width=6, color=color), line=dict(width=4, color=color),
name=name, name=name,
legendgroup=group,
showlegend=True, showlegend=True,
hoverinfo="skip",
)) ))
else: else:
fig.add_trace(go.Scatter3d( fig.add_trace(go.Scatter3d(
@@ -1108,36 +1342,25 @@ def render_all(ax, ay, b, coords_type, tab, t1, t2,
mode="markers", mode="markers",
marker=dict(size=8, color=color), marker=dict(size=8, color=color),
name=name, name=name,
legendgroup=group,
showlegend=True, showlegend=True,
hoverinfo="skip", hoverinfo="skip",
)) ))
def add_from_store(store): for pname, (px, py, pz), pcolor in pts:
nonlocal fig fig.add_trace(go.Scatter3d(
if not store: x=[px], y=[py], z=[pz],
return mode="markers+text",
marker=dict(size=6, color=pcolor),
text=[pname],
textposition="top center",
name=pname,
showlegend=False,
legendgroup=group,
))
pts = store.get("points") or [] for i, st in enumerate(stores, start=1):
if pts: add_method(st, f"Methode {i}")
fig = figure_points(fig, pts)
line = store.get("polyline")
if line:
fig = figure_lines(
fig,
line,
store.get("name", ""),
store.get("color", "#ff8c00"),
)
if tab == "tab-GHA1":
stores = (s1a, s1n, s1s, s1p)
else:
stores = (s2n, s2s, s2p)
for st in stores:
add_legend_for_store(st)
add_from_store(st)
fig.update_layout( fig.update_layout(
showlegend=True, showlegend=True,
@@ -1146,10 +1369,12 @@ def render_all(ax, ay, b, coords_type, tab, t1, t2,
yanchor="bottom", yanchor="bottom",
y=1.02, y=1.02,
xanchor="left", xanchor="left",
x=0.06, x=0.05,
groupclick="togglegroup",
itemclick="toggle",
itemdoubleclick="toggleothers",
), ),
) )
return fig return fig
@@ -1171,51 +1396,7 @@ def clear_all_stores_on_ellipsoid_change(ax, ay, b):
if None in (ax, ay, b): if None in (ax, ay, b):
return (no_update,)*7 return (no_update,)*7
return (None, None, None, None, None, None, None) return None, None, None, None, None, None, None
# Funktionen zur separaten Darstellung der Tabs
@app.callback(
Output("calc-token-gha1", "data"),
Output("gha1-header", "children", allow_duplicate=True),
Output("output-gha1-ana", "children", allow_duplicate=True),
Output("output-gha1-num", "children", allow_duplicate=True),
Output("output-gha1-stoch", "children", allow_duplicate=True),
Output("output-gha1-approx", "children", allow_duplicate=True),
Output("store-gha1-ana", "data", allow_duplicate=True),
Output("store-gha1-num", "data", allow_duplicate=True),
Output("store-gha1-stoch", "data", allow_duplicate=True),
Output("store-gha1-approx", "data", allow_duplicate=True),
Input("button-calc-gha1", "n_clicks"),
State("calc-token-gha1", "data"),
prevent_initial_call=True,
)
def start_calc_gha1(n, token):
if not n:
raise PreventUpdate
token = (token or 0) + 1
return token, "", "", "", "", "", None, None, None, None
@app.callback(
Output("calc-token-gha2", "data"),
Output("gha2-header", "children", allow_duplicate=True),
Output("output-gha2-num", "children", allow_duplicate=True),
Output("output-gha2-stoch", "children", allow_duplicate=True),
Output("output-gha2-approx", "children", allow_duplicate=True),
Output("store-gha2-num", "data", allow_duplicate=True),
Output("store-gha2-stoch", "data", allow_duplicate=True),
Output("store-gha2-approx", "data", allow_duplicate=True),
Input("button-calc-gha2", "n_clicks"),
State("calc-token-gha2", "data"),
prevent_initial_call=True,
)
def start_calc_gha2(n, token):
if not n:
raise PreventUpdate
token = (token or 0) + 1
return token, "", "", "", "", None, None, None
# Funktionen zur Erzeugung der Überschriften # Funktionen zur Erzeugung der Überschriften
@app.callback( @app.callback(
@@ -1296,6 +1477,6 @@ if __name__ == "__main__":
# Automatisiertes Öffnen der Seite im Browser # Automatisiertes Öffnen der Seite im Browser
HOST = "127.0.0.1" HOST = "127.0.0.1"
PORT = 8050 PORT = 8050
#Timer(1.0, webbrowser.open_new_tab(f"http://{HOST}:{PORT}/")).start # Timer(1.0, webbrowser.open_new_tab(f"http://{HOST}:{PORT}/")).start
app.run(host=HOST, port=PORT, debug=False) app.run(host=HOST, port=PORT, debug=False)

View File

@@ -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 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: import jacobian_Ligas
def __init__(self, a: float, b: float): from utils_angle import wrap_mhalfpi_halfpi, wrap_mpi_pi
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):
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: 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 = 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: class EllipsoidTriaxial:
"""
Klasse für dreiachsige Ellipsoide
Parameter: Formparameter
Funktionen: Koordinatenumrechnungen
"""
def __init__(self, ax: float, ay: float, b: float): def __init__(self, ax: float, ay: float, b: float):
self.ax = ax self.ax = ax
self.ay = ay self.ay = ay
@@ -124,14 +28,19 @@ class EllipsoidTriaxial:
self.Ex = sqrt(self.ax**2 - self.b**2) self.Ex = sqrt(self.ax**2 - self.b**2)
self.Ey = sqrt(self.ay**2 - self.b**2) self.Ey = sqrt(self.ay**2 - self.b**2)
self.Ee = sqrt(self.ax**2 - self.ay**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 @classmethod
def init_name(cls, name: str): def init_name(cls, name: str) -> EllipsoidTriaxial:
""" """
Mögliche Ellipsoide: BursaFialova1993, BursaSima1980, BursaSima1980round, Eitschberger1978, Bursa1972, Mögliche Ellipsoide: BursaSima1980round, KarneyTest2024, Fiction, BursaFialova1993, BursaSima1980, Eitschberger1978, Bursa1972,
Bursa1970, BesselBiaxial, Fiction, KarneyTest2024 Bursa1970
Panou et al (2020) Panou et al (2020)
:param name: Name des dreiachsigen Ellipsoids :param name: Name des dreiachsigen Ellipsoids
:return: dreiachsiger Ellipsoid
""" """
if name == "BursaFialova1993": if name == "BursaFialova1993":
ax = 6378171.36 ax = 6378171.36
@@ -164,11 +73,6 @@ class EllipsoidTriaxial:
ay = 6378105 ay = 6378105
b = 6356754 b = 6356754
return cls(ax, ay, b) 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": elif name == "Fiction":
ax = 6000000 ax = 6000000
ay = 4000000 ay = 4000000
@@ -179,6 +83,8 @@ class EllipsoidTriaxial:
ay = 1 ay = 1
b = 1 / sqrt(2) b = 1 / sqrt(2)
return cls(ax, ay, b) return cls(ax, ay, b)
else:
raise Exception(f"EllipsoidTriaxial.init_name: Name {name} unbekannt")
def func_H(self, point: NDArray) -> float: 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 - 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.ay ** 2 + self.b ** 2) * x ** 2 - (self.ax ** 2 + self.b ** 2) * y ** 2 - (
self.ax ** 2 + self.ay ** 2) * z ** 2) self.ax ** 2 + self.ay ** 2) * z ** 2)
if c1 ** 2 - 4 * c0 < 0: if c1 ** 2 - 4 * c0 < -1e-9:
t2 = np.nan raise Exception("t1, t2: Negativer Wurzelterm")
elif c1 ** 2 - 4 * c0 < 0:
t2 = 0
else: else:
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2 t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
if t2 == 0: if t2 == 0:
@@ -261,7 +169,6 @@ class EllipsoidTriaxial:
s1 = 2 * sqrt(p) * cos(omega/3) - c2/3 s1 = 2 * sqrt(p) * cos(omega/3) - c2/3
s2 = 2 * sqrt(p) * cos(omega/3 - 2*pi/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 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))) beta = arctan(sqrt((-self.b**2 - s2) / (self.ay**2 + s2)))
if abs((-self.ay**2 - s3) / (self.ax**2 + s3)) > 1e-7: 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, 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 B = self.Ex ** 2 * cos(beta) ** 2 + self.Ee ** 2 * sin(beta) ** 2
L = self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2 L = self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2
@@ -419,7 +331,7 @@ class EllipsoidTriaxial:
if delta_r > 1e-6: if delta_r > 1e-6:
raise Exception("Umrechnung cart2ell: Punktdifferenz") raise Exception("Umrechnung cart2ell: Punktdifferenz")
return beta, lamb return wrap_mhalfpi_halfpi(beta), wrap_mpi_pi(lamb)
except Exception as e: except Exception as e:
# Wenn die Berechnung fehlschlägt auf Grund von sehr kleinem y, solange anpassen, bis Umrechnung ohne Fehler # Wenn die Berechnung fehlschlägt auf Grund von sehr kleinem y, solange anpassen, bis Umrechnung ohne Fehler
@@ -577,6 +489,8 @@ class EllipsoidTriaxial:
invJ, fxE = jacobian_Ligas.case2(E, F, G, np.array([xG, yG, zG]), pE) invJ, fxE = jacobian_Ligas.case2(E, F, G, np.array([xG, yG, zG]), pE)
elif mode == "ligas3": elif mode == "ligas3":
invJ, fxE = jacobian_Ligas.case3(E, F, G, np.array([xG, yG, zG]), pE) 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 = pE.reshape(-1, 1) - invJ @ fxE.reshape(-1, 1)
pEi = pEi.reshape(1, -1).flatten() pEi = pEi.reshape(1, -1).flatten()
loa = sqrt((pEi[0]-pE[0])**2 + (pEi[1]-pE[1])**2 + (pEi[2]-pE[2])**2) 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) phi, lamb, h = self.cart2geod(point, f"ligas{new_mode}", maxIter, maxLoa)
else: else:
if xG < 0 and yG < 0: if xG < 0 and yG < 0:
lamb = -pi + lamb lamb += -pi
elif xG < 0: elif xG < 0:
lamb = pi + lamb lamb += pi
if abs(zG) < eps: if abs(zG) < eps:
phi = 0 phi = 0
wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb)
return phi, lamb, h return wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb), h
def para2cart(self, u: float | NDArray, v: float | NDArray) -> NDArray: 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) v = 2 * arctan2(v_check1, v_check2 + v_factor)
else: else:
v = pi/2 - 2 * arctan2(v_check2, v_check1 + v_factor) v = pi/2 - 2 * arctan2(v_check2, v_check1 + v_factor)
wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
return u, v return wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
def ell2para(self, beta: float, lamb: float) -> Tuple[float, float]: def ell2para(self, beta: float, lamb: float) -> Tuple[float, float]:
""" """
@@ -749,63 +663,71 @@ class EllipsoidTriaxial:
if __name__ == "__main__": if __name__ == "__main__":
ell = EllipsoidTriaxial.init_name("BursaSima1980") ell = EllipsoidTriaxial.init_name("KarneyTest2024")
diff_list = [] # cart = ell.ell2cart(pi/2, 0)
diffs_para = [] # print(cart)
diffs_ell = [] # cart = ell.ell2cart(pi/2*8999999999999999/9000000000000000, 0)
diffs_geod = [] # print(cart)
points = [] elli = ell.cart2ell(np.array([0, 0.0, 1/sqrt(2)]))
for v_deg in range(-180, 181, 5): print(elli)
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) # ell = EllipsoidTriaxial.init_name("BursaSima1980")
cart_elli = ell.ell2cart(elli[0], elli[1]) # diff_list = []
diff_ell = np.linalg.norm(point - cart_elli, axis=-1) # diffs_para = []
# diffs_ell = []
para = ell.cart2para(point) # diffs_geod = []
cart_para = ell.para2cart(para[0], para[1]) # points = []
diff_para = np.linalg.norm(point - cart_para, axis=-1) # for v_deg in range(-180, 181, 5):
# for u_deg in range(-90, 91, 5):
geod = ell.cart2geod(point, "ligas3") # v = wu.deg2rad(v_deg)
cart_geod = ell.geod2cart(geod[0], geod[1], geod[2]) # u = wu.deg2rad(u_deg)
diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1) # point = ell.para2cart(u, v)
# points.append(point)
diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3]) #
diffs_ell.append([diff_ell]) # elli = ell.cart2ell(point)
diffs_para.append([diff_para]) # cart_elli = ell.ell2cart(elli[0], elli[1])
diffs_geod.append([diff_geod3]) # diff_ell = np.linalg.norm(point - cart_elli, axis=-1)
#
diff_list = np.array(diff_list) # para = ell.cart2para(point)
diffs_ell = np.array(diffs_ell) # cart_para = ell.para2cart(para[0], para[1])
diffs_para = np.array(diffs_para) # diff_para = np.linalg.norm(point - cart_para, axis=-1)
diffs_geod = np.array(diffs_geod) #
# geod = ell.cart2geod(point, "ligas3")
pass # cart_geod = ell.geod2cart(geod[0], geod[1], geod[2])
# diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1)
points = np.array(points) #
fig = plt.figure() # diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3])
ax = fig.add_subplot(projection='3d') # diffs_ell.append([diff_ell])
# diffs_para.append([diff_para])
sc = ax.scatter( # diffs_geod.append([diff_geod3])
points[:, 0], #
points[:, 1], # diff_list = np.array(diff_list)
points[:, 2], # diffs_ell = np.array(diffs_ell)
c=diffs_ell, # Farbcode = diff # diffs_para = np.array(diffs_para)
cmap='viridis', # Colormap # diffs_geod = np.array(diffs_geod)
s=10 + 20 * diffs_ell, # optional: Größe abhängig vom diff #
alpha=0.8 # pass
) #
# points = np.array(points)
# Farbskala # fig = plt.figure()
cbar = plt.colorbar(sc) # ax = fig.add_subplot(projection='3d')
cbar.set_label("diff") #
# sc = ax.scatter(
ax.set_xlabel("X") # points[:, 0],
ax.set_ylabel("Y") # points[:, 1],
ax.set_zlabel("Z") # points[:, 2],
# c=diffs_ell, # Farbcode = diff
plt.show() # 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()

View File

@@ -1,6 +1,8 @@
from typing import Tuple
import numpy as np import numpy as np
from numpy.typing import NDArray from numpy.typing import NDArray
from typing import Tuple
def case1(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]: 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 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 Aufstellen des Gleichungssystem für den zweiten Fall
:param E: Konstante E :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 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 Aufstellen des Gleichungssystem für den dritten Fall
:param E: Konstante E :param E: Konstante E

View File

@@ -1,10 +1,20 @@
from numpy import *
import scipy as sp
from ellipsoide import EllipsoidBiaxial
from typing import Tuple 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]: 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) psi0 = re.phi2psi(phi0)
clairant = arcsin(cos(psi0) * sin(alpha0)) clairant = arcsin(cos(psi0) * sin(alpha0))
sigma0 = arcsin(sin(psi0) / cos(clairant)) sigma0 = arcsin(sin(psi0) / cos(clairant))

View File

@@ -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 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]: def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, eps: float = 1e-12) -> Tuple[float, float, float]:
""" """

View File

@@ -1,13 +1,26 @@
import runge_kutta as rk from typing import Tuple
from numpy import sin, cos, tan
import winkelumrechnungen as wu
from ellipsoide import EllipsoidBiaxial
import numpy as np import numpy as np
from ellipsoid_biaxial import EllipsoidBiaxial
from numpy import cos, sin, tan
from numpy.typing import NDArray 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]: 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 buildODE():
def ODE(s, v): def ODE(s: float, v: NDArray):
phi, lam, A = v phi, lam, A = v
V = re.V(phi) V = re.V(phi)
dphi = cos(A) * V ** 3 / re.c dphi = cos(A) * V ** 3 / re.c

View File

View File

@@ -17,10 +17,11 @@
"source": [ "source": [
"%reload_ext autoreload\n", "%reload_ext autoreload\n",
"%autoreload 2\n", "%autoreload 2\n",
"import numpy as np\n",
"\n",
"import winkelumrechnungen as wu\n", "import winkelumrechnungen as wu\n",
"from ellipsoide import EllipsoidTriaxial\n", "from GHA_triaxial.utils import alpha_ell2para, alpha_para2ell\n",
"from GHA_triaxial.utils import alpha_para2ell, alpha_ell2para\n", "from ellipsoid_triaxial import EllipsoidTriaxial"
"import numpy as np"
], ],
"id": "46aa84a937fea491", "id": "46aa84a937fea491",
"outputs": [], "outputs": [],

View File

@@ -20,13 +20,14 @@
"source": [ "source": [
"%reload_ext autoreload\n", "%reload_ext autoreload\n",
"%autoreload 2\n", "%autoreload 2\n",
"import pickle\n",
"import numpy as np\n",
"import winkelumrechnungen as wu\n",
"from itertools import product\n", "from itertools import product\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n", "import pandas as pd\n",
"from ellipsoide import EllipsoidTriaxial\n", "import plotly.graph_objects as go\n",
"import plotly.graph_objects as go" "\n",
"import winkelumrechnungen as wu\n",
"from ellipsoid_triaxial import EllipsoidTriaxial"
], ],
"outputs": [], "outputs": [],
"execution_count": null "execution_count": null

Binary file not shown.

Binary file not shown.

View File

View 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])

View File

@@ -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 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 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), alpha1 = arctan2(-cos(phi0) * sin(lamb1 - lamb0),
cos(phi1) * sin(phi0) - sin(phi1) * cos(phi0) * cos(lamb1 - lamb0)) cos(phi1) * sin(phi0) - sin(phi1) * cos(phi0) * cos(lamb1 - lamb0))
if alpha1 < 0: if alpha1 < 0:
alpha1 += 2 * np.pi alpha1 += 2 * pi
return alpha0, alpha1, s return alpha0, alpha1, s

View File

@@ -9,10 +9,11 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"import plotly.graph_objects as go\n",
"import numpy as np\n", "import numpy as np\n",
"from ellipsoide import EllipsoidTriaxial\n", "import plotly.graph_objects as go\n",
"import winkelumrechnungen as wu" "\n",
"import winkelumrechnungen as wu\n",
"from ellipsoid_triaxial import EllipsoidTriaxial"
], ],
"id": "731173e4745cfe7c", "id": "731173e4745cfe7c",
"outputs": [], "outputs": [],

8
nicht abgeben/test.py Normal file
View 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
View 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

View File

@@ -1,7 +1,10 @@
from typing import Callable
import numpy as np 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 Standard Runge-Kutta Verfahren 4. Ordnung
:param ode: ODE-System als Funktion :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 v0: Startwerte
:param weite: Integrationsweite :param weite: Integrationsweite
:param schritte: Schrittzahl :param schritte: Schrittzahl
:param fein: :param fein: Fein-Rechnung?
:return: Variable und Funktionswerte an jedem Stützpunkt :return: Variable und Funktionswerte an jedem Stützpunkt
""" """
h = weite/schritte h = weite/schritte
@@ -35,14 +38,32 @@ def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool
return t_list, werte 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) k1 = ode(t, v)
k2 = ode(t + 0.5 * h, v + 0.5 * h * k1) k2 = ode(t + 0.5 * h, v + 0.5 * h * k1)
k3 = ode(t + 0.5 * h, v + 0.5 * h * k2) k3 = ode(t + 0.5 * h, v + 0.5 * h * k2)
k4 = ode(t + h, v + h * k3) 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, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool = False): 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 h = weite / schritte
t = float(t0) t = float(t0)
v = np.array(v0, dtype=float, copy=True) v = np.array(v0, dtype=float, copy=True)
@@ -62,8 +83,19 @@ def rk4_end(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: b
return t, v return t, v
# RK4 mit Simpson bzw. Trapez # RK4 mit Simpson bzw. Trapez
def rk4_integral( ode, t0: float, v0: np.ndarray, weite: float, schritte: int, integrand_at, fein: bool = False, simpson: bool = True, ): 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 h = weite / schritte
habs = abs(h) habs = abs(h)

View File

@@ -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)

View File

@@ -1,13 +1,54 @@
import numpy as np import numpy as np
import winkelumrechnungen as wu
def arccot(x):
def arccot(x: float) -> float:
"""
Berechnung von arccot eines Winkels
:param x: Winkel
:return: arccot(Winkel)
"""
return np.arctan2(1.0, x) return np.arctan2(1.0, x)
def cot(a): def cot(x: float) -> float:
return np.cos(a) / np.sin(a) """
Berechnung von cot eines Winkels
:param x: Winkel
:return: cot(Winkel)
"""
return np.cos(x) / np.sin(x)
def wrap_to_pi(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 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))))