Skip to content

Commit

Permalink
empty space ok, started K
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Nov 6, 2023
1 parent 91c457c commit 82389c0
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 30 deletions.
37 changes: 37 additions & 0 deletions all_distances_eCDF_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from ij import IJ
from ij.process import StackStatistics
from ij.measure import ResultsTable
from fr.cnrs.mri.cialib.stats import Histogram


TABLE = "DistCenterCenterUnit"

table = ResultsTable.getResultsTable(TABLE)
image = IJ.getImage()
cal = image.getCalibration()
width, height, _, nSlices, _ = image.getDimensions()
print(width, height, nSlices)
width = cal.getX(width)
height = cal.getY(height)
depth = cal.getZ(nSlices)
print(width, height, depth)
volume = width * height * depth
print("volume", volume)

N = int(StackStatistics(image).max)
distances = []

for i in range(2, N+1):
dists = list(table.getColumn("V" + str(i)))
print(i, len(dists))
distances.extend(dists)

print(max(distances))
print(len(distances))

hist = Histogram(distances, start=0, end=100, nBins=1000)
hist.calculate()
hist.getPlot().show()
hist.cumulate()
hist.normalizeRipley(volume)
hist.getPlot().show()
2 changes: 1 addition & 1 deletion createESeCDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

image = IJ.getImage()
nrOfRefPoints = int(StackStatistics(image).max)
eCDF = EmptySpaceEmpiricalCDF(image, 300)
eCDF = EmptySpaceEmpiricalCDF(image, nrOfRefPoints)
hist = eCDF.get()
plot = hist.getPlot(title=image.getTitle()+" (empty space eCDF)")
plot.setStyle(0, COLOR+","+COLOR+",2,line")
Expand Down
10 changes: 5 additions & 5 deletions sample_clustered_points.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"label": "Number Of Samples: ",
"type": "int",
"sameRow": false,
"value": 1000,
"value": 910,
"key": "number",
"order": 8
},
Expand Down Expand Up @@ -85,7 +85,7 @@
"label": "Number of Images: ",
"type": "int",
"sameRow": true,
"value": 100,
"value": 10,
"key": "number-of-images",
"order": 15
},
Expand Down Expand Up @@ -118,7 +118,7 @@
"label": "Output Folder: ",
"type": "directory",
"sameRow": true,
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-spot-detection/clustered2/",
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-C-spot-detection-extreme-patterns/clustered/",
"key": "output-folder",
"order": 16
},
Expand All @@ -129,7 +129,7 @@
"label": "Max.-Dist. from cluster center: ",
"type": "float",
"sameRow": true,
"value": 5.0,
"value": 10.0,
"key": "max.-dist.",
"order": 13
},
Expand All @@ -140,7 +140,7 @@
"label": "Clusters: ",
"type": "int",
"sameRow": false,
"value": 50,
"value": 100,
"key": "clusters",
"order": 12
},
Expand Down
8 changes: 4 additions & 4 deletions sample_dispersed_points.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"label": "Batch ",
"type": "bool",
"sameRow": false,
"value": false,
"value": true,
"key": "batch",
"order": 11
},
Expand Down Expand Up @@ -85,7 +85,7 @@
"label": "Number of Images: ",
"type": "int",
"sameRow": true,
"value": 100,
"value": 10,
"key": "number-of-images",
"order": 12
},
Expand Down Expand Up @@ -118,7 +118,7 @@
"label": "Output Folder: ",
"type": "directory",
"sameRow": true,
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-spot-detection/",
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-C-spot-detection-extreme-patterns/dispersed/",
"key": "output-folder",
"order": 12
},
Expand All @@ -129,7 +129,7 @@
"label": "Max.-Dist. from grid: ",
"type": "float",
"sameRow": false,
"value": 3.0,
"value": 2.0,
"key": "max.-dist.",
"order": 9
},
Expand Down
4 changes: 2 additions & 2 deletions sample_random_points.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"label": "Number of Images: ",
"type": "int",
"sameRow": true,
"value": 100,
"value": 10,
"key": "number-of-images",
"order": 11
},
Expand Down Expand Up @@ -118,7 +118,7 @@
"label": "Output Folder: ",
"type": "directory",
"sameRow": true,
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-spot-detection/uniform/",
"value": "/home/baecker/Documents/mri/2023/mifobio/experiments/A01-C-spot-detection-extreme-patterns/uniform/",
"key": "output-folder",
"order": 12
},
Expand Down
86 changes: 70 additions & 16 deletions spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ def __init__(self, density):
def getPlot(self, start, end, n):
X = [start + (x * ((end-start)/n)) for x in range(0, n)]
Y = [self.v(x) for x in X]
plot = Plot(self.name() +"(density=" + str(self.density) + ")", "distance d[micron]", "fraction of distances <= d")
plot = Plot(self.getPlotTitle(), "distance d[micron]", "fraction of distances <= d")
plot.setLineWidth(2)
plot.setLimitsToFit(True)
plot.add("line", X, Y)
return plot


