Merge remote-tracking branch 'origin/main'

# Conflicts:
#	Hansen_ES_CMA.py
#	dashboard.py
This commit is contained in:
2026-01-12 15:27:06 +01:00
2 changed files with 479 additions and 167 deletions

View File

@@ -1,5 +1,5 @@
import numpy as np import numpy as np
from typing import Callable
def felli(x): def felli(x):
N = x.shape[0] N = x.shape[0]
@@ -9,16 +9,24 @@ def felli(x):
return float(np.sum((1e6 ** exponents) * (x ** 2))) return float(np.sum((1e6 ** exponents) * (x ** 2)))
def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval, def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None,
bestEver = np.inf, noImproveGen = 0, absTolImprove = 1e-10, maxNoImproveGen = 100, sigmaImprove = 1e-12): func_args=(), func_kwargs=None, seed=None):
#Initialization
# User defined input parameters if func_kwargs is None:
# N = 10 func_kwargs = {}
# xmean = np.random.rand(N)
# sigma = 0.5 if seed is not None:
# stopfitness = 1e-10 np.random.seed(seed)
# stopeval = int(1e3 * N**2)
# Initialization (aus Parametern statt hart verdrahtet)
if xmean is None:
xmean = np.random.rand(N)
else:
xmean = np.asarray(xmean, dtype=float)
N = xmean.shape[0]
if stopeval is None:
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)))
@@ -47,7 +55,7 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
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
arx = np.zeros((N, lambda_)) arx = np.zeros((N, lambda_))
arz = np.zeros((N, lambda_)) arz = np.zeros((N, lambda_))
@@ -64,7 +72,7 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
for k in range(lambda_): for k in range(lambda_):
arz[:, k] = np.random.randn(N) arz[:, k] = np.random.randn(N)
arx[:, k] = xmean + sigma * (B @ D @ arz[:, k]) arx[:, k] = xmean + sigma * (B @ D @ arz[:, k])
arfitness[k] = fitnessfct(arx[:, k]) arfitness[k] = float(func(arx[:, k], *func_args, **func_kwargs)) # <-- allgemein
counteval += 1 counteval += 1
# Sort by fitness and compute weighted mean into xmean # Sort by fitness and compute weighted mean into xmean
@@ -145,6 +153,6 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
if __name__ == "__main__": if __name__ == "__main__":
xmin = escma() xmin = escma(felli, N=10) # <-- Zielfunktion wird übergeben
print("Bestes gefundenes x:", xmin) print("Bestes gefundenes x:", xmin)
print("f(xmin) =", felli(xmin)) print("f(xmin) =", felli(xmin))

View File

