This commit is contained in:
27
script/AreaDetectorROI.py
Normal file
27
script/AreaDetectorROI.py
Normal file
@@ -0,0 +1,27 @@
|
||||
device = det
|
||||
det.imageCounter.polling = 500
|
||||
|
||||
class AreaDetectorROI(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
|
||||
def __init__(self, name, detector, x, y, w, h):
|
||||
ReadonlyRegisterBase.__init__(self, name)
|
||||
self.detector = detector
|
||||
self.x, self.y, self.w, self.h = x, y, w, h
|
||||
|
||||
def doRead(self):
|
||||
data = self.detector.dataMatrix.take()
|
||||
ret = Convert.matrixRoi(data, self.x, self.y, self.w, self.h)
|
||||
return ret
|
||||
|
||||
def getWidth(self):
|
||||
return self.w
|
||||
|
||||
def getHeight(self):
|
||||
return self.h
|
||||
|
||||
|
||||
add_device(AreaDetectorROI("roi1", device, 10,10,10,5), True)
|
||||
add_device(AreaDetectorROI("roi2", device,100,30,7,3), True)
|
||||
|
||||
#tscan((roi1, roi2), 10, 0.1)
|
||||
|
||||
mscan(device.imageCounter, (roi1, roi2), 10, async=False)
|
||||
0
script/TestPID.py
Normal file
0
script/TestPID.py
Normal file
@@ -1,18 +1,21 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.groovy
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
import ch.psi.pshell.scan.ScanRecord
|
||||
import ch.psi.pshell.scan.ScanRecord
|
||||
|
||||
System.out.println("OK")
|
||||
|
||||
before_readout = { double[] pos-> println (pos) }
|
||||
|
||||
after_readout = { ScanRecord rec->println (rec) }
|
||||
after_readout = { ch.psi.pshell.scan.ScanRecord rec->println (rec) }
|
||||
|
||||
def onBeforeReadout(double[]pos){
|
||||
println (pos)
|
||||
}
|
||||
|
||||
def onAfterReadout(ScanRecord rec){
|
||||
def onAfterReadout(ch.psi.pshell.scan.ScanRecord rec){
|
||||
println (rec)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////
|
||||
@@ -10,4 +10,5 @@ function onAfterReadout(rec){
|
||||
|
||||
|
||||
|
||||
run("SimulatedDEvices")
|
||||
run("SimulatedDEvices")
|
||||
|
||||
|
||||
@@ -8,17 +8,21 @@ import ch.psi.pshell.crlogic.CrlogicPositioner as CrlogicPositioner
|
||||
import ch.psi.pshell.crlogic.CrlogicSensor as CrlogicSensor
|
||||
|
||||
|
||||
def on_command_started(info):
|
||||
print "Started: " + str(info.script) + str(info.error)
|
||||
|
||||
def on_command_finished(info):
|
||||
print "Finished: " + str(info.script) + str(info.error)
|
||||
###################################################################################################
|
||||
# Layout setup
|
||||
###################################################################################################
|
||||
import ch.psi.pshell.data.LayoutSF as LayoutSF
|
||||
|
||||
LayoutSF.setExperimentArguments([pv, motor, pe, cv, en, sin])
|
||||
LayoutSF.setExperimentArguments([pv, motor, pe, cv, energy, sin])
|
||||
|
||||
|
||||
|
||||
#Libraries
|
||||
#Librariesenergy
|
||||
#import Jama.Matrix
|
||||
#sys.path.append('/Users/gobbo_a/dev/pshell/config/home/script/Lib/diffcalc')
|
||||
|
||||
@@ -136,14 +140,14 @@ get_context().addListener(clistener)
|
||||
def trig_scienta():
|
||||
time.sleep(1.0)
|
||||
|
||||
energy = None
|
||||
en_val = None
|
||||
class SimulatedEnergy(Writable):
|
||||
def write(self, value):
|
||||
self.put(value)
|
||||
|
||||
def put(self, value, timeout = None):
|
||||
global energy
|
||||
energy = value
|
||||
global en_val
|
||||
en_val = value
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
@@ -155,8 +159,8 @@ class SimulatedEnergy(Writable):
|
||||
|
||||
class SimulatedEnergyReadback(Readable):
|
||||
def read(self):
|
||||
global energy
|
||||
return energy;
|
||||
global en_val
|
||||
return en_val;
|
||||
|
||||
def get(self):
|
||||
return self.read()
|
||||
|
||||
14
script/test/CustomPlot.py
Normal file
14
script/test/CustomPlot.py
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
p = plot(None, title="Custom Plot")[0]
|
||||
p.addSeries(LinePlotSeries("My Series"))
|
||||
proc_data = "/proc/calc"
|
||||
|
||||
create_dataset(proc_data , 'd')
|
||||
|
||||
def AfterReadout(record, scan):
|
||||
val = record.values[1] - record.values[0]
|
||||
p.getSeries(0).appendData(record.positions[0], val)
|
||||
append_dataset(proc_data , val)
|
||||
|
||||
lscan(inp, (out, sin), 0.0, 10.0, 1.0, latency = 0.1, after_read=AfterReadout)
|
||||
22
script/test/TestChanel.py
Normal file
22
script/test/TestChanel.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import ch.psi.pshell.epics.CAS as CAS
|
||||
import random
|
||||
class Waveform(ReadonlyRegisterBase, ReadonlyRegisterArray):
|
||||
def doRead(self):
|
||||
ret = []
|
||||
for i in range(self.getSize()):
|
||||
ret.append(random.random())
|
||||
ret = to_array(ret, 'd')
|
||||
return ret
|
||||
|
||||
def getSize(self):
|
||||
return 1000
|
||||
|
||||
|
||||
wf = Waveform("wf")
|
||||
wf.initialize()
|
||||
print wf.read()[0]
|
||||
|
||||
casN = CAS("TESTCAS:VAL", wf, 'double')
|
||||
print casN
|
||||
|
||||
print caget("TESTCAS:VAL")
|
||||
78
script/test/TestData.py
Normal file
78
script/test/TestData.py
Normal file
@@ -0,0 +1,78 @@
|
||||
###################################################################################################
|
||||
#Data Manipulation: Using the data access API to generate and retrieve data
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Creating a 1D dataset from an array
|
||||
path="group/data1"
|
||||
data1d = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
save_dataset(path, data1d)
|
||||
#Reading ii back
|
||||
read =load_data(path)
|
||||
print read.tolist()
|
||||
assert data1d==read.tolist()
|
||||
plot(read)
|
||||
|
||||
#Creating a 2D dataset from an array with some attributes
|
||||
data2d = [ [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, ], [3.0, 4.0, 5.0, 6.0, 7.0]]
|
||||
path="group/data2"
|
||||
save_dataset(path, data2d)
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", True)
|
||||
#Reading it back
|
||||
read =load_data(path)
|
||||
print read.tolist()
|
||||
plot(read)
|
||||
|
||||
#Creating a 3D dataset from an array
|
||||
data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]], [ [3,2,3,4,5], [4,3,4,5,6], [5,4,5,6,7]]]
|
||||
path="group/data3"
|
||||
save_dataset(path, data3d)
|
||||
#Reading it back
|
||||
read =load_data(path,0)
|
||||
print read.tolist()
|
||||
read =load_data(path,1)
|
||||
print read.tolist()
|
||||
|
||||
#Creating a INT dataset adding elements one by one
|
||||
path = "group/data4"
|
||||
create_dataset(path, 'i')
|
||||
for i in range(10):
|
||||
append_dataset(path,i)
|
||||
|
||||
|
||||
#Creating a 2D data FLOAT dataset adding lines one by one
|
||||
path = "group/data5"
|
||||
create_dataset(path, 'd', False, (0,0))
|
||||
for row in data2d:
|
||||
append_dataset(path, row)
|
||||
|
||||
|
||||
#Creating a Table (compund type)
|
||||
path = "group/data6"
|
||||
names = ["a", "b", "c", "d"]
|
||||
types = ["d", "d", "d", "[d"]
|
||||
lenghts = [0,0,0,5]
|
||||
table = [ [1,2,3,[0,1,2,3,4]],
|
||||
[2,3,4,[3,4,5,6,7]],
|
||||
[3,4,5,[6,7,8,9,4]] ]
|
||||
create_table(path, names, types, lenghts)
|
||||
for row in table:
|
||||
append_table(path, row)
|
||||
flush_data()
|
||||
#Read it back
|
||||
read =load_data(path)
|
||||
print read
|
||||
|
||||
|
||||
#Writing scalars (datasets with rank 0)
|
||||
save_dataset("group/val1", 1)
|
||||
save_dataset("group/val2", 3.14)
|
||||
save_dataset("group/val3", "test")
|
||||
print load_data("group/val1")
|
||||
print load_data("group/val2")
|
||||
print load_data("group/val3")
|
||||
|
||||
|
||||
22
script/test/TestDetectorROI.py
Normal file
22
script/test/TestDetectorROI.py
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DetectorRoi(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
|
||||
def doRead(self):
|
||||
#data = caget(“PINK:GEYES:image2:ArrayData")
|
||||
data = caget("TESTCAS:VAL", '[d', self.getHeight() * self.getWidth())
|
||||
return Convert.reshape(data,self.getHeight(), self.getWidth()) #
|
||||
|
||||
def getWidth(self):
|
||||
return 50
|
||||
|
||||
def getHeight(self):
|
||||
return 20
|
||||
|
||||
add_device (DetectorRoi("detector_roi"), True)
|
||||
|
||||
|
||||
add_device(RegisterMatrixSource("detector_roi_img", detector_roi), True)
|
||||
detector_roi_img.polling = -500
|
||||
557
script/test/TestDiff.py
Normal file
557
script/test/TestDiff.py
Normal file
@@ -0,0 +1,557 @@
|
||||
###################################################################################################\
|
||||
# Diffcalc utilities
|
||||
###################################################################################################
|
||||
|
||||
###################################################################################################\
|
||||
# Installaling
|
||||
###################################################################################################
|
||||
|
||||
#1- Download from: https://github.com/DiamondLightSource/diffcalc/archive/master.zip
|
||||
#2- Extract the contents to {script}/Lib/diffcalc
|
||||
#3- Download http://central.maven.org/maven2/gov/nist/math/jama/1.0.3/jama-1.0.3.jar
|
||||
# to the extensions folder.
|
||||
|
||||
###################################################################################################\
|
||||
# Library loading and Hardware setup
|
||||
###################################################################################################
|
||||
|
||||
#1- Create a MotorGroup with the diffractometer motors
|
||||
# e.g. 'sixc', containing mu, delta, gam, eta, chi, phi motors (gam = nu)
|
||||
# or 'fivec', containing delta, gam, eta, chi, phi motors
|
||||
# or 'fourc', containing delta, eta, chi, phi motors
|
||||
#2- Create positioner to read/set the energy in kEv, e.g. named 'en'
|
||||
#3- Execute: run("diffutils")
|
||||
#4- Execute: setup_diff(sixc, en)
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
import traceback
|
||||
|
||||
|
||||
import Jama.Matrix
|
||||
diffcalc_path = os.path.abspath(get_context().setup.expandPath("{script}/Lib/diffcalc"))
|
||||
if not diffcalc_path in sys.path:
|
||||
sys.path.append(diffcalc_path)
|
||||
|
||||
import diffcalc
|
||||
from diffcalc import settings
|
||||
from diffcalc.hkl.you.geometry import YouGeometry,SixCircle, FiveCircle, FourCircle, YouPosition
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
from diffcalc.ub.persistence import UbCalculationNonPersister
|
||||
from diffcalc.gdasupport.minigda.scannable import ScannableBase, ScannableGroup
|
||||
#from diffcalc.gdasupport.minigda import command
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
|
||||
|
||||
import ch.psi.pshell.device.PositionerConfig as PositionerConfig
|
||||
import ch.psi.pshell.device.RegisterConfig as RegisterConfig
|
||||
import ch.psi.pshell.device.Register as Register
|
||||
|
||||
_difcalc_names = {}
|
||||
|
||||
#
|
||||
# Disable error handling designed for interactive use
|
||||
#diffcalc.util.DEBUG = True
|
||||
|
||||
###################################################################################################
|
||||
# Device mapping to difcalc
|
||||
###################################################################################################
|
||||
class PositionerScannable(ScannableBase):
|
||||
def __init__(self, positioner, name = None):
|
||||
self.positioner = positioner
|
||||
self.name = positioner.name if name is None else name
|
||||
self.inputNames = [self.name]
|
||||
self.outputFormat = ['% 6.4f']
|
||||
self.level = 3
|
||||
|
||||
def isBusy(self):
|
||||
return self.positioner.state == State.Busy
|
||||
|
||||
def waitWhileBusy(self):
|
||||
self.positioner.waitReady(-1)
|
||||
|
||||
def asynchronousMoveTo(self, new_position):
|
||||
#print "Moving " , self.name, " to: ", new_position
|
||||
self.positioner.moveAsync(float(new_position), -1)
|
||||
|
||||
def getPosition(self):
|
||||
return self.positioner.getPosition()
|
||||
|
||||
def _get_diffcalc_axis_names():
|
||||
nu_name=diffcalc.hkl.you.constraints.NUNAME
|
||||
return ("mu", "delta", nu_name, "eta", "chi", "phi")
|
||||
|
||||
class PositionerScannableGroup(ScannableGroup):
|
||||
def __init__(self, name, motors, diffcalc_axis_names=None):
|
||||
self.name = name
|
||||
global _difcalc_names
|
||||
_difcalc_names = {}
|
||||
positioners = []
|
||||
if diffcalc_axis_names is None:
|
||||
if len(motors) == 6: diffcalc_axis_names = _get_diffcalc_axis_names()
|
||||
elif len(motors) == 5: diffcalc_axis_names = ("delta", "gam", "eta", "chi", " phi")
|
||||
elif len(motors) == 4: diffcalc_axis_names = ("delta", "eta", "chi", " phi")
|
||||
for i in range(len(motors)):
|
||||
_difcalc_names[motors[i]] = diffcalc_axis_names[i]
|
||||
exec('self.' + diffcalc_axis_names[i] + ' = PositionerScannable(' + motors[i].name + ', "' +diffcalc_axis_names[i] + '")')
|
||||
exec('positioners.append(self.' + diffcalc_axis_names[i] + ')' )
|
||||
#for m in motors:
|
||||
# exec('self.' + m.name + ' = PositionerScannable(' + m.name + ', "' + m.name + '")')
|
||||
# exec('positioners.append(self.' + m.name + ')' )
|
||||
ScannableGroup.__init__(self, self.name, positioners)
|
||||
|
||||
class MotorGroupScannable(PositionerScannableGroup):
|
||||
def __init__(self, motor_group, diffcalc_axis_names=None):
|
||||
self.motor_group = motor_group
|
||||
PositionerScannableGroup.__init__(self, motor_group.name, motor_group.motors, diffcalc_axis_names)
|
||||
|
||||
|
||||
class ScannableAdapter(HardwareAdapter):
|
||||
def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1):
|
||||
self.diffractometer = diffractometer
|
||||
self.energy = energy
|
||||
self.energy_multiplier_to_kev = energy_multiplier_to_kev
|
||||
input_names = diffractometer.getInputNames()
|
||||
HardwareAdapter.__init__(self, input_names)
|
||||
|
||||
#Returns the current physical POSITIONS
|
||||
def get_position(self):
|
||||
"""
|
||||
pos = getDiffractometerPosition() -- returns the current physical
|
||||
diffractometer position as a list in degrees
|
||||
"""
|
||||
return self.diffractometer.getPosition()
|
||||
|
||||
#returns energy in kEv
|
||||
def get_energy(self):
|
||||
"""energy = get_energy() -- returns energy in kEv (NOT eV!) """
|
||||
multiplier = self.energy_multiplier_to_kev
|
||||
energy = self.energy.getPosition() * multiplier
|
||||
if energy is None:
|
||||
raise DiffcalcException("Energy has not been set")
|
||||
return energy
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.diffractometer.getName()
|
||||
|
||||
class MotorGroupAdapter(ScannableAdapter):
|
||||
def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1, diffcalc_axis_names=None):
|
||||
self.diffractometer = MotorGroupScannable(diffractometer, diffcalc_axis_names)
|
||||
self.energy = PositionerScannable(energy)
|
||||
self.energy.level = 3
|
||||
ScannableAdapter.__init__(self, self.diffractometer, self.energy, energy_multiplier_to_kev)
|
||||
|
||||
class Wavelength(RegisterBase):
|
||||
def doRead(self):
|
||||
try:
|
||||
return get_wavelength().getPosition()
|
||||
except:
|
||||
return None
|
||||
|
||||
def doWrite(self, val):
|
||||
get_wavelength().asynchronousMoveTo(val)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# HKL Pseudo-devices
|
||||
###################################################################################################
|
||||
class HklPositoner (PositionerBase):
|
||||
def __init__(self, name, index, hkl_group):
|
||||
PositionerBase.__init__(self, name, PositionerConfig())
|
||||
self.setParent(hkl_group)
|
||||
self.index = index
|
||||
|
||||
def isReady(self):
|
||||
return PositionerBase.isReady(self) and self.getParent().isReady()
|
||||
|
||||
def doRead(self):
|
||||
return self.getParent()._setpoint[self.index]
|
||||
|
||||
def doWrite(self, value):
|
||||
#print "Setting " , self.getName(), "to: ", value
|
||||
pos = [None, None, None]
|
||||
pos[self.index] = value
|
||||
self.getParent().write(pos)
|
||||
|
||||
def doReadReadback(self):
|
||||
if java.lang.Thread.currentThread() != self.getParent()._updating_thread:
|
||||
self.getParent().update()
|
||||
return self.getParent()._readback[self.index]
|
||||
|
||||
class HklGroup(RegisterBase, Register.RegisterArray):
|
||||
def __init__(self, name):
|
||||
RegisterBase.__init__(self, name, RegisterConfig())
|
||||
self.hkl=get_hkl()
|
||||
self.h, self.k, self.l = HklPositoner("h", 0, self), HklPositoner("k", 1, self), HklPositoner("l", 2, self)
|
||||
add_device(self.h, True)
|
||||
add_device(self.k, True)
|
||||
add_device(self.l, True)
|
||||
self._setpoint = self.doRead()
|
||||
self._updating = False
|
||||
|
||||
def getSize(self):
|
||||
return 3
|
||||
|
||||
def doRead(self):
|
||||
try:
|
||||
self._readback = self.hkl.getPosition()
|
||||
self._updating_thread = java.lang.Thread.currentThread()
|
||||
self.h.update()
|
||||
self.k.update()
|
||||
self.l.update()
|
||||
except:
|
||||
#traceback.print_exc()
|
||||
self._readback = (None, None, None)
|
||||
finally:
|
||||
self._updating_thread = None
|
||||
return self._readback
|
||||
|
||||
def doWrite(self, pos):
|
||||
self._setpoint = pos
|
||||
#print "Moving to: " + str(pos)
|
||||
self.hkl.asynchronousMoveTo(pos)
|
||||
|
||||
def sim(self, pos):
|
||||
return self.hkl.simulateMoveTo(pos)
|
||||
|
||||
###################################################################################################
|
||||
# System setup
|
||||
###################################################################################################
|
||||
you = None
|
||||
dc, ub, hardware, hkl = None, None, None, None
|
||||
_motor_group = None
|
||||
def setup_diff(diffractometer, energy, diffcalc_axis_names = None, geometry=None):
|
||||
"""
|
||||
diffractometer: Diffraction motor group
|
||||
energy: Positioner having energy in kev
|
||||
geometry: YouGeometry extension. If none, uses default
|
||||
diffcalc_axis_names: if None use defaults:
|
||||
- mu, delta, gam, eta, chi, phi (six circle)
|
||||
- delta, gam, eta, chi, phi (ficve circle)
|
||||
- delta, eta, chi, phi (four circle)
|
||||
"""
|
||||
global you, dc, ub, hardware, hkl, _motor_group
|
||||
_motor_group = diffractometer
|
||||
you = None
|
||||
if geometry is not None:
|
||||
settings.geometry = geometry
|
||||
elif diffcalc_axis_names is not None:
|
||||
class CustomGeometry(YouGeometry):
|
||||
def __init__(self):
|
||||
self.all_axis_names = _get_diffcalc_axis_names()
|
||||
self.my_axis_names = diffcalc_axis_names
|
||||
fixed_constraints = {}
|
||||
for axis in self.all_axis_names:
|
||||
if not axis in self.my_axis_names:
|
||||
fixed_constraints[axis] = 0
|
||||
YouGeometry.__init__(self, diffractometer.name, fixed_constraints)
|
||||
def physical_angles_to_internal_position(self, physical_angle_tuple):
|
||||
pos=[]
|
||||
index = 0
|
||||
for axis in self.all_axis_names:
|
||||
pos.append(physical_angle_tuple[index] if (axis in self.my_axis_names) else 0)
|
||||
index = index+1
|
||||
return YouPosition(*pos)
|
||||
def internal_position_to_physical_angles(self, internal_position):
|
||||
pos = internal_position.totuple()
|
||||
ret = []
|
||||
for i in range (len(self.all_axis_names)):
|
||||
if self.all_axis_names[i] in self.my_axis_names:
|
||||
ret.append(pos[i])
|
||||
return tuple(ret)
|
||||
settings.geometry = CustomGeometry()
|
||||
elif len(diffractometer.motors) == 6:
|
||||
settings.geometry = SixCircle()
|
||||
elif len(diffractometer.motors) == 5:
|
||||
settings.geometry = FiveCircle()
|
||||
elif len(diffractometer.motors) == 4:
|
||||
settings.geometry = FourCircle()
|
||||
else:
|
||||
raise Exception("Invalid motor group")
|
||||
settings.hardware = MotorGroupAdapter(diffractometer, energy, diffcalc_axis_names = diffcalc_axis_names)
|
||||
settings.ubcalc_persister = UbCalculationNonPersister()
|
||||
settings.axes_scannable_group = settings.hardware.diffractometer
|
||||
settings.energy_scannable = settings.hardware.energy
|
||||
settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy()
|
||||
settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl
|
||||
from diffcalc.gdasupport import you
|
||||
reload(you)
|
||||
|
||||
# These must be imported AFTER the settings have been configured
|
||||
from diffcalc.dc import dcyou as dc
|
||||
from diffcalc.ub import ub
|
||||
from diffcalc import hardware
|
||||
from diffcalc.hkl.you import hkl
|
||||
|
||||
add_device(HklGroup("hkl_group"), True)
|
||||
add_device(Wavelength("wavelength", 6), True)
|
||||
hkl_group.polling = 250
|
||||
wavelength.polling = 250
|
||||
|
||||
def setup_axis(motor, min=None, max=None, cut=None):
|
||||
name = _difcalc_names[motor]
|
||||
if min is not None: hardware.setmin(name, min)
|
||||
if max is not None: hardware.setmax(name, max)
|
||||
if cut is not None: hardware.setcut(name, cut)
|
||||
|
||||
def print_axis_setup():
|
||||
print "Diffcalc names:"
|
||||
for m in _difcalc_names.keys():
|
||||
print " \t" + m.name + " = " + _difcalc_names[m]
|
||||
print "------------------------------------------------------"
|
||||
hardware.hardware()
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Acceess functions
|
||||
###################################################################################################
|
||||
def get_diff():
|
||||
return settings.hardware.diffractometer
|
||||
|
||||
def get_en():
|
||||
return settings.hardware.energy
|
||||
|
||||
def get_motor_group():
|
||||
return _motor_group
|
||||
|
||||
def get_wavelength():
|
||||
return you.wl
|
||||
|
||||
def get_hkl():
|
||||
return you.hkl
|
||||
|
||||
def hkl_to_angles(h, k, l, energy=None):
|
||||
return dc.hkl_to_angles(h, k, l, energy)
|
||||
|
||||
def angles_to_hkl(positions, energy=None):
|
||||
return dc.angles_to_hkl(positions, energy)
|
||||
|
||||
def hkl_read():
|
||||
return hkl_group.read()
|
||||
|
||||
def hkl_write(h, k, l):
|
||||
hkl_group.write([h,k,l])
|
||||
|
||||
def hkl_simulate(h, k, l):
|
||||
return hkl_group.sim([h,k,l])
|
||||
|
||||
def con(*args):
|
||||
hkl.con(*args)
|
||||
|
||||
def uncon(name):
|
||||
hkl.uncon(name)
|
||||
|
||||
def print_con():
|
||||
hkl.con()
|
||||
###################################################################################################
|
||||
# HKL Combined Scan
|
||||
###################################################################################################
|
||||
def hklscan(vector, readables,latency = 0.0, passes = 1, **pars):
|
||||
"""
|
||||
HKL Scan:
|
||||
|
||||
Args:
|
||||
vector(list of lists): HKL values to be scanned
|
||||
readables(list of Readable): Sensors to be sampled on each step.
|
||||
latency(float, optional): settling time for each step before readout, defaults to 0.0.
|
||||
passes(int, optional): number of passes
|
||||
pars(keyworded variable length arguments, optional): scan optional named arguments:
|
||||
- title(str, optional): plotting window name.
|
||||
- hidden(bool, optional): if true generates no effects on user interface.
|
||||
- before_read (function, optional): callback on each step, before sampling. Arguments: positions, scan
|
||||
- after_read (function, optional): callback on each step, after sampling. Arguments: record, scan.
|
||||
- before_pass (function, optional): callback before each scan pass execution. Arguments: pass_num, scan.
|
||||
- after_pass (function, optional): callback after each scan pass execution. Arguments: pass_num, scan.
|
||||
- Aditional arguments defined by set_exec_pars.
|
||||
Returns:
|
||||
ScanResult object.
|
||||
|
||||
"""
|
||||
readables=to_list(string_to_obj(readables))
|
||||
pars["initial_move"] = False
|
||||
scan = ManualScan([h,k,l], readables ,vector[0], vector[-1], [len(vector)-1] * 3, dimensions = 1)
|
||||
if not "domain_axis" in pars.keys():
|
||||
pars["domain_axis"] = "Index"
|
||||
processScanPars(scan, pars)
|
||||
scan.start()
|
||||
try:
|
||||
for pos in vector:
|
||||
#print "Writing ", pos
|
||||
hkl_group.write(pos)
|
||||
time.sleep(0.1) #Make sure is busy
|
||||
get_motor_group().update()
|
||||
get_motor_group().waitReady(-1)
|
||||
time.sleep(latency)
|
||||
hkl_group.update()
|
||||
scan.append ([h.take(), k.take(), l.take()], [h.getPosition(), k.getPosition(), l.getPosition()], [readable.read() for readable in readables ])
|
||||
finally:
|
||||
scan.end()
|
||||
return scan.result
|
||||
|
||||
|
||||
def test_diffcalc():
|
||||
print "Start test"
|
||||
en.move(20.0)
|
||||
delta.config.maxSpeed = 50.0
|
||||
delta.speed = 50.0
|
||||
delta.move(1.0)
|
||||
|
||||
#Setup
|
||||
setup_diff(sixc, en)
|
||||
setup_axis('gam', 0, 179)
|
||||
setup_axis('delta', 0, 179)
|
||||
setup_axis('delta', min=0)
|
||||
setup_axis('phi', cut=-180.0)
|
||||
print_axis_setup()
|
||||
|
||||
#Orientation
|
||||
help(ub.ub)
|
||||
ub.listub()
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
ub.setlat('cubic', 1, 1, 1, 90, 90, 90)
|
||||
# Add 1st reflection (demonstrating the hardware adapter)
|
||||
settings.hardware.wavelength = 1
|
||||
ub.c2th([1, 0, 0]) # energy from hardware
|
||||
settings.hardware.position = 0, 60, 0, 30, 0, 0
|
||||
ub.addref([1, 0, 0])# energy and position from hardware
|
||||
# Add 2nd reflection (this time without the harware adapter)
|
||||
ub.c2th([0, 1, 0], 12.39842)
|
||||
ub.addref([0, 1, 0], [0, 60, 0, 30, 0, 90], 12.39842)
|
||||
# check the state
|
||||
ub.ub()
|
||||
ub.checkub()
|
||||
|
||||
#Constraints
|
||||
help(hkl.con)
|
||||
hkl.con('qaz', 90)
|
||||
hkl.con('a_eq_b')
|
||||
hkl.con('mu', 0)
|
||||
hkl.con()
|
||||
|
||||
#Motion
|
||||
print angles_to_hkl((0., 60., 0., 30., 0., 0.))
|
||||
print hkl_to_angles(1, 0, 0)
|
||||
sixc.write([0, 60, 0, 30, 90, 0])
|
||||
print "sixc=" , sixc.position
|
||||
wavelength.write(1.0)
|
||||
print "wavelength = ", wavelength.read()
|
||||
ub.lastub()
|
||||
ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
ub.showref()
|
||||
ub.swapref(1,2)
|
||||
#print you.hkl
|
||||
#pos(get_hkl())
|
||||
hkl_group.read()
|
||||
#you.hkl.simulateMoveTo([0,1,1])
|
||||
#sim(get_hkl(), [0,1,1])
|
||||
hkl_group.sim([0.0,1.0,1.0])
|
||||
#pos(get_hkl(), [0,1,1])
|
||||
hkl_group.write([0.0,1.0,1.0])
|
||||
|
||||
#Scans
|
||||
lscan(l, [sin], 1.0, 1.5, 0.1)
|
||||
ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False)
|
||||
vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]]
|
||||
hklscan(vector, [sin, arr], 0.9)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
#run("diffutils")
|
||||
|
||||
###################################################################################################\
|
||||
#Setup
|
||||
###################################################################################################
|
||||
|
||||
#alpha, delta, gamma, omegaV
|
||||
setup_diff(fourcv, energy, ("mu", "delta", "gam", "eta"))
|
||||
print_axis_setup()
|
||||
|
||||
|
||||
setup_axis(mu, mu.getMinValue(), mu.getMaxValue())
|
||||
setup_axis(delta, delta.getMinValue(), 90) #delta.getMaxValue())
|
||||
setup_axis(gamma, 0, gamma.getMaxValue())
|
||||
setup_axis(eta, eta.getMinValue(), eta.getMaxValue())
|
||||
|
||||
|
||||
wavelength.write(1.0)
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Orientation
|
||||
###################################################################################################
|
||||
help(ub.ub)
|
||||
ub.listub()
|
||||
|
||||
#alpha delta gamma omegaV
|
||||
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
|
||||
"""
|
||||
ub.setlat('cubic', 5.114, 5.8361, 11.058, 90, 90, 90)
|
||||
en = 8
|
||||
#ub.c2th([0, 0, 4], en)
|
||||
#ub.addref([0, 0, 4]) #From current position and ekergy
|
||||
ub.addref([0, 0, 4], [16.2785, 0.0, 32.5568, 0.0], en)
|
||||
#ub.c2th([2, 0, 12], en)
|
||||
ub.addref([2, 0, 12], [71.8285, 37.3082, 138.7440, 0.0], en)
|
||||
#ub.c2th([1, -4, 10], en)
|
||||
ub.addref([1, -4, 10], [27.7185, 17.6409 , 128.4220, 0.0], en)
|
||||
"""
|
||||
|
||||
ub.setlat('cubic', 1.0, 1.0, 1.0, 90, 90, 90)
|
||||
|
||||
en = 12.4
|
||||
#ub.c2th([0, 0, 4], en)
|
||||
#ub.addref([0, 0, 4]) #From current position and ekergy
|
||||
ub.addref([0, 0, 1], [30.0, 0.0, 60.0, 0.0], en)
|
||||
#ub.c2th([2, 0, 12], en)
|
||||
ub.addref([1, 0, 1], [20.0, 45.5564,90.000, 44.4437], en)
|
||||
#ub.c2th([1, -4, 10], en)
|
||||
ub.addref([0, 1, 1], [20.0, 45.5564,90.000, 134.4437], en)
|
||||
|
||||
ub.ub()
|
||||
|
||||
#ub.setub([[1.22862,0.00000,0.00000], [-0.00000,1.07663,0.00000], [-0.00000,-0.00000,0.56820]])
|
||||
|
||||
|
||||
# check the state
|
||||
|
||||
ub.checkub()
|
||||
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Constraints
|
||||
###################################################################################################
|
||||
help(hkl.con)
|
||||
hkl.con('a_eq_b')
|
||||
#hkl.con('eta:0')
|
||||
|
||||
|
||||
#hkl.con( 'eta', 0) #OmegaV constant
|
||||
#hkl.con( 'mu', 20) #Alpha constant
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Motion
|
||||
###################################################################################################
|
||||
|
||||
#print angles_to_hkl((16.278, 0.0000, 32.5568, 0.0))
|
||||
#print angles_to_hkl((44.3400, 0.0000, 123.7322 , 0.0))
|
||||
#print hkl_to_angles(2, -2, 10)
|
||||
|
||||
|
||||
154
script/test/TestNilson.py
Normal file
154
script/test/TestNilson.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# Greateyes scan
|
||||
|
||||
#******** SCAN Settings ********
|
||||
Note="DESY - "
|
||||
|
||||
Exp_Time= 1
|
||||
|
||||
X0=4200
|
||||
Xstep=450
|
||||
XNum_points=3
|
||||
|
||||
Y0=5960
|
||||
Ystep=-40
|
||||
YNum_points=10
|
||||
|
||||
GE_ROI_Line = 3
|
||||
|
||||
GE_AreaDet = det
|
||||
|
||||
GE_ROI_Image= det.getDataMatrix()
|
||||
GE_Raw_Image= det.getDataMatrix()
|
||||
GE_BG_Image = det.getDataMatrix()
|
||||
GE_Spectrum_Conv = det.getDataArray()
|
||||
GE_Spectrum = det.getDataArray()
|
||||
GE_BG_Line = det.getArraySize2()
|
||||
GE_BG_SizeX = det.getArraySize0()
|
||||
GE_BG_SizeY = det.getArraySize1()
|
||||
GE_ROI_Line = det.getArraySize2()
|
||||
GE_ROI_SizeX = det.getArraySize0()
|
||||
GE_ROI_SizeY = det.getArraySize1()
|
||||
IZero_Profile = det.getDataArray()
|
||||
TFY_Profile = det.getDataArray()
|
||||
IZero=sin
|
||||
TFY = sin
|
||||
GE_Sensor_Temp = sin
|
||||
GE_FrameID = sin
|
||||
Press_Diag_PV= sin
|
||||
Press_Spec_PV= sin
|
||||
Press_Spec_HV =sin
|
||||
Press_Sample_Ch=sin
|
||||
Press_Diag_HV = sin
|
||||
GE_Spectrum_Sum = det.getDataArray()
|
||||
|
||||
#******** Functions Definitions ********
|
||||
def Save_Pre_Scan_Data():
|
||||
save_dataset("RAW/GE_BG_Image", GE_BG_Image.read())
|
||||
save_dataset("Processed/GE_Spectrum_Convertion", GE_Spectrum_Conv.read())
|
||||
save_dataset("Detector/GE_ROI_Line", GE_ROI_Line.read())
|
||||
save_dataset("Detector/GE_ROI_SizeX", GE_ROI_SizeX.read())
|
||||
save_dataset("Detector/GE_ROI_SizeY", GE_ROI_SizeY.read())
|
||||
save_dataset("Detector/Exposure_Time", GE_AreaDet.getExposure())
|
||||
save_dataset("Detector/GE_Open_Delay", 1)
|
||||
save_dataset("Detector/GE_Close_Delay", 1)
|
||||
save_dataset("Detector/GE_Num_Images", GE_AreaDet.getNumImages())
|
||||
save_dataset("Detector/Gain_Type", 1)
|
||||
save_dataset("Scan/Scan_Start_Time", time.ctime())
|
||||
save_dataset("Scan/Note", Note)
|
||||
#save_dataset("Scan/Note", Note)
|
||||
|
||||
def Create_Scan_Dataset():
|
||||
create_dataset("RAW/GE_Raw_Image", 'd', False, (Num_Images, int(GE_BG_SizeY.take()), int(GE_BG_SizeX.take())))
|
||||
create_dataset("RAW/IZero_Profile", 'd', False, (Num_Images, 100))
|
||||
create_dataset("RAW/TFY_Profile", 'd', False, (Num_Images, 100))
|
||||
create_dataset("Processed/GE_ROI_Image", 'd', False, (Num_Images, int(GE_ROI_SizeY.take()), int(GE_ROI_SizeX.take())))
|
||||
create_dataset("Processed/GE_Spectrum", 'd', False, (Num_Images, int(GE_BG_SizeX.take())))
|
||||
create_dataset("Processed/Izero", 'd', False)
|
||||
create_dataset("Processed/TFY", 'd', False)
|
||||
create_dataset("Detector/GE_Sensor_Temp", 'd', False)
|
||||
create_dataset("Scan/GE_FrameID", 'i', False)
|
||||
create_dataset("Scan/Timestamps", 'l', False)
|
||||
create_dataset("Pressure/Diagnostic_PV", 'd', False)
|
||||
create_dataset("Pressure/Diagnostic_HV", 'd', False)
|
||||
create_dataset("Pressure/Spectrometer_PV", 'd', False)
|
||||
create_dataset("Pressure/Spectrometer_HV", 'd', False)
|
||||
create_dataset("Pressure/Sample_Chamber", 'd', False)
|
||||
create_dataset("RAW/Xposition", 'd', False)
|
||||
create_dataset("RAW/Yposition", 'd', False)
|
||||
|
||||
|
||||
|
||||
def Save_Scan_Data():
|
||||
#sleep(0.2)
|
||||
append_dataset("RAW/GE_Raw_Image", GE_Raw_Image.read())
|
||||
append_dataset("RAW/IZero_Profile", IZero_Profile.take())
|
||||
append_dataset("RAW/TFY_Profile", TFY_Profile.take())
|
||||
append_dataset("Processed/GE_ROI_Image", GE_ROI_Image.read())
|
||||
append_dataset("Processed/GE_Spectrum", GE_Spectrum.take())
|
||||
append_dataset("Processed/Izero", IZero.take())
|
||||
append_dataset("Processed/TFY", TFY.take())
|
||||
append_dataset("Detector/GE_Sensor_Temp", GE_Sensor_Temp.take())
|
||||
append_dataset("Scan/GE_FrameID", GE_FrameID.take())
|
||||
append_dataset("Scan/Timestamps", GE_FrameID.getTimestampNanos())
|
||||
append_dataset("Pressure/Diagnostic_PV", Press_Diag_PV.take())
|
||||
append_dataset("Pressure/Diagnostic_HV", Press_Diag_HV.take())
|
||||
append_dataset("Pressure/Spectrometer_PV", Press_Spec_PV.take())
|
||||
append_dataset("Pressure/Spectrometer_HV", Press_Spec_HV.take())
|
||||
append_dataset("Pressure/Sample_Chamber", Press_Sample_Ch.take())
|
||||
#Scan_Progress = (100*calcprog(GE_FrameID.take(),GE_start_frame,Num_Images))
|
||||
|
||||
def Save_Pos_Scan_Data():
|
||||
sleep(1)
|
||||
save_dataset("Processed/GE_Spectrum_Sum", GE_Spectrum_Sum.read())
|
||||
save_dataset("Scan/Scan_Finish_Time", time.ctime())
|
||||
|
||||
#******** Test limits on sample vertical and horizontal motor ********
|
||||
X0=float(X0)
|
||||
Xstep=float(Xstep)
|
||||
Y0=float(Y0)
|
||||
Ystep=float(Ystep)
|
||||
|
||||
X1=X0+(XNum_points*Xstep)
|
||||
Y1=Y0+(YNum_points*Ystep)
|
||||
Num_Images= XNum_points*YNum_points
|
||||
|
||||
#******** Setting up Caenels ********
|
||||
values_p_reading=1000*Exp_Time
|
||||
Scan_Progress = 1
|
||||
|
||||
############### Scan ###############
|
||||
|
||||
|
||||
#******** Scan Script Begins here ********
|
||||
|
||||
# Set Nr of images to NofImages
|
||||
#******** Saving Pre Scan data ********
|
||||
Save_Pre_Scan_Data()
|
||||
|
||||
#******** Pre Scan Setup ********
|
||||
print("Scan starting: " + time.ctime())
|
||||
GE_start_frame =1
|
||||
Create_Scan_Dataset()
|
||||
#Sample_Horiz.move(X0)
|
||||
|
||||
|
||||
#******** Main Scan Function ********
|
||||
|
||||
for j in range(XNum_points):
|
||||
#Sample_Horiz.move(X0+(j*Xstep))
|
||||
for i in range(YNum_points):
|
||||
#Sample_Vert.move(Y0+(i*Ystep))
|
||||
print GE_start_frame , " / ", (XNum_points*YNum_points)
|
||||
time.sleep(0.001)
|
||||
Save_Scan_Data()
|
||||
GE_start_frame = GE_start_frame+1
|
||||
|
||||
#Save_Scan_Data()
|
||||
#Save_Scan_Data()
|
||||
#******** Saving Pos Scan data ********
|
||||
Save_Pos_Scan_Data()
|
||||
|
||||
#******** Post Scan ********
|
||||
print("Scan Finished: " + time.ctime())
|
||||
|
||||
|
||||
172
script/test/TestNilson2.py
Normal file
172
script/test/TestNilson2.py
Normal file
@@ -0,0 +1,172 @@
|
||||
#features = {"compression" : "true", "shuffle": "false", "chunk":[1, 100, 200]}
|
||||
features = {"compression" : True, "shuffle": False}
|
||||
#features =None
|
||||
FIXED = False
|
||||
# Greateyes scan
|
||||
|
||||
|
||||
|
||||
#******** SCAN Settings ********
|
||||
Note="DESY - "
|
||||
|
||||
Exp_Time= 1
|
||||
|
||||
X0=4200
|
||||
Xstep=450
|
||||
XNum_points=10
|
||||
|
||||
Y0=5960
|
||||
Ystep=-40
|
||||
YNum_points=10
|
||||
|
||||
GE_ROI_Line = 3
|
||||
|
||||
GE_AreaDet = det
|
||||
|
||||
GE_ROI_Image= det.getDataMatrix()
|
||||
GE_Raw_Image= det.getDataMatrix()
|
||||
GE_BG_Image = det.getDataMatrix()
|
||||
GE_Spectrum_Conv = arr #det.getDataArray()
|
||||
GE_Spectrum = arr #det.getDataArray()
|
||||
GE_BG_Line = det.getArraySize2()
|
||||
GE_BG_SizeX = det.getArraySize0()
|
||||
GE_BG_SizeY = det.getArraySize1()
|
||||
GE_ROI_Line = det.getArraySize2()
|
||||
GE_ROI_SizeX = det.getArraySize0()
|
||||
GE_ROI_SizeY = det.getArraySize1()
|
||||
IZero_Profile = arr #det.getDataArray()
|
||||
TFY_Profile = arr #det.getDataArray()
|
||||
IZero=sin
|
||||
TFY = sin
|
||||
GE_Sensor_Temp = sin
|
||||
GE_FrameID = sin
|
||||
Press_Diag_PV= sin
|
||||
Press_Spec_PV= sin
|
||||
Press_Spec_HV =sin
|
||||
Press_Sample_Ch=sin
|
||||
Press_Diag_HV = sin
|
||||
GE_Spectrum_Sum = det.getDataArray()
|
||||
Sample_Horiz=motor
|
||||
Sample_Vert=motor2
|
||||
|
||||
#******** Functions Definitions ********
|
||||
def Save_Pre_Scan_Data():
|
||||
save_dataset("RAW/GE_BG_Image", GE_BG_Image.read())
|
||||
save_dataset("Processed/GE_Spectrum_Convertion", GE_Spectrum_Conv.read())
|
||||
save_dataset("Detector/GE_ROI_Line", GE_ROI_Line.read())
|
||||
save_dataset("Detector/GE_ROI_SizeX", GE_ROI_SizeX.read())
|
||||
save_dataset("Detector/GE_ROI_SizeY", GE_ROI_SizeY.read())
|
||||
save_dataset("Detector/Exposure_Time", GE_AreaDet.getExposure())
|
||||
save_dataset("Detector/GE_Open_Delay", 1)
|
||||
save_dataset("Detector/GE_Close_Delay", 1)
|
||||
save_dataset("Detector/GE_Num_Images", GE_AreaDet.getNumImages())
|
||||
save_dataset("Detector/Gain_Type", 1)
|
||||
save_dataset("Scan/Scan_Start_Time", time.ctime())
|
||||
save_dataset("Scan/Note", Note)
|
||||
#save_dataset("Scan/Note", Note)
|
||||
|
||||
def Create_Scan_Dataset():
|
||||
create_dataset("RAW/GE_Raw_Image", 'd', False, (Num_Images if FIXED else 0, int(GE_BG_SizeY.take()), int(GE_BG_SizeX.take())), features)
|
||||
create_dataset("RAW/IZero_Profile", 'd', False, (Num_Images if FIXED else 0, 100))
|
||||
create_dataset("RAW/TFY_Profile", 'd', False, (Num_Images if FIXED else 0, 100))
|
||||
#create_dataset("Processed/GE_ROI_Image", 'd', False, (Num_Images if FIXED else 0Images, int(GE_ROI_SizeY.take()), int(GE_ROI_SizeX.take())))
|
||||
create_dataset("Processed/GE_Spectrum", 'd', False, (Num_Images if FIXED else 0, int(GE_BG_SizeX.take())))
|
||||
create_dataset("Processed/Izero", 'd', False)
|
||||
create_dataset("Processed/TFY", 'd', False)
|
||||
create_dataset("Detector/GE_Sensor_Temp", 'd', False)
|
||||
create_dataset("Scan/GE_FrameID", 'i', False)
|
||||
create_dataset("Scan/Timestamps", 'l', False)
|
||||
create_dataset("Pressure/Diagnostic_PV", 'd', False)
|
||||
create_dataset("Pressure/Diagnostic_HV", 'd', False)
|
||||
create_dataset("Pressure/Spectrometer_PV", 'd', False)
|
||||
create_dataset("Pressure/Spectrometer_HV", 'd', False)
|
||||
create_dataset("Pressure/Sample_Chamber", 'd', False)
|
||||
create_dataset("RAW/Xposition", 'd', False)
|
||||
create_dataset("RAW/Yposition", 'd', False)
|
||||
|
||||
|
||||
|
||||
def Save_Scan_Data():
|
||||
#sleep(0.2)
|
||||
append_dataset("RAW/GE_Raw_Image", GE_Raw_Image.read())
|
||||
append_dataset("RAW/IZero_Profile", IZero_Profile.take())
|
||||
append_dataset("RAW/TFY_Profile", TFY_Profile.take())
|
||||
#append_dataset("Processed/GE_ROI_Image", GE_ROI_Image.read())
|
||||
append_dataset("Processed/GE_Spectrum", GE_Spectrum.take())
|
||||
append_dataset("Processed/Izero", IZero.take())
|
||||
append_dataset("Processed/TFY", TFY.take())
|
||||
append_dataset("Detector/GE_Sensor_Temp", GE_Sensor_Temp.take())
|
||||
append_dataset("Scan/GE_FrameID", GE_FrameID.take())
|
||||
append_dataset("Scan/Timestamps", GE_FrameID.getTimestampNanos())
|
||||
append_dataset("Pressure/Diagnostic_PV", Press_Diag_PV.take())
|
||||
append_dataset("Pressure/Diagnostic_HV", Press_Diag_HV.take())
|
||||
append_dataset("Pressure/Spectrometer_PV", Press_Spec_PV.take())
|
||||
append_dataset("Pressure/Spectrometer_HV", Press_Spec_HV.take())
|
||||
append_dataset("Pressure/Sample_Chamber", Press_Sample_Ch.take())
|
||||
#Scan_Progress = (100*calcprog(GE_FrameID.take(),GE_start_frame,Num_Images))
|
||||
|
||||
def Save_Pos_Scan_Data():
|
||||
sleep(1)
|
||||
save_dataset("Processed/GE_Spectrum_Sum", GE_Spectrum_Sum.read())
|
||||
save_dataset("Scan/Scan_Finish_Time", time.ctime())
|
||||
|
||||
#******** Test limits on sample vertical and horizontal motor ********
|
||||
X0=float(X0)
|
||||
Xstep=float(Xstep)
|
||||
Y0=float(Y0)
|
||||
Ystep=float(Ystep)
|
||||
|
||||
X1=X0+(XNum_points*Xstep)
|
||||
Y1=Y0+(YNum_points*Ystep)
|
||||
Num_Images= XNum_points*YNum_points
|
||||
|
||||
#******** Setting up Caenels ********
|
||||
values_p_reading=1000*Exp_Time
|
||||
Scan_Progress = 1
|
||||
|
||||
############### Scan ###############
|
||||
|
||||
create_dataset("RAW/GE_Raw_Image2", 'd', False, (Num_Images if FIXED else 0, int(GE_BG_SizeY.take()), int(GE_BG_SizeX.take())), features)
|
||||
|
||||
|
||||
|
||||
|
||||
Save_Pre_Scan_Data()
|
||||
|
||||
#******** Pre Scan Setup ********
|
||||
print("Scan starting: " + time.ctime())
|
||||
GE_start_frame =1
|
||||
Create_Scan_Dataset()
|
||||
|
||||
#Sample_Horiz.move(X0)
|
||||
|
||||
|
||||
#******** Main Scan Function ********
|
||||
#XNum_points, YNum_points 3, 4
|
||||
X0, Y0, Xstep, Ystep = 0, 0, 0.1, 0.1
|
||||
|
||||
for j in range(XNum_points):
|
||||
#Sample_Horiz.move(X0+(j*Xstep))
|
||||
for i in range(YNum_points):
|
||||
#Sample_Vert.move(Y0+(i*Ystep))
|
||||
print GE_start_frame , " / ", (XNum_points*YNum_points)
|
||||
time.sleep(0.001)
|
||||
Save_Scan_Data()
|
||||
GE_start_frame = GE_start_frame+1
|
||||
|
||||
|
||||
"""
|
||||
def after(record, scan):
|
||||
Save_Scan_Data()
|
||||
|
||||
ascan((Sample_Horiz, Sample_Vert), (GE_Raw_Image), (X0, Y0), (X1, Y1), (Xstep, Ystep), after_read = after)
|
||||
"""
|
||||
#Save_Scan_Data()
|
||||
#Save_Scan_Data()
|
||||
#******** Saving Pos Scan data ********
|
||||
Save_Pos_Scan_Data()
|
||||
|
||||
#******** Post Scan ********
|
||||
print("Scan Finished: " + time.ctime())
|
||||
|
||||
|
||||
23
script/test/TestNilson3.py
Normal file
23
script/test/TestNilson3.py
Normal file
@@ -0,0 +1,23 @@
|
||||
features = None
|
||||
size = 5
|
||||
typ = 'd'
|
||||
features = {"compression" : True, "shuffle": True}
|
||||
|
||||
#features = {"layout" : "chunked", "chunk_size":[1, 500, 1000]}
|
||||
|
||||
|
||||
create_dataset("group/contiguous", typ, False, (size, 1000, 1000), features)
|
||||
create_dataset("group/chunked", typ, False, (0, 1000, 1000), features)
|
||||
|
||||
|
||||
|
||||
|
||||
for i in range(size):
|
||||
data = [ [int(i)] * 1000, ] * 1000
|
||||
#data = Convert.flatten(to_array(data, typ))
|
||||
append_dataset("group/chunked", data )
|
||||
append_dataset("group/contiguous", data)
|
||||
|
||||
|
||||
|
||||
|
||||
17
script/test/TestPID.py
Normal file
17
script/test/TestPID.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
PID = get_context().getClassByName("PID")
|
||||
|
||||
|
||||
|
||||
pid=PID(1,1,1);
|
||||
|
||||
|
||||
while True:
|
||||
sensor = sin.read()
|
||||
target = 30.0
|
||||
#set some sort of target value
|
||||
output=pid.getOutput(sensor,target);
|
||||
print output
|
||||
#do something with the output
|
||||
inp.write(output)
|
||||
time.sleep(1.0)
|
||||
5
script/test/TestPlotLayout.py
Normal file
5
script/test/TestPlotLayout.py
Normal file
@@ -0,0 +1,5 @@
|
||||
tscan([out, inp, sin, arr], 10, 0.1)
|
||||
set_exec_pars(plot_layout = "Grid")
|
||||
tscan([out, inp, sin, arr], 10, 0.1, plot_layout = "Grid")
|
||||
set_exec_pars(defaults=True)
|
||||
tscan([out, inp, sin, arr], 10, 0.1)
|
||||
2
script/test/TestThen.py
Normal file
2
script/test/TestThen.py
Normal file
@@ -0,0 +1,2 @@
|
||||
lscan(inp, sin, 0, 10, 0.1)
|
||||
set_exec_pars(then="lscan(inp, sin, 0, 10, 0.2)")
|
||||
143
script/test/TestTiff.py
Normal file
143
script/test/TestTiff.py
Normal file
@@ -0,0 +1,143 @@
|
||||
from ijutils import *
|
||||
|
||||
|
||||
#Image Loading
|
||||
ip = load_image("/Users/gobbo_a/dev/pshell/config/home/images/img.tiff", title="Image")
|
||||
|
||||
#Basic image manipulation: creation, copying, padding, saving
|
||||
resized = resize(ip, 300,300)
|
||||
save_image(resized, get_context().setup.expandPath("{images}/resized.tiff") ,"tiff")
|
||||
crop=sub_image(ip,10,20,50,30)
|
||||
bin_im = binning(ip,2)
|
||||
new_im = new_image(256, 256, "color")
|
||||
copy_image_to(bin_im, new_im, 20, 20)
|
||||
pad_im = pad_image(ip, 1, 2, 3, 4, Color.RED)
|
||||
stack=create_stack([ip,resized,crop, bin_im, new_im, pad_im], title = "Basic Functions")
|
||||
save_image(stack, get_context().setup.expandPath("{images}/stack.tiff") ,"tiff")
|
||||
stack.show()
|
||||
|
||||
|
||||
#Decomposing color channels
|
||||
|
||||
create_stack([ get_channel(ip, "red"),
|
||||
get_channel(ip, "green"),
|
||||
get_channel(ip, "blue"),
|
||||
get_channel(ip, "alpha"),
|
||||
grayscale(get_channel(ip, "brightness"), False)], title = "Color Decomposition").show()
|
||||
|
||||
|
||||
#Basic functions (in_place)
|
||||
aux = ip.duplicate()
|
||||
aux.show()
|
||||
grayscale(aux)
|
||||
gaussian_blur(aux); aux.repaintWindow()
|
||||
invert(aux); aux.repaintWindow()
|
||||
smooth(aux); aux.repaintWindow()
|
||||
sharpen(aux); aux.repaintWindow()
|
||||
noise(aux, 100); aux.repaintWindow()
|
||||
|
||||
|
||||
#Changing LUT
|
||||
aux = ip.duplicate()
|
||||
aux = grayscale(aux, in_place=False)
|
||||
r,g,b = [],[],[]
|
||||
for i in range(256):
|
||||
r.append(0)
|
||||
g.append(0)
|
||||
b.append(i)
|
||||
set_lut(aux, r, g, b)
|
||||
aux.show()
|
||||
|
||||
|
||||
#Histogram
|
||||
plot(get_histogram(ip))
|
||||
|
||||
|
||||
aux = grayscale(ip, in_place = False)
|
||||
bin = ip.duplicate()
|
||||
ip_bin = auto_threshold(aux, in_place=False)
|
||||
create_stack([ ip_bin,
|
||||
binary_fill_holes(ip_bin, in_place=False),
|
||||
binary_outline(ip_bin, in_place=False),
|
||||
binary_outline(binary_fill_holes(ip_bin, in_place=False)),
|
||||
binary_dilate(ip_bin, in_place=False),
|
||||
binary_erode(ip_bin, in_place=False),
|
||||
binary_open(ip_bin, in_place=False),
|
||||
binary_close(ip_bin, in_place=False),
|
||||
binary_skeletonize(ip_bin, in_place=False)], title = "Binarization").show()
|
||||
|
||||
|
||||
#EDM, const & image operations
|
||||
aux = grayscale(ip, in_place = False)
|
||||
ip_bin = auto_threshold(aux, in_place=False)
|
||||
binary_fill_holes(ip_bin)
|
||||
|
||||
edm = edm(ip_bin, in_place=False)
|
||||
ws = watershed(ip_bin, in_place=False)
|
||||
up = ultimate_points(ip_bin, in_place=False)
|
||||
vr = veronoi(ip_bin, in_place=False)
|
||||
edm_disp = remap(edm, in_place=False)
|
||||
ws_disp = grayscale(ws, False)
|
||||
up_disp = enhance_contrast(up, in_place=False)
|
||||
vr_disp = enhance_contrast(vr, in_place=False)
|
||||
create_stack([edm_disp, aux, ip_bin, ws_disp, up_disp, vr_disp], title = "EDM Operations").show()
|
||||
final = grayscale(ip_bin, in_place = False)
|
||||
op_const(final,"add", -200)
|
||||
op_image(final, vr_disp, 'or')
|
||||
op_image(final, up_disp, 'or')
|
||||
final.show()
|
||||
|
||||
aux = grayscale(ip, in_place = False)
|
||||
|
||||
create_stack([ aux,
|
||||
subtract_background(aux, in_place=False),
|
||||
smooth(aux, False),
|
||||
sharpen(aux, False),
|
||||
edges(aux, False),
|
||||
bandpass_filter(aux,0, 5, in_place=False),
|
||||
bandpass_filter(aux,5, 100, in_place=False),
|
||||
op_const(aux,"and", 127, False),
|
||||
convolve(aux, KERNEL_BLUR, False),
|
||||
convolve(aux, KERNEL_SHARPEN, False),
|
||||
convolve(aux, KERNEL_SHARPEN_2, False),
|
||||
convolve(aux, KERNEL_LIGHT, False),
|
||||
convolve(aux, KERNEL_DARK, False),
|
||||
convolve(aux, KERNEL_EDGE_DETECT, False),
|
||||
convolve(aux, KERNEL_EDGE_DETECT_2, False),
|
||||
convolve(aux, KERNEL_DIFFERENTIAL_EDGE_DETECT, False),
|
||||
convolve(aux, KERNEL_PREWITT, False),
|
||||
convolve(aux, KERNEL_SOBEL, False)
|
||||
], title = "General Operations").show()
|
||||
|
||||
|
||||
#Rank operators
|
||||
rank_opers = []
|
||||
for op in "mean", "min", "max", "variance", "median", "close_maxima", "open_maxima", "remove_outliers", "remove_nan", "despeckle":
|
||||
rank_opers.append(op_rank(aux,op, in_place=False, kernel_radius=1))
|
||||
create_stack(rank_opers, title = "Rank Operations").show()
|
||||
|
||||
|
||||
#Reslicing
|
||||
#orig = load_image("{data}/img/img2.png")
|
||||
orig = resize(ip, 300,200)
|
||||
grayscale(orig)
|
||||
images=[]
|
||||
for i in range (20):
|
||||
images.append(orig.duplicate())
|
||||
op_const(orig, "multiply", 0.9)
|
||||
stack=create_stack(images, title = "Original Stack")
|
||||
#stack.show()
|
||||
r1 = reslice(stack, start_at="Left", title="Reslice Horizontally")
|
||||
r2 = reslice(stack, start_at="Top", title="Reslice Vertically")
|
||||
r1.show()
|
||||
r2.show()
|
||||
|
||||
|
||||
#Particle Analysis
|
||||
aux = grayscale(ip, in_place = False)
|
||||
auto_threshold(aux)
|
||||
#binary_fill_holes(aux)
|
||||
#aux.show()
|
||||
(results,output_img)=analyse_particles(aux, 100,1000, print_table=True)
|
||||
output_img.show()
|
||||
|
||||
31
script/test/TestTypes.py
Normal file
31
script/test/TestTypes.py
Normal file
@@ -0,0 +1,31 @@
|
||||
class StringDev(ReadonlyRegisterBase, Readable.StringType):
|
||||
def doRead(self):
|
||||
time.sleep(0.001)
|
||||
return str(time.time())
|
||||
|
||||
class BoolDevS(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
return (int(time.time()) %2) == 0
|
||||
|
||||
class BoolDev(ReadonlyRegisterBase, Readable.BooleanType):
|
||||
def doRead(self):
|
||||
return (int(time.time()) %2) == 0
|
||||
|
||||
class ImageDev(ReadonlyRegisterBase, ReadonlyRegisterMatrix, Readable.IntegerType):
|
||||
def doRead(self):
|
||||
return mt1.read()
|
||||
|
||||
def getWidth(self):
|
||||
return mt1.width
|
||||
|
||||
def getHeight(self):
|
||||
return mt1.height
|
||||
|
||||
|
||||
|
||||
add_device(StringDev(), True)
|
||||
add_device(BoolDev(), True)
|
||||
add_device(BoolDevS(), True)
|
||||
add_device(ImageDev(), True)
|
||||
|
||||
tscan((StringDev, BoolDev, BoolDevS, sin, arr, arr1, mt, mt1, cm1, ImageDev), 10, 0.1, compression =ImageDev)
|
||||
55
script/test/test_multipass.py
Normal file
55
script/test/test_multipass.py
Normal file
@@ -0,0 +1,55 @@
|
||||
def set_energy(v):
|
||||
motor.move(v)
|
||||
energy_setpoint = motor
|
||||
energy = motor.getReadback()
|
||||
set_device_alias(energy, "energy")
|
||||
|
||||
|
||||
START, STOP, STEP = 0, 40, 2
|
||||
ENERGIES = [0.0, 0.5, 0.25]
|
||||
sensors = (sin,out, energy)
|
||||
|
||||
|
||||
|
||||
#def before_pass(pass_num):
|
||||
# set_energy(ENERGIES[pass_num-1])
|
||||
#ret= lscan(inp, sensors, START, STOP, STEP, 0.2, passes = len(ENERGIES), before_pass = before_pass, latency = 0.5)
|
||||
|
||||
|
||||
#positions = frange(START, STOP, STEP , True)
|
||||
#vector = [[pos, en] for en in ENERGIES for pos in positions]
|
||||
#ret = vscan((inp,energy_setpoint), sensors, vector, line = True, latency = 0.5)
|
||||
|
||||
|
||||
"""
|
||||
plots = plot([None]*len(sensors), name = [d.name for d in sensors])
|
||||
for p in plots: p.clear()
|
||||
def AfterReadout(record, scan):
|
||||
if record.setpoints[1] == scan.getStart()[1]:
|
||||
for p in plots: p.addSeries(LinePlotSeries(str(record.positions[0])))
|
||||
for i in range(len(plots)):
|
||||
plots[i].getSeries(plots[i].numberOfSeries-1).appendData(record.positions[1], record.values[i])
|
||||
|
||||
class EnergyIndex("Writable):
|
||||
def write(self, value):
|
||||
if not hasattr(self, 'setpoint') or self.setpoint != value:
|
||||
self.setpoint = value
|
||||
set_energy(ENERGIES[int(value)])
|
||||
|
||||
positions = frange(START, STOP, STEP , True)
|
||||
ret = ascan([EnergyIndex(), inp], sensors, (0,START), (len(ENERGIES)-1,STOP), (1.0,STEP), latency = 0.1, after_read=AfterReadout, plot_disabled=True)
|
||||
"""
|
||||
|
||||
plots = plot([None]*len(sensors), name = [d.name for d in sensors])
|
||||
for p in plots:
|
||||
p.clear()
|
||||
p.legendVisible = True
|
||||
def after_readout(record, scan):
|
||||
for i in range(len(plots)):
|
||||
plots[i].getSeries(plots[i].numberOfSeries-1).appendData(record.positions[0], record.values[i])
|
||||
def before_pass(pass_num):
|
||||
en = ENERGIES[pass_num-1]
|
||||
set_energy(en)
|
||||
for p in plots: p.addSeries(LinePlotSeries(str(en)))
|
||||
|
||||
ret= lscan(inp, sensors, START, STOP, STEP, latency = 0.2, passes = len(ENERGIES), before_pass = before_pass, after_read=after_readout, plot_disabled=True)
|
||||
Reference in New Issue
Block a user