Tag Archives: translate

Day 37 – First Code Demo Summary

Well, I’ve taken quite a break in between posts, I think it’s about time I remedy this, and for good reason. Recently, a rather big moment (atleast for me) happened in my quest to develop code for SunPy: I built a functioning HEK to VSO translating module. Now it still has room for improvements and already I know of a couple of tweaks that I need to make, but as far as it goes it works and I was able to demo it to my mentors and other members of the SunPy group last Friday. With that said, this post will focus on recapitulating the demo and be a “how to” for using it.

First I would like to start with some background: this module arose from a need to translate the results from a HEK query into a usable data type that can be used in turn to query the VSO web-service. This module successfully performs this operation and returns the eventual VSO results in the form of a list. With that, let me show you how to use this module.

First, make sure you have the most recent copy of my fork which can be found with:

git pull https://github.com/mjm159/sunpy.git master

Next, open a python interpreter, my example will be done with ipython (which if you haven’t tried it yet, it’s awesome and totally worth the time and bandwidth to install).

Import the following modules:

from sunpy.net import hek2vso
from sunpy.net import hek
Next I’m creating the variables tstart, tend, and event_type to correspondingly hold the start time of the range, the end time, and the event type of interest:
tstart = '2011/08/09 07:23:56'
tend = '2011/08/09 12:40:29'
event_type = 'FL'
Now I’m creating an instance of the H2VClient():
h2v = hek2vso.H2VClient()
You may have been wondering why I had you import the hek module in conjunction with the hek2vso module, the reason is that the H2VClient() takes HEK style queries and as such I’m using the HEK attributes to form the queries. The results from the full query will be stored in the ‘results’ variable:
results = h2v.query(hek.attrs.Time(tstart, tend), hek.attrs.EventType(event_type))
When you run the query, it will act as a complete transaction between the HEK web-service and the VSO web-service. This process takes a while, and in response to that, when the full query is run a progress bar will appear. All that is simple enough, but there are a few more methods that should be mentioned.
On top of the results being stored in the variable, the instance will also hold a local copy of the HEK results and the VSO results, these can be returned at any time by calling the following methods (h2v being the previously declared instance of H2VClient()):
h2v.return_hek_results()
h2v.return_vso_results()
The instance will also keep track of the number of records returned from the previous query which can be accessed via this method:
h2v.return_num_records()
Finally, should you already have HEK results of your own that you would like to translate into a VSO formatted query, there is a method you can use easily use, which by passing in a list of HEK results, it will return a list of VSO style queries. To utilize, simply follow this form:
vso_formatted_query = h2v.translate_results_to_query(list_of_hek_results)

That’s all for now, following below are a list of intended future improvements:

  • Organize VSO results via the corresponding original HEK query
  • Break up the query stages to give multiple points in the process for the user to influence
  • Include the VSO.get() method

With that, that’s all my demo entailed, updates will come as I tweak the code and implement the desired improvements. If there are any questions in regard to this module, please message me either via wordpress or github.

Thanks everybody I’m calling it a night.