Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This tutorial is not designed to be worked through in order! Pick the section you find most appealing useful and go for it!

Workflows

Workflows are a powerful labview-esque visual programming language. There are good guides on how to use Workflows in the DAWN cheatsheets, this section of the tutorial will guide you through one of the cheatsheets, allowing the others to be explored during the class or at your leisure.

  • Open DAWN, go to the Help - > Cheatsheets and from the Cheat Sheet Selection go to Workflows and pipelines and open the Workflow and pipelines tutorials.

  • Follow the tutorial Take a Tour of Workflows which will guide you through building a simple Workflow which displays a message box, as shown below:

  • The first real introduction to the power of the Workflows system is the

...

  • Some Simple Maths

...

  • tutorial. This tutorial uses multiple workflow actors to load, process, export and open data.

If, after this brief introduction, the Workflows are of interest to you, carry on with the Workflow Cheatsheets.  The instructors in the class will be happy to help with any problems you might have.

...

This section is a quick guide to running scripts in the python perspective and using debug mode.

Running Scripts

The first step in running Python scripts is to open the Python Perspective, set up a new console, create a new PyDev project and you are ready to go.
 

  • Open DAWN, go to the Python Perspective and start a Python console (follow the steps in the last tutorial if you don't know how to do this).
  • Create a new PyDev project called MyProject and make sure

...

  • Create 'src' folder and add it to the PYTHONPATH

...

  • is selected.

Image Added

  • Right click on the src folder and select New PyDev Module. Leave the Package name blank and call the module MyScript.
  • At the top of MyScript.py add the line import scisoftpy as dnp.
  • Open the file MoKedge_1_15.nxs by right-clicking the file and select Open With -> NeXus Data Editor.
  • Find the dataset entry1/counterTimer01/Energy and drag and drop it into the python console.

Image Added

  • dnp.io.load('C:\\PATHTODAWNWORKSPACE\\data\\examples\\MoKedge_1_15.nxs')['/entry1/counterTimer01/Energy'] should now be visible in the console.
  • Change this to say energy = dnp.io.load('C:\\PATHTODAWNWORKSPACE\\data\\examples\\MoKedge_1_15.nxs')['/entry1/counterTimer01/Energy'][...] and press enter.

(The scisoftpy module doesn't load nexus data until it is needed and only loads what it needs. The [...] tells it to load the complete dataset into a numpy array).

  • Do the same for the datasets I0 and It.
  • Copy these lines into the MyScript.py editor, and add the extra lines as shown below to take the log of the ratio of i0/it and plot it against energy.
Code Block
languagepython
import scisoftpy as dnp

import numpy as np

energy = dnp.io.load('C:\\DAWNWORKSPACELOCATION\\data\\examples\\MoKedge_1_15.nxs')['/entry1/counterTimer01/Energy'][...]

i0 =dnp.io.load('C:\\DAWNWORKSPACELOCATION\\data\\examples\\MoKedge_1_15.nxs')['/entry1/counterTimer01/I0'][...]

it= dnp.io.load('C:\\DAWNWORKSPACELOCATION\\data\\examples\\MoKedge_1_15.nxs')['/entry1/counterTimer01/It'][...]

ratio = i0/it

ln_ratio = np.log(ratio)

dnp.plot.plot(energy,ln_ratio)
  • Run the script in the current console by pressing Ctrl-Alt-Enter or the Image Modified toolbar button. A trace should appear in Plot 1.

If you just want to run a small section of the code, highlighting it and pressing Ctrl-Alt-Enter will send the highlighted lines to the console.

...

Debugging allows you to stop the running of a script at specific points to check everything is proceeding as expected.  This is very useful for finding the cause of incorrect output.

  • Put a breakpoint next to the line ratio = i0/it (either double-click on the grey bar on the side of the code editor next to the line or right-click and select Add Breakpoint)
  • From the Debug tool bar drop-down, select Debug As -> Python Run.
  • Say Yes to opening the Debug perspective.

The layout of DAWN will change to the debugging perspective.

  • Look at the Variables view, what does it show?
  • Type it.shape into the console and press enter, what does it show?
  • Type ratio.shape into the console and press enter, what does it show?

The variable ratio has not been created yet, the debugger stopped the script just before this line was executed.

  • Press F6 (or the step over toolbar action) to execute the line with the breakpoint.
  • Again type ratio.shape into the console and press enter, what does it show now?

The interactive console and variables view are really useful for developing scripts and fixing broken code.

...

Hyper3D is a view added to DExplore for visualising 3 dimensional datasets. DAWN 1.2 is contains the first version with this view, included for user feedback and collecting further requirements.

The Hyper3D view was specifically designed to work with hyperspectral image datasets (stacks of images where each images corresponds to a different wavelength and a single pixel traced down the stack is a spectrum), but it also works well for other stacks of images.

  • Go the the DExplore perspective and open the example file

...

  • 315029.dat

...

  • .
  • Select the Pilatus dataset, and in the dataset inspector select Hyper3D from the inspector tab
  • What shape is this dataset?
  • Select

...

  • eta

...

  • as the trace-coord, drag the Hyper3D view to a convenient place and double click the tab to maximise the view

The two plots in this view show different sections of the 3D pilatus dataset. The image shows the dimensions perpendicular to the dimension selected as the trace-coord. The actual image shown is an integration of the image stack over the window shown in the trace plot on the right.

  • Move the region on the right hand plot, what happens to the image on the left hand plot?

The trace in the right hand plot shows the average of all the traces corresponding to the pixels selected by the box region on the image.

  • Move the region on the left hand plot, what happens to the trace on the right hand plot?
  • Add more regions to the image, using the Create New Profile toolbar action. Traces can be exported to a .dat file using the Export... toolbar action.

Experiment with your own 3D datasets (or ask for more exciting datasets), the instructors in the class will be happy to help with any questions/problems you might have.

...