Scripting Automatic Calibration in Jython

In the current DAWN release (1.6) a few steps must be taken to correctly set up the Jython interpreter to run a calibration. These steps will likely be unnecessary in future releases.

 

Add following Jars from DAWN installation plugin folder to Jython path (Window - Preferences - PyDev - Interpreter - Jython Interpreter - New Jar):

uk.ac.diamond.scisoft.diffraction.powder_version.jar

uk.ac.diamond.org.jscience4_version.jar

com.throughtworks.xstream_version.jar

where _version is a version number for the jar.

Once these Jars are included, the following script may be used to calibrate an image.

import scisoftpy as dnp

from uk.ac.diamond.scisoft.diffraction.powder import PowderCalibration as Cal
from uk.ac.diamond.scisoft.analysis.crystallography import CalibrationFactory as Fac
from uk.ac.diamond.scisoft.analysis.diffraction.powder import PixelSplittingIntegration as PSI

#pixel size in mm, number of rings to use for calibration (from centre)
pixelSize = 0.2
numberOfRings = 6

#Load data (and plot in "Plot 1")
data = dnp.io.load(r"/Path/To/Calibration/File.tiff")["image_01"]
dnp.plot.image(data)

#Get standard, if using a new standard, configure in DAWN first
#Use name of standard in DAWN list
std = Fac.getCalibrationStandards()
ceo2 = std.getCalibrationPeakMap("CeO2")

#Calibrate, get diffraction metadata object out - required for integration routines.
out = Cal.calibrateSingleImage(data._jdataset(),pixelSize,ceo2.getHKLs(),numberOfRings)
print "Residual from fit: " + str(out.getResidual())
meta = Cal.createMetadataFromOutput(out, 0, data.shape, pixelSize)


#Integrate
integrator = PSI(meta, 2000)
result = integrator.integrate(data._jdataset())
dnp.plot.line(result[0], result[1])