def getPlotTitle(self):
title = self.name() +"(density=" + str(self.density) + ")"
return title


class GFunction(SpatialStatFunction):

Expand All @@ -49,7 +53,6 @@ def __init__(self, density):


def v(self, r):
l = self.density
res = 1 - math.exp(self.factor * r**3)
return res

Expand All @@ -68,7 +71,6 @@ def __init__(self, density):


def v(self, r):
l = self.density
res = 1 - math.exp(self.factor * r**3)
return res

Expand All @@ -78,6 +80,70 @@ def name(self):



class KFunction(SpatialStatFunction):


def __init__(self):
self.factor = (4 * math.pi) / 3


def v(self, r):
res = self.factor * r**3
return res


def name(self):
return "K"


def getPlotTitle(self):
title = self.name()
return title



class LFunction(SpatialStatFunction):


def __init__(self):
factor = 1


def v(self, r):
return r


def name(self):
return "L"


def getPlotTitle(self):
title = self.name()
return title



class HFunction(SpatialStatFunction):


def __init__(self):
factor = 0


def v(self, r):
return 0


def name(self):
return "H"


def getPlotTitle(self):
title = self.name()
return title



class ECDF(object):


Expand Down Expand Up @@ -192,7 +258,7 @@ def calculateDistances(self):
pop.addObjects(objects)
refPop = Objects3DIntPopulation()
refPop.addObjects(refObjects)
analyzer = MeasurePopulationClosestDistance(pop, refPop, Double.POSITIVE_INFINITY, MeasurePopulationClosestDistance.CLOSEST_CC1_UNIT)
analyzer = MeasurePopulationClosestDistance(refPop, pop, Double.POSITIVE_INFINITY, MeasurePopulationClosestDistance.CLOSEST_CC1_UNIT)
table = analyzer.getResultsTableOnlyColoc(True)
self.distances = list(table.getColumn("V1"))

Expand All @@ -205,18 +271,6 @@ def getReferencePoints(self):
return self.referencePoints


def getGenerator(self, nrOfSamples):
generator = DispersedRandomSpotGenerator()
width, height, _, nSlices, _ = self.source.getDimensions()
generator.width = width
generator.height = height
generator.depth = nSlices
generator.calibration = self.source.getCalibration()
generator.bitDepth = self.source.getBitDepth()
generator.numberOfSamples = nrOfSamples
return generator



class Envelope(object):

Expand Down
14 changes: 13 additions & 1 deletion stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, data, start=0, end=0, nBins=0):
self.mode = 0
self.xLabel = "distance [micron]"
self.yLabel = "count"
self.N = 0


def calculate(self):
Expand All @@ -46,11 +47,22 @@ def cumulate(self):
self.calculate()
for i in range(1, len(self.counts)):
self.counts[i] = self.counts[i] + self.counts[i-1]
self.N = self.counts[-1]
print("N", self.N)
for i in range(0, len(self.counts)):
self.counts[i] = self.counts[i] / self.counts[-1]
self.counts[i] = self.counts[i] / self.N
self.xLabel = "distance d [micron]"
self.yLabel = "fraction of distances <= d"


def normalizeRipley(self, volume):
density = self.N / volume
print('N', self.N)
print("volume", volume)
print("density", density)
for i in range(0, len(self.counts)):
self.counts[i] = self.counts[i] / density


def getPlot(self, title = "data"):
label = self.xLabel + " (N=" + str(self.stats.count) \
Expand Down
6 changes: 6 additions & 0 deletions tools/K_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from fr.cnrs.mri.cialib.spatialstats import KFunction


k = KFunction()
plot = k.getPlot(0, 95, 1000)
plot.show()
2 changes: 1 addition & 1 deletion workspace3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cal = IJ.getImage().getCalibration()
gen.calibration = None

N = 3000
N = 1200
width = 1030
height = 1030
depth = 64
Expand Down

0 comments on commit 82389c0

Please sign in to comment.