Example #1
0
def check_mapexists(mdh, type='dark'):
    import os
    from PYME.IO import clusterIO
    from PYME.IO.FileUtils import nameUtils
    from PYME.Analysis.gen_sCMOS_maps import map_filename

    if type == 'dark':
        id = 'Camera.DarkMapID'
    elif type == 'variance':
        id = 'Camera.VarianceMapID'
    elif type == 'flatfield':
        id = 'Camera.FlatfieldMapID'
    else:
        raise RuntimeError('unknown map type %s' % type)

    mapfn = map_filename(mdh, type)

    # find and record calibration paths
    local_path = os.path.join(
        nameUtils.getCalibrationDir(mdh['Camera.SerialNumber']), mapfn)
    cluster_path = 'CALIBRATION/%s/%s' % (mdh['Camera.SerialNumber'], mapfn)

    if clusterIO.exists(cluster_path):
        c_path = 'PYME-CLUSTER://%s/%s' % (clusterIO.local_serverfilter,
                                           cluster_path)
        mdh[id] = c_path
        return c_path
    elif os.path.exists(local_path):
        mdh[id] = local_path
        return local_path
    else:
        return None
Example #2
0
def listCalibrationDirs():
    rootdir = nameUtils.getCalibrationDir('')
    result = [
        y for x in os.walk(rootdir) for y in glob(os.path.join(x[0], '*.tif'))
    ]
    if result is not None:
        print('List of installed maps:')
        for m in result:
            print(m)
def mkDefaultPath(stem, mdh, create=True, calibrationDir=None):
    if calibrationDir is None:
        camDir = nameUtils.getCalibrationDir(mdh['Camera.SerialNumber'],
                                             create=create)
    else:
        camDir = os.path.join(calibrationDir, mdh['Camera.SerialNumber'])
    if create:
        makePathUnlessExists(camDir)
    return mkDestPath(camDir, stem, mdh, create=create)
Example #4
0
    def OnSetMapsDefault(self, event):
        from PYME.IO.FileUtils.nameUtils import getCalibrationDir

        caldir = getCalibrationDir(self.analysisMDH['Camera.SerialNumber'])
        itime = int(1000 * self.analysisMDH['Camera.IntegrationTime'])
        darkpath = os.path.join(caldir, 'dark_%dms.tif' % (itime))
        varpath = os.path.join(caldir, 'variance_%dms.tif' % (itime))
        flatpath = os.path.join(caldir, 'flatfield.tif')

        if os.path.exists(darkpath):
            self.analysisMDH['Camera.DarkMapID'] = darkpath
        if os.path.exists(varpath):
            self.analysisMDH['Camera.VarianceMapID'] = varpath
        if os.path.exists(flatpath):
            self.analysisMDH['Camera.FlatfieldMapID'] = flatpath

        self.onMetaDataChange.send(self, mdh=self.analysisMDH)
Example #5
0
from PYME.localization.remFitBuf import CameraInfoManager
import PYME.Analysis.gen_sCMOS_maps as gmaps
from PYME.IO.MetaDataHandler import NestedClassMDHandler
from PYME.IO.image import ImageStack
from PYME.DSView import ViewIm3D
from PYME.IO.FileUtils import nameUtils
import numpy as np

import logging
logger = logging.getLogger(__name__)

defaultCalibrationDir = nameUtils.getCalibrationDir('', create=False)


def defaultMapName(source,
                   createPath=False,
                   calibrationDir=defaultCalibrationDir):
    resname = source.mdh.getOrDefault('Analysis.resultname', None)
    if resname is None:
        return None

    if resname == 'mean':
        if source.mdh.getOrDefault('Analysis.FlatField', False):
            maptype = 'flatfield'
        else:
            maptype = 'dark'
    else:
        maptype = 'variance'

    mapname = gmaps.mkDefaultPath(maptype,
                                  source.mdh,
Example #6
0
def mkDefaultPath(stem, mdh):
    caldir = nameUtils.getCalibrationDir(mdh['Camera.SerialNumber'])
    makePathUnlessExists(caldir)
    return mkDestPath(caldir, stem, mdh)
Example #7
0
    def __init__(self, boardNum=0, nbits = 8, isDeviceID = False):
        Camera.__init__(self)
        
        self._cont_mode = True
        self.initialised = False
        
        if nbits not in [8,10,12]:
            raise RuntimeError('Supporting only 8, 10 or 12 bit depth, requested %d bit' % (nbits))
        self.nbits = nbits

        self.boardHandle = uc480.HANDLE(boardNum)
        if isDeviceID:
            self.boardHandle = uc480.HANDLE(self.boardHandle.value | uc480.IS_USE_DEVICE_ID)

        ret = uc480.CALL('InitCamera', byref(self.boardHandle), uc480.HWND(0))
        print(('I',ret))
        if not ret == 0:
            raise RuntimeError('Error getting camera handle: %d: %s' % GetError(self.boardHandle))
            
        self.expTime = None
        self.initialised = True

        #register as a provider of metadata
        #MetaDataHandler.provideStartMetadata.append(self.GenStartMetadata)

        caminfo = uc480.CAMINFO()
        ret = uc480.CALL('GetCameraInfo', self.boardHandle, ctypes.byref(caminfo))
        if not ret == 0:
            raise RuntimeError('Error getting camera info: %d: %s' % GetError(self.boardHandle))
        
        self.serialNum = caminfo.SerNo

        logger.debug('caminfo: %s' %caminfo)

        #get the CCD size 
        sensorProps = uc480.SENSORINFO()
        
        ret = uc480.CALL('GetSensorInfo', self.boardHandle, ctypes.byref(sensorProps))
        if not ret == 0:
            raise RuntimeError('Error getting CCD size: %d: %s' % GetError(self.boardHandle))

        self.CCDSize=(sensorProps.nMaxWidth, sensorProps.nMaxHeight)
        senstype = ctypes.cast(sensorProps.strSensorName, ctypes.c_char_p)
        self.sensortype = senstype.value.decode()

        # work out the ROI limits for this sensortype
        matches = [self.ROIlimitlist[st] for st in self.ROIlimitlist.keys()
                   if self.sensortype.startswith(st)]
        if len(matches) > 0:
            self.ROIlimits = matches[0]
        else:
            self.ROIlimits = self.ROIlimitsDefault

        # work out the camera base parameters for this sensortype
        matches = [self.BaseProps[st] for st in self.BaseProps.keys()
                   if self.sensortype.startswith(st)]
        if len(matches) > 0:
            self.baseProps = matches[0]
        else:
            self.baseProps= self.BaseProps['default']

        #-------------------
        #Do initial setup with a whole bunch of settings I've arbitrarily decided are
        #reasonable and make the camera behave more or less like the PCO cameras.
        #These settings will hopefully be able to be changed with methods/ read from
        #a file later.
        
        dEnable = c_double(0); # don't enable
        uc480.CALL('SetAutoParameter', self.boardHandle, uc480.IS_SET_ENABLE_AUTO_GAIN, byref(dEnable), 0)
        uc480.CALL('SetAutoParameter', self.boardHandle, uc480.IS_SET_ENABLE_AUTO_SHUTTER, byref(dEnable), 0)
        #uc480.CALL('SetAutoParameter', self.boardHandle, uc480.IS_SET_ENABLE_AUTO_SENOR_GAIN, byref(dEnable), 0)
        
        # may need to revisit the gain - currently using 10 which translates into different gains depending on chip (I believe)
        # had to reduce from 100 to avoid saturating camera at lowish light levels
        ret = uc480.CALL('SetGainBoost', self.boardHandle, uc480.IS_SET_GAINBOOST_OFF)
        self.errcheck(ret,'SetGainBoost',fatal=False)
        ret = uc480.CALL('SetHardwareGain', self.boardHandle, 10, uc480.IS_IGNORE_PARAMETER, uc480.IS_IGNORE_PARAMETER, uc480.IS_IGNORE_PARAMETER)
        self.errcheck(ret,'SetHardwareGain',fatal=False)

        uc480.CALL('SetImageSize', self.boardHandle, self.CCDSize[0],self.CCDSize[1] )
        
        # pick the desired monochrom mode
        if self.nbits == 8:
            colormode = uc480.IS_CM_MONO8
        elif self.nbits == 10:
            colormode = uc480.IS_CM_MONO10
        elif self.nbits == 12:
            colormode = uc480.IS_CM_MONO12
        ret = uc480.CALL('SetColorMode', self.boardHandle, colormode)
        self.errcheck(ret,'setting ColorMode')

        uc480.CALL('SetBinning', self.boardHandle, uc480.IS_BINNING_DISABLE)
        self.binning=False #binning flag - binning is off
        self.binX=1 #1x1
        self.binY=1
        
        self.background = None
        self.flatfield = None
        self.flat = None
        self.dark = None
        
        #load flatfield (if present)
        calpath = nameUtils.getCalibrationDir(self.serialNum)
        ffname = os.path.join(calpath, 'flatfield.npy')
        if os.path.exists(ffname):
            self.flatfield = np.load(ffname).squeeze()
            self.flat = self.flatfield

        darkname = os.path.join(calpath, 'dark.npy')
        if os.path.exists(darkname):
            self.dark = np.load(darkname).squeeze()
            self.background = self.dark
        
        self.SetROI(0,0, self.CCDSize[0],self.CCDSize[1])
        #self.ROIx=(1,self.CCDSize[0])
        #self.ROIy=(1,self.CCDSize[1])
        
        self._buffers = []
        
        self.fullBuffers = Queue.Queue()
        self.freeBuffers = None
        
        self.nFull = 0
        
        self.nAccum = 1
        self.nAccumCurrent = 0
        
        self.Init()
        self.SetIntegTime(.1)