def test_logistic_and_linear_function(self): x_data = np.arange(-10, 10, 0.1) _ = logistic(x_data, x0=0, alpha=1) self.assertTrue(logistic(0, x0=0, alpha=1) == 0.5) _ = linear_function(x_data, 1, 2) self.assertTrue(linear_function(0, 1, 2) == 2) self.assertTrue(linear_function(3, 1, 2) == 5)
def peakScores(peaksx, x, y, hwtypical=10, verbose=1, fig=None): """ Calculate scores for list of peaks Args: x (array): independent variable data y (array): dependent variable data peaksx (list): list with detected peaks """ lowvalue = np.percentile(y, 5) highvalue = np.percentile(y, 99) kk = np.ones(3) / 3. ys = y for ki in range(8): ys = scipy.ndimage.filters.correlate1d(ys, kk, mode='nearest') noise = np.std(ys - y) stn2 = np.log2((highvalue - lowvalue) / noise) if not fig is None: plotPeaks(x, y, peaksx, plotLabels=True, fig=fig) plt.plot(x, ys, '-g') noisefac = logistic(stn2, x0=3.5, alpha=1) if verbose: print('peakScores: noise factor %.2f' % noisefac) for ii, peak in enumerate(peaksx): if not peak['valid']: peak['score'] = 0 continue h = peak['height'] # original height h = peak['y'] - peak['ybottoml'] # diff between top and bottom left h2 = 2 * (peak['y'] - peak['yhalfl']) if (h2 / h) < .3: # special case h = (h2 + h) / 2 hw = peak['p'] - peak['pbottom'] hw = np.abs(x[peak['p']] - peak['xhalfl']) vv = peak['phalf0'] slope1 = (y[vv + 1] - y[vv]) / (x[vv + 1] - x[vv]) slope2 = (y[vv] - y[vv - 1]) / (x[vv] - x[vv - 1]) slope1 = (ys[vv + 1] - ys[vv]) / (x[vv + 1] - x[vv]) slope2 = (ys[vv] - ys[vv - 1]) / (x[vv] - x[vv - 1]) peak['slope'] = (slope1 + slope2) / 2 peak['heightscore'] = h / (highvalue - lowvalue) peak['score'] = (h) * (2 / (1 + hw / hwtypical)) peak['scorerelative'] = (h / (highvalue - lowvalue)) * ( 2 / (1 + hw / hwtypical)) peak['noisefactor'] = noisefac if verbose: print('peakScores: %d: height %.1f halfwidth %.1f, score %.2f' % (ii, h, hw, peak['score'])) if verbose >= 2: print(' slope: %.1f, heightscore %.2f, score %.2f' % (peak['slope'], peak['heightscore'], peak['score']))
def test_analyseGateSweep(self, fig=None, verbose=0): x = np.arange(-800, 0, 1) # mV y = logistic(x, x0=-400, alpha=.05) data_set = makeDataSet1Dplain('plunger', x, 'current', y) result = analyseGateSweep(data_set, fig=fig, verbose=verbose) self.assertAlmostEqual(result['_pinchvalueX'], -450.0) self.assertAlmostEqual(result['lowvalue'], 9.445888759986548e-18, 6) self.assertAlmostEqual(result['highvalue'], 0.9999999999999998, 6) self.assertAlmostEqual(result['midvalue'], 0.29999999999999993, 6) self.assertEqual(result['type'], 'gatesweep') if fig: plot_pinchoff(result, ds=data_set, fig=fig) plt.close('all')
def test_logistic(): y = logistic(0.0, 1.0, alpha=1.0) np.testing.assert_almost_equal(y, 0.11920292202211755, decimal=6)