Skip to content

Commit 1743adf

Browse files
authored
Add files via upload
1 parent 42a747d commit 1743adf

File tree

3 files changed

+3401
-0
lines changed

3 files changed

+3401
-0
lines changed

notebooks/Complete_DLSFH_Dual_Overlay_Test.ipynb

Lines changed: 2498 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "view-in-github",
7+
"colab_type": "text"
8+
},
9+
"source": [
10+
"<a href=\"https://colab.research.google.com/github/geopayme/AstroPhysics/blob/main/DLSFH_Entropy_AutoAnalysis_Patched.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "c5b0c5e8",
16+
"metadata": {
17+
"id": "c5b0c5e8"
18+
},
19+
"source": [
20+
"# ☀️ DLSFH Enhanced Diagnostic Notebook\n",
21+
"Includes entropy mapping, SGCV coherence analysis, and NOAA sunspot timeline with fallback logic."
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "19cc100c",
28+
"metadata": {
29+
"id": "19cc100c"
30+
},
31+
"outputs": [],
32+
"source": [
33+
"# ✅ Install dependencies (Colab only)\n",
34+
"!apt-get install -y tesseract-ocr\n",
35+
"!pip install -q pytesseract\n"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "d917bec4",
42+
"metadata": {
43+
"id": "d917bec4"
44+
},
45+
"outputs": [],
46+
"source": [
47+
"import numpy as np\n",
48+
"import pandas as pd\n",
49+
"import matplotlib.pyplot as plt\n",
50+
"import matplotlib.dates as mdates\n",
51+
"from PIL import Image\n",
52+
"import pytesseract\n",
53+
"from datetime import datetime\n",
54+
"from scipy.ndimage import sobel, generic_filter\n",
55+
"from google.colab import files\n",
56+
"import io, requests\n"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "664dfaa1",
63+
"metadata": {
64+
"id": "664dfaa1"
65+
},
66+
"outputs": [],
67+
"source": [
68+
"# 📤 Upload solar magnetogram\n",
69+
"uploaded = files.upload()\n",
70+
"image_path = next(iter(uploaded))\n",
71+
"img = Image.open(image_path).convert('L')\n",
72+
"img_array = np.array(img)\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "9ea2dca5",
79+
"metadata": {
80+
"id": "9ea2dca5"
81+
},
82+
"outputs": [],
83+
"source": [
84+
"# 🧠 Extract date from filename → OCR → manual\n",
85+
"try:\n",
86+
" base = image_path.split('/')[-1]\n",
87+
" date_str = base[5:11] # e.g., '250328'\n",
88+
" year = int('20' + date_str[:2])\n",
89+
" month = int(date_str[2:4])\n",
90+
" day = int(date_str[4:6])\n",
91+
" image_date = datetime(year, month, day)\n",
92+
" print(f\"✅ Date from filename: {image_date.date()}\")\n",
93+
"except:\n",
94+
" try:\n",
95+
" text = pytesseract.image_to_string(img)\n",
96+
" date_parts = [int(p) for p in text.split()[0].split('-')]\n",
97+
" image_date = datetime(*date_parts)\n",
98+
" print(f\"✅ Date from OCR: {image_date.date()}\")\n",
99+
" except:\n",
100+
" manual = input(\"❗ Enter image date (YYYY-MM-DD): \")\n",
101+
" image_date = datetime.strptime(manual.strip(), \"%Y-%m-%d\")\n",
102+
" print(f\"✅ Using manual date: {image_date.date()}\")\n"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"id": "e66e0612",
109+
"metadata": {
110+
"id": "e66e0612"
111+
},
112+
"outputs": [],
113+
"source": [
114+
"# 📈 NOAA Observed Solar Cycle (API → fallback CSV)\n",
115+
"obs_url = \"https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json\"\n",
116+
"try:\n",
117+
" r = requests.get(obs_url)\n",
118+
" r.raise_for_status()\n",
119+
" data = r.json()\n",
120+
" df = pd.DataFrame(data)\n",
121+
" df['date'] = pd.to_datetime(df['time-tag'], errors='coerce')\n",
122+
" df = df[['date', 'ssn']].dropna()\n",
123+
" print(f\"✅ NOAA API loaded ({len(df)} records)\")\n",
124+
"except:\n",
125+
" print(\"⚠️ NOAA API failed. Upload fallback CSV (columns: date, ssn)\")\n",
126+
" uploaded_csv = files.upload()\n",
127+
" csv_name = next(iter(uploaded_csv))\n",
128+
" df = pd.read_csv(csv_name)\n",
129+
" df['date'] = pd.to_datetime(df['date'])\n"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "1dfdc983",
136+
"metadata": {
137+
"id": "1dfdc983"
138+
},
139+
"outputs": [],
140+
"source": [
141+
"# 📊 NOAA Sunspot Timeline\n",
142+
"fig, ax = plt.subplots(figsize=(10, 4))\n",
143+
"ax.plot(df['date'], df['ssn'], label='Smoothed Sunspot Number')\n",
144+
"ax.axvline(image_date, color='red', linestyle='--', label=f'Image Date: {image_date.date()}')\n",
145+
"ax.set_title('NOAA Solar Cycle Alignment')\n",
146+
"ax.set_ylabel('Sunspot Number')\n",
147+
"ax.legend()\n",
148+
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))\n",
149+
"plt.grid(True)\n",
150+
"plt.tight_layout()\n",
151+
"plt.show()\n"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"id": "5b0b6f8d",
158+
"metadata": {
159+
"id": "5b0b6f8d"
160+
},
161+
"outputs": [],
162+
"source": [
163+
"# 🔬 Enhanced Entropy Extraction\n",
164+
"h, w = img_array.shape\n",
165+
"cx, cy = w // 2, h // 2\n",
166+
"radius = min(cx, cy) - 10\n",
167+
"y, x = np.ogrid[:h, :w]\n",
168+
"mask = (x - cx)**2 + (y - cy)**2 <= radius**2\n",
169+
"\n",
170+
"gx = sobel(img_array, axis=1)\n",
171+
"gy = sobel(img_array, axis=0)\n",
172+
"grad = np.hypot(gx, gy)\n",
173+
"var = generic_filter(img_array, np.var, size=5)\n",
174+
"\n",
175+
"grad_n = (grad - grad.min()) / (np.ptp(grad) + 1e-8)\n",
176+
"var_n = (var - var.min()) / (np.ptp(var) + 1e-8)\n",
177+
"entropy_map = np.zeros_like(img_array, dtype=float)\n",
178+
"entropy_map[mask] = ((grad_n + var_n) / 2.0)[mask]\n",
179+
"\n",
180+
"# Visualize\n",
181+
"plt.figure(figsize=(6,6))\n",
182+
"plt.imshow(entropy_map, cmap='inferno')\n",
183+
"plt.title(f'Entropy Map ({image_date.date()})')\n",
184+
"plt.axis('off')\n",
185+
"plt.colorbar()\n",
186+
"plt.show()\n"
187+
]
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": null,
192+
"id": "c0615a74",
193+
"metadata": {
194+
"id": "c0615a74"
195+
},
196+
"outputs": [],
197+
"source": [
198+
"# 🧬 DLSFH Projection + Report\n",
199+
"angles = np.linspace(0, 2*np.pi, 21)[:-1]\n",
200+
"radii = [radius * 0.4, radius * 0.8]\n",
201+
"vec = []\n",
202+
"\n",
203+
"for r in radii:\n",
204+
" for theta in angles[:10]:\n",
205+
" x_pt = int(cx + r * np.cos(theta))\n",
206+
" y_pt = int(cy + r * np.sin(theta))\n",
207+
" vec.append(entropy_map[y_pt, x_pt])\n",
208+
"\n",
209+
"vec = np.array(vec)\n",
210+
"σ_c = 0.07\n",
211+
"collapsed = np.sum(vec >= σ_c)\n",
212+
"\n",
213+
"print(f\"=== DLSFH Entropy Report: {image_date.date()} ===\")\n",
214+
"print(f\"Mean Entropy: {vec.mean():.4f} | Std Dev: {vec.std():.4f}\")\n",
215+
"print(f\"Collapsed Nodes (≥ {σ_c}): {collapsed} / 20\")\n",
216+
"print(f\"Inner Mean: {vec[:10].mean():.4f} | Outer Mean: {vec[10:].mean():.4f}\")\n",
217+
"print(f\"Ring Divergence (Outer - Inner): {(vec[10:].mean() - vec[:10].mean()):.4f}\")\n",
218+
"if collapsed > 10:\n",
219+
" print('⚠️ Possible surface flux instability or decoherence.')\n"
220+
]
221+
}
222+
],
223+
"metadata": {
224+
"colab": {
225+
"provenance": [],
226+
"include_colab_link": true
227+
}
228+
},
229+
"nbformat": 4,
230+
"nbformat_minor": 5
231+
}

0 commit comments

Comments
 (0)