Compare commits
34 Commits
bd411a8cd7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d90ff5df69 | |||
| 59ad560f36 | |||
| 5a293a823a | |||
| 36b62059fc | |||
| 57a086f6cb | |||
| b8d07307aa | |||
| 798cace25d | |||
| 4f7b9aaef0 | |||
| 1fbfb555a4 | |||
|
|
db05f7b6db | ||
|
|
73e3694a2a | ||
| ffc8d3fbce | |||
|
|
fd02694ae4 | ||
| e1ac0415e7 | |||
| e7641ba64f | |||
|
|
fc9bc5defb | ||
|
|
2864ce50ff | ||
|
|
b44c25928e | ||
|
|
67248f9ca9 | ||
|
|
71c13c568a | ||
| 19887e4ac5 | |||
| 737e4730aa | |||
|
|
020d282420 | ||
|
|
cefa98e3b7 | ||
| e8624159e2 | |||
|
|
cfab70ac55 | ||
| ee85e8b0e6 | |||
| 02ce0c0b4a | |||
| 3fd967e843 | |||
| 322ac94299 | |||
| 49d03786dc | |||
| ef99294502 | |||
| b3a73270c2 | |||
| 7a425eae77 |
@@ -1,7 +1,8 @@
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
def felli(x):
|
||||
def felli(x: NDArray) -> float:
|
||||
N = x.shape[0]
|
||||
if N < 2:
|
||||
raise ValueError("dimension must be greater than one")
|
||||
@@ -12,7 +13,6 @@ def felli(x):
|
||||
def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000,
|
||||
func_args=(), func_kwargs=None, seed=0,
|
||||
bestEver=np.inf, noImproveGen=0, absTolImprove=1e-12, maxNoImproveGen=100, sigmaImprove=1e-12):
|
||||
|
||||
if func_kwargs is None:
|
||||
func_kwargs = {}
|
||||
|
||||
@@ -91,8 +91,7 @@ def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-14, stopeval=2000
|
||||
bestEver = fbest
|
||||
noImproveGen = 0
|
||||
else:
|
||||
noImproveGen = noImproveGen + 1
|
||||
|
||||
noImproveGen += 1
|
||||
|
||||
if gen == 1 or gen % 50 == 0:
|
||||
# print(f' [CMA-ES] Gen {gen}, best = {round(fbest, 6)}, sigma = {sigma:.3g}')
|
||||
@@ -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}')
|
||||
break
|
||||
|
||||
|
||||
|
||||
# Cumulation: Update evolution paths
|
||||
ps = (1 - cs) * ps + np.sqrt(cs * (2 - cs) * mueff) * (B @ zmean)
|
||||
norm_ps = np.linalg.norm(ps)
|
||||
hsig = norm_ps / np.sqrt(1 - (1 - cs)**(2 * counteval / lambda_)) / chiN < \
|
||||
(1.4 + 2 / (N + 1))
|
||||
hsig = norm_ps / np.sqrt(1 - (1 - cs) ** (2 * counteval / lambda_)) / chiN < (1.4 + 2 / (N + 1))
|
||||
hsig = 1.0 if hsig else 0.0
|
||||
|
||||
pc = (1 - cc) * pc + hsig * np.sqrt(cc * (2 - cc) * mueff) * (B @ D @ zmean)
|
||||
@@ -1,29 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from codeop import PyCF_ALLOW_INCOMPLETE_INPUT
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import List, Tuple
|
||||
|
||||
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_approx import gha1_approx
|
||||
from Hansen_ES_CMA import escma
|
||||
from utils_angle import wrap_to_pi
|
||||
from numpy.typing import NDArray
|
||||
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_
|
||||
from GHA_triaxial.utils import jacobi_konstante
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_mpi_pi
|
||||
|
||||
|
||||
def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
|
||||
@@ -40,7 +28,7 @@ def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
|
||||
R (XYZ) = Punkt in XYZ
|
||||
"""
|
||||
# Berechnungshilfen
|
||||
omega = wrap_to_pi(omega)
|
||||
omega = wrap_mpi_pi(omega)
|
||||
cb = np.cos(beta)
|
||||
sb = np.sin(beta)
|
||||
co = np.cos(omega)
|
||||
@@ -74,34 +62,19 @@ def ENU_beta_omega(beta: float, omega: float, ell: EllipsoidTriaxial) \
|
||||
# U = Grad(x^2/a^2 + y^2/b^2 + z^2/c^2 - 1)
|
||||
U = np.array([X/(ell.ax*ell.ax), Y/(ell.ay*ell.ay), Z/(ell.b*ell.b)], dtype=float)
|
||||
|
||||
En = np.linalg.norm(E)
|
||||
Nn = np.linalg.norm(N)
|
||||
Un = np.linalg.norm(U)
|
||||
En = float(np.linalg.norm(E))
|
||||
Nn = float(np.linalg.norm(N))
|
||||
Un = float(np.linalg.norm(U))
|
||||
|
||||
N_hat = N / Nn
|
||||
E_hat = E / En
|
||||
U_hat = U / Un
|
||||
E_hat = 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)
|
||||
|
||||
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:
|
||||
"""
|
||||
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
|
||||
vTn = max(np.linalg.norm(vT), 1e-18)
|
||||
vT_hat = vT / vTn
|
||||
#vT_hat = vT / np.linalg.norm(vT)
|
||||
sE = float(np.dot(vT_hat, E_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,
|
||||
@@ -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_omega = float(np.clip(d_omega, -0.2, 0.2)) # rad
|
||||
|
||||
|
||||
# d_beta = ds * float(np.cos(alpha_i)) / Nn_i
|
||||
# d_omega = ds * float(np.sin(alpha_i)) / En_i
|
||||
beta_pred = beta_i + d_beta
|
||||
omega_pred = wrap_to_pi(omega_i + d_omega)
|
||||
omega_pred = wrap_mpi_pi(omega_i + d_omega)
|
||||
|
||||
xmean = np.array([beta_pred, omega_pred], dtype=float)
|
||||
|
||||
@@ -175,7 +146,7 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
|
||||
:return: Fitnesswert (f)
|
||||
"""
|
||||
beta = x[0]
|
||||
omega = wrap_to_pi(x[1])
|
||||
omega = wrap_mpi_pi(x[1])
|
||||
|
||||
P = ell.ell2cart_karney(beta, omega) # in kartesischer Koordinaten
|
||||
d = float(np.linalg.norm(P - P_i)) # Distanz zwischen
|
||||
@@ -197,11 +168,10 @@ def optimize_next_point(beta_i: float, omega_i: float, alpha_i: float, ds: float
|
||||
|
||||
return f
|
||||
|
||||
|
||||
xb = escma(fitness, N=2, xmean=xmean, sigma=sigma0) # Aufruf CMA-ES
|
||||
|
||||
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)
|
||||
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)
|
||||
@@ -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
|
||||
|
||||
|
||||
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]:
|
||||
"""
|
||||
Aufruf der 1. GHA mittels CMA-ES
|
||||
@@ -223,8 +193,8 @@ def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float,
|
||||
:return: Zielpunkt Pk, Azimut am Zielpunkt und Punktliste
|
||||
"""
|
||||
beta = float(beta0)
|
||||
omega = wrap_to_pi(float(omega0))
|
||||
alpha = wrap_to_pi(float(alpha0))
|
||||
omega = wrap_mpi_pi(float(omega0))
|
||||
alpha = wrap_mpi_pi(float(alpha0))
|
||||
|
||||
gamma0 = jacobi_konstante(beta, omega, alpha, ell) # Referenz-γ0
|
||||
|
||||
@@ -243,9 +213,9 @@ def gha1_ES(ell: EllipsoidTriaxial, beta0: float, omega0: float, alpha0: float,
|
||||
ell=ell, maxSegLen=maxSegLen)
|
||||
s_acc += ds
|
||||
P_all.append(P)
|
||||
alpha_end.append(alpha)
|
||||
alpha_end.append(wrap_mpi_pi(alpha))
|
||||
if step > nsteps_est + 50:
|
||||
raise RuntimeError("Zu viele Schritte – vermutlich Konvergenzproblem / falsche Azimut-Konvention.")
|
||||
raise RuntimeError("GHA1_ES: Zu viele Schritte – vermutlich Konvergenzproblem / falsche Azimut-Konvention.")
|
||||
Pk = P_all[-1]
|
||||
alpha1 = float(alpha_end[-1])
|
||||
|
||||
@@ -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
|
||||
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ES.Hansen_ES_CMA import escma
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
from GHA_triaxial.utils import sigma2alpha, pq_ell
|
||||
|
||||
|
||||
|
||||
from GHA_triaxial.utils import sigma2alpha
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
|
||||
def Sehne(P1: NDArray, P2: NDArray) -> float:
|
||||
@@ -19,14 +18,11 @@ def Sehne(P1: NDArray, P2: NDArray) -> float:
|
||||
:return: Bogenlänge s
|
||||
"""
|
||||
R12 = P2-P1
|
||||
s = np.linalg.norm(R12)
|
||||
s = float(np.linalg.norm(R12))
|
||||
|
||||
return s
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def 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.
|
||||
@@ -109,7 +105,7 @@ def gha2_ES(ell: EllipsoidTriaxial, P0: NDArray, Pk: NDArray, maxSegLen: float =
|
||||
startIter += 1
|
||||
maxIter = 10000
|
||||
if startIter > maxIter:
|
||||
raise RuntimeError("Abbruch: maximale Iterationen überschritten.")
|
||||
raise RuntimeError("GHA2_ES: maximale Iterationen überschritten")
|
||||
new_points.append(B)
|
||||
|
||||
points = new_points
|
||||
@@ -3,12 +3,13 @@ from math import comb
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan2
|
||||
from numpy._typing import NDArray
|
||||
import winkelumrechnungen as wu
|
||||
from numpy import arctan2, cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.utils import pq_para
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int) -> Tuple[NDArray, float]:
|
||||
@@ -110,7 +111,7 @@ def gha1_ana_step(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: floa
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
|
||||
return p1, alpha1
|
||||
return p1, wrap_0_2pi(alpha1)
|
||||
|
||||
|
||||
def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, maxM: int, maxPartCircum: int = 4) -> Tuple[NDArray, float]:
|
||||
@@ -132,9 +133,9 @@ def gha1_ana(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, ma
|
||||
|
||||
_, _, h = ell.cart2geod(point_end, "ligas3")
|
||||
if h > 1e-5:
|
||||
raise Exception("Analytische Methode ist explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
raise Exception("GHA1_ana: explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
|
||||
return point_end, alpha_end
|
||||
return point_end, wrap_0_2pi(alpha_end)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -142,4 +143,3 @@ if __name__ == "__main__":
|
||||
p0 = ell.ell2cart(wu.deg2rad(10), wu.deg2rad(20))
|
||||
p1, alpha1 = gha1_ana(ell, p0, wu.deg2rad(36), 200000, 70)
|
||||
print(p1, wu.rad2gms(alpha1))
|
||||
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from GHA_triaxial.utils import func_sigma_ell, louville_constant
|
||||
import plotly.graph_objects as go
|
||||
import winkelumrechnungen as wu
|
||||
from typing import Tuple
|
||||
|
||||
def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float, ds: float, all_points: bool = False) -> Tuple[NDArray, float] | Tuple[NDArray, float, NDArray]:
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
from numpy import cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.utils import louville_constant, pq_ell
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float, ds: float, all_points: bool = False) \
|
||||
-> Tuple[NDArray, float] | Tuple[NDArray, float, NDArray, NDArray]:
|
||||
"""
|
||||
Berechung einer Näherungslösung der ersten Hauptaufgabe
|
||||
:param ell: Ellipsoid
|
||||
@@ -20,6 +27,8 @@ def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float,
|
||||
points = [p0]
|
||||
alphas = [alpha0]
|
||||
s_curr = 0.0
|
||||
last_sigma = None
|
||||
last_p = None
|
||||
|
||||
while s_curr < s:
|
||||
ds_step = min(ds, s - s_curr)
|
||||
@@ -29,21 +38,32 @@ def gha1_approx(ell: EllipsoidTriaxial, p0: np.ndarray, alpha0: float, s: float,
|
||||
p1 = points[-1]
|
||||
alpha1 = alphas[-1]
|
||||
|
||||
sigma = func_sigma_ell(ell, p1, alpha1)
|
||||
p, q = pq_ell(ell, p1)
|
||||
if last_p is not None and np.dot(p, last_p) < 0:
|
||||
p = -p
|
||||
q = -q
|
||||
last_p = p
|
||||
sigma = p * sin(alpha1) + q * cos(alpha1)
|
||||
if last_sigma is not None and np.dot(sigma, last_sigma) < 0:
|
||||
sigma = -sigma
|
||||
alpha1 += np.pi
|
||||
alpha1 = wrap_0_2pi(alpha1)
|
||||
p2 = p1 + ds_step * sigma
|
||||
p2 = ell.point_onto_ellipsoid(p2)
|
||||
|
||||
dalpha = 1e-6
|
||||
dalpha = 1e-9
|
||||
l2 = louville_constant(ell, p2, alpha1)
|
||||
dl_dalpha = (louville_constant(ell, p2, alpha1+dalpha) - l2) / dalpha
|
||||
if abs(dl_dalpha) < 1e-20:
|
||||
alpha2 = alpha1 + 0
|
||||
else:
|
||||
alpha2 = alpha1 + (l0 - l2) / dl_dalpha
|
||||
|
||||
points.append(p2)
|
||||
alphas.append(alpha2)
|
||||
alphas.append(wrap_0_2pi(alpha2))
|
||||
|
||||
ds_step = np.linalg.norm(p2 - p1)
|
||||
s_curr += ds_step
|
||||
if s_curr > 10000000:
|
||||
last_sigma = sigma
|
||||
pass
|
||||
|
||||
if all_points:
|
||||
@@ -78,11 +98,11 @@ def show_points(points: NDArray, p0: NDArray, p1: NDArray):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
P0 = ell.para2cart(0.2, 0.3)
|
||||
alpha0 = wu.deg2rad(35)
|
||||
s = 13000000
|
||||
P1_app, alpha1_app, points, alphas = gha1_approx(ell, P0, alpha0, s, ds=10000, all_points=True)
|
||||
P1_ana, alpha1_ana = gha1_ana(ell, P0, alpha0, s, maxM=60, maxPartCircum=16)
|
||||
show_points(points, P0, P1_ana)
|
||||
print(np.linalg.norm(P1_app - P1_ana))
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
P0 = ell.ell2cart(wu.deg2rad(15), wu.deg2rad(15))
|
||||
alpha0 = wu.deg2rad(270)
|
||||
s = 1
|
||||
P1_app, alpha1_app, points, alphas = gha1_approx(ell, P0, alpha0, s, ds=0.1, all_points=True)
|
||||
# P1_ana, alpha1_ana = gha1_ana(ell, P0, alpha0, s, maxM=40, maxPartCircum=32)
|
||||
# print(np.linalg.norm(P1_app - P1_ana))
|
||||
# show_points(points, P0, P0)
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from typing import Callable, List, Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan2
|
||||
import ellipsoide
|
||||
import runge_kutta as rk
|
||||
import winkelumrechnungen as wu
|
||||
import GHA_triaxial.numeric_examples_karney as ne_karney
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from typing import Callable, Tuple, List
|
||||
from numpy import arctan2, cos, sin
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import GHA_triaxial.numeric_examples_karney as ne_karney
|
||||
import runge_kutta as rk
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.gha1_ana import gha1_ana
|
||||
from GHA_triaxial.utils import alpha_ell2para, pq_ell
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def buildODE(ell: EllipsoidTriaxial) -> Callable:
|
||||
@@ -75,8 +76,11 @@ def gha1_num(ell: EllipsoidTriaxial, point: NDArray, alpha0: float, s: float, nu
|
||||
|
||||
alpha1 = arctan2(P, Q)
|
||||
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
alpha1 = wrap_0_2pi(alpha1)
|
||||
|
||||
_, _, h = ell.cart2geod(point1, "ligas3")
|
||||
if h > 1e-5:
|
||||
raise Exception("GHA1_num: explodiert, Punkt liegt nicht mehr auf dem Ellipsoid")
|
||||
|
||||
if all_points:
|
||||
return point1, alpha1, werte
|
||||
@@ -104,7 +108,7 @@ if __name__ == "__main__":
|
||||
# diffs_panou[mask_360] = np.abs(diffs_panou[mask_360] - 360)
|
||||
# print(diffs_panou)
|
||||
|
||||
ell: EllipsoidTriaxial = ellipsoide.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
ell: EllipsoidTriaxial = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
diffs_karney = []
|
||||
# examples_karney = ne_karney.get_examples((30499, 30500, 40500))
|
||||
examples_karney = ne_karney.get_random_examples(20)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
import plotly.graph_objects as go
|
||||
import winkelumrechnungen as wu
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from GHA_triaxial.gha2_num import gha2_num
|
||||
from GHA_triaxial.utils import sigma2alpha
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
|
||||
def gha2_approx(ell: EllipsoidTriaxial, p0: NDArray, p1: NDArray, ds: float, all_points: bool = False) -> Tuple[float, float, float] | Tuple[float, float, float, NDArray]:
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from runge_kutta import rk4, rk4_step, rk4_end, rk4_integral
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import GHA_triaxial.numeric_examples_karney as ne_karney
|
||||
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
|
||||
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):
|
||||
if a < 0.0:
|
||||
a += np.pi
|
||||
def norm_a(a: float) -> float:
|
||||
a = float(a) % (2 * np.pi)
|
||||
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):
|
||||
dlam = wrap_to_pi(lam2 - lam1)
|
||||
dlam = wrap_mpi_pi(lam2 - lam1)
|
||||
y = np.sin(dlam) * np.cos(beta2)
|
||||
x = np.cos(beta1) * np.sin(beta2) - np.sin(beta1) * np.cos(beta2) * np.cos(dlam)
|
||||
a = np.arctan2(y, x)
|
||||
@@ -24,6 +32,7 @@ def sph_azimuth(beta1, lam1, beta2, lam2):
|
||||
a += 2 * np.pi
|
||||
return a
|
||||
|
||||
|
||||
# Panou 2013
|
||||
def gha2_num(
|
||||
ell: EllipsoidTriaxial,
|
||||
@@ -49,65 +58,67 @@ def gha2_num(
|
||||
: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
|
||||
def BETA_LAMBDA(beta, lamb):
|
||||
BETA = (ell.ay ** 2 * np.sin(beta) ** 2 + ell.b ** 2 * np.cos(beta) ** 2) / (
|
||||
ell.Ex ** 2 - ell.Ey ** 2 * np.sin(beta) ** 2
|
||||
sb = np.sin(beta)
|
||||
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) / (
|
||||
ell.Ex ** 2 - ell.Ee ** 2 * np.cos(lamb) ** 2
|
||||
LAMBDA__ = (2.0 * b2 * Ee4 * (s2l * s2l)) / (denL * denL * denL) - (2.0 * b2 * Ee2 * s2l) / (
|
||||
denL * denL
|
||||
)
|
||||
|
||||
BETA_ = (ell.ax ** 2 * ell.Ey ** 2 * np.sin(2 * beta)) / (
|
||||
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
|
||||
Q = Ey2 * cb2 + Ee2 * sl2
|
||||
|
||||
BETA__ = (
|
||||
(2 * ell.ax ** 2 * ell.Ey ** 4 * np.sin(2 * beta) ** 2)
|
||||
/ (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 * Q
|
||||
G = LAMBDA * Q
|
||||
|
||||
E = BETA * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
|
||||
G = LAMBDA * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
|
||||
E_beta = BETA_ * Q - BETA * Ey2 * s2b
|
||||
E_lamb = BETA * Ee2 * s2l
|
||||
|
||||
E_beta = (
|
||||
BETA_ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
|
||||
- BETA * ell.Ey ** 2 * np.sin(2 * beta)
|
||||
)
|
||||
E_lamb = BETA * ell.Ee ** 2 * np.sin(2 * lamb)
|
||||
G_beta = -LAMBDA * Ey2 * s2b
|
||||
G_lamb = LAMBDA_ * Q + LAMBDA * Ee2 * s2l
|
||||
|
||||
G_beta = -LAMBDA * ell.Ey ** 2 * np.sin(2 * beta)
|
||||
G_lamb = (
|
||||
LAMBDA_ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
|
||||
+ LAMBDA * ell.Ee ** 2 * np.sin(2 * lamb)
|
||||
)
|
||||
E_beta_beta = BETA__ * Q - 2.0 * BETA_ * Ey2 * s2b - 2.0 * BETA * Ey2 * c2b
|
||||
E_beta_lamb = BETA_ * Ee2 * s2l
|
||||
E_lamb_lamb = 2.0 * BETA * Ee2 * c2l
|
||||
|
||||
E_beta_beta = (
|
||||
BETA__ * (ell.Ey ** 2 * np.cos(beta) ** 2 + ell.Ee ** 2 * np.sin(lamb) ** 2)
|
||||
- 2 * BETA_ * ell.Ey ** 2 * np.sin(2 * beta)
|
||||
- 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)
|
||||
)
|
||||
G_beta_beta = -2.0 * LAMBDA * Ey2 * c2b
|
||||
G_beta_lamb = -LAMBDA_ * Ey2 * s2b
|
||||
G_lamb_lamb = LAMBDA__ * Q + 2.0 * LAMBDA_ * Ee2 * s2l + 2.0 * LAMBDA * Ee2 * c2l
|
||||
|
||||
return (
|
||||
BETA,
|
||||
@@ -167,7 +178,7 @@ def gha2_num(
|
||||
)
|
||||
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)
|
||||
def q_coef(beta, lamb):
|
||||
@@ -220,15 +231,12 @@ def gha2_num(
|
||||
(_, _, E, G, *_) = BETA_LAMBDA(beta, lamb)
|
||||
return np.sqrt(E + G * lamb_p**2)
|
||||
|
||||
# Fall 1 (lambda_0 != lambda_1)
|
||||
if abs(lamb_1 - lamb_0) >= 1e-15:
|
||||
N = int(n)
|
||||
dlamb = float(lamb_1 - lamb_0)
|
||||
def solve_lambda_branch(beta0, lamb0, beta1, lamb1_target, N_run, N_newt, it_max):
|
||||
dlamb = float(lamb1_target - lamb0)
|
||||
if abs(dlamb) < 1e-15:
|
||||
return None
|
||||
|
||||
beta0 = float(beta_0)
|
||||
lamb0 = float(lamb_0)
|
||||
beta1 = float(beta_1)
|
||||
lamb1 = float(lamb_1)
|
||||
sgn = 1.0 if dlamb >= 0.0 else -1.0
|
||||
|
||||
def ode_lamb(lamb, v):
|
||||
beta, beta_p, X3, X4 = v
|
||||
@@ -237,16 +245,188 @@ def gha2_num(
|
||||
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
|
||||
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, lamb1)
|
||||
alpha0_sph = sph_azimuth(beta0, lamb0, beta1, lamb1_target)
|
||||
(_, _, E0, G0, *_) = BETA_LAMBDA(beta0, lamb0)
|
||||
beta_p0_sph = np.sqrt(G0 / E0) * cot(alpha0_sph)
|
||||
|
||||
N_newton = min(N, 4000)
|
||||
|
||||
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)
|
||||
for _ in range(iter_max):
|
||||
v0 = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float)
|
||||
@@ -262,34 +442,33 @@ def gha2_num(
|
||||
return False, None
|
||||
|
||||
step = delta / X3_end
|
||||
step = np.clip(step, -0.5, 0.5)
|
||||
step = float(np.clip(step, -0.5, 0.5))
|
||||
beta_p0 -= step
|
||||
|
||||
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:
|
||||
candidates = [-beta_p0_sph, 0.5 * beta_p0_sph, 2.0 * beta_p0_sph]
|
||||
N_quick = min(N, 2000)
|
||||
seeds = [beta_p0_sph, -beta_p0_sph, 0.5 * beta_p0_sph, 2.0 * beta_p0_sph]
|
||||
best = None
|
||||
for g in candidates:
|
||||
ok_g, sol = solve_newton(g)
|
||||
if not ok_g:
|
||||
for seed in seeds:
|
||||
ok_s, sol_s = solve_newton_refine(seed)
|
||||
if not ok_s:
|
||||
continue
|
||||
v0_g = np.array([beta0, sol, 0.0, 1.0], dtype=float)
|
||||
_, _, s_quick = rk4_integral(ode_lamb, lamb0, v0_g, dlamb, N_quick, integrand_lambda)
|
||||
if (best is None) or (s_quick < best[0]):
|
||||
best = (s_quick, sol)
|
||||
v0_s = np.array([beta0, sol_s, 0.0, 1.0], dtype=float)
|
||||
_, _, s_s = rk4_integral(ode_lamb, lamb0, v0_s, dlamb, min(N_full, 2000), integrand_lambda)
|
||||
if (best is None) or (s_s < best[0]):
|
||||
best = (float(s_s), float(sol_s))
|
||||
if best is None:
|
||||
raise RuntimeError("Keine Startwert-Variante konvergiert (lambda-Fall).")
|
||||
raise RuntimeError("GHA2_num: Keine Startwert-Variante konvergiert (lambda-Fall)")
|
||||
beta_p0_sol = best[1]
|
||||
|
||||
beta_p0 = float(beta_p0_sol)
|
||||
v0_final = np.array([beta0, beta_p0, 0.0, 1.0], dtype=float)
|
||||
|
||||
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)
|
||||
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)
|
||||
@@ -297,34 +476,35 @@ def gha2_num(
|
||||
(_, _, E_start, G_start, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0])
|
||||
(_, _, 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_2 = norm_a(arccot(np.sqrt(E_end / G_end) * beta_p_arr[-1]))
|
||||
alpha_0 = azimut(E_start, G_start, dbeta_du=beta_p_arr[0] * sgn, dlamb_du=1.0 * sgn)
|
||||
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 + 1, dtype=float)
|
||||
for i in range(N + 1):
|
||||
integrand = np.zeros(N_full + 1, dtype=float)
|
||||
for i in range(N_full + 1):
|
||||
(_, _, Ei, Gi, *_) = BETA_LAMBDA(beta_arr[i], lamb_arr[i])
|
||||
integrand[i] = np.sqrt(Ei * beta_p_arr[i] ** 2 + Gi)
|
||||
|
||||
h = abs(dlamb) / N
|
||||
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])
|
||||
h = abs(dlamb) / N_full
|
||||
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 = h / 3.0 * S
|
||||
else:
|
||||
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
|
||||
|
||||
(_, _, 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))
|
||||
alpha_2 = norm_a(arccot(np.sqrt(E_end / G_end) * beta_p_end))
|
||||
(_, _, E_end, G_end, *_) = BETA_LAMBDA(float(beta_end), float(lamb0 + dlamb))
|
||||
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)
|
||||
N = int(n)
|
||||
@@ -335,10 +515,7 @@ def gha2_num(
|
||||
return 0.0, 0.0, 0.0, np.array([]), np.array([])
|
||||
return 0.0, 0.0, 0.0
|
||||
|
||||
beta0 = float(beta_0)
|
||||
lamb0 = float(lamb_0)
|
||||
beta1 = float(beta_1)
|
||||
lamb1 = float(lamb_1)
|
||||
sgn = 1.0 if dbeta >= 0.0 else -1.0
|
||||
|
||||
def ode_beta(beta, v):
|
||||
lamb, lamb_p, Y3, Y4 = v
|
||||
@@ -347,10 +524,13 @@ def gha2_num(
|
||||
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
|
||||
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)
|
||||
|
||||
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):
|
||||
v0 = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float)
|
||||
_, y_end = rk4_end(ode_beta, beta0, v0, dbeta, N)
|
||||
@@ -362,10 +542,10 @@ def gha2_num(
|
||||
break
|
||||
|
||||
if abs(Y3_end) < 1e-20:
|
||||
raise RuntimeError("Abbruch (Ableitung ~ 0) im beta-Fall.")
|
||||
raise RuntimeError("GHA2_num: Ableitung ~ 0 im beta-Fall")
|
||||
|
||||
step = delta / Y3_end
|
||||
step = np.clip(step, -1.0, 1.0)
|
||||
step = float(np.clip(step, -1.0, 1.0))
|
||||
lamb_p0 -= step
|
||||
|
||||
v0_final = np.array([lamb0, lamb_p0, 0.0, 1.0], dtype=float)
|
||||
@@ -376,11 +556,11 @@ def gha2_num(
|
||||
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)
|
||||
|
||||
(BETA_s, LAMBDA_s, _, _, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0])
|
||||
(BETA_e, LAMBDA_e, _, _, *_) = BETA_LAMBDA(beta_arr[-1], lamb_arr[-1])
|
||||
(_, _, E_start, G_start, *_) = BETA_LAMBDA(beta_arr[0], lamb_arr[0])
|
||||
(_, _, 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_2 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_e / BETA_e) * lamb_p_arr[-1]))
|
||||
alpha_0 = azimut(E_start, G_start, dbeta_du=1.0 * sgn, dlamb_du=lamb_p_arr[0] * sgn)
|
||||
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)
|
||||
for i in range(N + 1):
|
||||
@@ -389,72 +569,75 @@ def gha2_num(
|
||||
|
||||
h = abs(dbeta) / N
|
||||
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(
|
||||
integrand[2:-1:2]
|
||||
)
|
||||
s = h / 3.0 * S
|
||||
else:
|
||||
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)
|
||||
lamb_end, lamb_p_end, _, _ = y_end
|
||||
|
||||
(BETA_s, LAMBDA_s, _, _, *_) = BETA_LAMBDA(beta0, lamb0)
|
||||
(BETA_e, LAMBDA_e, _, _, *_) = BETA_LAMBDA(beta1, lamb1)
|
||||
(_, _, E_start, G_start, *_) = BETA_LAMBDA(beta0, lamb0)
|
||||
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))
|
||||
alpha_2 = norm_a((np.pi/2.0) - arccot(np.sqrt(LAMBDA_e / BETA_e) * lamb_p_end))
|
||||
(_, _, E_end, G_end, *_) = BETA_LAMBDA(beta1, float(lamb_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__":
|
||||
# ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
# beta1 = np.deg2rad(75)
|
||||
# lamb1 = np.deg2rad(-90)
|
||||
# beta2 = np.deg2rad(75)
|
||||
# lamb2 = np.deg2rad(66)
|
||||
# a0, a1, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=5000)
|
||||
# print(aus.gms("a0", a0, 4))
|
||||
# print(aus.gms("a1", a1, 4))
|
||||
# print("s: ", s)
|
||||
# # 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)
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
beta1 = np.deg2rad(75)
|
||||
lamb1 = np.deg2rad(-90)
|
||||
beta2 = np.deg2rad(75)
|
||||
lamb2 = np.deg2rad(66)
|
||||
a0, a1, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=100)
|
||||
print(aus.gms("a0", a0, 4))
|
||||
print(aus.gms("a1", a1, 4))
|
||||
print("s: ", s)
|
||||
# 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)
|
||||
|
||||
# ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
# diffs_panou = []
|
||||
# examples_panou = ne_panou.get_random_examples(4)
|
||||
# for example in examples_panou:
|
||||
# beta0, lamb0, beta1, lamb1, _, alpha0, alpha1, s = example
|
||||
# P0 = ell.ell2cart(beta0, lamb0)
|
||||
# try:
|
||||
# alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
|
||||
# diffs_panou.append(
|
||||
# (wu.rad2deg(abs(alpha0 - alpha0_num)), wu.rad2deg(abs(alpha1 - alpha1_num)), abs(s - s_num)))
|
||||
# except:
|
||||
# print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
|
||||
# diffs_panou = np.array(diffs_panou)
|
||||
# print(diffs_panou)
|
||||
#
|
||||
# ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
# diffs_karney = []
|
||||
# # examples_karney = ne_karney.get_examples((30500, 40500))
|
||||
# examples_karney = ne_karney.get_random_examples(2)
|
||||
# for example in examples_karney:
|
||||
# beta0, lamb0, alpha0, beta1, lamb1, alpha1, s = example
|
||||
#
|
||||
# try:
|
||||
# alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
|
||||
# diffs_karney.append((wu.rad2deg(abs(alpha0-alpha0_num)), wu.rad2deg(abs(alpha1-alpha1_num)), abs(s-s_num)))
|
||||
# except:
|
||||
# print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
|
||||
# diffs_karney = np.array(diffs_karney)
|
||||
# print(diffs_karney)
|
||||
a1, a2, s = gha2_num(ell, beta1, lamb1, beta2, lamb2, n=5000)
|
||||
print(s)
|
||||
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980round")
|
||||
diffs_panou = []
|
||||
examples_panou = ne_panou.get_random_examples(4)
|
||||
for example in examples_panou:
|
||||
beta0, lamb0, beta1, lamb1, _, alpha0, alpha1, s = example
|
||||
P0 = ell.ell2cart(beta0, lamb0)
|
||||
try:
|
||||
alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
|
||||
diffs_panou.append(
|
||||
(wu.rad2deg(abs(alpha0 - alpha0_num)), wu.rad2deg(abs(alpha1 - alpha1_num)), abs(s - s_num)))
|
||||
except:
|
||||
print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
|
||||
diffs_panou = np.array(diffs_panou)
|
||||
print(diffs_panou)
|
||||
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
diffs_karney = []
|
||||
# examples_karney = ne_karney.get_examples((30500, 40500))
|
||||
examples_karney = ne_karney.get_random_examples(2)
|
||||
for example in examples_karney:
|
||||
beta0, lamb0, alpha0, beta1, lamb1, alpha1, s = example
|
||||
|
||||
try:
|
||||
alpha0_num, alpha1_num, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=4000, iter_max=10)
|
||||
diffs_karney.append((wu.rad2deg(abs(alpha0-alpha0_num)), wu.rad2deg(abs(alpha1-alpha1_num)), abs(s-s_num)))
|
||||
except:
|
||||
print(f"Fehler für {beta0}, {lamb0}, {beta1}, {lamb1}")
|
||||
diffs_karney = np.array(diffs_karney)
|
||||
print(diffs_karney)
|
||||
|
||||
pass
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import random
|
||||
from typing import List
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
from typing import List, Tuple
|
||||
from GHA_triaxial.utils import jacobi_konstante
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
file_path = r"Karney_2024_Testset.txt"
|
||||
|
||||
def line2example(line: str) -> List:
|
||||
"""
|
||||
@@ -26,7 +32,7 @@ def get_random_examples(num: int, seed: int = None) -> List:
|
||||
"""
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
with open(r"C:\Users\moell\OneDrive\Desktop\Vorlesungen\Master-Projekt\Python_Masterprojekt\GHA_triaxial\Karney_2024_Testset.txt") as datei:
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
for i in range(num):
|
||||
@@ -41,7 +47,7 @@ def get_examples(l_i: List) -> List:
|
||||
:param l_i: Liste von Indizes
|
||||
:return: Liste mit Beispielen
|
||||
"""
|
||||
with open("Karney_2024_Testset.txt") as datei:
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
for i in l_i:
|
||||
@@ -50,5 +56,63 @@ def get_examples(l_i: List) -> List:
|
||||
return examples
|
||||
|
||||
|
||||
def get_random_examples_gamma(group: str, num: int, seed: int = None, length: str = None) -> List:
|
||||
"""
|
||||
Zufällige Beispiele aus Karney in Gruppen nach Einteilung anhand der Jacobi-Konstanten
|
||||
:param group: Gruppe
|
||||
:param num: Anzahl
|
||||
:param seed: Random-Seed
|
||||
:param length: long oder short, sond egal
|
||||
:return: Liste mit Beispielen
|
||||
"""
|
||||
eps = 1e-20
|
||||
long_short = 2
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
with open(file_path) as datei:
|
||||
lines = datei.readlines()
|
||||
examples = []
|
||||
i = 0
|
||||
while len(examples) < num and i < len(lines):
|
||||
example = line2example(lines[random.randint(0, len(lines) - 1)])
|
||||
if example in examples:
|
||||
continue
|
||||
i += 1
|
||||
|
||||
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
|
||||
gamma = jacobi_konstante(beta0, lamb0, alpha0_ell, ell)
|
||||
|
||||
if group not in ["a", "b", "c", "d", "e", "de"]:
|
||||
break
|
||||
elif group == "a" and not 1 >= gamma >= 0.01:
|
||||
continue
|
||||
elif group == "b" and not 0.01 > gamma > eps:
|
||||
continue
|
||||
elif group == "c" and not abs(gamma) <= eps:
|
||||
continue
|
||||
elif group == "d" and not -eps > gamma > -1e-17:
|
||||
continue
|
||||
elif group == "e" and not -1e-17 >= gamma >= -1:
|
||||
continue
|
||||
elif group == "de" and not -eps > gamma > -1:
|
||||
continue
|
||||
|
||||
if length == "short":
|
||||
if example[6] < long_short:
|
||||
examples.append(example)
|
||||
elif length == "long":
|
||||
if example[6] >= long_short:
|
||||
examples.append(example)
|
||||
else:
|
||||
examples.append(example)
|
||||
|
||||
return examples
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_random_examples(10)
|
||||
examples_a = get_random_examples_gamma("a", 10, 42)
|
||||
examples_b = get_random_examples_gamma("b", 10, 42)
|
||||
examples_c = get_random_examples_gamma("c", 10, 42)
|
||||
examples_d = get_random_examples_gamma("d", 10, 42)
|
||||
examples_e = get_random_examples_gamma("e", 10, 42)
|
||||
pass
|
||||
@@ -1,11 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arctan2, sin, cos, sqrt
|
||||
from numpy._typing import NDArray
|
||||
from numpy import arctan2, cos, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ellipsoide import EllipsoidTriaxial
|
||||
from ellipsoid_triaxial import EllipsoidTriaxial
|
||||
from utils_angle import wrap_0_2pi
|
||||
|
||||
|
||||
def sigma2alpha(ell: EllipsoidTriaxial, sigma: NDArray, point: NDArray) -> float:
|
||||
@@ -21,7 +23,7 @@ def sigma2alpha(ell: EllipsoidTriaxial, sigma: NDArray, point: NDArray) -> float
|
||||
Q = float(q @ sigma)
|
||||
|
||||
alpha = arctan2(P, Q)
|
||||
return alpha
|
||||
return wrap_0_2pi(alpha)
|
||||
|
||||
|
||||
def alpha_para2ell(ell: EllipsoidTriaxial, u: float, v: float, alpha_para: float) -> Tuple[float, float, float]:
|
||||
@@ -43,10 +45,10 @@ def alpha_para2ell(ell: EllipsoidTriaxial, u: float, v: float, alpha_para: float
|
||||
alpha_ell = arctan2(p_ell @ sigma_para, q_ell @ sigma_para)
|
||||
sigma_ell = p_ell * sin(alpha_ell) + q_ell * cos(alpha_ell)
|
||||
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-12:
|
||||
raise Exception("Alpha Umrechnung fehlgeschlagen")
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
|
||||
raise Exception("alpha_para2ell: Differenz in den Richtungsableitungen")
|
||||
|
||||
return beta, lamb, alpha_ell
|
||||
return beta, lamb, wrap_0_2pi(alpha_ell)
|
||||
|
||||
|
||||
def alpha_ell2para(ell: EllipsoidTriaxial, beta: float, lamb: float, alpha_ell: float) -> Tuple[float, float, float]:
|
||||
@@ -68,10 +70,10 @@ def alpha_ell2para(ell: EllipsoidTriaxial, beta: float, lamb: float, alpha_ell:
|
||||
alpha_para = arctan2(p_para @ sigma_ell, q_para @ sigma_ell)
|
||||
sigma_para = p_para * sin(alpha_para) + q_para * cos(alpha_para)
|
||||
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-9:
|
||||
raise Exception("Alpha Umrechnung fehlgeschlagen")
|
||||
if np.linalg.norm(sigma_para - sigma_ell) > 1e-7:
|
||||
raise Exception("alpha_ell2para: Differenz in den Richtungsableitungen")
|
||||
|
||||
return u, v, alpha_para
|
||||
return u, v, wrap_0_2pi(alpha_para)
|
||||
|
||||
|
||||
def func_sigma_ell(ell: EllipsoidTriaxial, point: NDArray, alpha_ell: float) -> NDArray:
|
||||
@@ -124,18 +126,19 @@ def pq_ell(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
:param point: Punkt
|
||||
:return: p und q
|
||||
"""
|
||||
x, y, z = point
|
||||
n = ell.func_n(point)
|
||||
|
||||
beta, lamb = ell.cart2ell(point)
|
||||
if abs(cos(beta)) < 1e-15 and abs(np.sin(lamb)) < 1e-15:
|
||||
if beta > 0:
|
||||
p = np.array([0, -1, 0])
|
||||
else:
|
||||
p = np.array([0, 1, 0])
|
||||
else:
|
||||
B = ell.Ex ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(beta) ** 2
|
||||
L = ell.Ex ** 2 - ell.Ee ** 2 * cos(lamb) ** 2
|
||||
|
||||
c1 = x ** 2 + y ** 2 + z ** 2 - (ell.ax ** 2 + ell.ay ** 2 + ell.b ** 2)
|
||||
c0 = (ell.ax ** 2 * ell.ay ** 2 + ell.ax ** 2 * ell.b ** 2 + ell.ay ** 2 * ell.b ** 2 -
|
||||
(ell.ay ** 2 + ell.b ** 2) * x ** 2 - (ell.ax ** 2 + ell.b ** 2) * y ** 2 - (
|
||||
ell.ax ** 2 + ell.ay ** 2) * z ** 2)
|
||||
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
|
||||
_, t2 = ell.func_t12(point)
|
||||
|
||||
F = ell.Ey ** 2 * cos(beta) ** 2 + ell.Ee ** 2 * sin(lamb) ** 2
|
||||
p1 = -sqrt(L / (F * t2)) * ell.ax / ell.Ex * sqrt(B) * sin(lamb)
|
||||
@@ -171,13 +174,28 @@ def pq_para(ell: EllipsoidTriaxial, point: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
q[2] * n[0] - q[0] * n[2],
|
||||
q[0] * n[1] - q[1] * n[0]])
|
||||
|
||||
t1 = np.dot(n, q)
|
||||
t2 = np.dot(n, p)
|
||||
t3 = np.dot(p, q)
|
||||
if not (t1 < 1e-10 or t1 > 1-1e-10) and not (t2 < 1e-10 or t2 > 1-1e-10) and not (t3 < 1e-10 or t3 > 1-1e-10):
|
||||
raise Exception("Fehler in den normierten Vektoren")
|
||||
|
||||
p = p / np.linalg.norm(p)
|
||||
q = q / np.linalg.norm(q)
|
||||
|
||||
return p, q
|
||||
|
||||
|
||||
def jacobi_konstante(beta: float, omega: float, alpha: float, ell: EllipsoidTriaxial) -> float:
|
||||
"""
|
||||
Jacobi-Konstante nach Karney (2025), Gl. (14)
|
||||
:param beta: Beta Koordinate
|
||||
:param omega: Omega Koordinate
|
||||
:param alpha: Azimut alpha
|
||||
:param ell: Ellipsoid
|
||||
:return: Jacobi-Konstante
|
||||
"""
|
||||
gamma_jacobi = float((ell.k ** 2) * (np.cos(beta) ** 2) * (np.sin(alpha) ** 2) - (ell.k_ ** 2) * (np.sin(omega) ** 2) * (np.cos(alpha) ** 2))
|
||||
return gamma_jacobi
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
alpha_para = 0
|
||||
u, v = ell.ell2para(np.pi/2, 0)
|
||||
alpha_ell = alpha_para2ell(ell, u, v, alpha_para)
|
||||
pass
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
import numpy as np
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from GHA_biaxial.bessel import gha1 as gha1_bessel
|
||||
from GHA_biaxial.gauss import gha1 as gha1_gauss
|
||||
from GHA_biaxial.rk import gha1 as gha1_rk
|
||||
from GHA_biaxial.gauss import gha2 as gha2_gauss
|
||||
|
||||
re = EllipsoidBiaxial.init_name("Bessel")
|
||||
|
||||
# phi0 = 0.6
|
||||
# lamb0 = 1.2
|
||||
# alpha0 = 0.45
|
||||
# s = 123456
|
||||
#
|
||||
# values_bessel = gha1_bessel(re, phi0, lamb0, alpha0, s)
|
||||
# alpha1_bessel = values_bessel[-1]
|
||||
# p1_bessel = re.bi_ell2cart(values_bessel[0], values_bessel[1], 0)
|
||||
#
|
||||
# values_gauss1 = gha1_gauss(re, phi0, lamb0, alpha0, s)
|
||||
# alpha1_gauss1 = values_gauss1[-1]
|
||||
# p1_gauss = re.bi_ell2cart(values_gauss1[0], values_gauss1[1], 0)
|
||||
#
|
||||
# values_rk = gha1_rk(re, phi0, lamb0 , alpha0, s, 10000)
|
||||
# alpha1_rk = values_rk[-1]
|
||||
# p1_rk = re.bi_ell2cart(values_rk[0], values_rk[1], 0)
|
||||
#
|
||||
# alpha0_gauss, alpha1_gauss2, s_gauss = gha2_gauss(re, phi0, lamb0, values_gauss1[0], values_gauss1[1])
|
||||
|
||||
phi0 = 0.6
|
||||
lamb0 = 1.2
|
||||
|
||||
cart = re.bi_ell2cart(phi0, lamb0, 0)
|
||||
ell = re.bi_cart2ell(cart)
|
||||
pass
|
||||
@@ -21,5 +21,5 @@ def gms(name: str, rad: float, stellen: int) -> str:
|
||||
:param stellen: Anzahl Nachkommastellen
|
||||
:return: String zur Ausgabe des Winkels
|
||||
"""
|
||||
gms = wu.rad2gms(rad)
|
||||
return f"{name} = {int(gms[0])}° {int(gms[1])}' {round(gms[2],stellen):.{stellen}f}''"
|
||||
values = wu.rad2gms(rad)
|
||||
return f"{name} = {int(values[0])}° {int(values[1])}' {round(values[2], stellen):.{stellen}f}''"
|
||||
|
||||
687
dashboard.py
687
dashboard.py
File diff suppressed because it is too large
Load Diff
@@ -1,116 +1,20 @@
|
||||
import numpy as np
|
||||
from numpy import sin, cos, arctan, arctan2, sqrt, pi, arccos
|
||||
import winkelumrechnungen as wu
|
||||
import jacobian_Ligas
|
||||
import matplotlib.pyplot as plt
|
||||
from typing import Tuple
|
||||
from numpy.typing import NDArray
|
||||
import math
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arccos, arctan, arctan2, cos, pi, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
class EllipsoidBiaxial:
|
||||
def __init__(self, a: float, b: float):
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = a ** 2 / b
|
||||
self.e = sqrt(a ** 2 - b ** 2) / a
|
||||
self.e_ = sqrt(a ** 2 - b ** 2) / b
|
||||
import jacobian_Ligas
|
||||
from utils_angle import wrap_mhalfpi_halfpi, wrap_mpi_pi
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str):
|
||||
if name == "Bessel":
|
||||
a = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(a, b)
|
||||
elif name == "Hayford":
|
||||
a = 6378388
|
||||
f = 1/297
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "Krassowski":
|
||||
a = 6378245
|
||||
f = 298.3
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "WGS84":
|
||||
a = 6378137
|
||||
f = 298.257223563
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
@classmethod
|
||||
def init_af(cls, a: float, f: float):
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
V = lambda self, phi: sqrt(1 + self.e_ ** 2 * cos(phi) ** 2)
|
||||
M = lambda self, phi: self.c / self.V(phi) ** 3
|
||||
N = lambda self, phi: self.c / self.V(phi)
|
||||
|
||||
beta2psi = lambda self, beta: np.arctan2(self.a * np.sin(beta), self.b * np.cos(beta))
|
||||
beta2phi = lambda self, beta: np.arctan2(self.a ** 2 * np.sin(beta), self.b ** 2 * np.cos(beta))
|
||||
|
||||
psi2beta = lambda self, psi: np.arctan2(self.b * np.sin(psi), self.a * np.cos(psi))
|
||||
psi2phi = lambda self, psi: np.arctan2(self.a * np.sin(psi), self.b * np.cos(psi))
|
||||
|
||||
phi2beta = lambda self, phi: np.arctan2(self.b**2 * np.sin(phi), self.a**2 * np.cos(phi))
|
||||
phi2psi = lambda self, phi: np.arctan2(self.b * np.sin(phi), self.a * np.cos(phi))
|
||||
|
||||
phi2p = lambda self, phi: self.N(phi) * cos(phi)
|
||||
|
||||
def bi_cart2ell(self, point: NDArrayself, Eh: float = 0.001, Ephi: float = wu.gms2rad([0, 0, 0.001])) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Umrechnung von kartesischen in ellipsoidische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
:param Eh: Grenzwert für die Höhe
|
||||
:param Ephi: Grenzwert für die Breite
|
||||
:return: ellipsoidische Breite, Länge, geodätische Höhe
|
||||
"""
|
||||
x, y, z = point
|
||||
|
||||
lamb = arctan2(y, x)
|
||||
|
||||
p = sqrt(x**2+y**2)
|
||||
|
||||
phi_null = arctan2(z, p*(1 - self.e**2))
|
||||
|
||||
hi = [0]
|
||||
phii = [phi_null]
|
||||
|
||||
i = 0
|
||||
|
||||
while True:
|
||||
N = self.a / sqrt(1 - self.e**2 * sin(phii[i])**2)
|
||||
h = p / cos(phii[i]) - N
|
||||
phi = arctan2(z, p * (1-(self.e**2*N) / (N+h)))
|
||||
hi.append(h)
|
||||
phii.append(phi)
|
||||
dh = abs(hi[i]-h)
|
||||
dphi = abs(phii[i]-phi)
|
||||
i = i+1
|
||||
if dh < Eh:
|
||||
if dphi < Ephi:
|
||||
break
|
||||
return phi, lamb, h
|
||||
|
||||
def bi_ell2cart(self, phi: float, lamb: float, h: float) -> NDArray:
|
||||
"""
|
||||
Umrechnung von ellipsoidischen in kartesische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param phi: ellipsoidische Breite
|
||||
:param lamb: ellipsoidische Länge
|
||||
:param h: geodätische Höhe
|
||||
:return: Punkt in kartesischen Koordinaten
|
||||
"""
|
||||
W = sqrt(1 - self.e**2 * sin(phi)**2)
|
||||
N = self.a / W
|
||||
x = (N+h) * cos(phi) * cos(lamb)
|
||||
y = (N+h) * cos(phi) * sin(lamb)
|
||||
z = (N * (1-self.e**2) + h) * sin(phi)
|
||||
return np.array([x, y, z])
|
||||
|
||||
class EllipsoidTriaxial:
|
||||
"""
|
||||
Klasse für dreiachsige Ellipsoide
|
||||
Parameter: Formparameter
|
||||
Funktionen: Koordinatenumrechnungen
|
||||
"""
|
||||
def __init__(self, ax: float, ay: float, b: float):
|
||||
self.ax = ax
|
||||
self.ay = ay
|
||||
@@ -124,14 +28,19 @@ class EllipsoidTriaxial:
|
||||
self.Ex = sqrt(self.ax**2 - self.b**2)
|
||||
self.Ey = sqrt(self.ay**2 - self.b**2)
|
||||
self.Ee = sqrt(self.ax**2 - self.ay**2)
|
||||
nenner = sqrt(max(self.ax * self.ax - self.b * self.b, 0.0))
|
||||
self.k = sqrt(max(self.ay * self.ay - self.b * self.b, 0.0)) / nenner
|
||||
self.k_ = sqrt(max(self.ax * self.ax - self.ay * self.ay, 0.0)) / nenner
|
||||
self.e = sqrt(max(self.ax * self.ax - self.b * self.b, 0.0)) / self.ay
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str):
|
||||
def init_name(cls, name: str) -> EllipsoidTriaxial:
|
||||
"""
|
||||
Mögliche Ellipsoide: BursaFialova1993, BursaSima1980, BursaSima1980round, Eitschberger1978, Bursa1972,
|
||||
Bursa1970, BesselBiaxial, Fiction, KarneyTest2024
|
||||
Mögliche Ellipsoide: BursaSima1980round, KarneyTest2024, Fiction, BursaFialova1993, BursaSima1980, Eitschberger1978, Bursa1972,
|
||||
Bursa1970
|
||||
Panou et al (2020)
|
||||
:param name: Name des dreiachsigen Ellipsoids
|
||||
:return: dreiachsiger Ellipsoid
|
||||
"""
|
||||
if name == "BursaFialova1993":
|
||||
ax = 6378171.36
|
||||
@@ -164,11 +73,6 @@ class EllipsoidTriaxial:
|
||||
ay = 6378105
|
||||
b = 6356754
|
||||
return cls(ax, ay, b)
|
||||
elif name == "BesselBiaxial":
|
||||
ax = 6377397.15509
|
||||
ay = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(ax, ay, b)
|
||||
elif name == "Fiction":
|
||||
ax = 6000000
|
||||
ay = 4000000
|
||||
@@ -179,6 +83,8 @@ class EllipsoidTriaxial:
|
||||
ay = 1
|
||||
b = 1 / sqrt(2)
|
||||
return cls(ax, ay, b)
|
||||
else:
|
||||
raise Exception(f"EllipsoidTriaxial.init_name: Name {name} unbekannt")
|
||||
|
||||
def func_H(self, point: NDArray) -> float:
|
||||
"""
|
||||
@@ -218,8 +124,10 @@ class EllipsoidTriaxial:
|
||||
c0 = (self.ax ** 2 * self.ay ** 2 + self.ax ** 2 * self.b ** 2 + self.ay ** 2 * self.b ** 2 -
|
||||
(self.ay ** 2 + self.b ** 2) * x ** 2 - (self.ax ** 2 + self.b ** 2) * y ** 2 - (
|
||||
self.ax ** 2 + self.ay ** 2) * z ** 2)
|
||||
if c1 ** 2 - 4 * c0 < 0:
|
||||
t2 = np.nan
|
||||
if c1 ** 2 - 4 * c0 < -1e-9:
|
||||
raise Exception("t1, t2: Negativer Wurzelterm")
|
||||
elif c1 ** 2 - 4 * c0 < 0:
|
||||
t2 = 0
|
||||
else:
|
||||
t2 = (-c1 + sqrt(c1 ** 2 - 4 * c0)) / 2
|
||||
if t2 == 0:
|
||||
@@ -261,7 +169,6 @@ class EllipsoidTriaxial:
|
||||
s1 = 2 * sqrt(p) * cos(omega/3) - c2/3
|
||||
s2 = 2 * sqrt(p) * cos(omega/3 - 2*pi/3) - c2/3
|
||||
s3 = 2 * sqrt(p) * cos(omega/3 - 4*pi/3) - c2/3
|
||||
# print(s1, s2, s3)
|
||||
|
||||
beta = arctan(sqrt((-self.b**2 - s2) / (self.ay**2 + s2)))
|
||||
if abs((-self.ay**2 - s3) / (self.ax**2 + s3)) > 1e-7:
|
||||
@@ -284,6 +191,11 @@ class EllipsoidTriaxial:
|
||||
|
||||
beta, lamb = np.broadcast_arrays(beta, lamb)
|
||||
|
||||
beta = np.where(
|
||||
np.isclose(np.abs(beta), pi / 2, atol=1e-15),
|
||||
beta * 8999999999999999 / 9000000000000000,
|
||||
beta
|
||||
)
|
||||
B = self.Ex ** 2 * cos(beta) ** 2 + self.Ee ** 2 * sin(beta) ** 2
|
||||
L = self.Ex ** 2 - self.Ee ** 2 * cos(lamb) ** 2
|
||||
|
||||
@@ -412,14 +324,14 @@ class EllipsoidTriaxial:
|
||||
i += 1
|
||||
|
||||
if i == maxI:
|
||||
raise Exception("Umrechnung ist nicht konvergiert")
|
||||
raise Exception("Umrechnung cart2ell: nicht konvergiert")
|
||||
|
||||
point_n = self.ell2cart(beta, lamb)
|
||||
delta_r = np.linalg.norm(point - point_n, axis=-1)
|
||||
if delta_r > 1e-6:
|
||||
raise Exception("Fehler in der Umrechnung cart2ell")
|
||||
raise Exception("Umrechnung cart2ell: Punktdifferenz")
|
||||
|
||||
return beta, lamb
|
||||
return wrap_mhalfpi_halfpi(beta), wrap_mpi_pi(lamb)
|
||||
|
||||
except Exception as e:
|
||||
# Wenn die Berechnung fehlschlägt auf Grund von sehr kleinem y, solange anpassen, bis Umrechnung ohne Fehler
|
||||
@@ -511,7 +423,7 @@ class EllipsoidTriaxial:
|
||||
i += 1
|
||||
|
||||
if i == maxI:
|
||||
raise Exception("Umrechung ist nicht konvergiert")
|
||||
raise Exception("Umrechnung cart2ell: nicht konvergiert")
|
||||
|
||||
return phi, lamb
|
||||
|
||||
@@ -577,6 +489,8 @@ class EllipsoidTriaxial:
|
||||
invJ, fxE = jacobian_Ligas.case2(E, F, G, np.array([xG, yG, zG]), pE)
|
||||
elif mode == "ligas3":
|
||||
invJ, fxE = jacobian_Ligas.case3(E, F, G, np.array([xG, yG, zG]), pE)
|
||||
else:
|
||||
raise Exception(f"cart2geod: Modus {mode} nicht bekannt")
|
||||
pEi = pE.reshape(-1, 1) - invJ @ fxE.reshape(-1, 1)
|
||||
pEi = pEi.reshape(1, -1).flatten()
|
||||
loa = sqrt((pEi[0]-pE[0])**2 + (pEi[1]-pE[1])**2 + (pEi[2]-pE[2])**2)
|
||||
@@ -598,15 +512,15 @@ class EllipsoidTriaxial:
|
||||
phi, lamb, h = self.cart2geod(point, f"ligas{new_mode}", maxIter, maxLoa)
|
||||
else:
|
||||
if xG < 0 and yG < 0:
|
||||
lamb = -pi + lamb
|
||||
lamb += -pi
|
||||
|
||||
elif xG < 0:
|
||||
lamb = pi + lamb
|
||||
lamb += pi
|
||||
|
||||
if abs(zG) < eps:
|
||||
phi = 0
|
||||
|
||||
return phi, lamb, h
|
||||
wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb)
|
||||
return wrap_mhalfpi_halfpi(phi), wrap_mpi_pi(lamb), h
|
||||
|
||||
def para2cart(self, u: float | NDArray, v: float | NDArray) -> NDArray:
|
||||
"""
|
||||
@@ -643,8 +557,8 @@ class EllipsoidTriaxial:
|
||||
v = 2 * arctan2(v_check1, v_check2 + v_factor)
|
||||
else:
|
||||
v = pi/2 - 2 * arctan2(v_check2, v_check1 + v_factor)
|
||||
|
||||
return u, v
|
||||
wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
|
||||
return wrap_mhalfpi_halfpi(u), wrap_mpi_pi(v)
|
||||
|
||||
def ell2para(self, beta: float, lamb: float) -> Tuple[float, float]:
|
||||
"""
|
||||
@@ -749,63 +663,71 @@ class EllipsoidTriaxial:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ell = EllipsoidTriaxial.init_name("BursaSima1980")
|
||||
diff_list = []
|
||||
diffs_para = []
|
||||
diffs_ell = []
|
||||
diffs_geod = []
|
||||
points = []
|
||||
for v_deg in range(-180, 181, 5):
|
||||
for u_deg in range(-90, 91, 5):
|
||||
v = wu.deg2rad(v_deg)
|
||||
u = wu.deg2rad(u_deg)
|
||||
point = ell.para2cart(u, v)
|
||||
points.append(point)
|
||||
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
# cart = ell.ell2cart(pi/2, 0)
|
||||
# print(cart)
|
||||
# cart = ell.ell2cart(pi/2*8999999999999999/9000000000000000, 0)
|
||||
# print(cart)
|
||||
elli = ell.cart2ell(np.array([0, 0.0, 1/sqrt(2)]))
|
||||
print(elli)
|
||||
|
||||
elli = ell.cart2ell(point)
|
||||
cart_elli = ell.ell2cart(elli[0], elli[1])
|
||||
diff_ell = np.linalg.norm(point - cart_elli, axis=-1)
|
||||
|
||||
para = ell.cart2para(point)
|
||||
cart_para = ell.para2cart(para[0], para[1])
|
||||
diff_para = np.linalg.norm(point - cart_para, axis=-1)
|
||||
|
||||
geod = ell.cart2geod(point, "ligas3")
|
||||
cart_geod = ell.geod2cart(geod[0], geod[1], geod[2])
|
||||
diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1)
|
||||
|
||||
diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3])
|
||||
diffs_ell.append([diff_ell])
|
||||
diffs_para.append([diff_para])
|
||||
diffs_geod.append([diff_geod3])
|
||||
|
||||
diff_list = np.array(diff_list)
|
||||
diffs_ell = np.array(diffs_ell)
|
||||
diffs_para = np.array(diffs_para)
|
||||
diffs_geod = np.array(diffs_geod)
|
||||
|
||||
pass
|
||||
|
||||
points = np.array(points)
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(projection='3d')
|
||||
|
||||
sc = ax.scatter(
|
||||
points[:, 0],
|
||||
points[:, 1],
|
||||
points[:, 2],
|
||||
c=diffs_ell, # Farbcode = diff
|
||||
cmap='viridis', # Colormap
|
||||
s=10 + 20 * diffs_ell, # optional: Größe abhängig vom diff
|
||||
alpha=0.8
|
||||
)
|
||||
|
||||
# Farbskala
|
||||
cbar = plt.colorbar(sc)
|
||||
cbar.set_label("diff")
|
||||
|
||||
ax.set_xlabel("X")
|
||||
ax.set_ylabel("Y")
|
||||
ax.set_zlabel("Z")
|
||||
|
||||
plt.show()
|
||||
# ell = EllipsoidTriaxial.init_name("BursaSima1980")
|
||||
# diff_list = []
|
||||
# diffs_para = []
|
||||
# diffs_ell = []
|
||||
# diffs_geod = []
|
||||
# points = []
|
||||
# for v_deg in range(-180, 181, 5):
|
||||
# for u_deg in range(-90, 91, 5):
|
||||
# v = wu.deg2rad(v_deg)
|
||||
# u = wu.deg2rad(u_deg)
|
||||
# point = ell.para2cart(u, v)
|
||||
# points.append(point)
|
||||
#
|
||||
# elli = ell.cart2ell(point)
|
||||
# cart_elli = ell.ell2cart(elli[0], elli[1])
|
||||
# diff_ell = np.linalg.norm(point - cart_elli, axis=-1)
|
||||
#
|
||||
# para = ell.cart2para(point)
|
||||
# cart_para = ell.para2cart(para[0], para[1])
|
||||
# diff_para = np.linalg.norm(point - cart_para, axis=-1)
|
||||
#
|
||||
# geod = ell.cart2geod(point, "ligas3")
|
||||
# cart_geod = ell.geod2cart(geod[0], geod[1], geod[2])
|
||||
# diff_geod3 = np.linalg.norm(point - cart_geod, axis=-1)
|
||||
#
|
||||
# diff_list.append([v_deg, u_deg, diff_ell, diff_para, diff_geod3])
|
||||
# diffs_ell.append([diff_ell])
|
||||
# diffs_para.append([diff_para])
|
||||
# diffs_geod.append([diff_geod3])
|
||||
#
|
||||
# diff_list = np.array(diff_list)
|
||||
# diffs_ell = np.array(diffs_ell)
|
||||
# diffs_para = np.array(diffs_para)
|
||||
# diffs_geod = np.array(diffs_geod)
|
||||
#
|
||||
# pass
|
||||
#
|
||||
# points = np.array(points)
|
||||
# fig = plt.figure()
|
||||
# ax = fig.add_subplot(projection='3d')
|
||||
#
|
||||
# sc = ax.scatter(
|
||||
# points[:, 0],
|
||||
# points[:, 1],
|
||||
# points[:, 2],
|
||||
# c=diffs_ell, # Farbcode = diff
|
||||
# cmap='viridis', # Colormap
|
||||
# s=10 + 20 * diffs_ell, # optional: Größe abhängig vom diff
|
||||
# alpha=0.8
|
||||
# )
|
||||
#
|
||||
# # Farbskala
|
||||
# cbar = plt.colorbar(sc)
|
||||
# cbar.set_label("diff")
|
||||
#
|
||||
# ax.set_xlabel("X")
|
||||
# ax.set_ylabel("Y")
|
||||
# ax.set_zlabel("Z")
|
||||
#
|
||||
# plt.show()
|
||||
@@ -1,6 +1,8 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def case1(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
@@ -34,7 +36,7 @@ def case1(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArr
|
||||
|
||||
return invJ, fxE
|
||||
|
||||
def case2(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple[NDArray, NDArray]:
|
||||
def case2(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Aufstellen des Gleichungssystem für den zweiten Fall
|
||||
:param E: Konstante E
|
||||
@@ -68,7 +70,7 @@ def case2(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple
|
||||
|
||||
return invJ, fxE
|
||||
|
||||
def case3(E: float, F: float, G: float, pG: np.ndarray, pE: np.ndarray) -> Tuple[NDArray, NDArray]:
|
||||
def case3(E: float, F: float, G: float, pG: NDArray, pE: NDArray) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Aufstellen des Gleichungssystem für den dritten Fall
|
||||
:param E: Konstante E
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
from numpy import *
|
||||
import scipy as sp
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
import scipy as sp
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import *
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0:float, s: float) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnung der 1.GHA auf einem Rotationsellipsoid nach Bessel
|
||||
:param re:
|
||||
:param phi0:
|
||||
:param lamb0:
|
||||
:param alpha0:
|
||||
:param s:
|
||||
:return:
|
||||
"""
|
||||
psi0 = re.phi2psi(phi0)
|
||||
clairant = arcsin(cos(psi0) * sin(alpha0))
|
||||
sigma0 = arcsin(sin(psi0) / cos(clairant))
|
||||
@@ -1,8 +1,8 @@
|
||||
from numpy import sin, cos, pi, sqrt, tan, arcsin, arccos, arctan
|
||||
import ausgaben as aus
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import arctan, cos, sin, sqrt, tan
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, eps: float = 1e-12) -> Tuple[float, float, float]:
|
||||
"""
|
||||
@@ -1,13 +1,26 @@
|
||||
import runge_kutta as rk
|
||||
from numpy import sin, cos, tan
|
||||
import winkelumrechnungen as wu
|
||||
from ellipsoide import EllipsoidBiaxial
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from ellipsoid_biaxial import EllipsoidBiaxial
|
||||
from numpy import cos, sin, tan
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import runge_kutta as rk
|
||||
|
||||
|
||||
def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, num: int) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnung der 1. GHA auf einem Rotationsellipsoid mittels RK4
|
||||
:param re:
|
||||
:param phi0:
|
||||
:param lamb0:
|
||||
:param alpha0:
|
||||
:param s:
|
||||
:param num:
|
||||
:return:
|
||||
"""
|
||||
def buildODE():
|
||||
def ODE(s, v):
|
||||
def ODE(s: float, v: NDArray):
|
||||
phi, lam, A = v
|
||||
V = re.V(phi)
|
||||
dphi = cos(A) * V ** 3 / re.c
|
||||
0
nicht abgeben/Tests/__init__.py
Normal file
0
nicht abgeben/Tests/__init__.py
Normal file
9253
nicht abgeben/Tests/algorithms_test.ipynb
Normal file
9253
nicht abgeben/Tests/algorithms_test.ipynb
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,56 +1,41 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:30:31.978159Z",
|
||||
"start_time": "2026-01-20T15:30:31.835157Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
],
|
||||
"id": "a78faf7f4883772f",
|
||||
"outputs": [],
|
||||
"execution_count": 1
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:30:33.910807Z",
|
||||
"start_time": "2026-01-20T15:30:32.803089Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"%reload_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"from GHA_triaxial.utils import alpha_para2ell, alpha_ell2para\n",
|
||||
"import numpy as np"
|
||||
"from GHA_triaxial.utils import alpha_ell2para, alpha_para2ell\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"id": "9ad815aea55574e3",
|
||||
"id": "46aa84a937fea491",
|
||||
"outputs": [],
|
||||
"execution_count": 2
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:33:40.785362Z",
|
||||
"start_time": "2026-01-20T15:33:34.296487Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"ell = EllipsoidTriaxial.init_name(\"KarneyTest2024\")\n",
|
||||
"diffs = []\n",
|
||||
"for beta_deg in range(-180, 181, 45):\n",
|
||||
" for lamb_deg in range(-90, 91, 45):\n",
|
||||
" for alpha_deg in range(0, 360, 45):\n",
|
||||
"for beta_deg in range(-90, 91, 15):\n",
|
||||
" for lamb_deg in range(-180, 180, 15):\n",
|
||||
" for alpha_deg in range(0, 360, 15):\n",
|
||||
" beta = wu.deg2rad(beta_deg)\n",
|
||||
" lamb = wu.deg2rad(lamb_deg)\n",
|
||||
" u, v = ell.ell2para(beta, lamb)\n",
|
||||
@@ -67,17 +52,12 @@
|
||||
" diffs.append((beta_deg, lamb_deg, alpha_deg, diff_1, diff_2))\n",
|
||||
"diffs = np.array(diffs)"
|
||||
],
|
||||
"id": "98b9b220118deb3f",
|
||||
"id": "82fc6cbbe7d5abcb",
|
||||
"outputs": [],
|
||||
"execution_count": 6
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2026-01-20T15:33:50.497990Z",
|
||||
"start_time": "2026-01-20T15:33:50.261115Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"i_max_ell = np.argmax(diffs[:, 3])\n",
|
||||
@@ -92,18 +72,9 @@
|
||||
"print(f'Für parametrisches Alpha = {point_max_para[2]}° und beta = {point_max_para[0]}°, lamb = {point_max_para[1]}°: diff = {max_ell}\"')\n",
|
||||
"pass"
|
||||
],
|
||||
"id": "3c74b65b0e85e3c2",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Für elliptisches Alpha = 315.0° und beta = -90.0°, lamb = -90.0°: diff = 3.426945967752335e-05\"\n",
|
||||
"Für parametrisches Alpha = 315.0° und beta = -90.0°, lamb = -90.0°: diff = 3.426945967752335e-05\"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 7
|
||||
"id": "97b5b8c9ca5377ab",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -20,13 +20,14 @@
|
||||
"source": [
|
||||
"%reload_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
"import pickle\n",
|
||||
"import numpy as np\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from itertools import product\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"import plotly.graph_objects as go"
|
||||
"import plotly.graph_objects as go\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
BIN
nicht abgeben/Tests/gha_resultsKarney.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsKarney.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsPanou.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsPanou.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsRandom.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsRandom.pkl
Normal file
Binary file not shown.
BIN
nicht abgeben/Tests/gha_resultsRandom_num.pkl
Normal file
BIN
nicht abgeben/Tests/gha_resultsRandom_num.pkl
Normal file
Binary file not shown.
0
nicht abgeben/__init__.py
Normal file
0
nicht abgeben/__init__.py
Normal file
126
nicht abgeben/ellipsoid_biaxial.py
Normal file
126
nicht abgeben/ellipsoid_biaxial.py
Normal file
@@ -0,0 +1,126 @@
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arctan2, cos, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
|
||||
|
||||
class EllipsoidBiaxial:
|
||||
"""
|
||||
Klasse für Rotationsellipdoide
|
||||
"""
|
||||
def __init__(self, a: float, b: float):
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = a ** 2 / b
|
||||
self.e = sqrt(a ** 2 - b ** 2) / a
|
||||
self.e_ = sqrt(a ** 2 - b ** 2) / b
|
||||
|
||||
@classmethod
|
||||
def init_name(cls, name: str) -> EllipsoidBiaxial:
|
||||
"""
|
||||
Erstellen eines Rotationsellipdoids nach Namen
|
||||
:param name: Name des Rotationsellipsoids
|
||||
:return: Rotationsellipsoid
|
||||
"""
|
||||
if name == "Bessel":
|
||||
a = 6377397.15508
|
||||
b = 6356078.96290
|
||||
return cls(a, b)
|
||||
elif name == "Hayford":
|
||||
a = 6378388
|
||||
f = 1/297
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "Krassowski":
|
||||
a = 6378245
|
||||
f = 298.3
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
elif name == "WGS84":
|
||||
a = 6378137
|
||||
f = 298.257223563
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
else:
|
||||
raise Exception(f"EllipsoidBiaxial.init_name: Name {name} unbekannt")
|
||||
|
||||
@classmethod
|
||||
def init_af(cls, a: float, f: float) -> EllipsoidBiaxial:
|
||||
"""
|
||||
Erstellen eines Rotationsellipdoids aus der großen Halbachse und der Abplattung
|
||||
:param a: große Halbachse
|
||||
:param f: großen Halbachse
|
||||
:return: Rotationsellipsoid
|
||||
"""
|
||||
b = a - a * f
|
||||
return cls(a, b)
|
||||
|
||||
V = lambda self, phi: sqrt(1 + self.e_ ** 2 * cos(phi) ** 2)
|
||||
M = lambda self, phi: self.c / self.V(phi) ** 3
|
||||
N = lambda self, phi: self.c / self.V(phi)
|
||||
|
||||
beta2psi = lambda self, beta: arctan2(self.a * sin(beta), self.b * cos(beta))
|
||||
beta2phi = lambda self, beta: arctan2(self.a ** 2 * sin(beta), self.b ** 2 * cos(beta))
|
||||
|
||||
psi2beta = lambda self, psi: arctan2(self.b * sin(psi), self.a * cos(psi))
|
||||
psi2phi = lambda self, psi: arctan2(self.a * sin(psi), self.b * cos(psi))
|
||||
|
||||
phi2beta = lambda self, phi: arctan2(self.b**2 * sin(phi), self.a**2 * cos(phi))
|
||||
phi2psi = lambda self, phi: arctan2(self.b * sin(phi), self.a * cos(phi))
|
||||
|
||||
phi2p = lambda self, phi: self.N(phi) * cos(phi)
|
||||
|
||||
def bi_cart2ell(self, point: NDArray, Eh: float = 0.001, Ephi: float = wu.gms2rad([0, 0, 0.001])) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Umrechnung von kartesischen in ellipsoidische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param point: Punkt in kartesischen Koordinaten
|
||||
:param Eh: Grenzwert für die Höhe
|
||||
:param Ephi: Grenzwert für die Breite
|
||||
:return: ellipsoidische Breite, Länge, geodätische Höhe
|
||||
"""
|
||||
x, y, z = point
|
||||
|
||||
lamb = arctan2(y, x)
|
||||
|
||||
p = sqrt(x**2+y**2)
|
||||
|
||||
phi_null = arctan2(z, p*(1 - self.e**2))
|
||||
|
||||
hi = [0]
|
||||
phii = [phi_null]
|
||||
|
||||
i = 0
|
||||
|
||||
while True:
|
||||
N = self.a / sqrt(1 - self.e**2 * sin(phii[i])**2)
|
||||
h = p / cos(phii[i]) - N
|
||||
phi = arctan2(z, p * (1-(self.e**2*N) / (N+h)))
|
||||
hi.append(h)
|
||||
phii.append(phi)
|
||||
dh = abs(hi[i]-h)
|
||||
dphi = abs(phii[i]-phi)
|
||||
i += 1
|
||||
if dh < Eh:
|
||||
if dphi < Ephi:
|
||||
break
|
||||
return phi, lamb, h
|
||||
|
||||
def bi_ell2cart(self, phi: float, lamb: float, h: float) -> NDArray:
|
||||
"""
|
||||
Umrechnung von ellipsoidischen in kartesische Koordinaten auf einem Rotationsellipsoid
|
||||
# TODO: Quelle
|
||||
:param phi: ellipsoidische Breite
|
||||
:param lamb: ellipsoidische Länge
|
||||
:param h: geodätische Höhe
|
||||
:return: Punkt in kartesischen Koordinaten
|
||||
"""
|
||||
W = sqrt(1 - self.e**2 * sin(phi)**2)
|
||||
N = self.a / W
|
||||
x = (N+h) * cos(phi) * cos(lamb)
|
||||
y = (N+h) * cos(phi) * sin(lamb)
|
||||
z = (N * (1-self.e**2) + h) * sin(phi)
|
||||
return np.array([x, y, z])
|
||||
@@ -1,7 +1,9 @@
|
||||
import numpy as np
|
||||
from numpy import sqrt, arctan2, sin, cos, arcsin, arccos
|
||||
from numpy.typing import NDArray
|
||||
from typing import Tuple
|
||||
|
||||
import numpy as np
|
||||
from numpy import arccos, arcsin, arctan2, cos, pi, sin, sqrt
|
||||
from numpy.typing import NDArray
|
||||
|
||||
import winkelumrechnungen as wu
|
||||
|
||||
|
||||
@@ -77,7 +79,7 @@ def gha2(R: float, phi0: float, lamb0: float, phi1: float, lamb1: float) -> Tupl
|
||||
alpha1 = arctan2(-cos(phi0) * sin(lamb1 - lamb0),
|
||||
cos(phi1) * sin(phi0) - sin(phi1) * cos(phi0) * cos(lamb1 - lamb0))
|
||||
if alpha1 < 0:
|
||||
alpha1 += 2 * np.pi
|
||||
alpha1 += 2 * pi
|
||||
|
||||
return alpha0, alpha1, s
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import plotly.graph_objects as go\n",
|
||||
"import numpy as np\n",
|
||||
"from ellipsoide import EllipsoidTriaxial\n",
|
||||
"import winkelumrechnungen as wu"
|
||||
"import plotly.graph_objects as go\n",
|
||||
"\n",
|
||||
"import winkelumrechnungen as wu\n",
|
||||
"from ellipsoid_triaxial import EllipsoidTriaxial"
|
||||
],
|
||||
"id": "731173e4745cfe7c",
|
||||
"outputs": [],
|
||||
8
nicht abgeben/test.py
Normal file
8
nicht abgeben/test.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import numpy as np
|
||||
|
||||
import ellipsoid_triaxial
|
||||
|
||||
ell = ellipsoid_triaxial.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
|
||||
cart = ell.para2cart(0, np.pi/2)
|
||||
print(cart)
|
||||
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
numpy~=2.3.4
|
||||
plotly~=6.4.0
|
||||
pandas~=2.3.3
|
||||
scipy~=1.16.3
|
||||
dash-bootstrap-components~=2.0.4
|
||||
dash~=4.0.0
|
||||
matplotlib~=3.10.7
|
||||
@@ -1,7 +1,10 @@
|
||||
from typing import Callable
|
||||
|
||||
import numpy as np
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool = False) -> tuple[list, list]:
|
||||
def rk4(ode: Callable, t0: float, v0: NDArray, weite: float, schritte: int, fein: bool = False) -> tuple[list, list]:
|
||||
"""
|
||||
Standard Runge-Kutta Verfahren 4. Ordnung
|
||||
:param ode: ODE-System als Funktion
|
||||
@@ -9,7 +12,7 @@ def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool
|
||||
:param v0: Startwerte
|
||||
:param weite: Integrationsweite
|
||||
:param schritte: Schrittzahl
|
||||
:param fein:
|
||||
:param fein: Fein-Rechnung?
|
||||
:return: Variable und Funktionswerte an jedem Stützpunkt
|
||||
"""
|
||||
h = weite/schritte
|
||||
@@ -35,14 +38,32 @@ def rk4(ode, t0: float, v0: np.ndarray, weite: float, schritte: int, fein: bool
|
||||
|
||||
return t_list, werte
|
||||
|
||||
def rk4_step(ode, t: float, v: np.ndarray, h: float) -> np.ndarray:
|
||||
def rk4_step(ode: Callable, t: float, v: NDArray, h: float) -> NDArray:
|
||||
"""
|
||||
Ein Schritt des Runge-Kutta Verfahrens 4. Ordnung
|
||||
:param ode: ODE-System als Funktion
|
||||
:param t: unabhängige Variable
|
||||
:param v: abhängige Variablen
|
||||
:param h: Schrittweite
|
||||
:return: abhängige Variablen nach einem Schritt
|
||||
"""
|
||||
k1 = ode(t, v)
|
||||
k2 = ode(t + 0.5 * h, v + 0.5 * h * k1)
|
||||
k3 = ode(t + 0.5 * h, v + 0.5 * h * k2)
|
||||
k4 = ode(t + h, v + h * k3)
|
||||
return v + (h / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
|
||||
|
||||
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
|
||||
t = float(t0)
|
||||
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
|
||||
|
||||
# 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
|
||||
habs = abs(h)
|
||||
|
||||
|
||||
7
test.py
7
test.py
@@ -1,7 +0,0 @@
|
||||
import numpy as np
|
||||
import ellipsoide
|
||||
|
||||
ell = ellipsoide.EllipsoidTriaxial.init_name("KarneyTest2024")
|
||||
|
||||
cart = ell.para2cart(0, np.pi/2)
|
||||
print(cart)
|
||||
@@ -1,13 +1,54 @@
|
||||
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)
|
||||
|
||||
|
||||
def cot(a):
|
||||
return np.cos(a) / np.sin(a)
|
||||
def cot(x: float) -> float:
|
||||
"""
|
||||
Berechnung von cot eines Winkels
|
||||
:param x: Winkel
|
||||
:return: cot(Winkel)
|
||||
"""
|
||||
return np.cos(x) / np.sin(x)
|
||||
|
||||
|
||||
def wrap_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
|
||||
|
||||
|
||||
def wrap_mhalfpi_halfpi(x: float) -> float:
|
||||
"""
|
||||
Wrap eines Winkels in den Wertebereich [-π/2, π/2)
|
||||
:param x: Winkel
|
||||
:return: Winkel in [-π/2, π/2)
|
||||
"""
|
||||
return (x + np.pi / 2) % np.pi - np.pi / 2
|
||||
|
||||
|
||||
def wrap_0_2pi(x: float) -> float:
|
||||
"""
|
||||
Wrap eines Winkels in den Wertebereich [0, 2π)
|
||||
:param x: Winkel
|
||||
:return: Winkel in [0, 2π)
|
||||
"""
|
||||
return x % (2 * np.pi)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(wu.rad2deg(wrap_mhalfpi_halfpi(wu.deg2rad(181))))
|
||||
print(wu.rad2deg(wrap_0_2pi(wu.deg2rad(181))))
|
||||
print(wu.rad2deg(wrap_mpi_pi(wu.deg2rad(181))))
|
||||
|
||||
Reference in New Issue
Block a user