First make sure that the repos are up to date
sudo apt-get update
Then add in all the packages which are required for the SDA
sudo apt-get install python-dev python-numpy python-scipy
python-matplotlib python-setuptools ipython libtiff4
openjdk-6-jdk subversion
Insert the sda disk, and copy the program into your home dir (or wherever you want it), and unzip it
cp /media/sda/Scisoft-client-r12345-Linux32.zip .
unzip Scisoft-client-r12345-Linux32.zip
You now need to install the pyTiffLib library, which can be obtained online, however we include it in the SDA release for ease
sudo easy_install client/plugins/uk.ac.diamond.scisoft.python_1.0.0.12345/pylibtiff
Now you are ready to launch the SDA
client/scisoft
To set up Python, go to ‘Window->Preferences->Pydev->Interpreter-Python’ and click on Auto-Config, then click ok and ok.
To make a pydev project work well with the scisoft functionality, there is a small addition to make, on the project right click and select properties. Then select pydev-PythonPath and in the External Librarys tab click ‘add source folder’ and browse to the directory ‘/home/name/client/plugins/uk.ac.diamond/scisoft/python_1.0.0.12345’ and click ok.
If you have a pydev project the Python console should pick up the configuration correctly, however if it dosent you can make the console work in the following way Open the console view(Window->Showview->Console) and in the far right dropdown menu in the console view (open console) click on Pydev Console. Then select Python console from the available list and click OK. Finally there is a single line of code which needs to be run (this can be made easier by enabling a new feature for path completion, Window->Preferences->Pydev->Interactive console->Completions and check both Enable completions and Request completions on /). The command to enable python is
sys.path.append('/home/name/client/plugins/uk.ac.diamond.scisoft.python_1.0.0.12345')
Then you should be able to use
import scisoftpy as dnp
First use module to load up everything you need
module load python/2.6
module load sda/nightly
You will need some information later which is easiest to get hold of now so do the following and copy the result apart from the ‘sda’ on the end
which sda
you will also need to get the following path
which python
Now you are ready to launch the SDA
sda
To set up Python, go to ‘Window->Preferences->Pydev->Interpreter-Python’ and click on new. In the Interpreter name field enter the name ‘Python’ and in the Interpreter Executable filed paste the result of your ‘which python’ command from earlier. Finally click apply and then OK once it has finished.
To make a pydev project work well with the scisoft functionality, there is a small addition to make, on the project right click and select properties. Then select pydev-PythonPath and in the External Librarys tab click ‘add source folder’ and browse to the directory ‘/copied/from/which/command//release/plugins/uk.ac.diamond/scisoft/python_1.0.0.12345’ and click ok.
If you have a pydev project the Python console should pick up the configuration correctly, however if it dosent you can make the console work in the following way Open the console view(Window->Showview->Console) and in the far right dropdown menu in the console view (open console) click on Pydev Console. Then select Python console from the available list and click OK. Finally there is a single line of code which needs to be run (this can be made easier by enabling a new feature for path completion, Window->Preferences->Pydev->Interactive console->Completions and check both Enable completions and Request completions on /). The command to enable python is
sys.path.append('/copied/from/which/command//release/plugins/uk.ac.diamond/scisoft/python_1.0.0.12345')
Then you should be able to use
import scisoftpy as dnp
As the SDA tries to use hardware acceleration as much as possible, sometimes there can be issues when graphics cards incorrectly identify themselves to the program. This will become apparent when using the program if any of the plots are empty or incredibly slow and unresponsive. If this is the case then there are 2 levels of forced graphics which can be applied to try to make sure that you can still use the majority of the sda’s functionality. To activate these methods you need to start the sda with the following commands
scisoft -vmargs -Duk.ac.diamond.analysis.rcp.plotting.useGL13=True
scisoft -vmargs -Duk.ac.diamond.analysis.rcp.plotting.useSoftware=True
The first will stop the SDA using more modern graphics card features, this will disable some feature and reduce the proformace of some others. The second will move to software rendering, all plotting will be slower, but should still work with no issues.
Now we have a working python environment we can make use of some of the nice python functionality, lets first create a python project. In the pydev package explorer view right click and select New->Project then select Pydev->Pydev Project. Fill in the information that is needed, and then click finish. Now that the package is created, we can write some code, lets start with something simple. Right click on the src directory of the new project and click on New->Pydev Module. In the wizards give this the name “hello” and select Module: Main from the template list, then click finish. The new file is then opened in the editor area and your ready to go, so replace pass with
print("Hello World")
Now we have a script thats ready to go, so to run it, find its name in the project explorer, right click and select Run As->Python Run. The console should then pop to the front and show you the text “Hello World”.
Now that we have a basic script lets look at using some python packages to keep your code nice and tidy, and also introduce some of the scisoftpy functionality. Right click on the src folder and select New->Python Package and enter the name plotting. In the project explorer right click on the package plotting and select New->Pydev Module, then give the name plottest and select Module: Class from the dropdown. The new file should have opened, and there will be several sections to change to the template. Change the class name from MyClass to PlotClass and then fill out the class to look like the following
import scisoftpy as dnp
class PlotClass(object):
'''
docs
'''
def __init__(self):
'''
Constructor
'''
pass
def plot_1d(self):
x = dnp.arrange(0,10,0.1)
y = dnp.sin(x)
z = dnp.cos(x)
dnp.plot.line(x,[y,z])
def plot_stack(self):
x = dnp.arrange(0,10,0.1)
y = dnp.sin(x)
z = dnp.cos(x)
dnp.plot.stack(x,[y,z])
def plot_2d(self):
im = dnp.random.rand(100,100)
dnp.plot.image(im)
def plot_surf(self):
im = dnp.random.rand(100,100)
dnp.plot.surface(im)
Now that this class is set up to do some plotting for us, let’s make use of it in out hello script, so open this and change the code to the following
from time import sleep
from plotting.plottest import PlotClass # This is where we bring in the class we have just made
if __name__ == '__main__':
print("hello world")
pc = PlotClass()
pc.plot_1d()
sleep(2)
pc.plot_2d()
sleep(2)
pc.plot_stack()
sleep(2)
pc.plot_surf()
Now open the plot 1 view, which is where all this output will go by clicking Window->Show Plot View-> Plot 1. Then run the hello script and watch the output, if any of the screens show nothing then it might be wise to check the section above entitled Graphics Issues
A very powerful feature of pydev is its debuging functionality, we will use the example above to demonstrate this. in the hello.py script, right click in the left margin next to the line
print("hello world")
And select add breakpoint from the drop down menu. Now instead of using the run command, right click and say ‘debug as-> python run’. This should then show a screen suggesting that you move to the debug perspective, click yes to this. You should see that the script has now paused on the line you specified earlier, and you can now look at what’s going on inside your script. The Variables window lets you look at all the classes and variables that are alive at this point in the script and you can then use the buttons in the debug view to move through the code a step at a time or go into or out of functions. For example, if you press F6, this will step you on one, and you should see the console output appear. If you then press F5 you will follow the code into the constructor of your PlotClass, F6 will then return you back to the script as the construction is completed. Open the Plot 1 window on this perspective and you can watch the plots appear as you step over them with F6, or F5 to look back to the functions you wrote in the class. If you get in too deep and want to come out, F7 will return you up a level, so you can keep pressing this till you get back to somewhere you recognise. Finally if you want to just keep going till the next breakpoint, press F8.