Commit ·
218d05a
1
Parent(s): 5f3578b
bug fixes
Browse files- .gitignore +2 -1
- data/align_aia_sxr.py +4 -10
- data/build_dataset.py +3 -1
- data/combine_sxr.py +12 -4
.gitignore
CHANGED
|
@@ -173,4 +173,5 @@ download/download_flares.py
|
|
| 173 |
download/test_download_sdo.py
|
| 174 |
forecasting/models/test_vit_mask.py
|
| 175 |
forecasting/griffin_config.yaml
|
| 176 |
-
/data/foxes_data
|
|
|
|
|
|
| 173 |
download/test_download_sdo.py
|
| 174 |
forecasting/models/test_vit_mask.py
|
| 175 |
forecasting/griffin_config.yaml
|
| 176 |
+
/data/foxes_data
|
| 177 |
+
*.nc
|
data/align_aia_sxr.py
CHANGED
|
@@ -19,9 +19,6 @@ from tqdm import tqdm
|
|
| 19 |
|
| 20 |
warnings.filterwarnings('ignore')
|
| 21 |
|
| 22 |
-
# Set by main() before the worker Pool is created; read by process_batch in workers.
|
| 23 |
-
OUTPUT_SXR_DIR = None
|
| 24 |
-
|
| 25 |
|
| 26 |
def load_and_prepare_goes_data(goes_data_dir):
|
| 27 |
"""
|
|
@@ -114,7 +111,7 @@ def create_combined_lookup_table(goes_data_dict, target_timestamps):
|
|
| 114 |
return lookup_data
|
| 115 |
|
| 116 |
|
| 117 |
-
def process_batch(batch_data):
|
| 118 |
"""
|
| 119 |
Process a batch of timestamps efficiently.
|
| 120 |
This is much more efficient than processing one timestamp per process.
|
|
@@ -129,7 +126,7 @@ def process_batch(batch_data):
|
|
| 129 |
sxr_b = data['sxr_b']
|
| 130 |
instrument = data['instrument']
|
| 131 |
|
| 132 |
-
np.save(f"{
|
| 133 |
|
| 134 |
successful_count += 1
|
| 135 |
results.append((timestamp, True, f"Success using {instrument}"))
|
|
@@ -150,9 +147,6 @@ def split_into_batches(data, batch_size):
|
|
| 150 |
def align_aia_sxr(goes_data_dir, aia_processed_dir, output_sxr_dir, aia_missing_dir,
|
| 151 |
max_processes=None, batch_size_multiplier=4, min_batch_size=1):
|
| 152 |
"""Match AIA .npy timestamps to combined GOES SXR data, writing one xrsb_flux .npy per match."""
|
| 153 |
-
global OUTPUT_SXR_DIR
|
| 154 |
-
OUTPUT_SXR_DIR = output_sxr_dir
|
| 155 |
-
|
| 156 |
print("=" * 60)
|
| 157 |
print("GOES Data Alignment Tool")
|
| 158 |
print("=" * 60)
|
|
@@ -212,7 +206,7 @@ def align_aia_sxr(goes_data_dir, aia_processed_dir, output_sxr_dir, aia_missing_
|
|
| 212 |
# Single-threaded processing for small datasets
|
| 213 |
pbar = tqdm(batches, desc="Processing batches")
|
| 214 |
for batch in pbar:
|
| 215 |
-
results, successful, failed = process_batch(batch)
|
| 216 |
total_successful += successful
|
| 217 |
total_failed += failed
|
| 218 |
pbar.set_postfix(success=total_successful, failed=total_failed)
|
|
@@ -222,7 +216,7 @@ def align_aia_sxr(goes_data_dir, aia_processed_dir, output_sxr_dir, aia_missing_
|
|
| 222 |
# Process all batches
|
| 223 |
results = []
|
| 224 |
for batch in tqdm(batches, desc="Submitting batches"):
|
| 225 |
-
result = pool.apply_async(process_batch, (batch,))
|
| 226 |
results.append(result)
|
| 227 |
|
| 228 |
# Collect results with progress bar
|
|
|
|
| 19 |
|
| 20 |
warnings.filterwarnings('ignore')
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def load_and_prepare_goes_data(goes_data_dir):
|
| 24 |
"""
|
|
|
|
| 111 |
return lookup_data
|
| 112 |
|
| 113 |
|
| 114 |
+
def process_batch(batch_data, output_sxr_dir):
|
| 115 |
"""
|
| 116 |
Process a batch of timestamps efficiently.
|
| 117 |
This is much more efficient than processing one timestamp per process.
|
|
|
|
| 126 |
sxr_b = data['sxr_b']
|
| 127 |
instrument = data['instrument']
|
| 128 |
|
| 129 |
+
np.save(f"{output_sxr_dir}/{timestamp}.npy", np.array([sxr_b], dtype=np.float32))
|
| 130 |
|
| 131 |
successful_count += 1
|
| 132 |
results.append((timestamp, True, f"Success using {instrument}"))
|
|
|
|
| 147 |
def align_aia_sxr(goes_data_dir, aia_processed_dir, output_sxr_dir, aia_missing_dir,
|
| 148 |
max_processes=None, batch_size_multiplier=4, min_batch_size=1):
|
| 149 |
"""Match AIA .npy timestamps to combined GOES SXR data, writing one xrsb_flux .npy per match."""
|
|
|
|
|
|
|
|
|
|
| 150 |
print("=" * 60)
|
| 151 |
print("GOES Data Alignment Tool")
|
| 152 |
print("=" * 60)
|
|
|
|
| 206 |
# Single-threaded processing for small datasets
|
| 207 |
pbar = tqdm(batches, desc="Processing batches")
|
| 208 |
for batch in pbar:
|
| 209 |
+
results, successful, failed = process_batch(batch, output_sxr_dir)
|
| 210 |
total_successful += successful
|
| 211 |
total_failed += failed
|
| 212 |
pbar.set_postfix(success=total_successful, failed=total_failed)
|
|
|
|
| 216 |
# Process all batches
|
| 217 |
results = []
|
| 218 |
for batch in tqdm(batches, desc="Submitting batches"):
|
| 219 |
+
result = pool.apply_async(process_batch, (batch, output_sxr_dir))
|
| 220 |
results.append(result)
|
| 221 |
|
| 222 |
# Collect results with progress bar
|
data/build_dataset.py
CHANGED
|
@@ -61,7 +61,9 @@ def main():
|
|
| 61 |
|
| 62 |
if steps.get('combine_sxr', True):
|
| 63 |
print("\n--- Step 3/5: Combine raw GOES satellite files ---")
|
| 64 |
-
SXRDataProcessor(data_dir=sxr['raw_dir'], output_dir=sxr['combined_dir']).combine_goes_data(
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
print("\n--- Step 3/5: Combine raw GOES satellite files (skipped) ---")
|
| 67 |
|
|
|
|
| 61 |
|
| 62 |
if steps.get('combine_sxr', True):
|
| 63 |
print("\n--- Step 3/5: Combine raw GOES satellite files ---")
|
| 64 |
+
SXRDataProcessor(data_dir=sxr['raw_dir'], output_dir=sxr['combined_dir']).combine_goes_data(
|
| 65 |
+
apply_pre_goes16_scaling=sxr.get('apply_pre_goes16_scaling', True)
|
| 66 |
+
)
|
| 67 |
else:
|
| 68 |
print("\n--- Step 3/5: Combine raw GOES satellite files (skipped) ---")
|
| 69 |
|
data/combine_sxr.py
CHANGED
|
@@ -37,10 +37,15 @@ class SXRDataProcessor:
|
|
| 37 |
self.used_g17_files = []
|
| 38 |
self.used_g18_files = []
|
| 39 |
|
| 40 |
-
def combine_goes_data(self, columns_to_interp=["xrsb_flux", "xrsa_flux"]):
|
| 41 |
"""
|
| 42 |
Combine GOES-16 and GOES-18 files and track source files used.
|
| 43 |
Parameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
"""
|
| 45 |
print("Scanning for GOES data files...")
|
| 46 |
|
|
@@ -104,9 +109,12 @@ class SXRDataProcessor:
|
|
| 104 |
|
| 105 |
# Scaling factors for GOES-13, GOES-14, and GOES-15
|
| 106 |
if satellite_name in ['GOES-13', 'GOES-14', 'GOES-15']:
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
print(f"Converting to DataFrame...")
|
| 112 |
df = combined_ds.to_dataframe().reset_index()
|
|
|
|
| 37 |
self.used_g17_files = []
|
| 38 |
self.used_g18_files = []
|
| 39 |
|
| 40 |
+
def combine_goes_data(self, columns_to_interp=["xrsb_flux", "xrsa_flux"], apply_pre_goes16_scaling=True):
|
| 41 |
"""
|
| 42 |
Combine GOES-16 and GOES-18 files and track source files used.
|
| 43 |
Parameters
|
| 44 |
+
----------
|
| 45 |
+
apply_pre_goes16_scaling : bool
|
| 46 |
+
Whether to apply the legacy GOES-13/14/15 (pre-GOES-16) scaling
|
| 47 |
+
correction. Set to False if your GOES-13/14/15 files are already
|
| 48 |
+
scaled to match GOES-16 (as with NOAA's newest reprocessed data).
|
| 49 |
"""
|
| 50 |
print("Scanning for GOES data files...")
|
| 51 |
|
|
|
|
| 109 |
|
| 110 |
# Scaling factors for GOES-13, GOES-14, and GOES-15
|
| 111 |
if satellite_name in ['GOES-13', 'GOES-14', 'GOES-15']:
|
| 112 |
+
if apply_pre_goes16_scaling:
|
| 113 |
+
print(f"Applying scaling factors for {satellite_name}...")
|
| 114 |
+
combined_ds['xrsa_flux'] = combined_ds['xrsa_flux'] / .85
|
| 115 |
+
combined_ds['xrsb_flux'] = combined_ds['xrsb_flux'] / .7
|
| 116 |
+
else:
|
| 117 |
+
print(f"Skipping pre-GOES-16 scaling factors for {satellite_name}...")
|
| 118 |
|
| 119 |
print(f"Converting to DataFrame...")
|
| 120 |
df = combined_ds.to_dataframe().reset_index()
|