Beispiel #1
0
    def alignSignalProfiles(self, signalChannel, sideChannels=[]):
        """Aligns signal profiles.
					
		.. warning:: When we align here, then this is done per stack. Thus, single stacks might get aligned differently.
		   This is not a problem if there was a projection before, since then there is only a single stack. 
		   Otherwise this part should be used with caution. Will need to fix this later.
		
		Args:
			signalChannel (str): Name of channel to align.
			
		Keyword Args:
			sideChannels (list): List of channel names that are supposed to be aligned the same way as signalChannel.
		
		"""

        #Collecting all results and aligning them
        anglesAligned = []
        signalsAligned = []

        #Loop through all experiments
        for exp in self.exps:

            #Grab channels and set back their aligned lists
            channel = exp.getChannel(signalChannel)
            channel.anglesAligned = []
            channel.signalsAligned = []

            if len(sideChannels) > 0:
                for sideChannel in sideChannels:
                    sideChannels[i] = exp.getChannel(sideChannel)
                    sideChannels[i].anglesAligned = []
                    sideChannels[i].signalsAligned = []

            #Check some reqs
            if self.checkMinPix(channel.angles):

                angles, signals = self.filterNaNStacks(channel.angles,
                                                       channel.signals,
                                                       name=exp.series)

                #Loop through all stacks
                for j in range(len(channel.angles)):

                    #Build arrays for passing it to aligment function
                    anglesSub = channel.angles[j]
                    signalsSub = [channel.signals[j]]

                    if len(sideChannels) > 0:
                        for sideChannel in sideChannels:
                            signalsSub.append(sideChannel.signals[j])
                    else:
                        signalsSub.append(channel.signals[j])

                    signalsSub = np.asarray(signalsSub)

                    #Aligning
                    angles, signals = angleAligned, signalAligned = am.alignDorsal(
                        anglesSub, signalsSub, method=self.fitMethod)

                    #Dumping results in respecting channels
                    channel.anglesAligned.append(angles)
                    channel.signalsAligned.append(signals[0, :])

                    for i, sideChannel in enumerate(sideChannels):
                        channel.anglesAligned.append(angles)
                        channel.signalsAligned.append(signals[0, :])

        return
Beispiel #2
0
    for j in range(len(angles)):

        if bool(np.isnan(angles[j]).sum()):
            printWarning("Had to exclude dataset " +
                         os.path.basename(tifFiles[i]) +
                         " due to minPix requirement.")
            continue

        if bool(np.isnan(signals[j]).sum()):
            printWarning("Had to exclude dataset " +
                         os.path.basename(tifFiles[i]) +
                         " due to minPix requirement.")
            continue

        #Align with maximum value
        angleAligned, signalAligned = am.alignDorsal(
            angles[j], np.asarray([signals[j], signals[j]]), method=fitMethod)

        if len(signalAligned[0, :]) == 0:
            printWarning("Had to exclude dataset " +
                         os.path.basename(tifFiles[i]) +
                         " due to empty list problem.")
        else:
            anglesAligned.append(angleAligned)
            signalsAligned.append(signalAligned[0, :])

    try:
        x = len(signalsAligned[-1])
    except:
        printWarning("Had to exclude dataset " +
                     os.path.basename(tifFiles[i]) +
                     " due to empty list problem.")
#Loop through all probability files
for i,fn in enumerate(probFiles):
		
	#Generate angular distributions	
	angles,signals=am.createSignalProfileFromH5(images[i],fn,signalChannel=signalChannel,probThresh=probThresh,probIdx=probIdx,
					     maxInt=maxInt,hist=hist,bins=bins,maskBkgd=maskBkgd,debug=debug)

	#Bookkeeping lists
	anglesAligned=[]
	signalsAligned=[]
	
	#Align distributions
	for j in range(len(angles)):
		
		#Align with maximum value
		angleAligned,signalAligned=am.alignDorsal(angles[j],np.asarray([signals[j],signals[j]]))
		anglesAligned.append(angleAligned)
		signalsAligned.append(signalAligned[0,:])
	
	allAnglesAligned.append(anglesAligned)
	allSignalsAligned.append(signalsAligned)
	
#Plot angular distributions
figSeries=plt.figure()
figSeries.show()

figAll=plt.figure()
figAll.show()

