def __init__(self, host, port):
        super(SimulatorDetector, self).__init__()

        # self._AcqDefaults = {'acqExpoTime': 1,
        #                      'acqNbFrames': 10,
        #                      'acqMode': 'Single',
        #                      'accMaxExpoTime': 1,
        #                      'concatNbFrames': 0,
        #                      'triggerMode': 'Internal',
        #                      'latencyTime': 0,
        #                      # 'AUTO_EXPO_MODE': 0 # NOT ACCESSIBLE in Simulator (at least)!
        #                      }
        #
        # self._SavingDefaults = {'directory': './',
        #                         'prefix': 'img_',
        #                         'suffix': '.cbf',
        #                         'nextNumber': 0,
        #                         'fileFormat': 'CBF',
        #                         'savingMode': 'AUTO_FRAME',
        #                         'overwritePolicy': 'OVERWRITE',
        #                         'framesPerFile': 1,
        #                         'nbframes': 0
        #                         }

        try:
            if not port:
                self.cam = Simulator.Camera()
            else:
                self.cam = Simulator.Camera(port)
            time.sleep(2)
            self.hwint = Simulator.Interface(self.cam)
        except Exception, e:
            logging.error('Error initializing detector object: \n%s', e)
Example #2
0
    def _init(self):
        self.scalingType = None
        self.forceUpdate = False
        self.camMirror = None

        self.__brightnessExists = False
        self.__contrastExists = False
        self.__gainExists = False
        self.__gammaExists = False

        self.camType = self.getProperty("type").lower()
        self.camAddress = self.getProperty("address")
        #self.camMirror = eval(self.getProperty("mirror_hor_ver"))

        if self.camType == 'prosilica':
            from Lima import Prosilica
            self.camera = Prosilica.Camera(self.camAddress)
            self.interface = Prosilica.Interface(self.camera)
        if self.camType == 'simulation':
            from Lima import Simulator
            self.camera = Simulator.Camera()
            self.interface = Simulator.Interface(self.camera)
        try:
            self.control = Core.CtControl(self.interface)
            self.video = self.control.video()
            self.video.setExposure(self.getProperty("interval") / 1000.0)
            self.__imageDimensions = self.camera.getMaxWidthHeight()
        except KeyError:
            logging.getLogger().warning(
                '%s: not initialized. Check camera settings', self.name())

        self.setImageTypeFromXml('imagetype')
        self.setIsReady(True)
Example #3
0
def get_control(**keys):
    global _SimuInterface
    if _SimuInterface is None:
        simu = Simulator.Camera()
        _SimuInterface = Simulator.Interface(simu)
        _SimuInterface._ref_interface = simu
    return Core.CtControl(_SimuInterface)
Example #4
0
    def __init__(self):

        self.cam = Simulator.Camera()
        self.cam_hw = Simulator.Interface(self.cam)

        self.ct_control = Core.CtControl(self.cam_hw)
        self.ct_saving = self.ct_control.saving()
        self.ct_image = self.ct_control.image()
        self.ct_acq = self.ct_control.acquisition()
        self.ct_config = self.ct_control.config()
        self.conf_dict = {
            'conf1': {
                'exptime': 0.1,
                'nbframes': 3,
                'bin': Core.Bin(2, 2),
                'rot': Core.Rotation_180,
                'prefix': 'conf1_',
                'opolicy': Core.CtSaving.Overwrite
            },
            'conf2': {
                'exptime': 0.8,
                'nbframes': 2,
                'bin': Core.Bin(4, 4),
                'rot': Core.Rotation_90,
                'prefix': 'conf1_',
                'opolicy': Core.CtSaving.Abort
            }
        }
Example #5
0
    def __init__(self, camera='simulator'):
        if camera == 'maxipix':
            try:
                from Lima import Maxipix
            except ImportError:
                print(
                    "Cannot use the Maxipix camera plugin, Maxipix python module is not installed"
                )
                sys.exit()
            self.cam = Maxipix.Camera(
                1, '/users/blissadm/local/maxipix/tpxatl25', 'tpxatl25', True)
            self.cam_hw = Maxipix.Interface(self.cam)
        else:
            self.cam = Simulator.Camera()
            self.cam_hw = Simulator.Interface(self.cam)

        self.ct_control = Core.CtControl(self.cam_hw)
        self.ct_saving = self.ct_control.saving()
        self.ct_acq = self.ct_control.acquisition()

        self.format_list = [
            fmt.lower() for fmt in self.ct_saving.getFormatListAsString()
        ]

        self.overwrite2limaoverwrite = {
            'abort': self.ct_saving.Abort,
            'append': self.ct_saving.Append,
            'multiset': self.ct_saving.MultiSet,
            'overwrite': self.ct_saving.Overwrite
        }
Example #6
0
	def __init__(self):
		self.simu = Simulator.Camera()
		self.simu_hw = Simulator.Interface(self.simu)
		self.ct_control = Core.CtControl(self.simu_hw)
		self.cb_end = threading.Event()
		self.cb = self.ImageStatusCallback(self, self.cb_end)
		self.ct_control.registerImageStatusCallback(self.cb)
