Sample

What the Sample object

The sample object holds details of the samples in an experiment. While most of the time this will refer to a single sample, it can describe a collection of samples. Specifically this holds information about a samples.

  • Material properties and chenmical copmosition
  • Shape and dimensions
  • Crystal Structure

Working with Sample object in Python

You can look at the Sample API reference for a full list of properties and operations, but here are some of the key ones.

Getting the Sample Object from a Workspace

ws=CreateWorkspace(DataX='1,2',DataY='1')
s=ws.sample()

Sample Properties

ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)
s = ws.sample()

# Dimensions
s.setHeight(0.1)
s.setWidth(0.2)
s.setThickness(0.3)
print("Height: " + str(s.getHeight()))
print("Width: " + str(s.getWidth()))
print("Thickness: " + str(s.getThickness()))

# Material
SetSampleMaterial(ws,ChemicalFormula="V")
m = s.getMaterial()
print("Material Name " + str(m.name()))
print("Total scattering X-Section: " + str(m.totalScatterXSection()))

# Crystal Structure
SetUB(ws,a=2,b=3,c=4,alpha=90,beta=90,gamma=90,u="1,0,0",v="0,0,1")
ol=s.getOrientedLattice()
print("Data lattice parameters are: {0} {1} {2} {3} {4} {5} ".format(ol.a(),ol.b(),ol.c(),ol.alpha(),ol.beta(),ol.gamma()))

Multiple Samples

The Sample() method actually returns a collection, however if you do not specify which sample you are after you will get he first member of the collection. So

ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)

s = ws.sample()
# Is the same as
s = ws.sample()[0]

# You can ask how many samples there are with
size = ws.sample().size()

Category: Concepts