Exemplo n.º 1
0
/** Parse table workspace
  */
void RemovePeaks::parsePeakTableWorkspace(TableWorkspace_sptr peaktablews,
                                          vector<double> &vec_peakcentre,
                                          vector<double> &vec_peakfwhm) {
  // Get peak table workspace information
  vector<string> colnames = peaktablews->getColumnNames();
  int index_centre = -1;
  int index_fwhm = -1;
  for (int i = 0; i < static_cast<int>(colnames.size()); ++i) {
    string colname = colnames[i];
    if (colname.compare("TOF_h") == 0)
      index_centre = i;
    else if (colname.compare("FWHM") == 0)
      index_fwhm = i;
  }

  if (index_centre < 0 || index_fwhm < 0) {
    throw runtime_error(
        "Input Bragg peak table workspace does not have TOF_h and/or FWHM");
  }

  // Get values
  size_t numrows = peaktablews->rowCount();
  vec_peakcentre.resize(numrows, 0.);
  vec_peakfwhm.resize(numrows, 0.);

  for (size_t i = 0; i < numrows; ++i) {
    double centre = peaktablews->cell<double>(i, index_centre);
    double fwhm = peaktablews->cell<double>(i, index_fwhm);
    vec_peakcentre[i] = centre;
    vec_peakfwhm[i] = fwhm;
  }

  return;
}
/** Copy table workspace content from one workspace to another
  * @param sourceWS :: table workspace from which the content is copied;
  * @param targetWS :: table workspace to which the content is copied;
  */
void ExtractMaskToTable::copyTableWorkspaceContent(
    TableWorkspace_sptr sourceWS, TableWorkspace_sptr targetWS) {
  // Compare the column names.  They must be exactly the same
  vector<string> sourcecolnames = sourceWS->getColumnNames();
  vector<string> targetcolnames = targetWS->getColumnNames();
  if (sourcecolnames.size() != targetcolnames.size()) {
    stringstream errmsg;
    errmsg << "Soruce table workspace " << sourceWS->name()
           << " has different number of columns (" << sourcecolnames.size()
           << ") than target table workspace's (" << targetcolnames.size()
           << ")";
    throw runtime_error(errmsg.str());
  }
  for (size_t i = 0; i < sourcecolnames.size(); ++i) {
    if (sourcecolnames[i].compare(targetcolnames[i])) {
      stringstream errss;
      errss << "Source and target have incompatible column name at column " << i
            << ". "
            << "Column name of source is " << sourcecolnames[i] << "; "
            << "Column name of target is " << targetcolnames[i];
      throw runtime_error(errss.str());
    }
  }

  // Copy over the content
  size_t numrows = sourceWS->rowCount();
  for (size_t i = 0; i < numrows; ++i) {
    double xmin, xmax;
    string speclist;
    TableRow tmprow = sourceWS->getRow(i);
    tmprow >> xmin >> xmax >> speclist;

    TableRow newrow = targetWS->appendRow();
    newrow << xmin << xmax << speclist;
  }

  return;
}
Exemplo n.º 3
0
bool PoldiPeakCollection::checkColumns(
    const TableWorkspace_sptr &tableWorkspace) {
  if (tableWorkspace->columnCount() != 9) {
    return false;
  }

  std::vector<std::string> shouldNames{"HKL", "d", "delta d", "Q", "delta Q",
                                       "Intensity", "delta Intensity",
                                       "FWHM (rel.)", "delta FWHM (rel.)"};

  std::vector<std::string> columnNames = tableWorkspace->getColumnNames();

  return columnNames == shouldNames;
}
  /** Parse table workspace to a map of Parameters
    */
  void RefinePowderInstrumentParameters2::parseTableWorkspace(TableWorkspace_sptr tablews,
                                                              map<string, Parameter>& parammap)
  {
    // 1. Process Table column names
    std::vector<std::string> colnames = tablews->getColumnNames();
    map<string, size_t> colnamedict;
    convertToDict(colnames, colnamedict);

    int iname = getStringIndex(colnamedict, "Name");
    int ivalue = getStringIndex(colnamedict, "Value");
    int ifit = getStringIndex(colnamedict, "FitOrTie");
    int imin = getStringIndex(colnamedict, "Min");
    int imax = getStringIndex(colnamedict, "Max");
    int istep = getStringIndex(colnamedict, "StepSize");

    if (iname < 0 || ivalue < 0 || ifit < 0)
      throw runtime_error("TableWorkspace does not have column Name, Value and/or Fit.");

    // 3. Parse
    size_t numrows = tablews->rowCount();
    for (size_t irow = 0; irow < numrows; ++irow)
    {
      string parname = tablews->cell<string>(irow, iname);
      double parvalue = tablews->cell<double>(irow, ivalue);
      string fitq = tablews->cell<string>(irow, ifit);

      double minvalue;
      if (imin >= 0)
        minvalue = tablews->cell<double>(irow, imin);
      else
        minvalue = -DBL_MAX;

      double maxvalue;
      if (imax >= 0)
        maxvalue = tablews->cell<double>(irow, imax);
      else
        maxvalue = DBL_MAX;

      double stepsize;
      if (istep >= 0)
        stepsize = tablews->cell<double>(irow, istep);
      else
        stepsize = 1.0;

      Parameter newpar;
      newpar.name = parname;
      newpar.value = parvalue;
      newpar.minvalue = minvalue;
      newpar.maxvalue = maxvalue;
      newpar.stepsize = stepsize;

      // If empty string, fit is default to be false
      bool fit = false;
      if (fitq.size() > 0)
      {
        if (fitq[0] == 'F' || fitq[0] == 'f')
          fit = true;
      }
      newpar.fit = fit;

      parammap.insert(make_pair(parname, newpar));
    }

    return;
  }
