Computing for Science

The Computing for Science (CS) group supports ILL scientists, students and visitors in a number of activities including data analysis, instrument simulation and sample simulation.

Back to ILL Homepage

All Software

6. Common Workspace Functions

Formula-entry and Do text area syntax is IDL

All text entered in the formula-entry area is parsed and then sent by LAMP to the Interactive Data Language (IDL). The main reason for parsing is to enable blocks of related arrays in a source workspace (see Main Concepts) to be passed together to a target workspace.

The passing rule is :-
The workspace, eg. w2, on the left of the '=' is the target workspace, whilst the first workspace, eg. w1 , on the right of the '=' is the source workspace.

Extensive on-line help is available on this language by pressing the IDL? button. You can make any IDL command through the formula-entry area, and these will normally be operations on workspaces. LAMP provides maximum flexibility by giving you access to the majority of its working variables, either for one line commands or for command files. You can put data into any variable that you have declared and operate on it with IDL, but these variables will not be managed by LAMP, the variables a,b,c,...z are available for your use. 3.14159... can be obtained by typing in " !PI"


Note: In the following we refer to data in the x-dimension as "channels" and in the y-direction as " spectra". Appologies to crystalography.

Simple Algebra with Workspaces ( +, -, /, * )

To add two workspaces w1 and w2 simply type:

w3=w1+w2


in the formula-entry window. Subtraction, multiplication etc. are similar. In these operations LAMP will transfer the parameters, axes values, titles (and monitors) of the first workspace after the " =" sign into the new workspace (see passing rule above).
Effectively, w3=w1+w2 also implies:
p3=p1; n3=n1; x3=x1; y3=y1; titles in w3=titles in w1 ...

To top

Extracting sub-arrays (channels/spectra)

To extract spectra 1 to 40 from w1 into w4

w4=w1(*,0:39)

In this example the * implies all channels. N.B. 1 has to be subtracted from the spectrum numbers to suit the IDL array numbering.

To extract channels 250 to 500 for all spectra from w1 into w4

w4=w1(249:499,*)

To extract channels 250 to 500 for spectra 30 to 40 from w1 into w4

w4=w1(249:499,29:39)

N.B. LAMP ensures that parameters, axes etc. are transferred correctly but it does not update the values for the number of spectra and number of channels in the new parameters. These can be edited using the Data Params button.

To top

Integrating (total)

To sum all the spectra of w4 into w5

w5=total(w4,2)


where 2 represents the second dimension (y) ie. the spectra.
The sum of a range of spectra could be made, say from Spectrum #30 to Spectrum #40 using

w2=w1(*,29:39) & w2=total(w2,2)
w2=total(w1(*,29:39),2) is correct but Lamp will not update new axis.

To sum across all the channels, eg. for s(Q)

w3=total(w1,1)


If only elastic s(Q) is required and the elastic-peak position is known to be from say 200 to 220

w3=w1(199:219,*) & w3=total(w3,1)
w3=total(w1(199:219,*),1) is correct but Lamp will not update new axis.

To top

Normalising on Monitors

Monitor spectra are stored in the array n (ie. n1 for w1, n2 for w2 etc.). If each channel is to be normalised with the corresponding channel in the monitor spectrum (diffraction instruments) then the data in w1 can be normalised using

w1=w1/n1

If you need to normalise with the integrated monitor spectrum, for spectra of say 512 channels you must sum across the channels using (n1 can be two-dimensions)

w1=w1/total(n1(*,0))

If the position of the peak in the monitor is known to be say 220 to 240 channels then a better result is obtained with

w1=w1/total(n1(219:239,0))


If this command is used frequently it should be put into a one-line macro, a command file or a macro.

To top

Maths-functions

These work on workspaces or arrays of any dimensions (including scalars):-
Multiplication:   x*2
Division:             x/2
Powers:               x^2
Square root:        sqrt(x)
Absolute value:   abs(x)
Exponential:       exp(x)
Logarithms:       alog(x)   (natural)     or     alog10(x)   (base 10)
Trig. functions eg.:   sin(x)     or     asin(x)   arc-sine

See IDL help for more functions.

To top

Showing Values (show)

The value of any variable or expression can be displayed in the formula-entry window with the command

show,x         eg.     show,total(w1,1)         show,a*5


If the result is an array only the first 10 elements are displayed. The IDL print command can be used to display the entire array in the shell window, eg.

print,x

Minimum and maximum values of workspaces are available in the formula-entry area. Otherwise to get min and max values between say channels 250 to 500 for spectra 30 to 40 of w1

show,max(w1(249:499,29:39))


The channel and spectrum in which the min or max occurs can be put into a user parameter, say c, as follows
a=max(w1(249:499,29:39),min=b,c)
show,a ;(display maximum)
show,b ;(display minimum)
show,c ;(display index where maximum occurs)

To top

Shifting axes

The values of the x-axis, in time, energy channels etc., are stored in x1 for w1, and x2 for w2 etc. To shift spectra simply add (or subtract) the appropriate value from the x array. For example, to shift data in w1 (say in energy) by 0.15

x1=x1+0.15

To top

Resizing an image (congrid)

To resize w1 which may, for example, contain a 128 by 512 image to another size, say 64 by 256 pixels in w2

w2=congrid(w1,64,256)

To top

Putting Workspaces together (join)

To join workspaces into first dimension(W4), second dimension(W5), third dimension(W6):

w4=[  w1  ,  w2  ,  w3  ]
w5=[ [w1] , [w2] , [w3] ]
w6=[[[w1]],[[w2]],[[w3]]]

Changing Data-type

Main data types are:
a=0                         short integer, limits: -32769 to 32768
b=0.0                    floating (real), limits: magnitude 10^-37 to 10^38-1
c="hello"              string (text), limit: 32767 characters

To top

Changing between data-types

d=long(a)               convert 'a' to long-integer (limits: -2^31 to 2^32-1) (a=0L is long integer)
e=fix(b)                 truncate 'b' to integer
f=float(b)             convert 'a' to floating
f=double(b)           convert 'a' to double float
g=string(b)           convert 'b' to string
h=round(b)             convert 'b' to nearest long integer


N.B. By default integers are 2 bytes. If you have numbers greater than 32768 you will get odd results unless you work with long-integers or floats, eg. enter w1=float(w1) in the formula-entry window.

To top

Graphics

plot,a,b
Simple line plot of 'a' against 'b'. If only 'a' is given it is plotted as a function of its point number.

oplot,a,b
Simple line plot of 'a' against 'b' over previous plot.

contour,a,b,c
Plots a contour map of the array in 'a'. If 'b' and 'c' are given these are the x and y values for the grid. b and c can be vectors or arrays.

surface,a,b,c
Plots a surface of the array in 'a'. If 'b' and 'c' are given these are the x and y values for the grid. b and c can be vectors or arrays.

shade_surf,a,b,c
As surface but with shading.

N.B. The plot-range buttons in main Lamp window only apply to workspaces. When you issue the above commands you must set xrange,yrange and zrange manually, eg. to plot monitor 1 of workspace w3 from 200 to 250 channels:

plot,n3(*,1),xrange=[200,250]

To top

Previous - 6. Common Workspace Funct. - Next