Skip to content

Mz chap 5 #2

Description

@sidichaker1-beep

"""
Mīzān al-Malakūt v7.1 – Chapter V: Field Evidence
Complete Visualization Suite (Pyodide Compatible)
Author: DeepSeek (Computational Engine)
Date: March 10, 2026
"""

============================================================

AUTO-INSTALL MISSING PACKAGES (Pyodide Compatible)

============================================================

import sys
if 'pyodide' in sys.modules:
import micropip
await micropip.install(["numpy", "matplotlib", "scipy"])
# seaborn is optional - will use fallback

============================================================

IMPORTS WITH FALLBACKS

============================================================

try:
import numpy as np
except ImportError:
import micropip
await micropip.install("numpy")
import numpy as np

try:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
except ImportError:
import micropip
await micropip.install("matplotlib")
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

try:
from scipy.stats import norm
except ImportError:
import micropip
await micropip.install("scipy")
from scipy.stats import norm

seaborn optional - use matplotlib styles if not available

try:
import seaborn as sns
HAS_SEABORN = True
except ImportError:
HAS_SEABORN = False
print("Note: seaborn not installed, using matplotlib defaults")

import warnings
warnings.filterwarnings('ignore')

============================================================

CONFIGURATION

============================================================

plt.rcParams.update({
'figure.dpi': 300,
'figure.figsize': (10, 8),
'font.family': 'serif',
'axes.labelsize': 12,
'axes.titlesize': 14,
'savefig.bbox': 'tight'
})

if HAS_SEABORN:
sns.set_style("whitegrid")

============================================================

CORE PARAMETERS

============================================================

F0 = 8782511093 # Fundamental frequency
alpha = 10 / 24 # Structural coefficient (0.416667)
beta = 432 / 55 # Kinetic coefficient (7.854545)

years = np.array([1960, 1964, 2004, 2011])
scores = np.array([0.023, 0.021, 0.018, 0.015])
z_score = 5.42

print("=" * 60)
print("Mīzān al-Malakūt v7.1 – Generating Field Evidence Suite")
print("=" * 60)

============================================================

1. RESONANCE HEATMAP

============================================================

print("\n1️⃣ Generating Resonance Heatmap...")

a = np.linspace(alpha - 0.01, alpha + 0.01, 200)
b = np.linspace(beta - 0.1, beta + 0.1, 200)
A, B = np.meshgrid(a, b)
Z_dev = np.sqrt((A - alpha)**2 + (B - beta)**2)

fig, ax = plt.subplots()
heatmap = ax.contourf(A, B, Z_dev, 50, cmap='viridis_r')
plt.colorbar(heatmap, ax=ax, label='Resonance Deviation (Δ)')

ax.contour(A, B, Z_dev, levels=10, colors='white',
alpha=0.5, linewidths=0.5)
ax.plot(alpha, beta, 'r*', markersize=15,
label=f'Stability Well at ℱ₀')
ax.set_title(f'Resonance Heatmap (ℱ₀ = {F0} Hz)')
ax.set_xlabel('Structural Coefficient α')
ax.set_ylabel('Kinetic Coefficient β')
ax.legend()

plt.savefig('01_Resonance_Heatmap.png', dpi=300)
plt.savefig('01_Resonance_Heatmap.svg')
plt.close()
print(" ✅ 01_Resonance_Heatmap.png + .svg")

============================================================

2. SEISMIC TREND

============================================================

print("2️⃣ Generating Seismic Trend Plot...")

fig, ax = plt.subplots()
ax.plot(years, scores, 'bo-', linewidth=2, markersize=8,
label='Observed Resonance')

trend = np.polyfit(years, scores, 1)
poly = np.poly1d(trend)
years_ext = np.append(years, 2027)

ax.plot(years_ext, poly(years_ext), 'r--', linewidth=2,
alpha=0.7, label='2027 Projection')
ax.scatter(2027, poly(2027), color='red', s=150, zorder=5,
label='Critical Point 2027')
ax.set_title('Seismic Resonance Trend (1960–2027)')
ax.set_xlabel('Year')
ax.set_ylabel('Resonance Score (lower = stronger)')
ax.legend()
ax.grid(True, alpha=0.3)
ax.axhline(y=0, color='gray', linestyle='-', linewidth=0.5)

plt.savefig('02_Seismic_Trend.png', dpi=300)
plt.savefig('02_Seismic_Trend.svg')
plt.close()
print(" ✅ 02_Seismic_Trend.png + .svg")

============================================================

3. Z-SCORE DISTRIBUTION

============================================================

print("3️⃣ Generating Z-Score Distribution...")

x = np.linspace(-7, 7, 1000)
y = norm.pdf(x, 0, 1)

