Changeset 7672
- Timestamp:
- 03/24/11 22:04:01 (9 years ago)
- Location:
- trunk/projects/slim-plugin/src/main/java/loci/slim
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/projects/slim-plugin/src/main/java/loci/slim/CursorHelper.java
r7671 r7672 120 120 returnValue[2] = baseline; 121 121 return returnValue; 122 } 123 124 public static int[] estimateDecayCursors(float xInc, double[] decay) { 125 int maxIndex = findMax(decay); 126 double[] diffed = new double[maxIndex]; 127 // "Differentiate" 128 for (int i = 0; i < maxIndex - 1; ++i) { 129 diffed[i] = decay[i + 1] - decay[i]; 130 } 131 int steepIndex = findMax(diffed); 132 133 int startIndex = 2 * maxIndex - steepIndex; 134 int stopIndex = 9 * decay.length / 10; 135 136 // sanity check 137 if (startIndex > stopIndex) { 138 startIndex = stopIndex - 1; 139 } 140 if (startIndex < 0) { 141 startIndex = 0; 142 } 143 144 return new int[] { startIndex, stopIndex }; 122 145 } 123 146 … … 216 239 } 217 240 218 // save estimates //TODO not in original 241 System.out.println("steepest prompt " + steepp + " steepest transient " + steept); 242 System.out.println("startt is " + startt); 243 System.out.println(" startp " + startp + " endp " + endp + " baseline " + baseline); 244 245 // "Now we've got estimates we can do some Marquardt fitting to fine-tune 246 // the estimates" 247 248 transStartIndex = startt - ATTEMPTS; 249 if (transStartIndex < 0) { 250 transStartIndex = 0; 251 } 252 transEndIndex = 9 * decay.length / 10; // "90% of transient" 253 if (transEndIndex <= transStartIndex + 2 * ATTEMPTS) { // "oops" 219 254 returnValue[0] = startp; 220 255 returnValue[1] = endp; 221 256 returnValue[2] = baseline; 222 257 returnValue[3] = startt; 223 returnValue[4] = endt; //TODO ITS JUST ZERO HERE!! 224 225 // "Now we've got estimates we can do some Marquardt fitting to fine-tune 226 // the estimates" 227 228 transStartIndex = startt - ATTEMPTS; 229 if (transStartIndex < 0) { 230 transStartIndex = 0; 231 } 232 transEndIndex = 9 * decay.length / 10; // "90% of transient" 233 if (transEndIndex <= transStartIndex + 2 * ATTEMPTS) { // "oops" 234 System.out.println("oops return"); 258 returnValue[4] = transEndIndex; 235 259 return returnValue; //TODO "do_estimate_resets; do_estimate_frees; " 236 260 } 237 261 262 System.out.println("prompt " + prompt.length + " decay " + decay.length); 263 264 //TODO convert everything to float, not double 265 double[] response = new double[decay.length]; 266 for (int n = 0; n < decay.length; ++n) { 267 response[n] = decay[index]; 268 } 269 238 270 for (i = 0; i < 2 * ATTEMPTS + 1; ++i, ++transStartIndex) { 239 271 240 272 transFitStartIndex = transStartIndex; 273 System.out.println("transStartIndex " + transStartIndex + " transFitStartIndex " + transFitStartIndex + " transEndIndex " + transEndIndex); 241 274 242 275 int fitStart = transFitStartIndex - transStartIndex; 243 276 int fitStop = transEndIndex - transStartIndex; 244 277 int nData = transEndIndex - transStartIndex; 245 System.out.println(" fitStart " + fitStart + " fitStop " + fitStop + " nData " + nData);278 System.out.println(" fitStart " + fitStart + " fitStop " + fitStop + " nData " + nData); 246 279 247 280 CurveFitData curveFitData = new CurveFitData(); … … 255 288 curveFitter.setXInc(xInc); 256 289 curveFitter.setFree(free); 290 curveFitter.setInstrumentResponse(response); 257 291 258 292 int ret = curveFitter.fitData(data, fitStart, fitStop); … … 276 310 } 277 311 System.out.println("index is " + index); 278 return null; //TODO do estimate resets/frees??? 312 returnValue[0] = startp; 313 returnValue[1] = endp; 314 returnValue[2] = baseline; 315 returnValue[3] = startt; 316 returnValue[4] = transEndIndex; 317 return returnValue; //TODO do estimate resets/frees??? 279 318 } 280 319 -
trunk/projects/slim-plugin/src/main/java/loci/slim/DecayGraph.java
r7671 r7672 105 105 * @param data fitted data 106 106 */ 107 DecayGraph(final String title, final int start, final int stop, final int bins, final double timeInc, ICurveFitData data) {107 DecayGraph(final String title, final int start, final int stop, final int bins, final double timeInc, final double[] irf, ICurveFitData data) { 108 108 m_start = start; 109 109 m_stop = stop; … … 111 111 112 112 // create the combined chart 113 JFreeChart chart = createCombinedChart(start, stop, bins, timeInc, data); //TODO got ugly; rethink params, globals etc113 JFreeChart chart = createCombinedChart(start, stop, bins, timeInc, irf, data); //TODO got ugly; rethink params, globals etc 114 114 m_panel = new ChartPanel(chart, true, true, true, false, true); 115 115 m_panel.setDomainZoomable(false); … … 184 184 * @return the chart 185 185 */ 186 JFreeChart createCombinedChart(int start, int stop, int bins, double timeInc, ICurveFitData data) {186 JFreeChart createCombinedChart(int start, int stop, int bins, double timeInc, double[] irf, ICurveFitData data) { 187 187 188 188 // create chart data 189 createDatasets(start, stop, bins, timeInc, data);189 createDatasets(start, stop, bins, timeInc, irf, data); 190 190 191 191 // make a common horizontal axis for both sub-plots … … 253 253 * @param data from the fit 254 254 */ 255 private void createDatasets(int start, int stop, int bins, double timeInc, ICurveFitData data) {256 //TODO lamp function; comes from where? 255 private void createDatasets(int start, int stop, int bins, double timeInc, double[] irf, ICurveFitData data) { 256 257 257 XYSeries series1 = new XYSeries("IRF"); 258 /* series1.add(1.0, 1.0); 259 series1.add(2.0, 4.0); 260 series1.add(3.0, 3.0); 261 series1.add(4.0, 5.0); 262 series1.add(5.0, 5.0); 263 series1.add(6.0, 7.0); 264 series1.add(7.0, 7.0); 265 series1.add(8.0, 8.0); */ 258 double xCurrent = 0; 259 if (null != irf) { 260 for (int i = 0; i < bins; ++i) { 261 if (irf[i] > 0.0) { 262 series1.add(xCurrent, irf[i]); 263 } 264 xCurrent += timeInc; 265 } 266 } 266 267 267 268 XYSeries series2 = new XYSeries("Fitted"); … … 269 270 XYSeries series4 = new XYSeries("Residuals"); 270 271 271 272 272 double yData, yFitted; 273 doublexCurrent = 0;273 xCurrent = 0; 274 274 for (int i = 0; i < bins; ++i) { 275 275 yData = data.getYCount()[i]; -
trunk/projects/slim-plugin/src/main/java/loci/slim/SLIMProcessor.java
r7671 r7672 343 343 ); 344 344 345 // set start and stop for now; will be updated if we load an excitation curvce 346 updateDecayCursors(uiPanel); 347 345 348 // processing loop; waits for UI panel input 346 349 while (!m_quit) { … … 373 376 } 374 377 378 private void updateDecayCursors(IUserInterfacePanel uiPanel) { 379 // sum selected channel 380 double[] decay = new double[m_timeBins]; 381 for (int i = 0; i < decay.length; ++i) { 382 decay[i] = 0.0; 383 } 384 for (int y = 0; y < m_height; ++y) { 385 for (int x = 0; x < m_width; ++x) { 386 for (int b = 0; b < m_timeBins; ++b) { 387 decay[b] += getData(m_cursor, m_channel, x, y, b); 388 } 389 } 390 } 391 392 int[] results = CursorHelper.estimateDecayCursors(m_timeRange, decay); 393 uiPanel.setStart(results[0]); 394 uiPanel.setStop(results[1]); 395 } 396 375 397 private boolean updateExcitation(IUserInterfacePanel uiPanel, Excitation excitation) { 376 398 boolean success = false; … … 398 420 excitation.setBase(results[2]); 399 421 400 uiPanel.setStart( 22);401 uiPanel.setStop( 33);422 uiPanel.setStart((int) results[3]); 423 uiPanel.setStop((int) results[4]); 402 424 403 425 m_excitationPanel = new ExcitationPanel(excitation); … … 660 682 double yFitted[]; 661 683 662 // sum up all the photons 684 // sum up all the photons for all the pixels 663 685 curveFitData = new CurveFitData(); 664 686 curveFitData.setParams(params); … … 668 690 } 669 691 int photons = 0; 670 692 int pixels = 0; 671 693 if (-1 == m_channel) { 672 694 // sum all of the channels … … 679 701 photons += (int) count; 680 702 } 703 ++pixels; 681 704 } 682 705 } … … 692 715 photons += (int) count; 693 716 } 717 ++pixels; 694 718 } 695 719 } 696 720 } 697 System.out.println("Summed photons " + photons );721 System.out.println("Summed photons " + photons + " Summed pixels " + pixels); 698 722 699 723 curveFitData.setYCount(yCount); … … 711 735 712 736 // show decay and update UI parameters 713 showDecayGraph("Summed ", uiPanel, dataArray, 0); 737 double[] irf = null; 738 if (null != m_excitationPanel) { 739 irf = m_excitationPanel.getValues(); 740 } 741 showDecayGraph("Summed ", uiPanel, irf, dataArray, 0); 714 742 uiPanel.setParameters(dataArray[0].getParams()); 715 743 … … 771 799 772 800 // show the decay graphs 801 double[] irf = null; 802 if (null != m_excitationPanel) { 803 irf = m_excitationPanel.getValues(); 804 } 773 805 double min = Double.MAX_VALUE; 774 806 double max = Double.MIN_VALUE; 775 807 roiNumber = 1; 776 808 for (Roi roi: getRois()) { 777 showDecayGraph("Roi " + roiNumber, uiPanel, dataArray, roiNumber - 1);809 showDecayGraph("Roi " + roiNumber, uiPanel, irf, dataArray, roiNumber - 1); 778 810 double lifetime = dataArray[roiNumber - 1].getParams()[3]; 779 811 if (lifetime < min) { … … 858 890 getCurveFitter(uiPanel).fitData(dataArray, m_startBin, m_stopBin); 859 891 860 // show decay graph for visible channel //TODO need m_visibleChannel or the like 861 showDecayGraph("Pixel " + x + " " + y, uiPanel, dataArray, 0); 892 // show decay graph for visible channel //TODO need m_visibleChannel or the like 893 double irf[] = null; 894 if (null != m_excitationPanel) { 895 irf = m_excitationPanel.getValues(); 896 } 897 showDecayGraph("Pixel " + x + " " + y, uiPanel, irf, dataArray, 0); 862 898 863 899 // update UI parameters … … 1442 1478 curveFitter.setXInc(m_timeRange); 1443 1479 curveFitter.setFree(translateFree(uiPanel.getFunction(), uiPanel.getFree())); 1480 if (null != m_excitationPanel) { 1481 curveFitter.setInstrumentResponse(m_excitationPanel.getValues()); 1482 } 1444 1483 return curveFitter; 1445 1484 } … … 1499 1538 * @param index to show 1500 1539 */ 1501 private void showDecayGraph(String title, final IUserInterfacePanel uiPanel, ICurveFitData dataArray[], int index) {1540 private void showDecayGraph(String title, final IUserInterfacePanel uiPanel, double irf[], ICurveFitData dataArray[], int index) { 1502 1541 if (index < dataArray.length) { 1503 DecayGraph decayGraph = new DecayGraph(title, m_startBin, m_stopBin, m_timeBins, m_timeRange, dataArray[index]);1542 DecayGraph decayGraph = new DecayGraph(title, m_startBin, m_stopBin, m_timeBins, m_timeRange, irf, dataArray[index]); 1504 1543 decayGraph.setStartStopListener( 1505 1544 new IStartStopListener() { -
trunk/projects/slim-plugin/src/main/java/loci/slim/ui/ExcitationPanel.java
r7668 r7672 128 128 } 129 129 130 public double[] getValues() { 131 float floatValues[] = m_excitation.getValues(); 132 double[] values = new double[floatValues.length]; 133 for (int i = 0; i < values.length; ++i) { 134 if (i < m_start || i >= m_stop) { 135 values[i] = 0.0; 136 } 137 else if (floatValues[i] > m_base) { 138 values[i] = floatValues[i]; 139 } 140 else { 141 values[i] = 0.0; 142 } 143 } 144 return values; 145 } 146 130 147 /* 131 148 * Creates a panel with file name.
Note: See TracChangeset
for help on using the changeset viewer.