nberliner / pointobject Goto Github PK
View Code? Open in Web Editor NEWAnalysing pipeline for localisation super-resolution data.
Analysing pipeline for localisation super-resolution data.
If the user selects a point that is not within 100nm of one contour the association with the contour fails and an error is raised.
To test which contour the user selected is currently done by finding the contour line that is within 100nm of the point the user clicked. If the curvature just separated (i.e. switched from one contour line to two contour lines) the separation might be below the threshold. In this case the pipeline cannot distinguish which side was selected and raises an error.
The current implementation of curvature calculation uses the local curvature expression. Calculation of the derivatives is done exploiting the fact that (f*g)'= f'*g = f*g'
with *
the convolution (see wikipedia and stackoverflow). This however implicates that we are not calculating the derivative of our function but of the function convolved with a gaussian.
In general this might work fine for many data points, whereas smoothing might become problematic for low sampling or few datapoints with significant edge contributions. As an example I generate points on a half circle with radius 5 and plotted the calculated curvature at each point. Towards the edges of the path the radii values are deviating significantly from the true value!
This plot can be generated using the following code:
import numpy as np
import matplotlib.pylab as plt
from scipy.ndimage import gaussian_filter1d
class Color:
"""
Helper to assign colors to float or integer values mapped to a given range.
"""
def __init__(self, scaleMin=None, scaleMax=None):
self.Nglobal = dict()
self.cmap = plt.get_cmap('seismic_r')
self.scaleMin = scaleMin
self.scaleMax = scaleMax
if scaleMin == scaleMax and scaleMin is not None:
print('Warning: trying to set zero scaling range!')
self.scaleMin = scaleMin
self.scaleMax = scaleMin * 1.1
def __call__(self, N):
if self.scaleMin is None and self.scaleMax is not None:
c = float(N) / self.scaleMax
elif self.scaleMin is not None and self.scaleMax is None:
c = float(N) - self.scaleMin
elif self.scaleMin is None and self.scaleMax is None:
c = float(N)
else:
c = (float(N) - self.scaleMin) / ( self.scaleMax - self.scaleMin )
return self.cmap(c)
def curvature(x, y, sigma=1, absolute=False):
# Credit goes here: http://stackoverflow.com/a/28310758/1922650
#first and second derivative
x1 = gaussian_filter1d(x, sigma=sigma, order=1, mode='wrap')
x2 = gaussian_filter1d(x1, sigma=sigma, order=1, mode='wrap')
y1 = gaussian_filter1d(y, sigma=sigma, order=1, mode='wrap')
y2 = gaussian_filter1d(y1, sigma=sigma, order=1, mode='wrap')
if absolute:
return np.abs(x1*y2 - y1*x2) / np.power(x1**2 + y1**2, 3./2)
else:
return (x1*y2 - y1*x2) / np.power(x1**2 + y1**2, 3./2)
# The user defined parameters
radius = 5.0
sampling = 30
sigma = 1
# Generate the test data
alpha = np.linspace(-np.pi/2,np.pi/2, sampling)
X = radius*np.cos(alpha)
Y = radius*np.sin(alpha)
# Calculate the radius from the curvature
C = 1/curvature(X, Y, sigma=sigma)
curvatureMax = np.max(C)
curvatureMin = np.min(C)
color = Color(scaleMin=curvatureMin, scaleMax=curvatureMax)
cColor = [ color(i) for i in C ]
# Plot the test data color coded for curvature
fig = plt.figure(figsize=(14,7), dpi=120)
ax1 = fig.add_subplot(121)
ax1.set_title("Generated data")
ax1.set_xlim( [-radius-1,radius+1] )
ax1.set_ylim( [-radius-1,radius+1] )
ax1.scatter(x=X, y=Y, c=cColor, alpha=1, edgecolor='none', s=10, cmap=plt.cm.seismic_r)
ax2 = fig.add_subplot(122)
ax2.set_title("Calculated curvature")
ax2.plot(C)
ax2.axhline(y=radius, color='red')
I haven't checked the current version of the PointObject.save()
function. It definitely does not save the total curvature and the selected curvature values. This needs to be added and the rest of the function needs to be checked.
I also propose to rename the function to export()
instead of save()
since this is clearer and can not so easily be confused with what savePointObject()
is for.
More specifically add a comment what can be done if the following warning appears
/home/berliner/08 GitHub/PointObject/lib/contour.py:202: UserWarning: Warning: see bandwidth parameter was estimated to be optimal at one sample boundary
warnings.warn("Warning: see bandwidth parameter was estimated to be optimal at one sample boundary")
/home/berliner/08 GitHub/PointObject/lib/contour.py:203: UserWarning: Try shifting the sample window!
warnings.warn("Try shifting the sample window!")
Instead of using kernel density estimation to generate a high-resolution image from the point localisations, one could also directly load an image from external source.
The pipeline would then start with contour fitting and would allow curvature extraction as is already implemented.
add an option to read Falcon localisation data instead of rapidstorm output
The contour is stored as a series of points. Calculating the curvature on this series of points will have two "boundaries" where the contour "starts" and "ends".
In the following figure the red dot represents the "start" and the "end" of the contour. At this position the curvature calculation will be incorrect.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.