Пример #1
0
/**
 * Create an output workspace filled with data simulated with the fitting
 * function.
 * @param baseName :: The base name for the workspace
 * @param function :: The function used for the calculation
 * @param domain :: A pointer to the input domain
 * @param values :: A pointer to the calculated values
 * @param outputWorkspacePropertyName :: The property name
 */
boost::shared_ptr<API::Workspace>
FitMD::createOutputWorkspace(const std::string &baseName,
                             API::IFunction_sptr function,
                             boost::shared_ptr<API::FunctionDomain> domain,
                             boost::shared_ptr<API::FunctionValues> values,
                             const std::string &outputWorkspacePropertyName) {
  if (!values) {
    return boost::shared_ptr<API::Workspace>();
  }
  auto functionMD = boost::dynamic_pointer_cast<API::FunctionDomainMD>(domain);
  if (!functionMD) {
    return boost::shared_ptr<API::Workspace>();
  }
  API::IMDWorkspace_const_sptr domainWS = functionMD->getWorkspace();

  auto inputEventWS =
      boost::dynamic_pointer_cast<const API::IMDEventWorkspace>(domainWS);
  if (inputEventWS) {
    return createEventOutputWorkspace(baseName, *inputEventWS, *values,
                                      outputWorkspacePropertyName);
  }

  auto inputHistoWS =
      boost::dynamic_pointer_cast<const API::IMDHistoWorkspace>(domainWS);
  if (inputHistoWS) {
    return createHistoOutputWorkspace(baseName, function, inputHistoWS,
                                      outputWorkspacePropertyName);
  }

  return boost::shared_ptr<API::Workspace>();
}
Пример #2
0
/*!
 * \brief WindowManager::checkWorkspace Asks the system to see if a workspace exists.
 *
 * If so, then auto-load all projects in the workspace.
 * If not- then prompt the user to set a workspace and set that workspace.
 */
