Giter Club home page Giter Club logo

hamamatsu's Introduction

Hamamatsu python library

Hamamatsu C11440-36U

This library is used to control basic features of Hamamatsu cameras. It is composed of a core library, an optional simulator and an optional lima plugin together with its tango device class.

It has been tested with C11440-36U model, but should work with other models.

Installation

From within your favorite python environment type:

$ pip install hamamatsu

Usage

import logging
from hamamatsu.dcam import copy_frame, dcam, Stream

logging.basicConfig(level=logging.INFO)

with dcam:
    camera = dcam[0]
    with camera:
        print(camera.info)
        print(camera['image_width'].value, camera['image_height'].value)

        # Simple acquisition example
        nb_frames = 10
        camera["exposure_time"] = 0.1
        with Stream(camera, nb_frames) as stream:
                logging.info("start acquisition")
                camera.start()
                for i, frame_buffer in enumerate(stream):
                    frame = copy_frame(frame_buffer)
                    logging.info(f"acquired frame #%d/%d: %s", i+1, nb_frames, frame)
                logging.info("finished acquisition")

Lima

Install extra dependencies with:

$ pip install hamamatsu[lima]

Command line usage:

$ limatb hamamatsu scan

$ limatb hamamatu -i 0 info

$ limatb hamamatu -i 0 dump

$ limatb hamamatu -i 0 acquire -n 10 -e 0.1

Tango

Please refer to the Lima documentation

Simulator

Only simulates a RemoteEx TCP interface. Under development.

hamamatsu's People

Contributors

tiagocoutinho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hamamatsu's Issues

Real time imaging

I've been trying to create a program which displays frames in real time, mainly for adjustment. Using Stream, I've been able to capture several pictures but it doesn't allow me to capture images in real time as Stream has the number of frames in argument.
I've tried calling Stream multiple times : "stream=Stream(camera, nb_frames)", but it doesn't seem to let me : "hamamatsu.dcam.DCAMError: DCAMError: 'dcambuf_alloc' raised NOTSTABLE (2147483908)"
Do you know of an alternative I can use to take pictures multiple times without having to restart my program?

Too long time on acqusition

Hi,

I am running it on python3.9.7 on windows. Basically everything works well, except that the acquisition time is too long for our experiment. I set integral time to be 0.01s, but the total time consumed to acquire one frame is almost 0.9s.

I didn't go deep into the dcam.py, but I found that a lot of time was consumed on allocating buffers. Basically every time I send a commend to acquire a frame, the program will allocate buffer, lock frame, copy it back and release buffer. I am wondering is there any way to not allocate buffer every time, but just one time for all? Also is it possible to set a region-of-interest thus decrease the space of the buffer and decrease the time of allocation?

Thanks

Lima Installation Problems

Thank you for the nice Hamamatsu Python interface.

At the step of the integration in Lima following error appears to the command pip install ./hamamatsu[lima]:

ERROR: For req: hamamatsu==0.1.3. Invalid script entry point: <ExportEntry hamamatsu-lima = hamamatsu.lima:None ['lima']> - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.

Further, a question regarding the manual integration of the Hamamatsu camera into the limatoolbox:
The hamamatsu/lima/cli.py file should be moved to the lima-toolbox/src/limatb/camera folder?
and then the entry_points in the lima-toolbox/setup.py should look like that:

    entry_points={
        "console_scripts": ["limatb = limatb.cli:main"],
        "limatb.cli.camera": [
            "Basler = limatb.camera.basler:basler [basler]",
            "Eiger = limatb.camera.eiger:eiger [eiger]",
            "Hamamatsu = limatb.camera.hamamatsu:hamamatsu [hamamatsu]",
        ],
        "limatb.cli.camera.scan": [
            "Basler = limatb.camera.basler:scan [basler]",
            "Eiger = limatb.camera.eiger:scan [eiger]",
            "Hamamatsu = limatb.camera.hamamatsu:scan [hamamatsu]",
        ],
    },

The command limatb hamamatsu scan returns:

Usage: limatb [OPTIONS] COMMAND [ARGS]...
Try 'limatb --help' for help.

Error: No such command 'hamamatsu'.

Memory problem, and repeat capture bug

Hello,

I am trying to use this software with a C9100-23B camera, and am having trouble with the basic example code. Running Python 3.8.8 on Windows.

I am able to take one set of images from the camera using the code below, which is heavily based on the example code provided:


