This tutorial teaches you how to take one of the Jython tasks included in HIPE and modify it to suit your needs.


Read this tutorial if you want to change the behaviour of a task included in HIPE. For example, you may want to tweak the algorithm used in a pipeline task. This tutorial explains how to modify a Jython task. Jython tasks are used mainly by PACS. If you want to modify a Java task, read the Modifying an existing Java task tutorial.


This tutorial assumes that you are familiar with the following:
  • Basic Jython syntax and scripting. If this is not the case, read Chapter 1 of the Scripting Guide.
  • Basic notions about HIPE tasks. If this is not the case, read What is a HIPE task? in the Creating your first Jython task tutorial.


This tutorial will teach you the following:
  • How to get the source code of an existing HIPE task.
  • How to create a modified version of the task.
  • How to import the modified task into HIPE.
  • How to switch between the original and the modified version.
  • How to share the modified task.


For this tutorial we will use as example the PACS task isSolarSystemObject.


Obtaining the task source code

To complete these steps you must have the source code of HIPE installed. You must have ticked the Would you like to have the source code installed? checkbox when installing HIPE.
  1. Locate the task in the Tasks view of HIPE. You can open the All folder and type the first letters of the task name to find the task more quickly.
  2. Right click on the task name and choose View source. The source code opens in a new tab inside the Editor view.
  3. Choose File -> Save as and save the file to a different location.
You now have a working copy of the task source code. In this tutorial we save the original task source code as a new file called MyIsSolarSystemObjectTask.py.

Modifying the task

  1. Change the source code according to your needs. For this tutorial we will just add a printstatement, so that we can distinguish between the modified and the original task. Immediately below the line def func_isSolarSystemObject (obs):, add the line print "This is the modified version", so that the code looks like this:
    def func_isSolarSystemObject (obs):
      print "This is the modified version"
      _naifid = ""

    Remember to indent the new line by two spaces, like the line coming after it.
  2. Change the task name by adding a My in front of it. You can change the task name by modifying the following code
    class IsSolarSystemObjectTask(Task):
       def __init__(self, name = "isSolarSystemObject"):

    to look like this:
    class MyIsSolarSystemObjectTask(Task):
        def __init__(self, name = "myIsSolarSystemObject"):
  3. Save the file.
The changes to the task are complete.
The next step is importing the task into HIPE. There are two ways to do that:
  • Loading the script manually into HIPE.
  • Creating and installing a HIPE plugin.
These alternatives are explained in the next two sections.

Manually importing the modified task into HIPE

  1. Load the task into the Editor view by choosing File -> Open File or by double clicking on the task file in the Navigator view.
  2. Execute the whole task script by clicking the double arrow icon in the HIPE toolbar.
  3. Create an instance of the task by issuing this command in the Consoleview:myIsSolarSystemObject = MyIsSolarSystemObjectTask(). You can add this line at the end of the task script to have it executed automatically.
You can now execute the modified task.
Our example task needs an Observation Context as input, so we will create an empty one for testing purposes:
obs = ObservationContext()
result = myIsSolarSystemObject(obs)
You should see the string This is the modified version printed to the Console view, confirming that we ran the modified task instead of the original one.
If you close and reopen HIPE, the modified task will no longer be available. You will have to load and execute the task script again. Moreover, the task will not appear in the Tasks view.

Creating a HIPE plug-in

By creating a plug-in, you can have your task automatically available in the Tasks view every time you start HIPE. Creating a plug-in is as easy as creating a zip file.
  1. Create a Jython script called plugin.py. In our case the script would be the following:
    from herschel.ia.gui.apps.plugin import PluginRegistry
    reg = PluginRegistry.getInstance()
    name = 'ModifiedTaskPlugin'
    plugin = reg.get(name)
    basedir = plugin.pluginDir.absolutePath
    execfile(basedir + '/MyIsSolarSystemObjectTask.py')
    toolRegistry = TaskToolRegistry.getInstance()
    toolRegistry.register(MyIsSolarSystemObjectTask(), [Category.PACS])

    This script does the following:
    • It defines a name for the plug-in (in this case ModifiedTaskPlugin) and registers it.
    • It references the file MyIsSolarSystemObjectTask.py, which contains the actual task.
    • Creates an instance of the task and registers it. In this case, it registers it to the PACS category.
  2. Pack the plugin.py file and the task file (in our case MyIsSolarSystemObjectTask.py) into a zip file.The name of the zip file must follow these rules for the plug-in to install correctly:
    • The plug-in name as defined in the plugin.py file, in our case ModifiedTaskPlugin.
    • An underscore character.
    • A version number, made by digits separated by dots. For example, 0.1.
    In our case the zip file is called ModifiedTaskPlugin_0.1.zip and contains the two files plugin.py and MyIsSolarSystemObjectTask.py, on the same level.
Your plug-in is now ready. Read on to learn how to install it.

Installing the HIPE plug-in

  1. In HIPE, choose Tools -> Plug-ins . The Plug-ins dialogue window opens.
  2. Click Install new. The Install new plug-in dialogue window opens.
  3. Click the folder icon and navigate to the zip file you have created. Click Open.
  4. Click Install. HIPE should inform you that the plug-in has been installed correctly.
  5. Restart HIPE.
The plug-in should now be installed correctly. Go to the Tasks view, open the All folder and type the first letters of the task name to jump to the right place in the list. You should see your new task. The task should also appear in any category you added it to, inside the By Category folder.

Switching between the original and the modified task

Now you have the original and modified task loaded in HIPE. You may have a pipeline script that calls the original task, and you may want it to call the modified task instead. You can of course modify the pipeline script and replace the original task name with the modified task name. However, this can be tedious and error-prone if the script calls the task many times.
To complete this task you must know the fully qualified name of the original task. To find the fully qualified name of a task, right click on the task name in the Tasks view and choose Help in URM. The task entry in the User's Reference Manual opens in your browser. The Full Name entry in the table at the top is the fully qualified name. For the isSolarSystemObject task, the qualified name is herschel.pacs.spg.common.IsSolarSystemObjectTask.
You can create an alias to use the modified task instead of the original one, as in the following example:
obs = ObservationContext()  # Creating an empty observation context
print isSolarSystemObject(obs)  # Executing the original task
# False
isSolarSystemObject = myIsSolarSystemObject  # Creating alias
print isSolarSystemObject(obs)  # Now the modified task is executed
# This is the modified version
# False
After the above steps, the original task is hidden by the modified task. The following example shows how to revert to the previous situation. This is where the fully qualified name of the task comes into play:
del (isSolarSystemObject)  # Removing the alias
# Recreating instance of original task
isSolarSystemObject = herschel.pacs.spg.common.IsSolarSystemObjectTask()
The original task is now available again, while you can still call the modified task by using the myIsSolarSystemObject name.

Sharing your modified task

You may want to share your task with your colleagues or with a wider user base. You have the following options:
  • To share your task among a small circle of colleagues: You can simply circulate by email the .py file with the modified task or the .zip plug-in file, if you created one.
  • To share your task among a wider circle of users: You can post the .py file with the task or the .zip plug-in file to the HIPE Community wiki. Open a free account, then click Pages and Files in the top left corner of the page to upload your file. Then edit one of the pages, or add a discussion post, with a link to the file you uploaded.
  • To add your task to the official list of Herschel user-contributed software: Open a Helpdesk ticket with your request. For more information read the Herschel Tools Contributor's Guide.
  • To add your plug-in to the official list of HIPE plug-ins: Send an email to Alvar GarcĂ­a.