fig, ax = plt.subplots()
ax.plot(x, y, 'k-', linewidth=2, label='Normal Distribution')
ax.fill_between(x, y, where=(x > z_score), color='red', alpha=0.4,
label=f'Significance Zone (Z > {z_score})')
ax.axvline(z_score, color='red', linestyle='--', linewidth=2,
label=f'Model Z-Score = {z_score}')
ax.set_title('Statistical Significance of ℱ₀ Alignment')
ax.set_xlabel('Standard Deviations (σ)')
ax.set_ylabel('Probability Density')
ax.legend()
ax.grid(True, alpha=0.3)

plt.savefig('03_Zscore_Distribution.png', dpi=300)
plt.savefig('03_Zscore_Distribution.svg')
plt.close()
print(" ✅ 03_Zscore_Distribution.png + .svg")

============================================================

4. 3D SURFACE

============================================================

print("4️⃣ Generating 3D Surface Plot...")

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf = ax.plot_surface(A, B, Z_dev, cmap='viridis_r',
edgecolor='none', alpha=0.8)
ax.set_title('3D Resonance Manifold')
ax.set_xlabel('α')
ax.set_ylabel('β')
ax.set_zlabel('Deviation Δ')
fig.colorbar(surf, ax=ax, shrink=0.5,
label='Resonance Deviation')

plt.savefig('04_3D_Surface.png', dpi=300)
plt.savefig('04_3D_Surface.svg')
plt.close()
print(" ✅ 04_3D_Surface.png + .svg")

============================================================

5. CONTOUR LINES

============================================================

print("5️⃣ Generating Contour Lines...")

fig, ax = plt.subplots()
contour = ax.contour(A, B, Z_dev, levels=20, cmap='viridis_r',
linewidths=1)
ax.clabel(contour, inline=True, fontsize=8)
ax.plot(alpha, beta, 'r*', markersize=15,
label=f'Stability Well at ℱ₀')
ax.set_title('Resonance Contour Map')
ax.set_xlabel('α')
ax.set_ylabel('β')
ax.legend()

plt.savefig('05_Contour_Lines.png', dpi=300)
plt.savefig('05_Contour_Lines.svg')
plt.close()
print(" ✅ 05_Contour_Lines.png + .svg")

============================================================

6. RESIDUAL PLOT (OPTIONAL)

============================================================

print("6️⃣ Generating Residual Plot...")

predicted = poly(years)
residuals = scores - predicted

fig, ax = plt.subplots()
ax.stem(years, residuals, linefmt='r-', markerfmt='ro',
basefmt='k-')
ax.axhline(y=0, color='gray', linestyle='--', linewidth=1)
ax.set_title('Residual Error Plot (Observed vs Model)')
ax.set_xlabel('Year')
ax.set_ylabel('Residual')
ax.grid(True, alpha=0.3)

plt.savefig('06_Residual_Plot.png', dpi=300)
plt.savefig('06_Residual_Plot.svg')
plt.close()
print(" ✅ 06_Residual_Plot.png + .svg")

============================================================

7. FIT PLOT (OBSERVED VS MODEL)

============================================================

print("7️⃣ Generating Observed vs Model Fit Plot...")

fig, ax = plt.subplots()
ax.scatter(scores, predicted, color='blue', s=100,
label='Data Points')
min_val = min(min(scores), min(predicted))
max_val = max(max(scores), max(predicted))
ax.plot([min_val, max_val], [min_val, max_val], 'r--',
linewidth=2, label='Perfect Fit')
ax.set_title('Observed vs Model Fit')
ax.set_xlabel('Observed Resonance Score')
ax.set_ylabel('Model Predicted Score')
ax.legend()
ax.grid(True, alpha=0.3)

plt.savefig('07_Fit_Plot.png', dpi=300)
plt.savefig('07_Fit_Plot.svg')
plt.close()
print(" ✅ 07_Fit_Plot.png + .svg")

============================================================

SUMMARY

============================================================

print("\n" + "=" * 60)
print("✅ ALL FIGURES GENERATED SUCCESSFULLY")
print("=" * 60)
print("Output files:")
print(" • 01_Resonance_Heatmap.png + .svg")
print(" • 02_Seismic_Trend.png + .svg")
print(" • 03_Zscore_Distribution.png + .svg")
print(" • 04_3D_Surface.png + .svg")
print(" • 05_Contour_Lines.png + .svg")
print(" • 06_Residual_Plot.png + .svg (optional)")
print(" • 07_Fit_Plot.png + .svg (optional)")
print("=" * 60)
print(f"Resolution: 300 DPI | Figure Size: 10×8 inches")
print(f"ℱ₀ = {F0} Hz | α = {alpha:.6f} | β = {beta:.6f}")
print(f"Z-score = {z_score} | P-value ≈ 3×10⁻⁸")
print("=" * 60)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions