Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_data(file_bz, file_by, file_bx, file_bz_err, file_by_err, file_bx_err, file_conf_disambig, file_bitmap, file_los):
"""function: get_data
This function reads the appropriate data and metadata.
"""
try:
bz_map = sunpy.map.Map(file_bz)
except:
print("Could not open the bz fits file")
sys.exit(1)
try:
by_map = sunpy.map.Map(file_by)
except:
print("Could not open the by fits file")
sys.exit(1)
try:
bx_map = sunpy.map.Map(file_bx)
except:
print("Could not open the bx fits file")
sys.exit(1)
sys.exit(1)
try:
bx_map = sunpy.map.Map(file_bx)
except:
print("Could not open the bx fits file")
sys.exit(1)
try:
bz_err_map = sunpy.map.Map(file_bz_err)
except:
print("Could not open the bz_err fits file")
sys.exit(1)
try:
by_err_map = sunpy.map.Map(file_by_err)
except:
print("Could not open the by_err fits file")
sys.exit(1)
try:
bx_err_map = sunpy.map.Map(file_bx_err)
except:
print("Could not open the bx_err fits file")
sys.exit(1)
try:
conf_disambig_map = sunpy.map.Map(file_conf_disambig)
except:
print("Could not open the conf_disambig fits file")
sys.exit(1)
radial_intensity_distribution_summary = get_radial_intensity_summary(
smap, radial_bin_edges, scale=scale, summary=width_function, **width_function_kwargs
)
# Storage for the filtered data
data = np.zeros_like(smap.data)
# Calculate the filter value for each radial bin.
for i in range(0, radial_bin_edges.shape[1]):
here = np.logical_and(map_r >= radial_bin_edges[0, i], map_r < radial_bin_edges[1, i])
here = np.logical_and(here, map_r > application_radius)
data[here] = smap.data[here] - radial_intensity[i]
if radial_intensity_distribution_summary[i] != 0.0:
data[here] = data[here] / radial_intensity_distribution_summary[i]
return sunpy.map.Map(data, smap.meta)
radial_bin_summary.to(u.R_sun).value <= fit_range[1].to(u.R_sun).value,
)
# Fits a polynomial function to the natural logarithm of an estimate of
# the intensity as a function of radius.
polynomial = fit_polynomial_to_log_radial_intensity(
radial_bin_summary[fit_here], radial_intensity[fit_here], degree
)
# Calculate the enhancement
enhancement = 1 / normalize_fit_radial_intensity(map_r, polynomial, normalization_radius)
enhancement[map_r < normalization_radius] = 1
# Return a map with the intensity enhanced above the normalization radius
# and the same meta data as the input map.
return sunpy.map.Map(smap.data * enhancement, smap.meta)
radial_intensity_distribution_summary = get_radial_intensity_summary(
smap, radial_bin_edges, scale=scale, summary=width_function, **width_function_kwargs
)
# Storage for the filtered data
data = np.zeros_like(smap.data)
# Calculate the filter for each radial bin.
for i in range(0, radial_bin_edges.shape[1]):
here = np.logical_and(map_r > radial_bin_edges[0, i], map_r < radial_bin_edges[1, i])
here = np.logical_and(here, map_r > application_radius)
data[here] = (
smap.data[here] - radial_intensity[i]
) / radial_intensity_distribution_summary[i]
return sunpy.map.Map(data, smap.meta)
aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
# The original image is plotted to showcase the difference.
fig = plt.figure()
ax = plt.subplot(projection=aia_map)
aia_map.plot()
###########################################################################
# Applying Multi-scale Gaussian Normalization on a solar image.
# The `sunkit_image.enhance.mgn` function takes a `numpy.ndarray` as a input so we will pass only
# the data part of `~sunpy.map.GenericMap`
out = enhance.mgn(aia_map.data)
# The value returned is also a numpy.ndarray so we convert it back to
# a sunpy.map.GenericMap.
out = sunpy.map.Map(out, aia_map.meta)
###########################################################################
# The resulting map is plotted.
fig = plt.figure()
ax = plt.subplot(projection=out)
out.plot()
# All the plots are plotted at the end
plt.show()
import astropy.io
import sunpy.map
from astropy import units as u
import sunkit_image.trace as trace
###########################################################################
# We will be using `astropy.io.fits.open` to read the FITS file from the tutorial website
# and read in the header and data information.
hdu = astropy.io.fits.open(
"http://www.lmsal.com/~aschwand/software/tracing/TRACE_19980519.fits", ignore_missing_end=True
)[0]
# We can now make this into a `sunpy.map.GenericMap`. There is currently not an instrument specific
# class for the TRACE instrument.
trace_map = sunpy.map.Map(hdu.data, hdu.header)
# We can now plot the map, of which we can see coronal loops.
trace_map.plot()
###########################################################################
# Now the loop tracing will begin. We will use the same set of parameters
# as in the IDL tutorial.
# The lowpass filter boxcar filter size ``nsm1`` is taken to be 3.
# The minimum radius of curvature at any point in the loop ``rmin`` is 30 pixels.
# The length of the smallest loop to be detected ``lmin`` is 25 pixels.
# The maximum number of structures to be examined ``nstruc`` is 1000.
# The number of extra points in the loop below noise level to terminate a loop tracing ``ngap`` is 0.
# The base flux and median flux ratio ``qthresh1`` is 0.0.
# The noise threshold in the image with repect to median flux ``qthresh2`` is 3.0 .
# For the meaning of these parameters please consult the OCCULT2 article.
loops = trace.occult2(
radial_bin_summary.to(u.R_sun).value <= fit_range[1].to(u.R_sun).value,
)
# Fits a polynomial function to the natural logarithm of an estimate of
# the intensity as a function of radius.
polynomial = fit_polynomial_to_log_radial_intensity(
radial_bin_summary[fit_here], radial_intensity[fit_here], degree
)
# Calculate the enhancement
enhancement = 1 / normalize_fit_radial_intensity(map_r, polynomial, normalization_radius)
enhancement[map_r < normalization_radius] = 1
# Return a map with the intensity enhanced above the normalization radius
# and the same meta data as the input map.
return sunpy.map.Map(smap.data * enhancement, smap.meta)