New to SunPy, trying to make time-lapse videos of AIA data

360 views
Skip to first unread message

Miles Gordon

unread,
Nov 2, 2017, 4:37:59 PM11/2/17
to SunPy
Hi everyone, I'm currently trying to port the functionality of an IDL script to python using SunPy, and I'm running in to a bit of trouble. The script's purpose is to make time-lapse videos out of a directory of AIA fits files.

I can sunpy.map.Map(My Fits File), and when I .peek() at it, it shows me the image processed exactly as I expect it to be, but with a lot of additional information that I don't quite need. Is there a convenient way to get sunpy.map to do all of the color mapping and normalizing but without adding all of the graphing data on top? I'm sorry if that's somewhere obvious in the documentation, but I've gone in circles with it a couple of times and can't quite get it.

Cheers!

Larry Manley

unread,
Nov 2, 2017, 11:34:57 PM11/2/17
to SunPy
I use https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imsave.html?highlight=matplotlib%20pyplot%20imsave#matplotlib.pyplot.imsave

Basic example:
plt.imsave('filename.png', aiamap.data, cmap=aiamap.plot_settings['cmap'], origin='lower')
but this doesn't use the map's normalization method.
I pre-process the data with the values from aia_intscale.pro

If you want timestamps that's a little more involved.
E-mail me (larry.ju...@gmail.com) and I can send you some of my scripts.

Miles Gordon

unread,
Nov 3, 2017, 11:54:50 AM11/3/17
to SunPy
This is a big step in the right direction, thank you! As I understand it, sunpy.instr.aia.aiaprep will do the extra bit of preprocessing that I need, but when I try to run it I get an error:
     

KeyError: 'crpix1'


Any idea what that's about?

Larry Manley

unread,
Nov 4, 2017, 6:51:42 AM11/4/17
to SunPy
How are you getting your AIA files?  Check if there is header info in your FITS files.  For example, if you get data from JSOC "as-is" rather than "FITS" it will only generate the image portion without the meta data.

Kolja Glogowski

unread,
Nov 6, 2017, 1:28:20 PM11/6/17
to SunPy
Unlike HMI FITS files, AIA files do actually contain full FITS headers when they are exported using protocol="as-is". But these "as-is" headers are most likely outdated because they are not updated after the files have been imported into the JSOC system, so you need to use the "FITS" export protocol to get FITS files with updated headers.

But, even if they are possibly outdated, AIA FITS files should always contain WCS keywords, regardless of the export protocol. Maybe the KeyError exception has something to do with the Rice compression that is used. This compression method results in FITS files with an empty primary HDU, and an extension HDU that contains the metadata (including the WCS keywords) and the compressed image data.

Cheers,
Kolja

Miles Gordon

unread,
Nov 8, 2017, 11:52:09 AM11/8/17
to SunPy
The answer to this problem for anyone who has it in the future came courtesy of Jack Ireland:


from __future__ import print_function, division                             
import matplotlib.pyplot as plt                     
import sunpy.map                    
from sunpy.data.sample import AIA_193_IMAGE
import numpy as np                             
import matplotlib.pylab as plt

smap = sunpy.map.Map(AIA_193_IMAGE)
sizes = np.shape(smap.data)     
fig = plt.figure()
fig.set_size_inches(1. * sizes[0] / sizes[1], 1, forward = False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(smap.data, norm=smap.plot_settings['norm'], cmap=smap.plot_settings['cmap'], origin='lower')
plt.savefig('test_image.png', dpi = sizes[0]) 
plt.close()

This works well in my use case, rendering square processed AIA images at native resolution. I never solved the KeyError, but the file that generated it was older, and not from the source that I'm working with primarily, so I'm abandoning it for now.

Stuart Mumford

unread,
Nov 8, 2017, 1:58:07 PM11/8/17
to su...@googlegroups.com
I don't know if it will do exactly what you want but there is also the `badic_plot` keyword argument to map.peek which does something similar to the example.

Stuart
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

miles gordon

unread,
Nov 8, 2017, 2:10:24 PM11/8/17
to su...@googlegroups.com
Hi Stuart- 

The "basic_plot" kwarg achieved close to what I wanted, but it was forcing a change in aspect ratio that I could not override through any combination of arguments. It's worth noting that map.plot() also has a "_basic_plot" argument, however that seemed to be ignored, as I always ended up with labeled axes using this method.

--
You received this message because you are subscribed to a topic in the Google Groups "SunPy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sunpy/lsjhzi6mRxQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sunpy+unsubscribe@googlegroups.com.
To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages