From Van Essen Lab

Jump to: navigation, search


Using Caret6 with Jython

Python is a popular object-oriented scripting language, most likely written using the C-programming language. Jython is a version of Python written in the Java programming language. Being written in Java, Jython provides the user with easy access to Java objects.

Jython can be used just like Python to create powerful scripting and for developing scripts that use caret6_command. However, Jython allows the user to access any part of Caret6's underlying Java code.

Installing Jython

Download and install Jython from the Jython Web-Site.

Setup for Jython and Caret6

There are two methods to integrate Jython and Caret6. One is to set the CLASSPATH environment variable prior to starting Jython and the other is to load the Caret6 JAR file after starting Jython.

Prior to using either method, you must determine the full path to the file caret6.jar. This file, caret6.jar contains the Java class files (object code) for all of the Caret6 programs (caret6, caret6_command, and the WebBrowser Caret6). The file caret6.jar is located in the Caret6 installation's jar directory. For example, /usr/local/caret6/jars/caret6.jar.

Method 1: Set the CLASSPATH Environment Variable

In the C-Shell or T-Shell on UNIX, execute the command: setenv CLASSPATH /usr/local/caret6/jars/caret6.jar.

Method 2: Load the Caret6 JAR File in Jython

After starting Jython, run the commands:

>>> import sys
>>> sys.path.append("/usr/local/caret6/jarss/caret6.jar")

Using Caret6 with Jython

Start Jython with Caret6 as described in the previous section.

Read a GIFTI Surface File and Examine the Number of Nodes and Triangles

>>> from edu.wustl.caret.files import SurfaceFile
>>> sf = SurfaceFile() 
>>> sf.readFile("/Users/john/caret_data/caret6_test_files/morphing/")
>>> sf.getNumberOfNodes()
>>> sf.getNumberOfTriangles()

Examine the Surface Normal for Node 45

>>> norm = sf.getNormal(45)
>>> norm
array('f', [0.3656187653541565, 0.3579605221748352, -0.8591782450675964])

Examine the First Data Array in the Surface File and its Metadata

>>> dataArray = sf.getDataArray(0)
>>> metaData = dataArray.getMetaData()
>>> metaData
edu.wustl.caret.giftijlib.GiftiMetaData [AnatomicalStructurePrimary: CortexRight]
[AnatomicalStructureSecondary: MidLayer]
[Caret-Version: 5.614]
[Date: 2010-03-03T08:35:27]
[GeometricType: Anatomical]
[UniqueID: {63b82a95-af36-48bc-89fa-ef84f0c3beb7}]
[UserName: john]
>>> metaData.get("Date")

Change the Value of Coordinate 1000

 >>> coord = sf.getCoordinate(1000)
 >>> coord
 array('f', [38.29424285888672, -16.298553466796875, -32.969764709472656])
 >>> coord[1] = 555.55
 >>> sf.setCoordinate(1000, coord)
 >>> sf.getCoordinate(1000)
 array('f', [38.29424285888672, 555.5499877929688, -32.969764709472656])
Personal tools
Sums Database