def test_default_pixel_size():
    """Create the simulator camera

    Check the default pixel size
    """
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    detInfo = hw.getHwCtrlObj(Core.HwCap.DetInfo)
    pixelsize = detInfo.getPixelSize()
    assert pixelsize == (1e-6, 1e-6)
def test_custom_pixel_size():
    """Change the simulator pixel size

    Check that the pixel size is the expected one
    """
    cam = Simulator.Camera()
    cam.setPixelSize(1e-3, 1e-4)
    hw = Simulator.Interface(cam)
    detInfo = hw.getHwCtrlObj(Core.HwCap.DetInfo)
    pixelsize = detInfo.getPixelSize()
    assert pixelsize == (1e-3, 1e-4)
def test_big_detector_size():
    """Change the size of the simulator

    Make sure the hardware detector size matches the request
    """
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    ct = Core.CtControl(hw)
    cam.setFrameDim(Core.FrameDim(2048, 2000, Core.Bpp32))
    dim = ct.image().getImageDim()
    assert dim.getSize() == Core.Size(2048, 2000)

    detinfo = hw.getHwCtrlObj(Core.HwCap.DetInfo)
    assert detinfo.getMaxImageSize() == Core.Size(2048, 2000)
def test_internal_trigger():
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    ct = Core.CtControl(hw)

    acq_status = AcquisitionStatusFromImageStatusCallback()
    ct.registerImageStatusCallback(acq_status)

    ct.prepareAcq()
    ct.startAcq()

    while ct.getStatus().AcquisitionStatus != Core.AcqReady:
        time.sleep(0.1)

    assert acq_status.last_image_ready == 0
def main(argv):
    exp_time = 0.1
    nb_frames = 180

    spec_name = 'GLDisplayTest'
    array_name = 'Simulator'

    if (len(argv) > 1) and (argv[1] == '--alternate-test'):
        alternate_test_image = True

    simu = Simulator.Camera()
    simu_fb = simu.getFrameBuilder()
    simu_fb.setPeaks(peaks)
    simu_fb.setPeakAngles(peak_angles)
    simu_fb.setRotationSpeed(360 / nb_frames)

    simu_hw = Simulator.Interface(simu)
    ct_control = Core.CtControl(simu_hw)
    ct_acq = ct_control.acquisition()

    ct_acq.setAcqExpoTime(exp_time)
    ct_acq.setAcqNbFrames(nb_frames)

    ct_gl_display = GLDisplay.CtSPSGLDisplay(ct_control, argv)
    ct_gl_display.setSpecArray(spec_name, array_name)
    ct_gl_display.createWindow()

    ct_control.prepareAcq()
    ct_control.startAcq()

    try:
        refresh_loop(ct_gl_display)
    except KeyboardInterrupt:
        pass

    ct_status = ct_control.getStatus()

    if ct_status.AcquisitionStatus == Core.AcqRunning:
        ct_control.stopAcq()
        while ct_status.AcquisitionStatus == Core.AcqRunning:
            time.sleep(refresh_time)
            ct_status = ct_control.getStatus()

    del ct_gl_display
    del ct_control

    return 0
def test_update_mode():
    """Change the simulator mode of the detector

    Check that the size have not changed
    """
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    ct = Core.CtControl(hw)
    cam.setFrameDim(Core.FrameDim(100, 100, Core.Bpp32))
    dim = ct.image().getImageDim()
    assert dim.getSize() == Core.Size(100, 100)

    new_mode = Simulator.Camera.MODE_GENERATOR_PREFETCH
    cam.setMode(new_mode)

    dim = ct.image().getImageDim()
    assert dim.getSize() == Core.Size(100, 100)
def test_external_trigger_single():
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    ct = Core.CtControl(hw)

    acq_status = AcquisitionStatusFromImageStatusCallback()
    ct.registerImageStatusCallback(acq_status)

    acq = ct.acquisition()
    acq.setTriggerMode(Core.ExtTrigSingle)
    acq.setAcqNbFrames(3)
    acq.setAcqExpoTime(0.01)

    ct.prepareAcq()
    cam.extTrigAcq()  # simulate an external trigger

    while ct.getStatus().AcquisitionStatus != Core.AcqReady:
        time.sleep(0.1)

    assert acq_status.last_image_ready == 2
def test_internal_trigger_multi():
    cam = Simulator.Camera()
    hw = Simulator.Interface(cam)
    ct = Core.CtControl(hw)

    acq_status = AcquisitionStatusFromImageStatusCallback()
    ct.registerImageStatusCallback(acq_status)

    acq = ct.acquisition()
    acq.setTriggerMode(Core.IntTrigMult)
    acq.setAcqNbFrames(3)
    acq.setAcqExpoTime(0.01)

    ct.prepareAcq()
    for _ in range(3):
        time.sleep(0.1)
        ct.startAcq()

    while ct.getStatus().AcquisitionStatus != Core.AcqReady:
        time.sleep(0.1)

    assert acq_status.last_image_ready == 2