void WindowManager::checkWorkspace()
{
    //If there is no workspace (first time load) go through the procedure to get it.
    if(getWorkspace()=="")
    {
        // Welcome the user.
        QMessageBox welcomeMsg;
        welcomeMsg.setText("Welcome to BioVision!");
        welcomeMsg.setInformativeText("The first step in using BioVision is to select a workspace directory.  This is where all of your projects and data will be stored.  Begin selection by clicking the ok button.  After you have done that, you can make a project and begin adding videos by clicking File -> New Project.");
        welcomeMsg.setStandardButtons(QMessageBox::Ok);
        welcomeMsg.exec();

        QString workspacePath = QFileDialog::getExistingDirectory(_mainWindow, "Please specify a workspace directory.", QDir::home().path());
        if(workspacePath != QString())
        {
            // Set the workspace.
            _bvSystem->setWorkspace(workspacePath);
        }
        else
        {
            QMessageBox errorMsg;
            errorMsg.setText("If you do not select a workspace you will be unable to create new projects.");
            errorMsg.setInformativeText("Set your workspace through the Options -> BioVision Settings menu.");
            errorMsg.setStandardButtons(QMessageBox::Ok);
            errorMsg.exec();
        }
    }
    // Otherwise, auto load all projects in the workspace.
    else
    {
        _bvSystem->autoLoadProjects();
        _mainWindow->refreshProjectBrowser();
    }
}
void TravelWorkbench::slotFileClose()
{
   BEGIN;

   CoaWorkspace *workspace = getWorkspace();
   if (workspace != 0){
      //MDI Handle
      QWidget *widget = workspace->activeWindow();
      if (widget != 0) {
         TravelMainWindow *window = qobject_cast<TravelMainWindow*>(widget);
         if (window != 0) window->close();
      }


   } else {
      //SDI Handle
      QWidget *widget = CoaApplication::activeWindow();
      if (widget != 0) {
         TravelMainWindow *window = qobject_cast<TravelMainWindow*>(widget);
         if (window != 0) window->slotFileClose();
         if (window != 0) window->close();
      }
   }

}
MPI_Segment* MPI_ParticleStroke::allocateSegment( MPI_Point2D const &firstpoint, MPI_Point2D const &secondpoint )
{

    float newsegposstart = getNumSegments();
    float newsegposend = newsegposstart + 1.0;

    return new MPI_ParticleSegment( getWorkspace(), *this, firstpoint, secondpoint, getOneSpace(), newsegposstart, newsegposend, getTrainElementFactory() );

}
Пример #5
0
void MainWindow::setWorkspace(int i) {
    Display *display = XOpenDisplay(0);

    if (!display) {
        printf("can't open display");
        exit(1);
    }

    XClientMessageEvent xev;

    xev.type = ClientMessage;
    xev.window = RootWindow(display, 0);
    xev.send_event = True;
    xev.display = display;
    xev.message_type = XInternAtom(display, "_NET_CURRENT_DESKTOP", True);
    xev.format = 32;
    xev.data.l[0] = i;

    XSendEvent(
        display,
        RootWindow(display, 0),
        False,
        (SubstructureNotifyMask | SubstructureRedirectMask),
        (XEvent *) &xev
    );

    XFlush(display);

    while (True) {
        int workspace = getWorkspace();

        if(workspace == i) {
            break;
        }

        usleep(5);
    }

    XCloseDisplay(display);
}
Пример #6
0
void resliceToolBox::startReformat()
{
    if (d->currentView && getWorkspace())
    {
        medAbstractData* data = d->currentView->layerData(d->currentView->currentLayer());
        bool is3D = false;
        if ((data->identifier().contains("itkDataImage"))
                && (dynamic_cast<medAbstractImageData *>(data)->Dimension() == 3))
        {
            is3D = true;
        }

        if (d->currentView->layersCount() && is3D)
        {
            d->help0->hide();
            d->reformatOptions->show();
            d->b_startReslice->hide();

            d->resliceViewer = new medResliceViewer(d->currentView,getWorkspace()->stackedViewContainers());
            d->resliceViewer->setToolBox(this);
            getWorkspace()->stackedViewContainers()->setAcceptDrops(false);
            connect(d->resliceViewer,SIGNAL(imageReformatedGenerated()),this,SLOT(saveReformatedImage()));
            medViewContainer * container = getWorkspace()->stackedViewContainers()->insertContainerInTab(0,"Reslice");
            getWorkspace()->stackedViewContainers()->setCurrentIndex(0);
            container->setDefaultWidget(d->resliceViewer->viewWidget());
            connect(container, SIGNAL(viewRemoved()),this, SLOT(stopReformat()), Qt::UniqueConnection);

            connect(d->spacingX,SIGNAL(valueChanged(double)),d->resliceViewer,SLOT(thickSlabChanged(double)));
            connect(d->spacingY,SIGNAL(valueChanged(double)),d->resliceViewer,SLOT(thickSlabChanged(double)));
            connect(d->spacingZ,SIGNAL(valueChanged(double)),d->resliceViewer,SLOT(thickSlabChanged(double)));
            connect(d->b_saveImage,SIGNAL(clicked()),d->resliceViewer,SLOT(saveImage()));

            d->reformatedImage = 0;

            // close the initial tab which is not needed anymore
            getWorkspace()->stackedViewContainers()->removeTab(1);
            updateView();
        }
Пример #7
0
/// Executes the algorithm
void PoldiFitPeaks2D::exec() {
  std::vector<PoldiPeakCollection_sptr> peakCollections =
      getPeakCollectionsFromInput();

  // Try to setup the 2D data and poldi instrument
  MatrixWorkspace_sptr ws = getProperty("InputWorkspace");
  setDeltaTFromWorkspace(ws);

  setPoldiInstrument(boost::make_shared<PoldiInstrumentAdapter>(ws));
  setTimeTransformerFromInstrument(m_poldiInstrument);

  // If a profile function is selected, set it on the peak collections.
  Property *profileFunctionProperty =
      getPointerToProperty("PeakProfileFunction");
  if (!profileFunctionProperty->isDefault()) {
    for (auto &peakCollection : peakCollections) {
      peakCollection->setProfileFunctionName(profileFunctionProperty->value());
    }
  }

  // Perform 2D-fit and return Fit algorithm to extract various information
  IAlgorithm_sptr fitAlgorithm = calculateSpectrum(peakCollections, ws);

  // The FitFunction is used to generate...
  IFunction_sptr fitFunction = getFunction(fitAlgorithm);

  // ...a calculated 1D-spectrum...
  MatrixWorkspace_sptr outWs1D = get1DSpectrum(fitFunction, ws);

  // ...a vector of peak collections.
  std::vector<PoldiPeakCollection_sptr> integralPeaks =
      getCountPeakCollections(fitFunction);

  for (size_t i = 0; i < peakCollections.size(); ++i) {
    assignMillerIndices(peakCollections[i], integralPeaks[i]);
  }

  // Get the calculated 2D workspace
  setProperty("OutputWorkspace", getWorkspace(fitAlgorithm));

  // Set the output peaks depending on whether it's one or more workspaces
  if (integralPeaks.size() == 1) {
    setProperty("RefinedPoldiPeakWorkspace",
                integralPeaks.front()->asTableWorkspace());
  } else {
    WorkspaceGroup_sptr peaksGroup = boost::make_shared<WorkspaceGroup>();

    for (auto &integralPeak : integralPeaks) {
      peaksGroup->addWorkspace(integralPeak->asTableWorkspace());
    }

    setProperty("RefinedPoldiPeakWorkspace", peaksGroup);
  }

  // Set the 1D-spectrum output
  setProperty("Calculated1DSpectrum", outWs1D);

  // If it was a PawleyFit, also produce one or more cell parameter tables.
  bool isPawleyFit = getProperty("PawleyFit");
  if (isPawleyFit) {
    Poldi2DFunction_sptr poldi2DFunction =
        boost::dynamic_pointer_cast<Poldi2DFunction>(fitFunction);

    std::vector<ITableWorkspace_sptr> cells;

    if (poldi2DFunction) {
      for (size_t i = 0; i < poldi2DFunction->nFunctions(); ++i) {
        try {
          ITableWorkspace_sptr cell =
              getRefinedCellParameters(poldi2DFunction->getFunction(i));
          cells.push_back(cell);
        } catch (const std::invalid_argument &) {
          // do nothing
        }
      }

      if (cells.size() == 1) {
        setProperty("RefinedCellParameters", cells.front());
      } else {
        WorkspaceGroup_sptr cellsGroup = boost::make_shared<WorkspaceGroup>();

        for (auto &cell : cells) {
          cellsGroup->addWorkspace(cell);
        }

        setProperty("RefinedCellParameters", cellsGroup);
      }

    } else {
      g_log.warning() << "Warning: Cell parameter table is empty.";
    }
  }

  // Optionally output the raw fitting parameters.
  Property *rawFitParameters = getPointerToProperty("RawFitParameters");
  if (!rawFitParameters->isDefault()) {
    ITableWorkspace_sptr parameters =
        fitAlgorithm->getProperty("OutputParameters");
    setProperty("RawFitParameters", parameters);
  }
}
Пример #8
0
    /** 
    *   Executes the algorithm
    */
    void PlotPeakByLogValue::exec()
    {

      // Create a list of the input workspace
      const std::vector<InputData> wsNames = makeNames();

      std::string fun = getPropertyValue("Function");
      //int wi = getProperty("WorkspaceIndex");
      std::string logName = getProperty("LogValue");
      bool sequential = getPropertyValue("FitType") == "Sequential";

      bool isDataName = false; // if true first output column is of type string and is the data source name
      ITableWorkspace_sptr result = WorkspaceFactory::Instance().createTable("TableWorkspace");
      if (logName == "SourceName")
      {
        result->addColumn("str","Source name");
        isDataName = true;
      }
      else if (logName.empty())
      {
        result->addColumn("double","axis-1");
      }
      else
      {
        result->addColumn("double",logName);
      }
      // Create an instance of the fitting function to obtain the names of fitting parameters
      IFitFunction* ifun = FunctionFactory::Instance().createInitialized(fun);
      if (!ifun)
      {
        throw std::invalid_argument("Fitting function failed to initialize");
      }
      for(size_t iPar=0;iPar<ifun->nParams();++iPar)
      {
        result->addColumn("double",ifun->parameterName(iPar));
        result->addColumn("double",ifun->parameterName(iPar)+"_Err");
      }
      result->addColumn("double","Chi_squared");
      delete ifun;
      setProperty("OutputWorkspace",result);

      double dProg = 1./static_cast<double>(wsNames.size());
      double Prog = 0.;
      for(int i=0;i<static_cast<int>(wsNames.size());++i)
      {
        InputData data = getWorkspace(wsNames[i]);

        if (!data.ws)
        {
          g_log.warning() << "Cannot access workspace " << wsNames[i].name << '\n';
          continue;
        }

        if (data.i < 0 && data.indx.empty())
        {
          g_log.warning() << "Zero spectra selected for fitting in workspace " << wsNames[i].name << '\n';
          continue;
        }

        int j,jend;
        if (data.i >= 0)
        {
          j = data.i;
          jend = j + 1;
        }
        else
        {// no need to check data.indx.empty()
          j = data.indx.front();
          jend = data.indx.back() + 1;
        }

        dProg /= abs(jend - j);
        for(;j < jend;++j)
        {

          // Find the log value: it is either a log-file value or simply the workspace number
          double logValue;
          if (logName.empty())
          {
            API::Axis* axis = data.ws->getAxis(1);
            logValue = (*axis)(j);
          }
          else if (logName != "SourceName")
          {
            Kernel::Property* prop = data.ws->run().getLogData(logName);
            if (!prop)
            {
              throw std::invalid_argument("Log value "+logName+" does not exist");
            }
            TimeSeriesProperty<double>* logp = 
              dynamic_cast<TimeSeriesProperty<double>*>(prop); 
            logValue = logp->lastValue();
          }

          std::string resFun = fun;
          std::vector<double> errors;
          double chi2;

          try
          {
            // Fit the function
            API::IAlgorithm_sptr fit = createSubAlgorithm("Fit");
            fit->initialize();
            fit->setProperty("InputWorkspace",data.ws);
            //fit->setPropertyValue("InputWorkspace",data.ws->getName());
            fit->setProperty("WorkspaceIndex",j);
            fit->setPropertyValue("Function",fun);
            fit->setPropertyValue("StartX",getPropertyValue("StartX"));
            fit->setPropertyValue("EndX",getPropertyValue("EndX"));
            fit->setPropertyValue("Minimizer",getPropertyValue("Minimizer"));
            fit->setPropertyValue("CostFunction",getPropertyValue("CostFunction"));
            fit->execute();
            resFun = fit->getPropertyValue("Function");
            errors = fit->getProperty("Errors");
            chi2 = fit->getProperty("OutputChi2overDoF");
          }
          catch(...)
          {
            g_log.error("Error in Fit subalgorithm");
            throw;
          }

          if (sequential)
          {
            fun = resFun;
          }

          // Extract the fitted parameters and put them into the result table
          TableRow row = result->appendRow();
          if (isDataName)
          {
            row << wsNames[i].name;
          }
          else
          {
            row << logValue;
          }
          ifun = FunctionFactory::Instance().createInitialized(resFun);
          for(size_t iPar=0;iPar<ifun->nParams();++iPar)
          {
            row << ifun->getParameter(iPar) << errors[iPar];
          }
          row << chi2;
          delete ifun;
          Prog += dProg;
          progress(Prog);
          interruption_point();
        } // for(;j < jend;++j)
      }
    }
Пример #9
0
bool Hdf5Dataset::load(map_generation::WorkSpace &ws)
{
  getWorkspace(ws);
}
Пример #10
0
std::size_t ConvFitModel::getNumberHistograms(std::size_t index) const {
  return getWorkspace(index)->getNumberHistograms();
}
Пример #11
0
boost::optional<double>
ConvFitModel::getInstrumentResolution(std::size_t dataIndex) const {
  if (dataIndex < numberOfWorkspaces())
    return instrumentResolution(getWorkspace(dataIndex));
  return boost::none;
}