Closed wkerzendorf closed 9 years ago
If you want to edit the code it's pretty easy. You can do it either live, in a session by changing the dictionary of values, or you can edit it more permanently if you want to have it stick, let me write an example, I'll add it to the docs for my pull request today too.
So, you could edit the dictionary at the moment (not - ideal) by doing (where a is my imexam object created when I called connect():
a.exam.imexam_option_funcs['z'] = a.exam.imexam_option_funcs.pop('a')
Now the aperture photometry is controlled with the 'z' key instead of the 'a' key:
In [9]: a.exam.imexam_option_funcs Out[9]:
...rest of dict removed for length...
'z': (<bound method Imexamine.aper_phot of <imexam.imexamine.Imexamine object at 0x10b813f90>>, 'aperture sum, with radius region_size ')}
You can also change the defaults for all the plotting, there are functions for each which mimic the iraf lpar defaults.... you can also edit this file too which contains the defaults, I might make that easier for the use to update in the future: imexam_defpars.py which lives in the imexam code directory, edit then reinstall for a permanent change to the defaults.
\ also in the pull request I'm merging today lets you call the imexamine functions separately. i.e. if you had a data array and a list of positions that you wanted to create any of the default plots without using a viewing tool or being interactive, you just need to import and call like this:
import imexam from imexam import imexamine import numpy as np
data=np.random.rand(100,100) #create a random array thats 100x100 pixels plots=imexamine.Imexamine() plots.plot_line(10,10,data) #make a line plot at 10
More info on how the code is structured for the key bindings:
I use a dictionary to store the key binding mappings, it lives in the imexamine class (imexamine.py). The function set_option_funcs() builds the dictionary. (I doesn't take any input parameters, but maybe I could let you send in a list or key mapping to replace the defaults, that would be easy). The dictionary keys are the key-mappings, and the values are a tuple of the function reference they are linked to and a short description which is nice for printingg, here are a few lines from the default dictionary so you can see what it looks like:
In [6]: a.exam.imexam_option_funcs Out[6]:
{'2': (<bound method Imexamine.new_plot_window of <imexam.imexamine.Imexamine object at 0x10b813f90>>, 'make the next plot in a new window'), 'a': (<bound method Imexamine.aper_phot of <imexam.imexamine.Imexamine object at 0x10b813f90>>, 'aperture sum, with radius region_size '), 'b': (<bound method Imexamine.gauss_center of <imexam.imexamine.Imexamine object at 0x10b813f90>>, 'return the gauss fit center of the object'), 'c': (<bound method Imexamine.plot_column of <imexam.imexamine.Imexamine object at 0x10b813f90>>, 'return column plot'),
... The code then just matches the key to the function, for both the ds9 and ginga viewers.
There's already an example in the docs of how to write your own exam function and register it so that it's available for imexam() , check out http://imexam.readthedocs.org/imexam/imexam_command.html#user-specified-functions
huh, git removed the function signature text, but you get the idea... :)
I'll add, that if you want to ignore all the functions in the imexam loop, and not use the register function to add your own additional key-function bindings, you can just flat out replace that dictionary. Make a new dictionary which contains the same details and attached it to the exam object:
a.exam.imexam_option_funcs = dict( 'a': ( signature reference of my random function that plots stuff I like, 'description'))
The code is structured just to look up the key values and then run the function with which they are associated.
Thanks @sosey, I just presented your tool here at ESO Data Science Group (they thought it was pretty nice) and that was a question (and as an example of how nice github is - I put that question in :wink: ). Thanks, I'll show them right now.
sweet.
Hi @sosey, we were wondering here at ESO how easy it is to change the keybindings