Example #15
0
def get_control(peaks=[], peak_angles=[], **keys):
    global _SimuCamera, _SimuFrameBuilder, _SimuInterface
    if _SimuInterface is None:
        _SimuCamera = SimuMod.Camera()
        _SimuFrameBuilder = _SimuCamera.getFrameBuilder()
        _SimuInterface = SimuMod.Interface(_SimuCamera)

        if peaks:
            if (type(peaks) != str and getattr(peaks, '__getitem__', None)
                    and type(peaks[0]) == str):
                peaks = ','.join(peaks)
            if type(peaks) == str:
                peaks = map(float, peaks.split(','))
            gauss_peaks = Simulator.getGaussPeaksFromFloatArray(peaks)
            _SimuFrameBuilder.setPeaks(gauss_peaks)
        if peak_angles:
            if type(peak_angles) == str:
                peak_angles = peak_angles.split(',')
            if type(peak_angles[0]) == str:
                peak_angles = map(float, peak_angles)
            _SimuFrameBuilder.setPeakAngles(peak_angles)

    return Core.CtControl(_SimuInterface)
#   + Starts the display in forked process (SIGCHLD signal ignored)
#   + The display performs auto-normalisation every second
#
# The acquired (processed) number of frames is updated on the screen

import time
import signal
from Lima import Core, Simulator, GLDisplay

class SimuForkCb(GLDisplay.GLForkCallback):
	def execInForked(self):
		print "Simulator GLDisplay: this is executed in forked context"

simu_fork_cb = SimuForkCb()

simu = Simulator.Camera()
hw_inter = Simulator.Interface(simu)
ct_control = Core.CtControl(hw_inter)

gldisplay = GLDisplay.CtSPSGLDisplay(ct_control, [])
gldisplay.setSpecArray('GLDisplayTest', 'Simulator')
gldisplay.addForkCallback(simu_fork_cb)
gldisplay.createWindow()
signal.signal(signal.SIGCHLD, signal.SIG_IGN)

ct_acq = ct_control.acquisition()
ct_acq.setAcqNbFrames(10)
ct_acq.setAcqExpoTime(0.1)

ct_control.prepareAcq()
ct_control.startAcq()
Example #17
0
#  (at your option) any later version.
# 
#  This software is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################

from Lima import Core, Simulator

Core.DebParams.setTypeFlags(Core.DebParams.AllFlags)

cam = Simulator.Camera()

frame_dim = Core.FrameDim(Core.Size(800, 600), Core.Bpp32)
cam = Simulator.Camera()
getter = cam.getFrameGetter() 
getter.setFrameDim(frame_dim)

hwint = Simulator.Interface(cam)
control = Core.CtControl(hwint)

acq = control.acquisition()
acq.setAcqNbFrames(1)

img = control.image()
roi = Core.Roi(300,50,450,300)
img.setRoi(roi)
def main(argv):
    global alternate_test_image, int_trig_mult, acq_stopped

    exp_time = 0.1
    nb_frames = 180

    spec_name = 'GLDisplayTest'
    array_name = 'Simulator'

    for arg in argv[1:]:
        if arg == '--alternate-test':
            alternate_test_image = True
        if arg == '--int-trig-mult':
            int_trig_mult = True

    trig_mode = Core.IntTrigMult if int_trig_mult else Core.IntTrig

    simu = Simulator.Camera()
    simu_fb = simu.getFrameBuilder()
    simu_fb.setPeaks(peaks)
    simu_fb.setPeakAngles(peak_angles)
    simu_fb.setRotationSpeed(360 / nb_frames)
    simu_fb.setGrowFactor(0)

    simu_hw = Simulator.Interface(simu)
    ct_control = Core.CtControl(simu_hw)
    ct_acq = ct_control.acquisition()

    ct_acq.setAcqExpoTime(exp_time)
    ct_acq.setAcqNbFrames(nb_frames)
    ct_acq.setTriggerMode(trig_mode)

    ct_gl_display = GLDisplay.CtSPSGLDisplay(ct_control, argv)
    ct_gl_display.setSpecArray(spec_name, array_name)
    ct_gl_display.createWindow()

    if trig_mode == Core.IntTrigMult:
        cb = ImageStatusCallback(simu, ct_control)
        ct_control.registerImageStatusCallback(cb)

    ct_control.prepareAcq()
    ct_control.startAcq()

    try:
        refresh_loop(ct_gl_display)
    except KeyboardInterrupt:
        pass

    ct_status = ct_control.getStatus()

    if ct_status.AcquisitionStatus == Core.AcqRunning:
        acq_stopped = True
        ct_control.stopAcq()
        while ct_status.AcquisitionStatus == Core.AcqRunning:
            time.sleep(refresh_time)
            ct_status = ct_control.getStatus()

    del ct_gl_display
    del ct_control

    return 0
Example #19
0
 def get_simu_hw_inter():
   cam = Simulator.Camera()
   hw_inter = Simulator.Interface(cam)
   return hw_inter, cam