...
Code Block |
---|
|
# Example script for use with the 'Python Script - XY to XY [Scripting]' processing plug-in.
#
# Last updated 2016-11-02 - For DAWN 2.3
#
# Copyright (c) 2016 Diamond Light Source Ltd.
#
#
# The DAWN Python PyDev actor will execute this script, invoking a 'run' method in this file.
# This actor will pass the data and any associated variables from the dataset, which we will
# catch as a dictionary.
#
# The dictionary keys passed for the XY to XY plugin are always:
#
# 'current_slice' = The current slice of the data, typically [0, Frame Number, X Length]
# 'data' = The data, as a 1D array
# 'data_dimensions' = The dimensionality of the data
# 'data_title' = The title of the data
# 'dataset_name' = By default, the NeXus path to the dataset, or a given title of the dataset
# 'file_path' = The path to the file
# 'total' = Number of frames passed
# 'xaxis' = The x axis values, i.e. the x axis scale
# 'xaxis_title' = The title of the y-axis values/scale
#
# with potentially one or more of the following, depending on the dataset passed:
#
# 'auxiliary' = Any auxiliary data associated with the dataset
# 'error' = Any error values for the data, as a 1D array
# 'mask' = A mask, indicating if there are any values not to evaluate, as a 1D boolean array
# 'yaxis' = The y axis values, i.e. the y axis scale
#
# The PyDev actor will expect, at least, all of the first set of keys to be returned.
# However, it will accept any of the second set of keys being inserted or removed to/from
# the returned dictionary.
#
# An error will be thrown back to the processing perspective GUI if the script does not execute.
#
# Below is a simple example where random data, of the same size to the input is returned
# complete with all the potential additional keys added as well.
# Always handy to have numpy
import numpy
# The method the the PyDev actor will call, we'll catch any and all arguements as a dictionary
def run(**kwargs):
# Extract out the data
data = kwargs['data']
# and find it's length
x, = data.shape
# Generate some random data the same length as the input
# N.B. The output data length can be different to the input but must be 1D
randomData = numpy.random.randn(x)
# Generate some error values for the plot
randomError = numpy.abs(randomData) * 10
# Generate some data values as well
randomData = numpy.abs(randomData) * 100
# Input the error values into the input dictionary
kwargs['data'] = randomData
# Input the data values into the input dictionary
kwargs['error'] = randomError
# Delineate some axes so that the axis titles plot
# (No data in the xaxis/yaxis variables means no titles!)
kwargs['xaxis'] = numpy.arange(0, x)
# Give new titles for everything
kwargs['data_title'] = "Random Data"
kwargs['xaxis_title'] = "New X-Axis Title"
# Return the dictionary to DAWN
return kwargs |
3) Take small angle scattering
vs
data and transform this to produce a Guinier plot (
click here to download)
...