Package com.mockturtlesolutions.snifflib.stats

Examples of com.mockturtlesolutions.snifflib.stats.Plot


    }
    //Make an overlay plot of the cummulative sum of Conc_i*Volume_Added_i versus pH_i
    int col=0;
    DblMatrix cv_total = new DblMatrix(0.0);
    DblMatrix v_total = new DblMatrix(0.0);
    Plot plot = new Plot(data);
    pHtoolsPrefs prefs = new pHtoolsPrefs();
    prefs.initialize();
   
    plot.setAxesPreferences(prefs);
    plot.setFigurePreferences(prefs);
    plot.setFigurePreferences(prefs);
    plot.setLineSegmentRendererPreferences(prefs);
    plot.setLegendPreferences(prefs);
   
    plot.setOverlay(true);
   
    boolean NANSENCOUNTERED = false;
    int NANLINE = 0;
    String NANSUB = "";
   
   
   
    for (int ss=0;ss<subsamples.size();ss++)
    {
   
      String ssid = (String)subsamples.get(ss);
      cv_total = new DblMatrix(0.0);
      v_total = new DblMatrix(new Double(this.parent.getInitialVolume(ssid)));
     
      data.addColumn("pH"+ssid,Double.class);
      data.addColumn("CV"+ssid,Double.class);
      plot.addResponseVariable("CV"+ssid);
      plot.addPredictorVariable("pH"+ssid);
     
      Vector observations = this.parent.getTitrationObservationNumbers(ssid);
      for (int obs=0;obs<observations.size();obs++)
      {
       
        String obsnum = (String)observations.get(obs);
       
        String val;
        Double nval;
       
        val = this.parent.getTitrantConcentration(ssid,obsnum);
        try
        {
          nval = new Double(val);
        }
        catch(Exception err)
        {
          NANSENCOUNTERED = true;
          nval = new Double(Double.NaN);
        }
       
        Double conc = nval;
       
        val = this.parent.getVolumeAdded(ssid,obsnum);
        try
        {
          nval = new Double(val);
        }
        catch(Exception err)
        {
          NANSENCOUNTERED = true;
          nval = new Double(Double.NaN);
        }
       
       
        Double volAdded = nval;
       
        cv_total = cv_total.plus(conc.doubleValue()*volAdded.doubleValue());
        v_total = v_total.plus(volAdded.doubleValue());
        //System.out.println("conc"+conc);
        //System.out.println("volAdded"+volAdded);
        //cv_total.show("cv_total","###.##E0");
       
        val = this.parent.getpH(ssid,obsnum);
        try
        {
          nval = new Double(val);
        }
        catch (Exception err)
        {
          NANSENCOUNTERED = true;
          NANLINE = obs;
          NANSUB = ssid;
         
          nval = new Double(Double.NaN);
        }
       
        Double pH = nval;
        //System.out.println("pH"+pH);
        data.setValueAt(pH,obs,col);
        data.setValueAt(cv_total.divideBy(v_total).getDoubleAt(0),obs,col+1)
      }
     
      col = col+2;//Moving to the next subsample.
    }
   
    try
    {
      this.plotPanel.setPlot(plot);
    }
    catch (Exception err)
    {
      throw new RuntimeException("Problem updating plot in TitrationPlotPanel",err);
    }
   
    SLAxes ax = plot.getAxes();
    ax.setYLabel("Total Moles Titrant Added");
    ax.setXLabel("pH")
    //plotstuff.setVisible(true);
    this.plotPanel.setVisible(true);
    this.parent.repaint();
