Skip to content

Commit 32b35ec

Browse files
committed
Comparison of the original and new Chimera codes
1 parent 622f06d commit 32b35ec

20 files changed

Lines changed: 867088 additions & 21 deletions

chimerapy/chimera.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,25 @@ def filter_ch(mask: NDArray, map_obj: Map, min_area: Quantity["area"] = 1e4 * u.
123123
on_disk :
124124
Remove CHs that are not on the disk (above the limb)
125125
"""
126+
log.debug("Calculating area map")
126127
area_map, disk_mask = calculate_area_map(map_obj)
127-
128+
log.debug("Labeling regions")
128129
labeled_mask = measure.label(mask * disk_mask if on_disk else mask)
130+
log.debug("Finding regions")
129131
regions = measure.regionprops(labeled_mask)
130-
breakpoint()
132+
log.debug("Filtering regions by pixel area size")
133+
134+
min_pixel_area = 100
135+
filtered_regions_pixel_area = [region for region in regions if region.area >= min_pixel_area]
136+
137+
log.debug(f"Found {len(regions)} regions, {len(filtered_regions_pixel_area)} after pixel area filtering")
131138

132139
filtered_regions = []
133-
for region in regions:
140+
log.debug(f"Found {len(filtered_regions_pixel_area)} regions")
141+
#import ipdb; ipdb.set_trace()
142+
#breakpoint()
143+
for region in filtered_regions_pixel_area:
144+
log.debug(f"Processing region {region.label} with area {region.area}")
134145
region_mask = labeled_mask == region.label
135146
contours = measure.find_contours(region_mask)
136147
if contours:
@@ -141,9 +152,6 @@ def filter_ch(mask: NDArray, map_obj: Map, min_area: Quantity["area"] = 1e4 * u.
141152
if region_surface_area >= min_area and not np.all(region_mask & disk_mask):
142153
region.surface_area = region_surface_area
143154
filtered_regions.append(region)
144-
else:
145-
log.debug(f"Removing CH region {region.label}")
146-
labeled_mask[region_mask] = 0
147155

148156
filtered_regions = sorted(filtered_regions, key=lambda region: region.surface_area, reverse=True)
149157

@@ -156,7 +164,6 @@ def get_coronal_holes(filtered_regions, map_obj, labeled_mask):
156164
for region in filtered_regions:
157165
coords = region.coords
158166
world_coords = map_obj.pixel_to_world(coords[:, 1] * u.pix, coords[:, 0] * u.pix)
159-
# heliographic_coords = world_coords.transform_to("heliographic_stonyhurst")
160167

161168
wb = world_coords[np.nanargmax(world_coords.Tx)]
162169
eb = world_coords[np.nanargmin(world_coords.Tx)]
@@ -217,10 +224,13 @@ def map_threshold(im_map):
217224

218225

219226
def chimera(m171, m193, m211):
227+
log.debug("Generating candidate mask")
220228
ch_mask = generate_candidate_mask(m171, m193, m211)
229+
log.debug("Filtering regions")
221230
labeled_mask, filtered_regions = filter_ch(ch_mask, m171)
222-
231+
log.debug("Getting coronal holes")
223232
coronal_holes = get_coronal_holes(filtered_regions, m171, labeled_mask)
233+
log.debug("Finished")
224234

225235
for ch in coronal_holes:
226236
print(
@@ -237,7 +247,7 @@ def chimera(m171, m193, m211):
237247
f"N: {ch['nb'].transform_to('heliographic_stonyhurst').lat.value:.2f}, S:{ch['sb'].transform_to('heliographic_stonyhurst').lat.value:.2f}"
238248
f"N-S Extent = {ch['extent_lat']:.2f} °"
239249
)
240-
250+
return labeled_mask, ch_mask, coronal_holes
241251

242252
def run_chimera(date):
243253
date = parse_time(date)

chimerapy/chimera_original.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,26 @@
1515

1616
import astropy.units as u
1717
from astropy import wcs
18+
from sunpy.map import Map
1819
from astropy.io import fits
1920
from astropy.modeling.models import Gaussian2D
2021

22+
def imhmi(m171):
23+
"""Create a dummy HMI map for the original CHIMERA code."""
24+
imhmi = Map(np.zeros_like(m171.data), m171.meta)
25+
return imhmi
2126

2227
def chimera_legacy(im171=None, im193=None, im211=None, imhmi=None):
2328
file_path = "./"
2429

2530
if im171 is None:
26-
im171 = glob.glob(file_path + "*171*.fts.gz")
27-
im193 = glob.glob(file_path + "*193*.fts.gz")
28-
im211 = glob.glob(file_path + "*211*.fts.gz")
29-
imhmi = glob.glob(file_path + "*hmi*.fts.gz")
31+
im171 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.171A_2016_10_31T00_00_10.35Z.image_lev1.fits")
32+
im193 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.193A_2016_10_31T00_00_05.85Z.image_lev1.fits")
33+
im211 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.211A_2016_10_31T00_00_10.62Z.image_lev1.fits")
34+
imhmi_map = imhmi(im171)
3035

3136
circ, data, datb, datc, dattoarc, hedb, iarr, props, rs, slate, center, xgrid, ygrid = chimera(
32-
im171, im193, im211, imhmi
37+
im171, im193, im211, imhmi_map
3338
)
3439

3540
# =====sets ident back to max value of iarr======
@@ -42,8 +47,8 @@ def chimera_legacy(im171=None, im193=None, im211=None, imhmi=None):
4247
return circ, data, datb, datc, dattoarc, hedb, iarr, props, rs, slate, center, xgrid, ygrid
4348

4449

45-
def chimera(im171, im193, im211, imhmi):
46-
if im171 == [] or im193 == [] or im211 == [] or imhmi == []:
50+
def chimera(im171, im193, im211, imhmi_map):
51+
if im171 == [] or im193 == [] or im211 == [] or imhmi_map == []:
4752
print("Not all required files present")
4853
sys.exit()
4954
# =====Reads in data and resizes images=====
@@ -61,8 +66,8 @@ def chimera(im171, im193, im211, imhmi):
6166
datc = fits.getdata(im211[0], ext=0) / (hedc["EXPTIME"])
6267
dn = RectBivariateSpline(x, x, datc, kx=1, ky=1)
6368
datc = dn(np.arange(0, 4096), np.arange(0, 4096))
64-
hedm = fits.getheader(imhmi[0], hdu_number)
65-
datm = fits.getdata(imhmi[0], ext=0)
69+
hedm = fits.getheader(imhmi_map[0], hdu_number)
70+
datm = fits.getdata(imhmi_map[0], ext=0)
6671
# dn = scipy.interpolate.interp2d(np.arange(4096), np.arange(4096), datm)
6772
# datm = dn(np.arange(0, 1024)*4, np.arange(0, 1024)*4)
6873
if hedm["crota1"] > 90:

chimerapy/scripts/comparison.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from sunpy.net import Fido, attrs as a
2+
import astropy.units as u
3+
import os
4+
from sunpy.map import Map
5+
import numpy as np
6+
import sys
7+
import chimerapy.chimera as chimera_new
8+
import chimerapy.chimera_original as chimera_old
9+
10+
"""
11+
date = "2016/11/04"
12+
wavelength = 193 * u.Angstrom
13+
14+
script_dir = os.path.dirname(os.path.abspath(__file__))
15+
save_path = os.path.join(script_dir, "downloaded_data")
16+
os.makedirs(save_path, exist_ok=True)
17+
18+
results = Fido.search(
19+
a.Time(f"{date} 00:00:00", f"{date} 00:00:30", near=True),
20+
a.Instrument("AIA"),
21+
a.Wavelength(wavelength)
22+
)
23+
24+
if results:
25+
downloaded_files = Fido.fetch(results[0], path=save_path)
26+
if downloaded_files:
27+
print(f"Downloaded file: {downloaded_files[0]}")
28+
else:
29+
print("Download failed.")
30+
else:
31+
print("No files found for the specified date and wavelength.")
32+
"""
33+
34+
def imhmi(m171):
35+
"""Create a dummy HMI map for the original CHIMERA code."""
36+
imhmi = Map(np.zeros_like(m171.data), m171.meta)
37+
return imhmi
38+
39+
m171 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.171A_2016_10_31T00_00_10.35Z.image_lev1.fits")
40+
m193 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.193A_2016_10_31T00_00_05.85Z.image_lev1.fits")
41+
m211 = Map("C:\\Users\\aoife\\CHIMERApy\\chimerapy\\scripts\\downloaded_data\\aia.lev1.211A_2016_10_31T00_00_10.62Z.image_lev1.fits")
42+
imhmi_map = imhmi(m171)
43+
44+
labeled_mask, ch_mask, coronal_holes = chimera_new.chimera(m171, m193, m211)
45+
46+
if coronal_holes:
47+
print("These are the new CHIMERA results")
48+
else:
49+
print("No coronal holes found for new CHIMERA.")
50+
51+
circ, data, datb, datc, dattoarc, hedb, iarr, props, rs, slate, center, xgrid, ygrid = chimera_old.chimera(m171, m193, m211, imhmi_map)
52+
53+
print("Chimera_original processing complete.")
54+
55+
num_coronal_holes = 0
56+
for i in range(1, props.shape[1]):
57+
if props[0, i].isdigit():
58+
num_coronal_holes += 1
59+
print(f"Chimera_original found {num_coronal_holes} coronal holes.")
60+
61+
for i in range(1, num_coronal_holes + 1):
62+
print(f"Coronal Hole {i}:")
63+
print(f" ID: {props[0, i]}")
64+
print(f" XCEN: {props[1, i]}")
65+
print(f" YCEN: {props[2, i]}")
66+
print(f" CENTROID: {props[3, i]}")
67+
print(f" X_EB: {props[4, i]}")
68+
print(f" Y_EB: {props[5, i]}")
69+
print(f" X_WB: {props[6, i]}")
70+
print(f" Y_WB: {props[7, i]}")
71+
print(f" X_NB: {props[8, i]}")
72+
print(f" Y_NB: {props[9, i]}")
73+
print(f" X_SB: {props[10, i]}")
74+
print(f" Y_SB: {props[11, i]}")
75+
print(f" WIDTH: {props[12, i]}")
76+
print(f" WIDTH: {props[13, i]}")
77+
print(f" AREA: {props[14, i]}")
78+
print(f" AREA%: {props[15, i]}")
79+
print(f" <B>: {props[16, i]}")
80+
print(f" <B+>: {props[17, i]}")
81+
print(f" <B->: {props[18, i]}")
82+
print(f" BMAX: {props[19, i]}")
83+
print(f" BMIN: {props[20, i]}")
84+
print(f" TOT_B+: {props[21, i]}")
85+
print(f" TOT_B-: {props[22, i]}")
86+
print(f" <PHI>: {props[23, i]}")
87+
print(f" <PHI+>: {props[24, i]}")
88+
print(f" <PHI->: {props[25, i]}")

chimerapy/scripts/downloaded_data/aia.lev1.171A_2016_10_31T00_00_10.35Z.image_lev1.fits

Lines changed: 61103 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.171A_2016_11_01T00_00_10.35Z.image_lev1.fits

Lines changed: 60925 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.171A_2016_11_02T00_00_10.35Z.image_lev1.fits

Lines changed: 61248 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.171A_2016_11_03T00_00_10.35Z.image_lev1.fits

Lines changed: 61158 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.171A_2016_11_04T00_00_10.35Z.image_lev1.fits

Lines changed: 61732 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.193A_2016_10_31T00_00_05.85Z.image_lev1.fits

Lines changed: 58539 additions & 0 deletions
Large diffs are not rendered by default.

chimerapy/scripts/downloaded_data/aia.lev1.193A_2016_11_01T00_00_05.84Z.image_lev1.fits

Lines changed: 58461 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)