Wavelets.py: available from http://www.phy.uct.ac.za/courses/python/examples/Wavelets.py . A version of the Torrence and Compo code (Torrence, Christopher, Gilbert P. Compo, 1998: A Practical Guide to Wavelet Analysis. Bull. Amer. Meteor. Soc., 79, 61–78.) The code as is drops some required namespace names, i.e., the square root is called as ‘sqrt’ instead of NP.sqrt, etc, so watch out.
kPyWavelet: available from https://github.com/regeirk/kPyWavelet . A more complete version of the Torrence and Compo code that includes a calculation of the cone of influence, significance levels, etc. The accompanying piece of code ‘sample.py’ is particularly useful in finding out how to use the code and how to display the results.
At the moment, I am spending more time using kPyWavelet as it has the wavelets I am interested in. I copied the kPyWavelet straight from the github download into my (OS X) Macports site packages location. It imported without any trouble. If you find any other wavelet packages that might be useful, let us know.
Today I tried to install pIDLy with my Macports-based Python installation. Macports-based Python is the currently recommended method of using sunpy on OSX. pIDLy, written by A. Smith and available here (http://astronomy.sussex.ac.uk/~anthonys/pidly/ ) is a free package that allows communication from a Python session to an IDL session. It is not available via Macports. pIDLy does use the package “pexpect”, which is available via Macports, so you will have to install via standard Macports commands to go any further with pIDLy and Macports-Python.
pIDLy uses the easy_install method to install itself. Out of the box, pIDLy does not install into the location where Macports-Python can find it. So what to do? So, I am not so clever with Python, so I choose a very simply approach. I copied the pidly.py file into the “site-packages” location for Macports-Python which is (for my machine):
I fired up Macports-Python, imported pidly, then applied the SSWIDL-pIDly script to tell pIDLy about SSWIDL (thanks to Shane and available here), and much to my surprise, it worked. Well, at least my simple SSWIDL test worked (>>> idl( ‘plot_image, findgen(10,10)’) ).
I have no doubt there are smarter ways of installing pIDLy into Macports-Python, and if you find one, please let me know. Finally, pIDLy has been tested up to Python 2.6, and I am running 2.7, so there is the potential for compatibility issues to show up.
SunPy is now listed on code.NASA.gov a website whose purpose is to serve to surface existing open-source projects at NASA, provide a forum for discussion, and guide internal and external groups in open development, release, and contribution.
A new feature introduced in Matplotlib 1.1 is a basic animation framework. While not providing nearly as much flexibility as callingFFmpeg yourself, it provides a quick and dirty way to create basic animations of anything that can be plotted with Matplotlib, including images.
Below is an example which reads in a series of FITS or JP2 images, displays an animation of the result and saves the animation as an MP4.
"""Based on http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html"""
import matplotlib.pyplot as plt
import matplotlib.animation as animation
imagedir = '/home/user/data'
filenames = sorted(os.listdir(imagedir))
fig = plt.figure()
ims = 
for x in filenames:
print("Processing %s" % x)
im = sunpy.make_map(os.path.join(imagedir, x)).resample((1024, 1024))
extent = im.xrange + im.yrange
axes = plt.imshow(im, origin='lower', extent=extent, norm=im.norm(), cmap=im.cmap)
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=1000)
There are a number of limitations with the above approach, but the main one is the lack of ability to control the quality and other settings for the video that gets saved. There is even a codec option that is available but doesn’t have any effect on the output. Future versions of Matplotlib should provide more control over the output.
As for SunPy, this now opens the door for simple animations with MapCube objects. For example, perhaps the SunPy plot tool could include support for displaying Mapcubes as movies, and the MapCubes themselves could include some options like “show()” and “save()” to display/save a movie of the data contents.
Looks like it is possible to improve the quality of the output video using the “frame_prefix” parameter, a string that is simply appended to the end of the FFmpeg command right before the output filename. E.g. using frame_prefix=”-vcodec libx264 -vpre ultrafast -crf 15 -an” will result in an H.264 video being generated on systems with libx264.
Here is a quick tutorial on making a difference movie using SunPy and FFmpeg. Some sample JPEG 2000 data used to make the example video is provided. Make sure you install OpenJPEG first though to be able to use the JP2 images, or else feel free to use your own FITS data.
#-*- coding:utf-8 -*-
from matplotlib import colors
from matplotlib import pyplot
"""Create running difference images for the specified data"""
imagedir = '/home/user/data'
outputdir = '/home/user/frames'
width = 1024
height = 1024
# Create output directory if it doesn't already exist
if not os.path.isdir(outputdir):
filenames = sorted(os.listdir(imagedir))
# Process first file
print("Processing %s" % filenames)
before = sunpy.make_map(os.path.join(imagedir, filenames.pop(0))).resample((width, height))
for i, filename in enumerate(filenames):
# Read in next file
print("Processing %s" % filename)
after = sunpy.make_map(os.path.join(imagedir, filename)).resample((width, height))
# Create difference image
diff = after - before
# Save difference image to file
plot = diff.plot(draw_limb=True, norm=colors.Normalize(-16, 16))
# Plot dimensions (1200x1200px at 100dpi)
plot.savefig("frame%d.png" % i, dpi=100, bbox_inches='tight', pad_inches=0.25)
pyplot.clf() # Free up memory
before = after
after = None
if __name__ == '__main__':
In the above command, the “-vpre ultrafast” switch just tells FFmpeg to use a specified set of configuration options as a baseline and FFmpeg may complain if it can’t find the .ffpreset file on your system. In that case just remove the option and it should work fine.
Another simpler example:
ffmpeg -i frames/frame%d.png -r 15 out.mp4
While putting together the example, I ran also encountered some problems. For instance, during the script execution I would sometimes run into MemoryError exception (or segfault) when too much memory was consumed (e.g. during the call to resample()). Working with only two images at a time helped to limit the errors, but has not completely solved the problem.
I also wasn’t able to figure out a simple way to generate a PNG such that the subplot has some specified pixel dimensions (e.g. 1024×1024). In the above, I simply settled for specifying that the entire plot (including the axes and colorbar) should have certain dimensions, and then trimming those down a bit with “bbox_inches” and “pad_inches”.
Florian Mayer has recently given a talk introducing Python and SunPy to students at the University of Graz, Austria. A recording of his talk (in German) and slides (in English) are available online. Thanks Florian!
We are proud to announce our first release, SunPy 0.1! In this release we have taken the first steps towards a viable data analysis environment for solar physics in Python. SunPy 0.1 can now
open and plot fits files from SDO/AIA, SOHO/EIT, TRACE, and RHESSI as well as other solar observatories along with many of the relevant color tables for these data.
Query and download data directly from the Virtual Solar Observatory (VSO) as well as query the Heliophysics Event Knowledgebase (HEK).
provide basic solar-related physical constants (e.g. solar radius, mass, luminosity) in a quick and convenient way.
provide a GUI tool to open fits files and interact with them.
The GSFC SunPy team (Steven Christe, Keith Hughitt, Jack Ireland, Alex Young, and Albert Shih) would like to thank our two SunPy summer students, Florian Mayer and Matt Earnshaw, for their contributions! We look forward to continuing to work with them and would like to encourage the solar community to join us and contribute to the SunPy effort.
Hi, I’m Matt Earnshaw, a first year Physics student at Imperial College London. Currently, I’m working on the SunPy Plot Manager GUI, aka. Plotman.
The goal of Plotman is to provide a convenient interface for manipulating plotted data such as spectrograms, light curves, images etc. making easy the tasks that would be tedious and time consuming to carry out at an interactive prompt. This is achieved by providing instant visual feedback and easy access to the relevant parts of SunPy such as its built in colour maps.
Thus far, I have implemented a tabbed window interface for working with multiple plots and a dockable colour options window that allows switching between any of SunPy’s or matplotlib’s colour maps, clip values selectors and a histogram of the plotted data, as well as integrating all of the plot manipulation functionality provided by matplotlib. At the moment I consider this is all to be very much at the prototype stage.
The interface thus far.
Next I will start work on the over-plotting interface for contours, limbs etc. and providing support for animations using the MapCube object. In the future we may add an interface for downloading data from VSO using Florian’s API, amongst other things.
Thanks to the SunPy team for their support and providing the opportunity to work on this great project. I am pleased to be supporting the effort to encourage the use of free and open source software in science, and hope that my contributions will be as valuable to SunPy as the experience of working on the project has been to me so far.
Hello! I am Florian, the student by the ESA SOCIS 2011 to work on SunPy. I am currently a student at the Vienna University of Technology in Austria majoring in Software and Information Engineering . The code I am working on can be found on GitHub segfaulthunter / sunpy. In this post I am going to give a short introduction to the work I have done so far. We will be posting short tutorials sometime soon.
First, I have been working on a VSO (Virtual Solar Observatory) adapter in Python (Code here, documentation here) which is now finished. The VSO is a service to obtain solar data from the instruments that observe it. I have conceived a new API that is capable of expressing more complicated queries than the one in IDL was able to; moreover I have added a legacy API that tries to mimic the IDL search query as closely as possible (it does not attempt of mimicing IDL’s feature for expanding substrings of parameters to the respective parameter because the feature does not make sense in the context of Python). I consider the adapter stable and functional by now.
I have also been working on an adapter for the HEK HER (Helioevents Registry). The HER is a service to query for solar metadata (data about events that happened on the Sun). It currently works but needs some more attention for users to be able to get the most out of it. I have also conceived an API for this service that I think naturally exposes it to Python programming language.
It has also been important to me to review and, if necessary, refactor old code, work on unittesting, and help the team to get the hang of git and the other tools used for developing SunPy. In less than a month I will be giving a talk at the University of Graz to introduce scientific computing with Python and SunPy and preparing it will be the main focus of the following weeks to come. If all goes well a recording of the talk will be available for everyone to view online.
At this point, I would like to thank the SunPy team and ESA for giving me the opportunity to work in a scientific environment and I hope that the following months will be as fun and productive as the last month!
The colors module of Matplotlib provides the ability to set the scale of the color table. It is necessary to set this by hand right now but this will be updated soon so that you don’t have to worry about it the first time you open an image.
We now provide convenience variables to access the test files available in SunPy. That means you no longer need to worry about where they are physically located.
Currently SunPy can only read in RHESSI fits files which contain only one image.