def Snap(self,frames):
        from hamamatsu.dcam import dcam, Stream, copy_frame, ECCDMode

        returnvec=[]
        with dcam:
            camera = dcam[0]
            with camera:
                print(camera.info)
                print(camera['image_width'].value, camera['image_height'].value)

                # Simple acquisition example
                nb_frames = 5

                camera['ccd_mode']=ECCDMode.NORMALCCD
                camera['readout_speed'] = 1
                camera["exposure_time"] = 5
                
                with Stream(camera, nb_frames) as stream:
                        camera.start()

                        for i, frame_buffer in enumerate(stream):
                            frame = copy_frame(frame_buffer)
                            returnvec.append(copy.deepcopy(frame))
                            print(f"acquired frame #%d/%d: %s", i+1, nb_frames)
                        print("finished acquisition")

        return returnvec

However, if I run the function a second time; the camera takes the right number of images, but now uses its default settings for exposure time, EMCCD mode, rather than setting up the camera correctly with the ones provided in this function.

Trying to debug this problem I tried a few things, and one thing I noticed was that when I run the similar code block as a standalone python script from command line, it fails with a memory error at the end. The program and output are below. I wonder if cleanup of the objects at the the of the 'with' scope is not occurring properly and this is what is preventing the camera from being able to take more than one image set in a given program?

I am not sure what else to try to debug, but would be very grateful for any guidance.

#!/usr/bin/env python

from hamamatsu.dcam import dcam, Stream, copy_frame, ECCDMode
import numpy as np

returnvec=[]
with dcam:
    camera = dcam[0]
    with camera:
        print(camera.info)
        print(camera['image_width'].value, camera['image_height'].value)

        # Simple acquisition example
        camera['ccd_mode']=ECCDMode.NORMALCCD
        camera['readout_speed'] = 1
        camera["exposure_time"] = 5



        with Stream(camera, 1) as stream:
                camera.start()

                for i, frame_buffer in enumerate(stream):
                    frame = copy_frame(frame_buffer)
                    np.savetxt('out_snap.txt',frame)
                    print(f"acquired frame #%d/%d: %s", i+1)
                print("finished acquisition")


$ ./snap.py
{<EIDString.BUS: 67109121>: 'OHCI 1394', <EIDString.CAMERAID: 67109122>: 'S/N: 000342', <EIDString.VENDOR: 67109123>: 'Hamamatsu', <EIDString.MODEL: 67109124>: 'C9100-23B', <EIDString.CAMERAVERSION: 67109125>: '1.21.00.D', <EIDString.DRIVERVERSION: 67109126>: '9.28.14.5162', <EIDString.MODULEVERSION: 67109127>: '16.10.642.5162', <EIDString.DCAMAPIVERSION: 67109128>: '4.00'}
512 512
acquired frame #%d/%d: %s 1
finished acquisition
Exception ignored in: <function DCAM.del at 0x00000000035423A0>
Traceback (most recent call last):
File "C:\Users\jonesb\Anaconda3\lib\site-packages\hamamatsu\dcam.py", line 1797, in del
File "C:\Users\jonesb\Anaconda3\lib\site-packages\hamamatsu\dcam.py", line 1857, in close
OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF

Cannot connect to orca flash v4.2

Dear project makers,

Thanks a lot for making this repository, it seems like it will save a lot of work :).

I tried to run the code, but when I connect to an orca flash v4.2, I get the following error:

 (naparicam) python -m hamamatsu.dcam

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\site-packages\hamamatsu\dcam.py", line 1892, in <module>
    main()
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\site-packages\hamamatsu\dcam.py", line 1882, in main
    with dcam[0] as camera:
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\site-packages\hamamatsu\dcam.py", line 1459, in __enter__
    self.open()
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\site-packages\hamamatsu\dcam.py", line 1668, in open
    self._build_capabilities()
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\site-packages\hamamatsu\dcam.py", line 1487, in _build_capabilities
    eprop = EProp(prop_id.value)
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\enum.py", line 360, in __call__
    return cls.__new__(cls, value)
  File "C:\ProgramData\Anaconda3\envs\naparicam\lib\enum.py", line 678, in __new__
    raise ve_exc
ValueError: 4327472 is not a valid EProp

I am using the latest hokawo and dcam api
hokawo (3.0.8.8)
dcam module 21.5.4322.6256
driver 8.26.1500.6256

Anything else you'd like me to test?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.