Commit ·
741ab87
1
Parent(s): c0e6537
added normalization to allignment code... should save time if we want to change normalization...
Browse files
flaring/{aligning_data.py → normalization_and_aligning_data.py}
RENAMED
|
@@ -5,6 +5,8 @@ import numpy as np
|
|
| 5 |
from astropy.io import fits
|
| 6 |
import warnings
|
| 7 |
import pandas as pd
|
|
|
|
|
|
|
| 8 |
warnings.filterwarnings('ignore')
|
| 9 |
|
| 10 |
import pandas as pd
|
|
@@ -74,6 +76,16 @@ wavelength_to_idx = {
|
|
| 74 |
'304': 5
|
| 75 |
}
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Load data for each timestamp and wavelength
|
| 78 |
for time_idx, timestamp in enumerate(common_timestamps):
|
| 79 |
sxr = goes[goes['time'] == pd.to_datetime(timestamp)]
|
|
@@ -91,11 +103,25 @@ for time_idx, timestamp in enumerate(common_timestamps):
|
|
| 91 |
for wavelength, wave_idx in wavelength_to_idx.items():
|
| 92 |
filepath = os.path.join(wavelength_dirs[wavelength], f"{timestamp}.fits")
|
| 93 |
with fits.open(filepath) as hdul:
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Store the wavelength data for this timestamp
|
| 96 |
-
np.save(f"/mnt/data2/ML-Ready
|
| 97 |
# Store the SXR data
|
| 98 |
-
np.save(f"/mnt/data2/ML-Ready
|
| 99 |
-
np.save(f"/mnt/data2/ML-Ready
|
| 100 |
print(f"Saved data for timestamp {timestamp} to disk.")
|
| 101 |
print(f"Percent: {time_idx + 1} / {len(common_timestamps)}")
|
|
|
|
| 5 |
from astropy.io import fits
|
| 6 |
import warnings
|
| 7 |
import pandas as pd
|
| 8 |
+
from astropy.visualization import ImageNormalize, AsinhStretch
|
| 9 |
+
|
| 10 |
warnings.filterwarnings('ignore')
|
| 11 |
|
| 12 |
import pandas as pd
|
|
|
|
| 76 |
'304': 5
|
| 77 |
}
|
| 78 |
|
| 79 |
+
sdo_norms = {0: ImageNormalize(vmin=0, vmax= np.float32(16.560747), stretch=AsinhStretch(0.005), clip=True),
|
| 80 |
+
1: ImageNormalize(vmin=0, vmax= np.float32(75.84181), stretch=AsinhStretch(0.005), clip=True),
|
| 81 |
+
2: ImageNormalize(vmin=0, vmax= np.float32(1536.1443), stretch=AsinhStretch(0.005), clip=True),
|
| 82 |
+
3: ImageNormalize(vmin=0, vmax= np.float32(2288.1), stretch=AsinhStretch(0.005), clip=True),
|
| 83 |
+
4: ImageNormalize(vmin=0, vmax=np.float32(1163.9178), stretch=AsinhStretch(0.005), clip=True),
|
| 84 |
+
5: ImageNormalize(vmin=0, vmax=np.float32(401.82352), stretch=AsinhStretch(0.001), clip=True),
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
# Load data for each timestamp and wavelength
|
| 90 |
for time_idx, timestamp in enumerate(common_timestamps):
|
| 91 |
sxr = goes[goes['time'] == pd.to_datetime(timestamp)]
|
|
|
|
| 103 |
for wavelength, wave_idx in wavelength_to_idx.items():
|
| 104 |
filepath = os.path.join(wavelength_dirs[wavelength], f"{timestamp}.fits")
|
| 105 |
with fits.open(filepath) as hdul:
|
| 106 |
+
raw_data = hdul[0].data
|
| 107 |
+
|
| 108 |
+
# Apply the appropriate normalization for this wavelength
|
| 109 |
+
if wave_idx in sdo_norms:
|
| 110 |
+
# Get the normalizer for this wavelength index
|
| 111 |
+
normalizer = sdo_norms[wave_idx]
|
| 112 |
+
|
| 113 |
+
# Apply normalization and convert to [-1, 1] range
|
| 114 |
+
normalized_data = normalizer(raw_data)
|
| 115 |
+
wavelength_data[wave_idx] = normalized_data * 2 - 1
|
| 116 |
+
else:
|
| 117 |
+
# Fallback if no normalizer exists for this wavelength
|
| 118 |
+
print(f"Warning: No normalizer found for wavelength index {wave_idx}")
|
| 119 |
+
wavelength_data[wave_idx] = raw_data
|
| 120 |
+
|
| 121 |
# Store the wavelength data for this timestamp
|
| 122 |
+
np.save(f"/mnt/data2/ML-Ready/AIA-Data/{timestamp}.npy", wavelength_data)
|
| 123 |
# Store the SXR data
|
| 124 |
+
np.save(f"/mnt/data2/ML-Ready/GOES-18-SXR-A/{timestamp}.npy", sxr_a_data)
|
| 125 |
+
np.save(f"/mnt/data2/ML-Ready/GOES-18-SXR-B/{timestamp}.npy", sxr_b_data)
|
| 126 |
print(f"Saved data for timestamp {timestamp} to disk.")
|
| 127 |
print(f"Percent: {time_idx + 1} / {len(common_timestamps)}")
|