Skip to content

Commit

Permalink
few fixes and added regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Deus1704 committed Jun 5, 2024
1 parent e057c54 commit d336b7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/finding_sunspots_using_stara.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import matplotlib.pyplot as plt
import sunpy.io._fits
import sunpy.map
from astropy.table import QTable
from astropy.time import Time
from skimage.measure import label, regionprops_table
from sunpy.net import Fido
from sunpy.net import attrs as a

Expand Down Expand Up @@ -91,3 +94,37 @@
ax.contour(segs, levels=0)

plt.show()

###############################################################################
# We can further enhance our analysis by extracting key properties from the
# segmented image and organizing them into a structured table.

# First, a labeled image is created where each connected component (sunspot)
# is assigned a unique label.
labelled = label(segs)
# If no sunspots are detected (labelled.max() == 0), print an empty table.
if labelled.max() == 0:
print(QTable())
else:
# Extract properties of the labeled regions (sunspots)
regions = regionprops_table(
labelled,
hmi_submap.data,
properties=[
"label", # Unique for each sunspot
"centroid", # Centroid coordinates (center of mass)
"area", # Total area (number of pixels)
"min_intensity",
],
)
# A new column named "obstime" is added to the table, which contains
# the observation date for each sunspot.
regions["obstime"] = Time([hmi_submap.date] * regions["label"].size)
# The pixel coordinates of sunspot centroids are converted to world coordinates
# (solar longitude and latitude) in the heliographic Stonyhurst projection.
regions["center_coord"] = hmi_submap.pixel_to_world(
regions["centroid-0"] * u.pix,
regions["centroid-1"] * u.pix,
).heliographic_stonyhurst
# Finally, the QTable containing the extracted sunspot properties is printed.
print(QTable(regions))
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"sunkit_image.tests.test_enhance.test_wow[map]": "f5535fad0fe2d6ff2bfdfb10a984bb6a21ece95d971070482136fe6e6f874f1a",
"sunkit_image.tests.test_radial.test_fig_nrgf": "ae38999f559e70365f71509ffc3add379e1fc0c1d6f534f4f9970cec7e04e157",
"sunkit_image.tests.test_radial.test_fig_fnrgf": "f54935e8f684bb474c4551728ee524b66de6cb6e935c54882617c03ace5db65a",
"sunkit_image.tests.test_stara.test_stara_plot": "86596467b2eb4a85066d55f83958e9d22b6593faa4b5e5ee563d5a53ae2bf7d8",
"sunkit_image.tests.test_trace.test_occult2_fig[array]": "c5ff1416cb51dc51ad1705174e5b13f8cb02486dc3c58fd79dc1b80534f6caf5",
"sunkit_image.tests.test_trace.test_occult2_fig[map]": "c5ff1416cb51dc51ad1705174e5b13f8cb02486dc3c58fd79dc1b80534f6caf5"
}

0 comments on commit d336b7f

Please sign in to comment.