View Full Code Here


      if (this.outSet.getRowCount() < 1)
      {
        return;
      }
     
      Plot p = new Plot(this.outSet);
      p.setAxesPreferences(this.prefs);
      p.setFigurePreferences(this.prefs);
      p.setLineSegmentRendererPreferences(this.prefs);
      p.setLegendPreferences(this.prefs);

      p.addPredictorVariable("pH");
      p.addResponseVariable("Cbplot");
      p.addByVariable("Experiment");
      p.addByVariable("Subsample");
      p.addByVariable("Observed");

      try
      {
        plotPanel.setPlot(p);
      }
      catch (Exception err)
      {
        throw new RuntimeException("Problem updating plot in DefaulPredictorPanel.",err);
      }
      //p = plotPanel.getPlot();
     
      SLAxes ax = p.getAxes();
      //this.axes = ax;
      if (ax == null)
      {
        Set subplots = p.getSubplotSet();
       
        throw new RuntimeException("Subplots="+subplots.size()+"Axes for "+p.getFocusAxes()+" was null after setting plot.");
      }
     
      ax.setYLabel("Total Moles Titrant Added");
      ax.setXLabel("pH");
       
View Full Code Here

      if (this.outSet.getRowCount() < 1)
      {
        return;
      }
     
      Plot p = new Plot(this.outSet);
      p.setAxesPreferences(this.prefs);
      p.setFigurePreferences(this.prefs);
      p.setLineSegmentRendererPreferences(this.prefs);
      p.setLegendPreferences(this.prefs);

      p.addPredictorVariable("pH");
      p.addResponseVariable("Cbplot");
      p.addByVariable("Experiment");
      p.addByVariable("Subsample");
      p.addByVariable("Observed");

      try
      {
        plotPanel.setPlot(p);
      }
      catch (Exception err)
      {
        throw new RuntimeException("Problem updating plot in DefaulPredictorPanel.",err);
      }
      //p = plotPanel.getPlot();
     
      SLAxes ax = p.getAxes();
      //this.axes = ax;
      if (ax == null)
      {
        Set subplots = p.getSubplotSet();
       
        throw new RuntimeException("Subplots="+subplots.size()+"Axes for "+p.getFocusAxes()+" was null after setting plot.");
      }
     
      ax.setYLabel("Total Moles Titrant Added");
      ax.setXLabel("pH");
       
View Full Code Here

                 
                  }
                 
                 
                  int i=1;
                  Plot Cbplot = new Plot(Cbdata);
                 
                  ////
                  pHtoolsPrefs prefs = new pHtoolsPrefs();
                  prefs.initialize();
                  Cbplot.setAxesPreferences(prefs);
                  Cbplot.setFigurePreferences(prefs);
                  Cbplot.setLineSegmentRendererPreferences(prefs);
                  Cbplot.setLegendPreferences(prefs);
                  ////
                 
                  while (iter.hasNext())
                  {
                    col = (String)iter.next();
                    Cbplot.addResponseVariable(col);
                    //System.out.println("Next column:"+col);
                    val = (DblMatrix)Cbresult.get(col);
                    Cbdata.addColumn(col,Double.class);
                   
                    for (int j=0;j<val.getN();j++)
                    { 
                      //System.out.println("Adding Cbdata row:"+j);
                      //Cbdata.addRow(j);
                      Cbdata.setValueAt(val.getDoubleAt(j),j,i)
                    }
                    i++;
                  }
                 
                  //Plot Cbplot = new Plot(Cbdata);
                  Cbplot.addPredictorVariable("pH");
                  //Cbplot.addResponseVariable("total");
                 
                  PlotFrame plotstuff = new PlotFrame(Cbplot);
                 
                  // pHtoolsPrefs prefs = new pHtoolsPrefs();
