Subject: Script for setting contour levels
From: Tom Goddard
Date: May 12, 2010

Previous: 708
Attachment: sparky_init.py

Sorry for the third posting of this. Yahoo Groups is screwing me up.
The inline script was shown without indentation in the preceding
message. Indentation is critical in the Python language. To see the
correct indentation on the Sparky Yahoo Group web site click Show
Message Options located in the right column and Use Fixed Width Font.

Although the Sparky Yahoo Group is configured to archive attachments on
the web site and not send them in the email it is doing just the
opposite (sending in email if you receive individual emails, and not
archiving).


Here is the sparky_init.py script.


def initialize_session(session):

def set_contour_levels():

p = session.project

from sparky import Contour_Levels

plev = Contour_Levels()
plev.lowest = 1000
plev.factor = 1.2
plev.levels = 5
plev.color = red

nlev = Contour_Levels()
nlev.lowest = -1000
nlev.factor = 1.2
nlev.levels = 5
nlev.color = green

for v in p.view_list():
v.positive_levels = plev
v.negative_levels = nlev

session.add_command(kl, Set all contour levels,
set_contour_levels)




Hi Marco,

You can add a shortcut and menu entry for setting all contour
levels using the attached Python code that you put in the Sparky
start-up file:

~/Sparky/Python/sparky_init.py

This will add a shortcut kl that sets the contour levels of all open
spectrum windows. The actual contour level is hard-coded in the
sparky_init.py file. If you wanted to be able to type the number into a
dialog that would take some more work to code the dialog in Python. It
is not too hard if you want me to show you.

Tom


Hi Tom,


I have a little question about sparky. Is there a way to make
an extension that lets you adjust the contour levels for multiple
spectra at the same time ? I need to open a bunch of 2D planes and I
would like to set the contour levels the same for all of them, but
doing it one at the time by hand takes a lot of time. I tried looking
at other extensions and the classes available, but I dont see anything.

Thanks a lot,

Marco