Code Monkey home page Code Monkey logo

pointobject's People

Contributors

nberliner avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

pointobject's Issues

selectCurvature() behaviour if contour lines are close together needs to be improved

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.

curvature calculation incorrect at path edges

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!

20150713_curvature_smoothing_edge_effects

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')

Check and fix the export of the calculated contour, curvature, etc.

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.

Add documentation for KDE cross-validation parameter sampling

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!")

Improve curvature calculation at contour "boundaries"

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.

150721_issue7_contour_start_end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.