PhotonicsOpenProjects/ONE-PIX

Error calculate_pattern_spectrum in DatacubeReconstructions.py

lucasbrodo opened this issue · 3 comments

Hello,

I have followed the procedure to add a new spectrometer to the code (Thorlabs CCS100 Spectrometer) on Windows and the Acquire spectrum in the Expert tab of the GUI app seems to work fine (I use Python 3.10) :

image

This is the class I've implemented for my spectrometer (correct array types for wavelengths and intensities) :

`import os
import time
from ctypes import *

class CCS100Bridge:

def __init__(self,integration_time_ms):
    self.integration_time_ms=integration_time_ms
    self.spec=[]
    self.DeviceName=''
    self.ccs_handle=c_int(0)

def spec_open(self):

    os.chdir(r"C:\Program Files\IVI Foundation\VISA\Win64\Bin")
    self.DeviceName='CCS100'
    self.spec = cdll.LoadLibrary("TLCCS_64.dll")
    self.spec.tlccs_init(b"USB0::0x1313::0x8081::M00479573::RAW", 1, 1, byref(self.ccs_handle))  

def set_integration_time(self):
    integration_time = c_double(self.integration_time_ms*1e-3)
    self.spec.tlccs_setIntegrationTime(self.ccs_handle, integration_time)
    #self.integration_time_ms = integration_time.value
    #print("Integration time :", self.integration_time_ms)
    #sprint("Get 1:", self.spec.tlccs_getIntegrationTime(self.ccs_handle))
    #print("Set IT :", self.spec.tlccs_setIntegrationTime(self.ccs_handle, integration_time))
    #print("Get 2:", self.spec.tlccs_getIntegrationTime(self.ccs_handle, byref(integration_time2)))

def get_wavelengths(self):
    self.spec.tlccs_startScan(self.ccs_handle)
    wavelengths=(c_double*3648)()
    self.spec.tlccs_getWavelengthData(self.ccs_handle, 0, byref(wavelengths), c_void_p(None), c_void_p(None))
    wavelengths_float = [float(i) for i in wavelengths]
    return wavelengths_float

def get_intensities(self):
    intensities=(c_double*3648)()
    self.spec.tlccs_getScanData(self.ccs_handle, byref(intensities))
    intensities_float = [float(i) for i in intensities]
    return intensities_float

def spec_close(self):
    self.spec.tlccs_close(self.ccs_handle)

`

However, when trying to acquire Hypercube in Simple mode, I obtain this error :

image

Furthermore, when trying to acquire Hypercube in Expert mode, I obtain this error :

image

Do I need to modify/add something else in the original code ?

Thanks for your help !

Hey,

Glad to hear that you were able to add easily a new class of spectrometers. When everything will be fixed and if you want to, you could push that new class so that other users could enjoy it.

Regarding your bugs, I suspect a problem with changing the integration time settings in your new class.

Can you for example send a screenshot of spectra measured simply with the GUI with several integration times, please?

Mathieu

Hello Mathieu, here are a few screenshots of spectra measured by GUI with the fiber pointing at a green light source (spectra change as I modify the integration times).
Really don't know why I get problems while trying to acquire hypercube.

image

image

image

OK, that sounds pretty good in terms of integration times. Two things could cause this error. Firstly, if the problem comes from the duration of the spectrometer/computer communications which would be too long with this model of spectrometer and which would not ensure a sufficiently large number of measurements per projected pattern and thus an inability to measure hypercubes.
You could try to increase the pattern duration so that your spectrometer has the time to make at least one measurement per pattern.
On the other hand, I have the impression that your spectra are normalised between 0 and 1 and the current scripts consider rather maximum measured intensities of the order of 65000 counts.
In your CS100 spectrometer class, try to obtain intensities between 0 and 65000 either by removing this normalization or by a direct multiplication.