#Create axis
axAll=figAll.add_subplot(1,1,1)
	
	#Align distributions
	for j in range(len(angles)):
	
		if bool(np.isnan(angles[j]).sum()):
			printWarning("Had to exclude dataset "  + os.path.basename(tifFiles[i]) + " due to minPix requirement.")
			continue
		
		if bool(np.isnan(signals[j]).sum()):
			printWarning("Had to exclude dataset "  + os.path.basename(tifFiles[i]) + " due to minPix requirement.")
			continue

	
	
		#Align with maximum value
		angleAligned,signalAligned=am.alignDorsal(angles[j],np.asarray([signals[j],signals[j]]),method=fitMethod)
		
		if len(signalAligned[0,:])==0:
			printWarning("Had to exclude dataset "  + os.path.basename(tifFiles[i]) + " due to empty list problem.")
		else:
			anglesAligned.append(angleAligned)
			signalsAligned.append(signalAligned[0,:])

	try:
		x=len(signalsAligned[-1])
	except:
		printWarning("Had to exclude dataset "  + os.path.basename(tifFiles[i]) + " due to empty list problem.")
		continue

	allAnglesAligned.append(anglesAligned)
	allSignalsAligned.append(signalsAligned)
Beispiel #5
0
	def alignSignalProfiles(self,signalChannel,sideChannels=[]):
		
		"""Aligns signal profiles.
					
		.. warning:: When we align here, then this is done per stack. Thus, single stacks might get aligned differently.
		   This is not a problem if there was a projection before, since then there is only a single stack. 
		   Otherwise this part should be used with caution. Will need to fix this later.
		
		Args:
			signalChannel (str): Name of channel to align.
			
		Keyword Args:
			sideChannels (list): List of channel names that are supposed to be aligned the same way as signalChannel.
		
		"""
		
		
		#Collecting all results and aligning them
		anglesAligned=[]
		signalsAligned=[]
		
		#Loop through all experiments
		for exp in self.exps:
			
			#Grab channels and set back their aligned lists
			channel=exp.getChannel(signalChannel)
			channel.anglesAligned=[]
			channel.signalsAligned=[]
			
			if len(sideChannels)>0:
				for sideChannel in sideChannels:
					sideChannels[i]=exp.getChannel(sideChannel)
					sideChannels[i].anglesAligned=[]
					sideChannels[i].signalsAligned=[]
					
			#Check some reqs
			if self.checkMinPix(channel.angles):
				
				angles,signals=self.filterNaNStacks(channel.angles,channel.signals,name=exp.series)
				
				#Loop through all stacks
				for j in range(len(channel.angles)):
					
					#Build arrays for passing it to aligment function
					anglesSub=channel.angles[j]
					signalsSub=[channel.signals[j]]
									
					if len(sideChannels)>0:
						for sideChannel in sideChannels:
							signalsSub.append(sideChannel.signals[j])
					else:
						signalsSub.append(channel.signals[j])
						
					signalsSub=np.asarray(signalsSub)
					
					#Aligning
					angles,signals=angleAligned,signalAligned=am.alignDorsal(anglesSub,signalsSub,method=self.fitMethod)
					
					#Dumping results in respecting channels
					channel.anglesAligned.append(angles)
					channel.signalsAligned.append(signals[0,:])
					
					for i,sideChannel in enumerate(sideChannels):
						channel.anglesAligned.append(angles)
						channel.signalsAligned.append(signals[0,:])
					
		return 	
import matplotlib.mlab as mlab
import math
import ilastik_module as il
import im_module as im
import analysis_module as am

import h5py

#Pick random mu
mu = np.random.rand()*4*math.pi-2*math.pi

#Pick random variance
variance = np.random.rand()*2*math.pi
sigma = math.sqrt(variance)

#Array from -pi to pi
x = np.linspace(-2*math.pi, 2*math.pi, 100)

#
heap = mlab.normpdf(x,mu,sigma)
intensity = np.array([heap,heap])
print(intensity.shape)

aligned = am.alignDorsal(x,intensity)
print(aligned[0])


plt.plot(aligned[0],aligned[1][0],'r')
plt.plot(x,heap)
plt.show()
Beispiel #7
0
                                                   probIdx=probIdx,
                                                   maxInt=maxInt,
                                                   hist=hist,
                                                   bins=bins,
                                                   maskBkgd=maskBkgd,
                                                   debug=debug)

    #Bookkeeping lists
    anglesAligned = []
    signalsAligned = []

    #Align distributions
    for j in range(len(angles)):

        #Align with maximum value
        angleAligned, signalAligned = am.alignDorsal(
            angles[j], np.asarray([signals[j], signals[j]]))
        anglesAligned.append(angleAligned)
        signalsAligned.append(signalAligned[0, :])

    allAnglesAligned.append(anglesAligned)
    allSignalsAligned.append(signalsAligned)

#Plot angular distributions
figSeries = plt.figure()
figSeries.show()

figAll = plt.figure()
figAll.show()

#Create axis
axAll = figAll.add_subplot(1, 1, 1)