Squares v1

../_images/Squares-v1_dlg.png

Squares dialog.

Properties

Name Direction Type Default Description
MaxRange Input number Mandatory A value for the end of the range(inclusive)
Preamble Input string Mandatory Required preamble
Sum Input boolean False If True, sum the squared values
OutputFile Input string Mandatory Allowed values: [‘txt’]
OutputWorkspace Output MatrixWorkspace Mandatory A workspace containing the squares

Description

An example python algorithm.

This creates a workspace with a value that increases as the square of the bin index. It also optionally logs a message and saves a file.

Usage

Example

#import the os path libraries for directory functions
import os

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "Square.txt")

# create histogram workspace
ws=Squares(MaxRange='20', Preamble='Hello', Sum=True, OutputFile=savefile)

print("The first five values are:")
print(ws.readY(0)[0:5])

#clean up the file I saved
os.remove(savefile)

Output:

The first five values are:
[  1.   4.   9.  16.  25.]

Categories: AlgorithmIndex | Examples

Source

Python: Squares.py (last modified: 2018-10-05)