Skip to content

Instantly share code, notes, and snippets.

@prateekiiest
Created March 27, 2018 12:58
Show Gist options
  • Save prateekiiest/bb7d29192fea03c908dbeb90f7bbf0b7 to your computer and use it in GitHub Desktop.
Save prateekiiest/bb7d29192fea03c908dbeb90f7bbf0b7 to your computer and use it in GitHub Desktop.
"""
========================================
Persistence Transform in Mapcubes
========================================
Persistence Transform is a simple image processing technique that is useful for the visualization
and depiction of gradually evolving structures.
This example illustrates persistence transform using the AIA_193_CUTOUT series.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cm
import sunpy.map
import sunpy.physics.differential_rotation as diffrot
from sunpy.data.sample import AIA_193_CUTOUT01_IMAGE, AIA_193_CUTOUT02_IMAGE, AIA_193_CUTOUT03_IMAGE
###############################################################################
# We create the MapCube using the AIA_193_CUTOUT sample data.
# To create a MapCube, we can call Map directly but add in a keyword to output a MapCube instead.
aiamapcube = sunpy.map.Map(AIA_193_CUTOUT01_IMAGE, AIA_193_CUTOUT02_IMAGE,
AIA_193_CUTOUT03_IMAGE, cube=True)
###############################################################################
# For a data set consisting of N images with intensity values I(x,y,t), the Persistence Map Pn is a
# function of several arguments, namely intensity, location and time:
# Pn(x,y,tn)=Q(I(x,y,t≤tn))
persistence_maps = []
for i, map_i in enumerate(aiamapcube[1:]):
per = np.array([aiamapcube[n].data for n in [i, i+1]]).max(axis=0)
smap = sunpy.map.Map(per, map_i.meta)
smap.plot_settings['cmap'] = cm.get_cmap('Greys_r')
smap.plot_settings['norm'] = colors.LogNorm(100, smap.max())
persistence_maps.append(smap)
###############################################################################
# This plots the original mapcube
aiamapcube.peek()
###############################################################################
# This plots the final mapcube after implementing the persistence transform
result_mapcube = sunpy.map.MapCube(persistence_maps)
result_mapcube.peek()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment