Beispiel #1
0
def showImage(roiLbl, imNum, imageDir, dataDir):

    # image = odp.stitchImage(imageFileName, pixSize, magnification, background)

    expPath = pathlib.Path(imageDir)

    # Generate image file Path by combining the region of interest lable with the experiment path
    roiFolder = pathlib.Path('./' + roiLbl)
    imageFileName = pathlib.Path('./' + roiLbl + '_' + f'{imNum:00d}' + '.mat')
    imageFilePath = expPath / roiFolder / imageFileName

    # Load Region of Interest Data.  This HDF5 file should containt location of image stitch coordinates
    dataPath = pathlib.Path(dataDir)
    initPath = list(dataPath.glob('*Index_ODELAYData.hdf5'))
    initData = fio.loadData(initPath[0])
    roiPath = dataPath / 'ODELAY Roi Data' / f'{roiLbl}.hdf5'

    roiData = fio.loadData(roiPath)
    background = initData['backgroundImage']

    # This data should be extracted from the Experiment Index file or stage data file.
    pixSize = initData['pixSize']
    magnification = initData['magnification']

    stInd = f'{imNum-1:03d}'
    stitchCorners = roiData['stitchMeta'][stInd]['imPix']
    # breakpoint()
    anImage = opl.assembleImage(imageFilePath, pixSize, magnification,
                                background, stitchCorners)
    im = anImage['Bf']
    # im = opl.SobelGradient(im)
    imSize = im.shape

    # This data should be recorded from image display to make sure the image is visible.
    imageHist = histogram1d(im.ravel(), 2**16, [0, 2**16],
                            weights=None).astype('float')
    # Calculate the cumulative probability ignoring zero values
    cumHist = np.cumsum(imageHist)
    cumProb = (cumHist - cumHist[0]) / (cumHist[2**16 - 1] - cumHist[0])
    # set low and high values ot normalize image contrast.
    loval = np.argmax(cumProb > 0.00001)
    hival = np.argmax(cumProb >= 0.9995)

    adjIm = np.array((im.astype('float') - loval.astype('float')) /
                     (hival.astype('float') - loval.astype('float')) * 254,
                     dtype='uint8')

    rsIm = cv2.resize(adjIm, (round(imSize[1] / 5), round(imSize[0] / 5)))

    cv2.imshow('Display Image', rsIm)
    k = cv2.waitKey(0)

    if k == 107 or k == -1:
        cv2.destroyWindow('Display Image')

    return k
def export_tiffs(fileloc, roi):
    ''' Export CSV file tables of Growth Curves and fit data. '''

    with open(fileloc.configfile, 'r') as fileIn:
        odelayConfig = json.load(fileIn)

    dataPath = pathlib.Path(odelayConfig['LocalDataDir'])
    expIndexPath = [*dataPath.glob('*Index_ODELAYData.*')]
    if len(expIndexPath) == 1:
        expData = fio.loadData(expIndexPath[0])
        roiList = [*expData['roiFiles']]
        roiList.sort()

        if roi == 'all':
            renderTiffs(odelayConfig, roiList)

        elif roi in roiList:
            # click.echo('This should not block')
            renderTiffs(odelayConfig, [roi])

    else:
        click.echo('Roi ID was not in the experiment Roi List')
    # df.to_csv(r'Path where you want to store the exported CSV file\File Name.csv')

    return None
def export_csv(fileloc, roiind):
    ''' Export CSV file tables of Growth Curves and fit data. '''

    with open(fileloc.configfile, 'r') as fileIn:
        odelayConfig = json.load(fileIn)

    dataPath = pathlib.Path(odelayConfig['LocalDataDir'])

    indexList = [k for k in dataPath.glob('*Index_ODELAYData.*')]
    if len(indexList) == 1:
        expIndexPath = dataPath / indexList[0]
        expData = fio.loadData(expIndexPath)
        expKeys = [*expData]

        if 'roiFiles' in expKeys:
            roiList = [*expData['roiFiles']]
            roiList.sort()

        elif 'ImageVars' in expKeys:
            roiList = [*expData['ImageVars']['StrainID']]
            roiList.sort()

        if roiind == 'all':
            fio.exportcsv(dataPath, roiList)
        elif roiind in roiList:
            fio.exportcsv(dataPath, [roiind])

    else:
        click.echo('Roi ID was not in the experiment Roi List')

    return None
def process_mac(fileloc, roi):
    '''Process region of interest or whole experiment'''

    with open(fileloc.configfile, 'r') as fileIn:
        odelayConfig = json.load(fileIn)

    imagePath = pathlib.Path(odelayConfig['LocalImageDir'])
    dataPath = pathlib.Path(odelayConfig['LocalDataDir'])

    indexList = [*dataPath.glob('*Index_ODELAYData.*')]
    if len(indexList) == 1:
        expIndexPath = dataPath / indexList[0]

        expData = fio.loadData(expIndexPath)
        roiList = [*expData['roiFiles']]
        roiList.sort()

        if roi == 'all':
            processMacAll(odelayConfig, roiList)

        elif roi in roiList:
            # click.echo('This should not block')

            processMacAll(odelayConfig, [roi])
            # click.echo('This is after the function that should not block')
    else:
        click.echo(
            'Could not find the correct index file or there were more than one in the diretory'
        )

    return None
Beispiel #5
0
    def readImage(self, lowcut=0.0005, highcut=0.99995):

        roiLbl = self.roiLbl
        imNum = self.imageNumber

        imagePath = pathlib.Path(self.odelayConfig['LocalImageDir'])
        dataPath = pathlib.Path(self.odelayConfig['LocalDataDir'])
        # Generate image file Path by combining the region of interest lable with the experiment path
        roiFolder = pathlib.Path('./' + roiLbl)
        imageFileName = pathlib.Path('./' + roiLbl + '_' + f'{imNum:00d}' +
                                     '.mat')
        imageFilePath = imagePath / roiFolder / imageFileName

        # Load Region of Interest Data.  This HDF5 file should containt location of image stitch coordinates
        roiPath = dataPath / 'ODELAY Roi Data' / f'{roiLbl}.hdf5'

        roiData = fio.loadData(roiPath)
        background = self.experimentData['backgroundImage']

        # This data should be extracted from the Experiment Index file or stage data file.
        pixSize = self.experimentData['pixSize']
        magnification = self.experimentData['magnification']

        stInd = f'{imNum-1:03d}'
        stitchCorners = roiData['stitchMeta'][stInd]['imPix']

        anImage = opl.assembleImage(imageFilePath, pixSize, magnification,
                                    background, stitchCorners)
        im = anImage['Bf']
        # make a histogram of the image in the bitdept that the image was recorded.
        imageHist = histogram1d(im.ravel(), 2**16, [0, 2**16],
                                weights=None).astype('float')

        # Calculate the cumulative probability ignoring zero values
        cumHist = np.zeros(imageHist.shape, dtype='float')
        cumHist[1:] = np.cumsum(imageHist[1:])

        # if you expect a lot of zero set
        cumProb = (cumHist - cumHist[0]) / (cumHist[2**16 - 1] - cumHist[0])

        # set low and high values ot normalize image contrast.
        loval = np.argmax(cumProb >= lowcut)
        hival = np.argmax(cumProb >= highcut)

        scIm = (im.astype('float') - loval.astype('float')) / (
            hival.astype('float') - loval.astype('float')) * 254
        lim = np.iinfo('uint8')
        scIm = np.clip(scIm, lim.min, lim.max)
        # Set image data type and make sure the array is contiguous in memory.
        imageData = np.require(scIm, dtype='uint8', requirements='C')
        # Set data as a QImage.  This is a greyscale image
        Qim = QImage(imageData.data, imageData.shape[1], imageData.shape[0],
                     imageData.shape[1], QImage.Format_Grayscale8)

        Qim.data = imageData

        return Qim
Beispiel #6
0
    def loadExperimentData(self):

        imagePath = pathlib.Path(self.odelayConfig['LocalImageDir'])
        dataPath = pathlib.Path(self.odelayConfig['LocalDataDir'])
        indexList = [k for k in dataPath.glob('*Index_ODELAYData.*')]

        if len(indexList) == 1:
            expIndexPath = dataPath / indexList[0]
            expData = fio.loadData(expIndexPath)

        return expData
def plot_summary(fileloc, organism):
    '''plot summary figure of entire experiment'''

    with open(fileloc.configfile, 'r') as fileIn:
        odelayConfig = json.load(fileIn)

    dataPath = pathlib.Path(odelayConfig['LocalDataDir'])

    summaryList = list(dataPath.glob('*summary.hdf5'))

    if len(summaryList) == 1 and summaryList[0].exists():
        expDict = fio.loadData(summaryList[0])
        click.echo('summary loaded')
        odp.figExpSummary(expDict, organism)

    return None
def plot_gc(fileloc, roiid):
    '''Plot a growth curve figure with the Region of Intrest'''

    with open(fileloc.configfile, 'r') as fileIn:
        odelayConfig = json.load(fileIn)

    dataPath = pathlib.Path(odelayConfig['LocalDataDir'])
    roi = roiid[0]
    organism = roiid[1]

    if roi == 'all':
        summaryList = list(dataPath.glob('*summary.hdf5'))
        roiFolder = list(dataPath.glob('ODELAY Roi Data'))

        if len(summaryList) == 1 and summaryList[0].exists():
            expDict = fio.loadData(summaryList[0])
            click.echo('summary loaded')

            saveFolder = dataPath / 'ODELAY Growth Curves'
            if not saveFolder.exists():
                saveFolder.mkdir()

            for roi in expDict.keys():
                try:
                    savePath = saveFolder / f'{roi}.png'
                    odp.figPlotGCs(expDict[roi],
                                   organism=organism,
                                   saveAll=True,
                                   savePath=savePath)
                except:
                    click.echo(f"{roi} didn't print")
        else:
            click.echo('Summary file does not exist please make one')

    else:

        summaryList = list(dataPath.glob('*summary.hdf5'))
        roiFolder = list(dataPath.glob('ODELAY Roi Data'))
        # roiPath  = roiFolder[0] / f'{roi}.hdf5'

        if len(summaryList) == 1 and summaryList[0].exists():
            expDict = fio.loadData(summaryList[0])
            click.echo('summary loaded')
            if roi in expDict.keys():

                odp.figPlotGCs(expDict[roi], organism=organism)

        elif len(roiFolder) == 1 and roiFolder[0].joinPath(
                f'{roi}.hdf5').exists():

            roiData = fio.loadData(roiPath)
            rc = roiData['fitData'].shape
            idVec = np.arange(rc[0], dtype='uint32')
            inds = roiData['fitData'][:, 0] > 0

            roiDict = {}
            roiDict['fitData'] = roiData['fitData'][inds, :]
            roiDict['objectArea'] = roiData['objectArea'][inds, :]
            roiDict['timePoints'] = roiData['timePoints']
            roiDict['objID'] = idVec[inds]
            roiDict['roi'] = roi
            roiDict['roiInfo'] = roiData['roiInfo']

            odp.figPlotGCs(roiDict, organism=organism)

        else:
            click.echo('Path to Roi file or to summary file broken.')
            click.echo('Please check local data path to experiment folder')

    return None