Exemplo n.º 5
0
/** Process input Mask bin TableWorkspace.
  * It will convert detector IDs list to spectra list
  * @param masktblws :: TableWorkspace for mask bins
  * @param dataws :: MatrixWorkspace to mask
  */
void MaskBinsFromTable::processMaskBinWorkspace(
    TableWorkspace_sptr masktblws, API::MatrixWorkspace_sptr dataws) {
  // Check input
  if (!masktblws)
    throw std::invalid_argument("Input workspace is not a table workspace.");
  g_log.debug() << "Lines of parameters workspace = " << masktblws->rowCount()
                << '\n';

  // Check column names type and sequence
  vector<std::string> colnames = masktblws->getColumnNames();

  // check colum name order
  id_xmin = -1;
  id_xmax = -1;
  id_spec = -1;
  id_dets = -1;
  m_useDetectorID = false;
  m_useSpectrumID = false;

  for (int i = 0; i < static_cast<int>(colnames.size()); ++i) {
    string colname = colnames[i];
    transform(colname.begin(), colname.end(), colname.begin(), ::tolower);
    if (colname.compare("xmin") == 0)
      id_xmin = i;
    else if (colname.compare("xmax") == 0)
      id_xmax = i;
    else if (boost::algorithm::starts_with(colname, "spec")) {
      id_spec = i;
    } else if (boost::algorithm::starts_with(colname, "detectorid")) {
      id_dets = i;
    } else {
      g_log.warning() << "In TableWorkspace " << masktblws->name()
                      << ", column " << i << " with name " << colname
                      << " is not used by MaskBinsFromTable.";
    }
  }

  if (id_xmin < 0 || id_xmax < 0 || id_xmin == id_xmax)
    throw runtime_error("Either Xmin nor Xmax is not given. ");
  if (id_spec == id_dets)
    throw runtime_error("Neither SpectraList nor DetectorIDList is given.");
  else if (id_dets >= 0)
    m_useDetectorID = true;
  else
    m_useSpectrumID = true;

  // Construct vectors for xmin, xmax and spectra-list
  size_t numrows = masktblws->rowCount();
  for (size_t i = 0; i < numrows; ++i) {
    double xmin = masktblws->cell<double>(i, static_cast<size_t>(id_xmin));
    double xmax = masktblws->cell<double>(i, static_cast<size_t>(id_xmax));

    string spectralist;
    if (m_useSpectrumID) {
      spectralist = masktblws->cell<string>(i, static_cast<size_t>(id_spec));
    } else {
      // Convert detectors list to spectra list
      string detidslist =
          masktblws->cell<string>(i, static_cast<size_t>(id_dets));
      spectralist = convertToSpectraList(dataws, detidslist);
    }

    g_log.debug() << "Row " << i << " XMin = " << xmin << "  XMax = " << xmax
                  << " SpectraList = " << spectralist << ".\n";

    // Store to class variables
    m_xminVec.push_back(xmin);
    m_xmaxVec.push_back(xmax);
    m_spectraVec.push_back(spectralist);
  }
}