//                   prefs.initialize();
//                  
//                  
//                   System.out.println("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
//                   plotstuff.setAxesPreferences(prefs);
//                   plotstuff.setFigurePreferences(prefs);
//                   plotstuff.setLineSegmentRendererPreferences(prefs);
//                  
                 
                  SLAxes ax = Cbplot.getAxes();
                  ax.setYLabel("Approx. Moles/L Hydroxyl Added");
                  ax.setXLabel("pH")
                  plotstuff.setVisible(true);
                 
                }
               
                if (selection.equalsIgnoreCase("get cb density"))
                {
               
                  JProgressBar progressBar = null;
                  Container parent = getParent();
                  System.out.println("Here");
                  if (parent !=null)
                  {
                    System.out.println("Here A");
                    if (parent instanceof WorkBenchPanel)
                    {
                      System.out.println("Here B");
                      Container frame;
                      while (true)
                      {
                        frame = parent.getParent();
                        parent = frame;
                        if (frame instanceof jpHtoolsWBFrame)
                        {
                          break;
                        }
                       
                        if (frame == null)
                        {
                          break;
                        }
                     
                      }
                     
                      if (frame != null)
                      {
                        jpHtoolsWBFrame wbframe =  (jpHtoolsWBFrame)frame;
                        progressBar = wbframe.getProgressBar();
                        progressBar.setVisible(true);
                        progressBar.setString("Determining HPD for Cb...");
                        progressBar.setIndeterminate(true);
                      }
                    }
                  }
                 
                  final JProgressBar bar = progressBar;
                 
                 
                  Thread t = new Thread(new Runnable()
                  {
                    public void run()
                    {
                      HashMap CbHPDresult = null;
                      DblMatrix pH2run = getpH();
                      double prob = 0.95;

                      try
                      {
                        //CbHPDresult = ((BufferSolution)model).CbHPD(pH2run,prob,true);
                      }
                      catch (Exception err)
                      {
                        throw new RuntimeException("Problem getting Cb.",err);
                      }


                      Set keys = CbHPDresult.keySet();
                      String[] hdrs = new String[keys.size()];
                      Class[] cls = new Class[keys.size()];

                      Iterator iter = keys.iterator();
                      String col;
                      DblMatrix val;
                      DataSet Cbdata = new DataSet("pH",Double.class);


                      for (int j=0;j<pH2run.getN();j++)
                      {
                        Cbdata.addRow(j);
                        Cbdata.setValueAt(pH2run.getDoubleAt(j),j,0);

                      }


                      int i=1;// pH is in the first column (index=0) so we start at index 1 now.
                      Plot Cbplot = new Plot(Cbdata);

                      ////
                      pHtoolsPrefs prefs = new pHtoolsPrefs();
                      prefs.initialize();
                      Cbplot.setAxesPreferences(prefs);
                      Cbplot.setFigurePreferences(prefs);
                      Cbplot.setLineSegmentRendererPreferences(prefs);
                      prefs.setConfigValue(repos,"legenddomainnamefilter","none");
                      Cbplot.setLegendPreferences(prefs);

                      ////

                      while (iter.hasNext())
                      {
                        col = (String)iter.next();
                        String upperLabel = (col+"_U"+prob);
                        String lowerLabel = (col+"_L"+prob);

                        Cbplot.addResponseVariable(lowerLabel);
                        Cbplot.addResponseVariable(upperLabel);

                        //System.out.println("Next column:"+col);
                        DblMatrix[] CI = (DblMatrix[])CbHPDresult.get(col);


                        Cbdata.addColumn(lowerLabel,Double.class);
                        Cbdata.addColumn(upperLabel,Double.class);

                        for (int j=0;j<CI[0].getN();j++)
                        { 
                          //System.out.println("Adding Cbdata row:"+j);
                          //Cbdata.addRow(j);
                          Cbdata.setValueAt(CI[0].getDoubleAt(j),j,i);
                          Cbdata.setValueAt(CI[1].getDoubleAt(j),j,i+1)
                        }
                        i = i+2;
                      }

                      //Plot Cbplot = new Plot(Cbdata);
                      Cbplot.addPredictorVariable("pH");
                      //Cbplot.addResponseVariable("total");

                      PlotFrame plotstuff = new PlotFrame(Cbplot);

                      // pHtoolsPrefs prefs = new pHtoolsPrefs();
    //                   prefs.initialize();
    //                  
    //                  
    //                   System.out.println("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
    //                   plotstuff.setAxesPreferences(prefs);
    //                   plotstuff.setFigurePreferences(prefs);
    //                   plotstuff.setLineSegmentRendererPreferences(prefs);
    //                  

                      SLAxes ax = Cbplot.getAxes();
                      ax.setYLabel("Approx. Moles/L Hydroxyl Added");
                      ax.setXLabel("pH")
                      plotstuff.setVisible(true);
                     
                      if (bar != null)
                      {
                        bar.setIndeterminate(false);
                        bar.setVisible(false);
                      }
                    }
                 
                  });
       
                  t.start(); // Start it running
                }
               
               
               
                if (selection.equalsIgnoreCase("get species concentration"))
                {
                  DblMatrix pH2run = getpH();
                  HashMap Cbresult = null;
                  try
                  {
                    Cbresult = ((BufferSolution)model).species(pH2run);
                  }
                  catch (Exception err)
                  {
                    throw new RuntimeException("Problem getting species concentration.",err);
                  }
                 
                  Set keys = Cbresult.keySet();
                  Set ionKeys;
                  String[] hdrs = new String[keys.size()];
                  Class[] cls = new Class[keys.size()];
                 
                  Iterator iter = keys.iterator();
                  Iterator ionIter;
                  String col,ion;
                  DblMatrix val;
                  DataSet Cbdata = new DataSet("pH",Double.class);
                  HashMap ionMap;
                 
                  for (int j=0;j<pH2run.getN();j++)
                  {
                    Cbdata.addRow(j);
                    Cbdata.setValueAt(pH2run.getDoubleAt(j),j,0);
                 
                  }
                 
                  Plot Cbplot = new Plot(Cbdata);
                 
                 
                  ////
                  pHtoolsPrefs prefs = new pHtoolsPrefs();
                  prefs.initialize();
                  Cbplot.setAxesPreferences(prefs);
                  Cbplot.setFigurePreferences(prefs);
                  Cbplot.setLineSegmentRendererPreferences(prefs);
                  Cbplot.setLegendPreferences(prefs);
                  ////
                 
                 
                  Log10 logfun = new Log10();
                  Cbplot.setYTransformation((UniUniFunction)logfun);
                 
                  Cbplot.addPredictorVariable("pH");
                  int i=1;
                  Vector labels = new Vector();
                  String label;
                  while (iter.hasNext())
                  {
                    col = (String)iter.next();
                    System.out.println("Next column:"+col);
                    ionMap = (HashMap)Cbresult.get(col);
                   
                    ionKeys = ionMap.keySet();
                    ionIter = ionKeys.iterator();
                    while (ionIter.hasNext())
                    {
                      ion = (String)ionIter.next();
                      label = col+":"+ion;
                      labels.add(label);
                      Cbdata.addColumn(label,Double.class);
                      val = (DblMatrix)ionMap.get(ion);
                      for (int j=0;j<val.getN();j++)
                      { 
                        //System.out.println("Adding Cbdata row:"+j);
                        //Cbdata.addRow(j);
                        Cbdata.setValueAt(val.getDoubleAt(j),j,i)
                      }
                     
                      Cbplot.addResponseVariable(label);
                      i++;
                    }
                   
                  }
                 
                 
                  //Cbplot.addPredictorVariable("pH");
                  //Cbplot.addResponseVariable("total");
                 
                  PlotFrame plotstuff = new PlotFrame(Cbplot);
                  SLAxes ax = Cbplot.getAxes();
                  ax.setYLabel("Log10 species concentation");
                  ax.setXLabel("pH")
                  plotstuff.setVisible(true);
                 
                 
                }
               
                if (selection.equalsIgnoreCase("get buffer capacity"))
                {
                   
                  DblMatrix pH2run = getpH();
                  HashMap Cbresult = null;
                  try
                  {
                    Cbresult = ((BufferSolution)model).buffCapEval(pH2run,true);
                  }
                  catch (Exception err)
                  {
                    throw new RuntimeException("Problem getting the buffer capacity.",err);
                  }
                 
                  Set keys = Cbresult.keySet();
                  String[] hdrs = new String[keys.size()];
                  Class[] cls = new Class[keys.size()];
                 
                  Iterator iter = keys.iterator();
                  String col;
                  DblMatrix val;
                  DataSet Cbdata = new DataSet("pH",Double.class);
                 
                 
                  for (int j=0;j<pH2run.getN();j++)
                  {
                    Cbdata.addRow(j);
                    Cbdata.setValueAt(pH2run.getDoubleAt(j),j,0);
                 
                  }
                 
                 
                  int i=1;
                  Plot Cbplot = new Plot(Cbdata);
                 
                  ////
                  pHtoolsPrefs prefs = new pHtoolsPrefs();
                  prefs.initialize();
                  Cbplot.setAxesPreferences(prefs);
                  Cbplot.setFigurePreferences(prefs);
                  Cbplot.setLineSegmentRendererPreferences(prefs);
                  Cbplot.setLegendPreferences(prefs);
                  ////
                 
                  while (iter.hasNext())
                  {
                    col = (String)iter.next();
                    Cbplot.addResponseVariable(col);
                    System.out.println("Next column:"+col);
                    val = (DblMatrix)Cbresult.get(col);
                    Cbdata.addColumn(col,Double.class);
                   
                    for (int j=0;j<val.getN();j++)
                    { 
                      //System.out.println("Adding Cbdata row:"+j);
                      //Cbdata.addRow(j);
                      Cbdata.setValueAt(val.getDoubleAt(j),j,i)
                    }
                    i++;
                  }
                 
                  //Plot Cbplot = new Plot(Cbdata);
                  Cbplot.addPredictorVariable("pH");
                  //Cbplot.addResponseVariable("total");
                 
                  PlotFrame plotstuff = new PlotFrame(Cbplot);
                  SLAxes ax = Cbplot.getAxes();
                  ax.setYLabel("Buffer Capacity");
                  ax.setXLabel("pH")
                  plotstuff.setVisible(true);
                }
               
                if (selection.equalsIgnoreCase("get ionic strength"))
                {
                  DblMatrix pH2run = getpH();
                  HashMap Cbresult = null;
                  try
                  {
                    Cbresult = ((BufferSolution)model).ionicStr(pH2run,true);
                  }
                  catch (Exception err)
                  {
                    throw new RuntimeException("Problem getting the ionic strength.",err);
                  }
                 
                  Set keys = Cbresult.keySet();
                  String[] hdrs = new String[keys.size()];
                  Class[] cls = new Class[keys.size()];
                 
                  Iterator iter = keys.iterator();
                  String col;
                  DblMatrix val;
                  DataSet Cbdata = new DataSet("pH",Double.class);
                 
                 
                  for (int j=0;j<pH2run.getN();j++)
                  {
                    Cbdata.addRow(j);
                    Cbdata.setValueAt(pH2run.getDoubleAt(j),j,0);
                 
                  }
                 
                 
                  int i=1;
                  Plot Cbplot = new Plot(Cbdata);
                 
                  ////
                  pHtoolsPrefs prefs = new pHtoolsPrefs();
                  prefs.initialize();
                  Cbplot.setAxesPreferences(prefs);
                  Cbplot.setFigurePreferences(prefs);
                  Cbplot.setLineSegmentRendererPreferences(prefs);
                  Cbplot.setLegendPreferences(prefs);
                  ////
                 
                  while (iter.hasNext())
                  {
                 
                   
                    col = (String)iter.next();
                    Cbplot.addResponseVariable(col);
                    //System.out.println("Next column:"+col);
                    val = (DblMatrix)Cbresult.get(col);
                   
                    val.show("val");
                    Cbdata.addColumn(col,Double.class);
                   
                    for (int j=0;j<val.getN();j++)
                    { 
                      System.out.println("Adding Cbdata row:"+j);
                      //Cbdata.addRow(j);
                      Cbdata.setValueAt(val.getDoubleAt(j),j,i)
                    }
                    i++;
                  }
                 
                  //Plot Cbplot = new Plot(Cbdata);
                  Cbplot.addPredictorVariable("pH");
                  //Cbplot.addResponseVariable("total");
                 
                  PlotFrame plotstuff = new PlotFrame(Cbplot);
                  SLAxes ax = Cbplot.getAxes();
                  ax.setYLabel("Ionic strength");
                  ax.setXLabel("pH")
                  plotstuff.setVisible(true);
                 
                }
View Full Code Here

TOP

Related Classes of com.mockturtlesolutions.snifflib.stats.Plot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.