Exceptions einheitlich

This commit is contained in:
2026-02-07 19:34:54 +01:00
parent 49d03786dc
commit 322ac94299
8 changed files with 153 additions and 250 deletions

View File

@@ -114,6 +114,7 @@
"# test = \"Karney\"\n",
"# test = \"Panou\"\n",
"test = \"Random\"\n",
"\n",
"if test == \"Karney\":\n",
" ell: EllipsoidTriaxial = EllipsoidTriaxial.init_name(\"KarneyTest2024\")\n",
" examples = get_examples_karney(4, seed=42)\n",
@@ -128,9 +129,9 @@
" examples.append(example)\n",
"elif test == \"Random\":\n",
" ell: EllipsoidTriaxial = EllipsoidTriaxial.init_name(\"BursaSima1980round\")\n",
" examples = [] # beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s\n",
" examples = []\n",
" random.seed(42)\n",
" for _ in range(30):\n",
" for _ in range(50):\n",
" beta0 = wu.deg2rad(random.randint(-90, 90))\n",
" lamb0 = wu.deg2rad(random.randint(-179, 180))\n",
" alpha0_ell = wu.deg2rad(random.randint(0, 359))\n",
@@ -151,134 +152,154 @@
},
"cell_type": "code",
"source": [
"if test != \"Random\":\n",
" results = {}\n",
" for i, example in enumerate(examples):\n",
" print(f\"----- Beispiel {i+1}/{len(examples)}\")\n",
" example_results = {}\n",
"results = {}\n",
"for i, example in enumerate(examples):\n",
" print(f\"----- Beispiel {i+1}/{len(examples)}\")\n",
" example_results = {}\n",
"\n",
" if test != \"Random\":\n",
" beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example\n",
" P0 = ell.ell2cart(beta0, lamb0)\n",
" P1 = ell.ell2cart(beta1, lamb1)\n",
" _, _, alpha0_para = alpha_ell2para(ell, beta0, lamb0, alpha0_ell)\n",
" else:\n",
" beta0, lamb0, alpha0_ell, s = example\n",
" P0 = ell.ell2cart(beta0, lamb0)\n",
" _, _, alpha0_para = alpha_ell2para(ell, beta0, lamb0, alpha0_ell)\n",
"\n",
" for steps in steps_gha1_num:\n",
" # try:\n",
" # P1, alpha1_para = gha1_ana(ell, P0, alpha0_para, s, maxM=80, maxPartCircum=8)\n",
" # beta1, lamb1 = ell.cart2ell(P1)\n",
" # u1, v1 = ell.cart2para(P1)\n",
" # _, _, alpha1_ell = alpha_para2ell(ell, u1, v1, alpha1_para)\n",
" # except Exception as e:\n",
" # print(\"Referenz-Berechnung analytisch fehlgeschlagen: \", e)\n",
" # continue\n",
"\n",
" try:\n",
" P1, alpha1_ell = gha1_num(ell, P0, alpha0_ell, s, num=10000)\n",
" beta1, lamb1 = ell.cart2ell(P1)\n",
" except Exception as e:\n",
" print(\"Referenz-Berechnung numerisch fehlgeschlagen: \", e)\n",
" continue\n",
"\n",
" for steps in steps_gha1_num:\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_num, alpha1_num_1 = gha1_num(ell, P0, alpha0_ell, s, num=steps)\n",
" print(f\"GHA1_num_{steps}\", P1_num)\n",
" end = time.perf_counter()\n",
" beta1_num, lamb1_num = ell.cart2ell(P1_num)\n",
" d_beta1 = abs(beta1_num - beta1)\n",
" d_lamb1 = abs(lamb1_num - lamb1)\n",
" d_alpha1 = abs(alpha1_num_1 - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_num_{steps}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_num_{steps}\"] = (nan, nan, nan, nan)\n",
"\n",
" for maxM in maxM_gha1_ana:\n",
" for parts in parts_gha1_ana:\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_num, alpha1_num_1 = gha1_num(ell, P0, alpha0_ell, s, num=steps)\n",
" print(f\"GHA1_num_{steps}\", P1_num)\n",
" P1_ana, alpha1_ana_para = gha1_ana(ell, P0, alpha0_para, s, maxM=maxM, maxPartCircum=parts)\n",
" end = time.perf_counter()\n",
" beta1_num, lamb1_num = ell.cart2ell(P1_num)\n",
" d_beta1 = abs(beta1_num - beta1)\n",
" d_lamb1 = abs(lamb1_num - lamb1)\n",
" d_alpha1 = abs(alpha1_num_1 - alpha1_ell)\n",
" beta1_ana, lamb1_ana = ell.cart2ell(P1_ana)\n",
" u1_ana, v1_ana = ell.cart2para(P1_ana)\n",
" _, _, alpha1_ana_ell = alpha_para2ell(ell, u1_ana, v1_ana, alpha1_ana_para)\n",
" d_beta1 = abs(beta1_ana - beta1)\n",
" d_lamb1 = abs(lamb1_ana - lamb1)\n",
" d_alpha1 = abs(alpha1_ana_ell - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_num_{steps}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_num_{steps}\"] = (nan, nan, nan, nan)\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (nan, nan, nan, nan)\n",
"\n",
" for maxM in maxM_gha1_ana:\n",
" for parts in parts_gha1_ana:\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_ana, alpha1_ana_para = gha1_ana(ell, P0, alpha0_para, s, maxM=maxM, maxPartCircum=parts)\n",
" end = time.perf_counter()\n",
" beta1_ana, lamb1_ana = ell.cart2ell(P1_ana)\n",
" u1_ana, v1_ana = ell.cart2para(P1_ana)\n",
" _, _, alpha1_ana_ell = alpha_para2ell(ell, u1_ana, v1_ana, alpha1_ana_para)\n",
" d_beta1 = abs(beta1_ana - beta1)\n",
" d_lamb1 = abs(lamb1_ana - lamb1)\n",
" d_alpha1 = abs(alpha1_ana_ell - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (nan, nan, nan, nan)\n",
" for dsPart in dsPart_gha1_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_ES, alpha1_ES = gha1_ES(ell, beta0, lamb0, alpha0_ell, s, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" beta1_ES, lamb1_ES = ell.cart2ell(P1_ES)\n",
" d_beta1 = abs(beta1_ES - beta1)\n",
" d_lamb1 = abs(lamb1_ES - lamb1)\n",
" d_alpha1 = abs(alpha1_ES - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha1_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_ES, alpha1_ES = gha1_ES(ell, beta0, lamb0, alpha0_ell, s, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" beta1_ES, lamb1_ES = ell.cart2ell(P1_ES)\n",
" d_beta1 = abs(beta1_ES - beta1)\n",
" d_lamb1 = abs(lamb1_ES - lamb1)\n",
" d_alpha1 = abs(alpha1_ES - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
" for dsPart in dsPart_gha1_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_approx, alpha1_approx = gha1_approx(ell, P0, alpha0_ell, s, ds=ds)\n",
" end = time.perf_counter()\n",
" beta1_approx, lamb1_approx = ell.cart2ell(P1_approx)\n",
" d_beta1 = abs(beta1_approx - beta1)\n",
" d_lamb1 = abs(lamb1_approx - lamb1)\n",
" d_alpha1 = abs(alpha1_approx - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha1_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_approx, alpha1_approx = gha1_approx(ell, P0, alpha0_ell, s, ds=ds)\n",
" end = time.perf_counter()\n",
" beta1_approx, lamb1_approx = ell.cart2ell(P1_approx)\n",
" d_beta1 = abs(beta1_approx - beta1)\n",
" d_lamb1 = abs(lamb1_approx - lamb1)\n",
" d_alpha1 = abs(alpha1_approx - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
" # ----------------------------------------------\n",
"\n",
" # ----------------------------------------------\n",
" for steps in steps_gha2_num:\n",
" start = time.perf_counter()\n",
" try:\n",
" with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\", RuntimeWarning)\n",
" alpha0_num, alpha1_num_2, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=steps)\n",
" print(alpha0_num, alpha1_num_2, s_num)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_num - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_num_2 - alpha1_ell)\n",
" d_s = abs(s_num - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_num_{steps}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_num_{steps}\"] = (nan, nan, nan, nan)\n",
"\n",
" for steps in steps_gha2_num:\n",
" start = time.perf_counter()\n",
" try:\n",
" with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\", RuntimeWarning)\n",
" alpha0_num, alpha1_num_2, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=steps)\n",
" print(alpha0_num, alpha1_num_2, s_num)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_num - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_num_2 - alpha1_ell)\n",
" d_s = abs(s_num - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_num_{steps}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_num_{steps}\"] = (nan, nan, nan, nan)\n",
" for dsPart in dsPart_gha2_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" with suppress_print():\n",
" alpha0_ES, alpha1_ES, s_ES = gha2_ES(ell, P0, P1, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_ES - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_ES - alpha1_ell)\n",
" d_s = abs(s_ES - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha2_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" with suppress_print():\n",
" alpha0_ES, alpha1_ES, s_ES = gha2_ES(ell, P0, P1, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_ES - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_ES - alpha1_ell)\n",
" d_s = abs(s_ES - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
" for dsPart in dsPart_gha2_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" alpha0_approx, alpha1_approx, s_approx = gha2_approx(ell, P0, P1, ds=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_approx - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_approx - alpha1_ell)\n",
" d_s = abs(s_approx - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha2_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" alpha0_approx, alpha1_approx, s_approx = gha2_approx(ell, P0, P1, ds=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(alpha0_approx - alpha0_ell)\n",
" d_alpha1 = abs(alpha1_approx - alpha1_ell)\n",
" d_s = abs(s_approx - s)\n",
" d_time = end - start\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" results[f\"beta0: {wu.rad2deg(beta0):.3f}, lamb0: {wu.rad2deg(lamb0):.3f}, alpha0: {wu.rad2deg(alpha0_ell):.3f}, s: {s}\"] = example_results"
" results[f\"beta0: {wu.rad2deg(beta0):.3f}, lamb0: {wu.rad2deg(lamb0):.3f}, alpha0: {wu.rad2deg(alpha0_ell):.3f}, s: {s}\"] = example_results"
],
"id": "fc45e0f618a0e4d8",
"outputs": [
@@ -303,131 +324,6 @@
],
"execution_count": 15
},
{
"metadata": {},
"cell_type": "code",
"source": [
"if test == \"Random\":\n",
" results = {}\n",
" for i, example in enumerate(examples):\n",
" print(f\"----- Beispiel {i+1}/{len(examples)}\")\n",
" example_results = {}\n",
"\n",
" beta0, lamb0, alpha0_ell, s = example\n",
" P0 = ell.ell2cart(beta0, lamb0)\n",
" _, _, alpha0_para = alpha_ell2para(ell, beta0, lamb0, alpha0_ell)\n",
"\n",
" # P1_ana, alpha1_ana_para = gha1_ana(ell, P0, alpha0_para, s, maxM=60, maxPartCircum=4)\n",
" # beta1_ana, lamb1_ana = ell.cart2ell(P1_ana)\n",
" # _, _, alpha1_ana = alpha_para2ell(ell, beta1_ana, lamb1_ana, alpha1_ana_para)\n",
"\n",
" P1, alpha1_ell = gha1_num(ell, P0, alpha0_ell, s, num=10000)\n",
" beta1, lamb1 = ell.cart2ell(P1)\n",
"\n",
" for maxM in maxM_gha1_ana:\n",
" for parts in parts_gha1_ana:\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_ana, alpha1_ana_para = gha1_ana(ell, P0, alpha0_para, s, maxM=maxM, maxPartCircum=parts)\n",
" end = time.perf_counter()\n",
" beta1_ana, lamb1_ana = ell.cart2ell(P1_ana)\n",
" _, _, alpha1_ana_ell = alpha_para2ell(ell, beta1_ana, lamb1_ana, alpha1_ana_para)\n",
" d_beta1 = abs(wu.rad2deg(beta1_ana - beta1)) / 3600\n",
" d_lamb1 = abs(wu.rad2deg(lamb1_ana - lamb1)) / 3600\n",
" d_alpha1 = abs(wu.rad2deg(alpha1_ana_ell - alpha1_ell)) / 3600\n",
" d_time = end - start\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_ana_{maxM}_{parts}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha1_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_approx, alpha1_approx = gha1_approx(ell, P0, alpha0_ell, s, ds=ds)\n",
" end = time.perf_counter()\n",
" beta1_approx, lamb1_approx = ell.cart2ell(P1_approx)\n",
" d_beta1 = abs(wu.rad2deg(beta1_approx - beta1)) / 3600\n",
" d_lamb1 = abs(wu.rad2deg(lamb1_approx - lamb1)) / 3600\n",
" d_alpha1 = abs(wu.rad2deg(alpha1_approx - alpha1_ell)) / 3600\n",
" d_time = end - start\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha1_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" P1_ES, alpha1_ES = gha1_ES(ell, beta0, lamb0, alpha0_ell, s, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" beta1_ES, lamb1_ES = ell.cart2ell(P1_ES)\n",
" d_beta1 = abs(beta1_ES - beta1)\n",
" d_lamb1 = abs(lamb1_ES - lamb1)\n",
" d_alpha1 = abs(alpha1_ES - alpha1_ell)\n",
" d_time = end - start\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (d_beta1, d_lamb1, d_alpha1, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA1_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for steps in steps_gha2_num:\n",
" start = time.perf_counter()\n",
" try:\n",
" with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\", RuntimeWarning)\n",
" alpha0_num, alpha1_num_2, s_num = gha2_num(ell, beta0, lamb0, beta1, lamb1, n=steps)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(wu.rad2deg(alpha0_num - alpha0_ell)) / 3600\n",
" d_alpha1 = abs(wu.rad2deg(alpha1_num_2 - alpha1_ell)) / 3600\n",
" d_s = abs(s_num - s) / 1000\n",
" d_time = end - start\n",
" example_results[f\"GHA2_num_{steps}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_num_{steps}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha2_ES:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" with suppress_print():\n",
" alpha0_ES, alpha1_ES, s_ES = gha2_ES(ell, P0, P1, maxSegLen=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(wu.rad2deg(alpha0_ES - alpha0_ell)) / 3600\n",
" d_alpha1 = abs(wu.rad2deg(alpha1_ES - alpha1_ell)) / 3600\n",
" d_s = abs(s_ES - s) / 1000\n",
" d_time = end - start\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_ES_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" for dsPart in dsPart_gha2_approx:\n",
" ds = ell.ax/dsPart\n",
" start = time.perf_counter()\n",
" try:\n",
" alpha0_approx, alpha1_approx, s_approx = gha2_approx(ell, P0, P1, ds=ds)\n",
" end = time.perf_counter()\n",
" d_alpha0 = abs(wu.rad2deg(alpha0_approx - alpha0_ell)) / 3600\n",
" d_alpha1 = abs(wu.rad2deg(alpha1_approx - alpha1_ell)) / 3600\n",
" d_s = abs(s_approx - s) / 1000\n",
" d_time = end - start\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (d_alpha0, d_alpha1, d_s, d_time)\n",
" except Exception as e:\n",
" print(e)\n",
" example_results[f\"GHA2_approx_{dsPart}\"] = (nan, nan, nan, nan)\n",
"\n",
" results[f\"beta0: {wu.rad2deg(beta0):.3f}, lamb0: {wu.rad2deg(lamb0):.3f}, alpha0: {wu.rad2deg(alpha0_ell):.3f}, s: {s}\"] = example_results\n",
"\n",
"\n"
],
"id": "6e20a077d522d5",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",