@@ -3,14 +3,16 @@ import dash
import plotly.graph_objects as go import plotly.graph_objects as go
import numpy as np import numpy as np
from GHA_triaxial.panou import gha1_ana
from GHA_triaxial.panou import gha1_num
from GHA_triaxial.panou_2013_2GHA_num import gha2_num
from GHA_triaxial.ES_gha2 import gha2_ES
from ellipsoide import EllipsoidTriaxial from ellipsoide import EllipsoidTriaxial
import winkelumrechnungen as wu import winkelumrechnungen as wu
import ausgaben as aus import ausgaben as aus
from GHA_triaxial.panou import gha1_ana
from GHA_triaxial.panou import gha1_num
from es_cma_gha1 import gha1_es
from GHA_triaxial.panou_2013_2GHA_num import gha2_num
app = Dash(__name__, suppress_callback_exceptions=True) app = Dash(__name__, suppress_callback_exceptions=True)
app.title = "Geodätische Hauptaufgaben" app.title = "Geodätische Hauptaufgaben"
@@ -115,6 +117,7 @@ def figure_constant_lines(fig, ell: EllipsoidTriaxial, coordsystem: str = "para"
return fig return fig
def figure_points(fig, points): def figure_points(fig, points):
""" """
@@ -151,12 +154,15 @@ def figure_lines(fig, line, color):
return fig return fig
# HTML-Elemente
app.layout = html.Div( app.layout = html.Div(
style={"fontFamily": "Arial", "padding": "5px", "width": "70%", "margin-left": "auto"}, style={"fontFamily": "Arial", "padding": "5px", "width": "70%", "margin-left": "auto"},
children=[ children=[
html.H1("Geodätische Hauptaufgaben"), html.H1("Geodätische Hauptaufgaben"),
html.H2("für dreiachsige Ellipsoide"), html.H2("für dreiachsige Ellipsoide"),
# Dropdown und Eingabefelder Ellipsoid
html.Label("Ellipsoid wählen:"), html.Label("Ellipsoid wählen:"),
dcc.Dropdown( dcc.Dropdown(
id="dropdown-ellipsoid", id="dropdown-ellipsoid",
@@ -169,8 +175,7 @@ app.layout = html.Div(
{"label": "Bursa1970", "value": "Bursa1970"}, {"label": "Bursa1970", "value": "Bursa1970"},
{"label": "BesselBiaxial", "value": "BesselBiaxial"}, {"label": "BesselBiaxial", "value": "BesselBiaxial"},
{"label": "Fiction", "value": "Fiction"}, {"label": "Fiction", "value": "Fiction"},
{"label": "KarneyTest2024", "value": "KarneyTest2024"}, #{"label": "Ei", "value": "Ei"},
# {"label": "Ei", "value": "Ei"},
], ],
value="", value="",
style={"width": "300px", "marginBottom": "20px"}, style={"width": "300px", "marginBottom": "20px"},
@@ -206,8 +211,10 @@ app.layout = html.Div(
style={"marginRight": "10px", "marginBottom": "20px"}, style={"marginRight": "10px", "marginBottom": "20px"},
), ),
# Ausgabebereich für Ellipsoid-Berechnung
html.Div(id="output-area", style={"marginBottom": "20px"}), html.Div(id="output-area", style={"marginBottom": "20px"}),
# Tabs für beide Hauptaufgaben - Inhalt wird per Funktion generiert s.u.
dcc.Tabs( dcc.Tabs(
id="tabs-GHA", id="tabs-GHA",
value="tab-GHA1", value="tab-GHA1",
@@ -223,15 +230,28 @@ app.layout = html.Div(
style={"marginRight": "10px", "marginBottom": "20px", "width": "50%"}, style={"marginRight": "10px", "marginBottom": "20px", "width": "50%"},
), ),
html.Div(id="output-gha1", style={"marginBottom": "20px"}), dcc.Loading(html.Div(id="output-gha1-ana")),
dcc.Loading(html.Div(id="output-gha1-num")),
dcc.Loading(html.Div(id="output-gha1-stoch")),
html.Div(id="output-gha2", style={"marginBottom": "20px"}), dcc.Store(id="store-gha1-ana"),
dcc.Store(id="store-gha1-num"),
dcc.Store(id="store-gha1-stoch"),
dcc.Loading(html.Div(id="output-gha2-num")),
dcc.Loading(html.Div(id="output-gha2-stoch")),
dcc.Store(id="store-gha2-num"),
dcc.Store(id="store-gha2-stoch"),
# Ausgabebereich für den Plot
dcc.Graph( dcc.Graph(
id="ellipsoid-plot", id="ellipsoid-plot",
style={"height": "500px", "width": "700px"}, style={"height": "500px", "width": "700px"},
), ),
# Fussleiste
html.P( html.P(
"© 2025", "© 2025",
style={ style={
@@ -243,7 +263,7 @@ app.layout = html.Div(
], ],
) )
# Funktion zur Wahl der Halbachsen
@app.callback( @app.callback(
Output("input-ax", "value"), Output("input-ax", "value"),
Output("input-ay", "value"), Output("input-ay", "value"),
@@ -254,13 +274,14 @@ def fill_inputs_from_dropdown(selected_ell):
if not selected_ell: if not selected_ell:
return None, None, None return None, None, None
ell = EllipsoidTriaxial.init_name(selected_ell) ell = EllipsoidTriaxial.init_name(selected_ell)
ax = ell.ax ax = ell.ax
ay = ell.ay ay = ell.ay
b = ell.b b = ell.b
return ax, ay, b return ax, ay, b
# Funktion zur Berechnung der Ellipsoid-Parameter
@app.callback( @app.callback(
Output("output-area", "children"), Output("output-area", "children"),
Input("calc-ell", "n_clicks"), Input("calc-ell", "n_clicks"),
@@ -276,8 +297,16 @@ def update_output(n_clicks, ax, ay, b):
if ay >= ax or b >= ay or ax <= 0 or ay <= 0 or b <= 0: if ay >= ax or b >= ay or ax <= 0 or ay <= 0 or b <= 0:
return html.Span("Eingabe inkorrekt.", style={"color": "red"}) return html.Span("Eingabe inkorrekt.", style={"color": "red"})
ell = EllipsoidTriaxial(ax, ay, b) ell = EllipsoidTriaxial(ax, ay, b)
return f"eₓ = {round(ell.ex, 6)}, ", f"eᵧ = {round(ell.ey, 6)}, ", f"eₑ = {round(ell.ee, 6)}" out_ell = []
out_ell.append(
html.Div([
html.P(f"eₓ = {round(ell.ex, 6)}, eᵧ = {round(ell.ey, 6)}, eₑ = {round(ell.ee, 6)}"),
#html.Br(),
html.P(f"Eₓ = {round(ell.Ex, 3)}, Eᵧ = {round(ell.Ey, 3)}, Eₑ = {round(ell.Ee, 3)}"),
]))
return out_ell
# Funktion zur Generierung der Tab-Inhalte
@app.callback( @app.callback(
Output("tabs-GHA-out", "children"), Output("tabs-GHA-out", "children"),
Input("tabs-GHA", "value"), Input("tabs-GHA", "value"),
@@ -318,6 +347,7 @@ def render_content(tab):
], ],
style={"marginBottom": "20px"}, style={"marginBottom": "20px"},
), ),
html.H4("Erste Hauptaufgabe"),
], ],
id="pane-gha1", id="pane-gha1",
style=show1, style=show1,
@@ -354,6 +384,7 @@ def render_content(tab):
], ],
style={"marginBottom": "20px"}, style={"marginBottom": "20px"},
), ),
html.H4("Zweite Hauptaufgabe"),
], ],
id="pane-gha2", id="pane-gha2",
style=show2, style=show2,
@@ -361,17 +392,341 @@ def render_content(tab):
return html.Div([pane_gha1, pane_gha2]) return html.Div([pane_gha1, pane_gha2])
# Funktion zur Berechnung der Hauptaufgaben
# @app.callback(
# Output("output-gha1", "children"),
# Output("output-gha2", "children"),
# Output("ellipsoid-plot", "figure"),
# Input("button-calc-gha1", "n_clicks"),
# Input("button-calc-gha2", "n_clicks"),
# State("input-GHA1-beta1", "value"),
# State("input-GHA1-lamb1", "value"),
# State("input-GHA1-s", "value"),
# State("input-GHA1-a", "value"),
# State("input-GHA2-beta1", "value"),
# State("input-GHA2-lamb1", "value"),
# State("input-GHA2-beta2", "value"),
# State("input-GHA2-lamb2", "value"),
# State("input-ax", "value"),
# State("input-ay", "value"),
# State("input-b", "value"),
# State("method-checklist-1", "value"),
# State("method-checklist-2", "value"),
#
# prevent_initial_call=True,
# )
#
# def calc_and_plot(n1, n2,
# beta11, lamb11, s, a_deg,
# beta21, lamb21, beta22, lamb22,
# ax, ay, b, method1, method2):
#
# if not (n1 or n2):
# return no_update, no_update, no_update
#
# if not ax or not ay or not b:
# return html.Span("Bitte Ellipsoid auswählen!", style={"color": "red"}), "", go.Figure()
#
# ell = EllipsoidTriaxial(ax, ay, b)
#
# if dash.ctx.triggered_id == "button-calc-gha1":
# if None in (beta11, lamb11, s, a_deg):
#
# return html.Span("Bitte β₁, λ₁, s und α eingeben.", style={"color": "red"}), "", go.Figure()
#
# beta_rad = wu.deg2rad(float(beta11))
# lamb_rad = wu.deg2rad(float(lamb11))
# alpha_rad = wu.deg2rad(float(a_deg))
# s_val = float(s)
#
# p1 = tuple(map(float, ell.ell2cart(beta_rad, lamb_rad)))
# out1 = []
#
# if "analytisch" in method1:
# # ana
# x2, y2, z2 = gha1_ana(ell, p1, alpha_rad, s_val, 70)
# p2_ana = (float(x2), float(y2), float(z2))
# beta2, lamb2 = ell.cart2ell([x2, y2, z2])
#
# #out1 += f"kartesisch: x₂={p2[0]:.5f} m, y₂={p2[1]:.5f} m, z₂={p2[2]:.5f} m; ellipsoidisch: {aus.gms("β₂", beta2, 5)}, {aus.gms("λ₂", lamb2, 5)},"
# out1.append(
# html.Div([
# html.Strong("Analytisch: "),
# html.Br(),
# html.Span(f"kartesisch: x₂={x2:.4f} m, y₂={y2:.4f} m, z₂={z2:.4f} m"),
# html.Br(),
# html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2, 4)}, {aus.gms('λ₂', lamb2, 4)}")
# ])
# )
#
# if "numerisch" in method1:
# # num
# x1, y1, z1, werte = gha1_num(ell, p1, alpha_rad, s_val, 10000)
# p2_num = x1, y1, z1
# beta2_num, lamb2_num = ell.cart2ell(p2_num)
#
# out1.append(
# html.Div([
# html.Strong("Numerisch: "),
# html.Br(),
# html.Span(f"kartesisch: x₂={p2_num[0]:.4f} m, y₂={p2_num[1]:.4f} m, z₂={p2_num[2]:.4f} m"),
# html.Br(),
# html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2_num, 4)}, {aus.gms('λ₂', lamb2_num, 4)}")
# ])
# )
#
# geo_line_num1 = []
# for x1, _, y1, _, z1, _ in werte:
# geo_line_num1.append([x1, y1, z1])
#
#
# if "stochastisch" in method1:
# # stoch
# p2_stoch = "noch nicht implementiert.."
#
# out1.append(
# html.Div([
# html.Strong("Stochastisch (ES): "),
# html.Span(f"{p2_stoch}")
# ])
# )
#
# if not method1:
# return html.Span("Bitte Berechnungsverfahren auswählen!", style={"color": "red"}), "", go.Figure()
#
# fig = ellipsoid_figure(ell, title="Erste Hauptaufgabe - analytisch")
# #fig = figure_constant_lines(fig, ell, "geod")
# fig = figure_constant_lines(fig, ell, "ell")
# #fig = figure_constant_lines(fig, ell, "para")
# if "analytisch" in method1:
# fig = figure_points(fig, [("P1", p1, "black"), ("P2", p2_ana, "red")])
# if "numerisch" in method1:
# fig = figure_lines(fig, geo_line_num1, "#ff8c00")
#
# #out1 = f"kartesisch: x₂={p2[0]:.5f} m, y₂={p2[1]:.5f} m, z₂={p2[2]:.5f} m; ellipsoidisch: {aus.gms("β₂", beta2, 5)}, {aus.gms("λ₂", lamb2, 5)}, {p2_num}"
# return out1, "", fig
#
# if dash.ctx.triggered_id == "button-calc-gha2":
# if None in (beta21, lamb21, beta22, lamb22):
# return html.Span("Bitte β₁, λ₁, β₂, λ₂ eingeben.", style={"color": "red"}), "", go.Figure()
#
# p1 = tuple(ell.ell2cart(np.deg2rad(float(beta21)), np.deg2rad(float(lamb21))))
# p2 = tuple(ell.ell2cart(np.deg2rad(float(beta22)), np.deg2rad(float(lamb22))))
#
# out2 = []
#
# if "numerisch" in method2:
# alpha_1, alpha_2, s12, beta_arr, lamb_arr = gha2_num(
# ell,
# np.deg2rad(float(beta21)), np.deg2rad(float(lamb21)),
# np.deg2rad(float(beta22)), np.deg2rad(float(lamb22))
# )
# geo_line_num = []
# for beta, lamb in zip(beta_arr, lamb_arr):
# point = ell.ell2cart(beta, lamb)
# geo_line_num.append(point)
#
# out2.append(
# html.Div([
# html.Strong("Numerisch: "),
# html.Span(f"{aus.gms('α₁₂', alpha_1, 4)}, {aus.gms('α₂₁', alpha_2, 4)}, s = {s12:.4f} m"),
# ])
# )
#
#
# if "stochastisch" in method2:
# # stoch
# a_stoch = "noch nicht implementiert.."
#
# out2.append(
# html.Div([
# html.Strong("Stochastisch (ES): "),
# html.Span(f"{a_stoch}")
# ])
# )
#
# if not method2:
# return html.Span("Bitte Berechnungsverfahren auswählen!", style={"color": "red"}), "", go.Figure()
#
# fig = ellipsoid_figure(ell, title="Zweite Hauptaufgabe")
# fig = figure_constant_lines(fig, ell, "ell")
# if "numerisch" in method2:
# fig = figure_lines(fig, geo_line_num, "#ff8c00")
# fig = figure_points(fig, [("P1", p1, "black"), ("P2", p2, "red")])
#
#
#
# return "", out2, fig
#
# return no_update, no_update, no_update
# -- GHA 1 ---
@app.callback( @app.callback(
Output("output-gha1", "children"), Output("output-gha1-ana", "children"),
Output("output-gha2", "children"), Output("store-gha1-ana", "data"),
Output("ellipsoid-plot", "figure"),
Input("button-calc-gha1", "n_clicks"), Input("button-calc-gha1", "n_clicks"),
Input("button-calc-gha2", "n_clicks"),
State("input-GHA1-beta1", "value"), State("input-GHA1-beta1", "value"),
State("input-GHA1-lamb1", "value"), State("input-GHA1-lamb1", "value"),
State("input-GHA1-s", "value"), State("input-GHA1-s", "value"),
State("input-GHA1-a", "value"), State("input-GHA1-a", "value"),
State("input-ax", "value"),
State("input-ay", "value"),
State("input-b", "value"),
State("method-checklist-1", "value"),
prevent_initial_call=True,
)
def compute_gha1_ana(n1, beta11, lamb11, s, a_deg, ax, ay, b, method1):
if not n1:
return no_update, no_update
if None in (ax, ay, b):
return html.Span("Bitte Ellipsoid wählen.", style={"color": "red"}), None
if None in (beta11, lamb11, s, a_deg):
return html.Span("Bitte β₁, λ₁, s und α eingeben.", style={"color": "red"}), None
if not method1:
return html.Span("Bitte Berechnungsverfahren wählen.", style={"color": "red"}), None
if "analytisch" not in (method1 or []):
return no_update, no_update
ell = EllipsoidTriaxial(ax, ay, b)
beta_rad = wu.deg2rad(float(beta11))
lamb_rad = wu.deg2rad(float(lamb11))
alpha_rad = wu.deg2rad(float(a_deg))
s_val = float(s)
p1 = tuple(map(float, ell.ell2cart(beta_rad, lamb_rad)))
x2, y2, z2 = gha1_ana(ell, p1, alpha_rad, s_val, 70)
p2 = (float(x2), float(y2), float(z2))
beta2, lamb2 = ell.cart2ell([x2, y2, z2])
out = html.Div([
html.Strong("Analytisch: "),
html.Br(),
html.Span(f"kartesisch: x₂={x2:.4f} m, y₂={y2:.4f} m, z₂={z2:.4f} m"),
html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2, 4)}, {aus.gms('λ₂', lamb2, 4)}"),
html.Br(),
])
store = {
"points": [("P1", p1, "black"), ("P2", p2, "red")],
"polyline": None,
"color": "#d62728"
}
return out, store
@app.callback(
Output("output-gha1-num", "children"),
Output("store-gha1-num", "data"),
Input("button-calc-gha1", "n_clicks"),
State("input-GHA1-beta1", "value"),
State("input-GHA1-lamb1", "value"),
State("input-GHA1-s", "value"),
State("input-GHA1-a", "value"),
State("input-ax", "value"),
State("input-ay", "value"),
State("input-b", "value"),
State("method-checklist-1", "value"),
prevent_initial_call=True,
)
def compute_gha1_num(n1, beta11, lamb11, s, a_deg, ax, ay, b, method1):
if not n1:
return no_update, no_update
if "numerisch" not in (method1 or []):
return no_update, no_update
ell = EllipsoidTriaxial(ax, ay, b)
beta_rad = wu.deg2rad(float(beta11))
lamb_rad = wu.deg2rad(float(lamb11))
alpha_rad = wu.deg2rad(float(a_deg))
s_val = float(s)
p1 = tuple(map(float, ell.ell2cart(beta_rad, lamb_rad)))
xN, yN, zN, werte = gha1_num(ell, p1, alpha_rad, s_val, 10000)
p2 = (xN, yN, zN)
beta2_num, lamb2_num = ell.cart2ell(p2)
out = html.Div([
html.Strong("Numerisch: "),
html.Br(),
html.Span(f"kartesisch: x₂={p2[0]:.4f} m, y₂={p2[1]:.4f} m, z₂={p2[2]:.4f} m"),
html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2_num, 4)}, {aus.gms('λ₂', lamb2_num, 4)}"),
html.Br(),
])
polyline = [[x1, y1, z1] for x1, _, y1, _, z1, _ in werte]
store = {
"points": [("P1", p1, "black"), ("P2", p2, "#ff8c00")],
"polyline": polyline,
"color": "#ff8c00"
}
return out, store
@app.callback(
Output("output-gha1-stoch", "children"),
Output("store-gha1-stoch", "data"),
Input("button-calc-gha1", "n_clicks"),
State("input-GHA1-beta1", "value"),
State("input-GHA1-lamb1", "value"),
State("input-GHA1-s", "value"),
State("input-GHA1-a", "value"),
State("input-ax", "value"),
State("input-ay", "value"),
State("input-b", "value"),
State("method-checklist-1", "value"),
prevent_initial_call=True,
)
def compute_gha1_stoch(n1, beta11, lamb11, s, a_deg, ax, ay, b, method1):
if not n1:
return no_update, no_update
if "stochastisch" not in (method1 or []):
return no_update, no_update
ell = EllipsoidTriaxial(ax, ay, b)
beta_rad = wu.deg2rad(float(beta11))
lamb_rad = wu.deg2rad(float(lamb11))
alpha_rad = wu.deg2rad(float(a_deg))
s_val = float(s)
betas, lambs, alphas, S_real = gha1_es(
beta_rad, lamb_rad, alpha_rad,
s_val,
10000,
ell,
sigma0=1e-10
)
beta2 = betas[-1]
lamb2 = lambs[-1]
alpha2 = alphas[-1]
p1 = ell.ell2cart(beta_rad, lamb_rad)
p2 = ell.ell2cart(beta2, lamb2)
x2, y2, z2 = p2[0], p2[1], p2[2]
out = html.Div([
html.Strong("Stochastisch: "),
html.Br(),
html.Span(f"kartesisch: x₂={x2:.4f} m, y₂={y2:.4f} m, z₂={z2:.4f} m"),
html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2, 4)}, {aus.gms('λ₂', lamb2, 4)}"),
])
store = {
"points": [("P1", p1, "black"), ("P2", p2, "red")],
"polyline": None,
"color": "#d62728"
}
return out, store
# --- GHA 2 ---
@app.callback(
Output("output-gha2-num", "children"),
Output("store-gha2-num", "data"),
Input("button-calc-gha2", "n_clicks"),
State("input-GHA2-beta1", "value"), State("input-GHA2-beta1", "value"),
State("input-GHA2-lamb1", "value"), State("input-GHA2-lamb1", "value"),
State("input-GHA2-beta2", "value"), State("input-GHA2-beta2", "value"),
@@ -379,163 +734,112 @@ def render_content(tab):
State("input-ax", "value"), State("input-ax", "value"),
State("input-ay", "value"), State("input-ay", "value"),
State("input-b", "value"), State("input-b", "value"),
State("method-checklist-1", "value"),
State("method-checklist-2", "value"), State("method-checklist-2", "value"),
prevent_initial_call=True, prevent_initial_call=True,
) )
def calc_and_plot(n1, n2, def compute_gha2_num(n2, beta1, lamb1, beta2, lamb2, ax, ay, b, method2):
beta11, lamb11, s, a_deg, if not n2:
beta21, lamb21, beta22, lamb22, return no_update, no_update
ax, ay, b, method1, method2): if None in (ax, ay, b):
return html.Span("Bitte Ellipsoid wählen.", style={"color": "red"}), None
if not (n1 or n2): if None in (beta1, lamb1, beta2, lamb2):
return no_update, no_update, no_update return html.Span("Bitte β₁, λ₁, β₂ und λ₂ eingeben.", style={"color": "red"}), None
if not method2:
if not ax or not ay or not b: return html.Span("Bitte Berechnungsverfahren wählen.", style={"color": "red"}), None
return html.Span("Bitte Ellipsoid auswählen!", style={"color": "red"}), "", go.Figure() if "numerisch" not in (method2 or []):
return no_update, no_update
ell = EllipsoidTriaxial(ax, ay, b) ell = EllipsoidTriaxial(ax, ay, b)
if dash.ctx.triggered_id == "button-calc-gha1": b1 = wu.deg2rad(float(beta1)); l1 = wu.deg2rad(float(lamb1))
if None in (beta11, lamb11, s, a_deg): b2 = wu.deg2rad(float(beta2)); l2 = wu.deg2rad(float(lamb2))
return html.Span("Bitte β₁, λ₁, s und α eingeben.", style={"color": "red"}), "", go.Figure() p1 = tuple(map(float, ell.ell2cart(b1, l1)))
p2 = tuple(map(float, ell.ell2cart(b2, l2)))
beta_rad = wu.deg2rad(float(beta11)) alpha_1, alpha_2, s12, beta_arr, lamb_arr = gha2_num(ell, b1, l1, b2, l2)
lamb_rad = wu.deg2rad(float(lamb11))
alpha_rad = wu.deg2rad(float(a_deg))
s_val = float(s)
p1 = ell.ell2cart(beta_rad, lamb_rad) # Polyline der Geodäte: [[x,y,z], ...]
out1 = [] polyline = []
for b_rad, l_rad in zip(beta_arr, lamb_arr):
x, y, z = ell.ell2cart(b_rad, l_rad)
polyline.append([float(x), float(y), float(z)])
if "analytisch" in method1: out = html.Div([
# ana html.Strong("Zweite Hauptaufgabe Numerisch: "),
p2_ana, alpha2 = gha1_ana(ell, p1, alpha_rad, s_val, 70) html.Span(f"{aus.gms('α₁₂', alpha_1, 4)}, {aus.gms('α₂₁', alpha_2, 4)}, s = {s12:.4f} m"),
x2, y2, z2 = p2_ana ])
beta2, lamb2 = ell.cart2ell(p2_ana)
# out1 += f"kartesisch: x₂={p2[0]:.5f} m, y₂={p2[1]:.5f} m, z₂={p2[2]:.5f} m; ellipsoidisch: {aus.gms("β₂", beta2, 5)}, {aus.gms("λ₂", lamb2, 5)}," store = {
out1.append( "points": [("P1", p1, "black"), ("P2", p2, "#1f77b4")],
html.Div([ "polyline": polyline,
html.Strong("Analytisch: "), "color": "#1f77b4",
html.Br(), }
html.Span(f"kartesisch: x₂={x2:.4f} m, y₂={y2:.4f} m, z₂={z2:.4f} m"), return out, store
html.Br(),
html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2, 4)}, {aus.gms('λ₂', lamb2, 4)}")
])
)
if "numerisch" in method1: # @app.callback(
# num # Output("output-gha2-stoch", "children"),
p2_num, alpha1, werte = gha1_num(ell, p1, alpha_rad, s_val, 10000, all_points=True) # Output("store-gha2-stoch", "data"),
beta2_num, lamb2_num = ell.cart2ell(p2_num) # Input("button-calc-gha2", "n_clicks"),
# State("input-GHA2-beta1", "value"),
# State("input-GHA2-lamb1", "value"),
# State("input-GHA2-beta2", "value"),
# State("input-GHA2-lamb2", "value"),
# State("input-ax", "value"),
# State("input-ay", "value"),
# State("input-b", "value"),
# State("method-checklist-2", "value"),
# prevent_initial_call=True,
# )
# def compute_gha2_stoch(n2, beta1, lamb1, beta2, lamb2, ax, ay, b, method2):
# if not n2:
# return no_update, no_update
# if "numerisch" not in (method2 or []):
# return no_update, no_update
#
# out = html.Div([
# html.Strong("Zweite Hauptaufgabe Stochastisch (ES): "),
# html.Span("noch nicht implementiert...")
# ])
#
# return out, {"points": None, "polyline": None, "color": "#9467bd"}
out1.append( @app.callback(
html.Div([ Output("ellipsoid-plot", "figure"),
html.Strong("Numerisch: "), Input("input-ax", "value"),
html.Br(), Input("input-ay", "value"),
html.Span(f"kartesisch: x₂={p2_num[0]:.4f} m, y₂={p2_num[1]:.4f} m, z₂={p2_num[2]:.4f} m"), Input("input-b", "value"),
html.Br(), Input("store-gha1-ana", "data"),
html.Span(f"ellipsoidisch: {aus.gms('β₂', beta2_num, 4)}, {aus.gms('λ₂', lamb2_num, 4)}") Input("store-gha1-num", "data"),
]) Input("store-gha2-num", "data"),
) Input("store-gha2-stoch", "data"),
)
def render_all(ax, ay, b, store_gha1_ana, store_gha1_num, store_gha2_num, store_gha2_stoch):
if None in (ax, ay, b):
return go.Figure()
geo_line_num1 = [] ell = EllipsoidTriaxial(ax, ay, b)
for x1, _, y1, _, z1, _ in werte: fig = ellipsoid_figure(ell, title="")
geo_line_num1.append([x1, y1, z1]) fig = figure_constant_lines(fig, ell, "ell")
if "stochastisch" in method1: def add_from_store(store):
# stoch if not store:
p2_stoch = "noch nicht implementiert.." return
pts = store.get("points")
if pts:
fig = figure_points(fig, pts)
line = store.get("polyline")
if line:
fig = figure_lines(fig, line, store.get("color", "#ff8c00"))
return fig
out1.append( for st in (store_gha1_ana, store_gha1_num, store_gha2_num, store_gha2_stoch):
html.Div([ res = add_from_store(st)
html.Strong("Stochastisch (ES): "), if res is not None:
html.Span(f"{p2_stoch}") fig = res
])
)
if not method1: return fig
return html.Span("Bitte Berechnungsverfahren auswählen!", style={"color": "red"}), "", go.Figure()
fig = ellipsoid_figure(ell, title="Erste Hauptaufgabe - analystisch")
# fig = figure_constant_lines(fig, ell, "geod")
fig = figure_constant_lines(fig, ell, "ell")
# fig = figure_constant_lines(fig, ell, "para")
if "analytisch" in method1:
fig = figure_points(fig, [("P1", p1, "black"), ("P2", p2_ana, "red")])
if "numerisch" in method1:
fig = figure_lines(fig, geo_line_num1, "#ff8c00")
# out1 = f"kartesisch: x₂={p2[0]:.5f} m, y₂={p2[1]:.5f} m, z₂={p2[2]:.5f} m; ellipsoidisch: {aus.gms("β₂", beta2, 5)}, {aus.gms("λ₂", lamb2, 5)}, {p2_num}"
return out1, "", fig
if dash.ctx.triggered_id == "button-calc-gha2":
if None in (beta21, lamb21, beta22, lamb22):
return html.Span("Bitte β₁, λ₁, β₂, λ₂ eingeben.", style={"color": "red"}), "", go.Figure()
p1 = tuple(ell.ell2cart(np.deg2rad(float(beta21)), np.deg2rad(float(lamb21))))
p2 = tuple(ell.ell2cart(np.deg2rad(float(beta22)), np.deg2rad(float(lamb22))))
out2 = []
if "numerisch" in method2:
alpha_1, alpha_2, s12, beta_arr, lamb_arr = gha2_num(
ell,
np.deg2rad(float(beta21)), np.deg2rad(float(lamb21)),
np.deg2rad(float(beta22)), np.deg2rad(float(lamb22)),
all_points=True
)
geo_line_num = []
for beta, lamb in zip(beta_arr, lamb_arr):
point = ell.ell2cart(beta, lamb)
geo_line_num.append(point)
out2.append(
html.Div([
html.Strong("Numerisch: "),
html.Span(f"{aus.gms('α₁₂', alpha_1, 4)}, {aus.gms('α₂₁', alpha_2, 4)}, s = {s12:.4f} m"),
])
)
if "stochastisch" in method2:
beta0 = np.deg2rad(float(beta21))
lamb0 = np.deg2rad(float(lamb21))
beta1 = np.deg2rad(float(beta22))
lamb1 = np.deg2rad(float(lamb22))
alpha_1, alpha_2, s12, geo_line_es = gha2_ES(
ell,
ell.ell2cart(beta0, lamb0),
ell.ell2cart(beta1, lamb1),
all_points=True
)
alpha_1 = 1
alpha_2 = 2
out2.append(
html.Div([
html.Strong("Stochastisch (ES): "),
html.Span(f"{aus.gms('α₁₂', alpha_1, 4)}, {aus.gms('α₂₁', alpha_2, 4)}, s = {s12:.4f} m"),
])
)
if not method2:
return html.Span("Bitte Berechnungsverfahren auswählen!", style={"color": "red"}), "", go.Figure()
fig = ellipsoid_figure(ell, title="Zweite Hauptaufgabe")
fig = figure_constant_lines(fig, ell, "ell")
if "numerisch" in method2:
fig = figure_lines(fig, geo_line_num, "#ff8c00")
if "stochastisch" in method2:
fig = figure_lines(fig, geo_line_es, "#ff8c00")
fig = figure_points(fig, [("P1", p1, "black"), ("P2", p2, "red")])
return "", out2, fig
return no_update, no_update, no_update
if __name__ == "__main__": if __name__ == "__main__":