/**
 * Cache some frequently used attributes
 * @param name :: The name of the attribute
 * @param value :: It's value
 */
void TobyFitResolutionModel::setAttribute(
    const std::string &name, const API::IFunction::Attribute &value) {
    MDResolutionConvolution::setAttribute(name, value);
    if (name == MC_MIN_NAME)
        m_mcLoopMin = value.asInt();
    else if (name == MC_MAX_NAME)
        m_mcLoopMax = value.asInt();
    else if (name == MC_LOOP_TOL)
        m_mcRelErrorTol = value.asDouble();
    else if (name == MC_TYPE) {
        m_mcType = value.asInt();
        if (m_mcType > 4 || m_mcType < 0) {
            throw std::invalid_argument("TobyFitResolutionModel: Invalid MCType "
                                        "argument, valid values are 0-4. Current "
                                        "value=" +
                                        boost::lexical_cast<std::string>(m_mcType));
        }
    } else if (name == CRYSTAL_MOSAIC) {
        m_mosaicActive = (value.asInt() != 0);
    } else if (name == FOREGROUNDONLY_NAME) {
        m_foregroundOnly = (value.asInt() != 0);
    } else {
        for (auto &iter : m_yvector) {
            iter.setAttribute(name, value);
        }
    }
}
Пример #2
0
/** Set Attribute
 * @param attName :: The attribute name. If it is not "n" exception is thrown.
 * @param att :: An int attribute containing the new value. The value cannot be
 * negative.
 * (identical to Polynomial)
 */
void Polynomial::setAttribute(const std::string &attName,
                              const API::IFunction::Attribute &att) {
  if (attName == "n") {
    // set the polynomial order
    if (m_n >= 0) {
      clearAllParameters();
    }
    m_n = att.asInt();
    if (m_n < 0) {
      throw std::invalid_argument(
          "Polynomial: polynomial order cannot be negative.");
    }
    for (int i = 0; i <= m_n; ++i) {
      std::string parName = "A" + boost::lexical_cast<std::string>(i);
      declareParameter(parName);
    }
  }
}
Пример #3
0
    /** Set an attribute for the function
     *
     * @param attName :: The name of the attribute to set
     * @param att :: The attribute to set
     */
    void CubicSpline::setAttribute(const std::string& attName, const API::IFunction::Attribute& att)
    {

      if (attName == "n")
      {
        //get the new and old number of data points
        int n = att.asInt();
        int oldN = getAttribute("n").asInt();

        //check that the number of data points is in a valid range
        if (n > oldN)
        {
          //get the name of the last x data point
          std::string oldXName = "x" + boost::lexical_cast<std::string>(oldN - 1);
          double oldX = getAttribute(oldXName).asDouble();

          //reallocate gsl object to new size
          reallocGSLObjects(n);

          //create blank a number of new blank parameters and attributes
          for (int i = oldN; i < n; ++i)
          {
            std::string num = boost::lexical_cast<std::string>(i);

            std::string newXName = "x" + num;
            std::string newYName = "y" + num;

            declareAttribute(newXName, Attribute(oldX + static_cast<double>(i - oldN + 1)));
            declareParameter(newYName, 0);
          }

          //flag that the spline + derivatives will now need to be recalculated
          m_recalculateSpline = true;
        }
        else if (n < oldN)
        {
          throw std::invalid_argument("Cubic Spline: Can't decrease the number of attributes");
        }
      }

      storeAttributeValue(attName, att);
    }
Пример #4
0
  /** Set Attribute
   * @param attName :: The attribute name. If it is not "nlayer" exception is thrown.
   * @param att :: An int attribute containing the new value. The value cannot be negative.
   * (identical to ReflectivityMulf)
   */
  void ReflectivityMulf::setAttribute(const std::string& attName,const API::IFunction::Attribute& att)
  {
    storeAttributeValue(attName,att);
    if (attName == "nlayer")
    {
      m_nlayer = att.asInt();
      if (m_nlayer < 0)
      {
        throw std::invalid_argument("ReflectivityMulf: reflectivity number of layers cannot be negative.");
      }

      // get the current parameter values using the old value of nlayer
      vector<double> coeff(m_nlayer*3+7, 0.0);
      for (int i = 0; i < 7; ++i)
        coeff[i] = getParameter(i);

      if(m_nlayer > m_nlayer_old){  
        for (int i = 0; i < m_nlayer_old; ++i)
        {
          coeff[7+i*3] = getParameter(7+i*3);
          coeff[8+i*3] = getParameter(8+i*3);
          coeff[9+i*3] = getParameter(9+i*3);
        }
        // fill in the missing values if m_nlayer>m_nlayer_old
        for (int i = m_nlayer_old; i < m_nlayer; ++i)
        {
          coeff[7+i*3] = 0.0;
          coeff[8+i*3] = 0.0;
          coeff[9+i*3] = 0.0;
        }
      }else {
        for (int i = 0; i < m_nlayer; ++i)
        {
          coeff[7+i*3] = getParameter(7+i*3);
          coeff[8+i*3] = getParameter(8+i*3);
          coeff[9+i*3] = getParameter(9+i*3);
        }
      }
      // now update the value of nlayer_old
      m_nlayer_old=m_nlayer;


      // set the reflectivity layers
      if (m_nlayer >= 0)
      {
        clearAllParameters();
      }
    
      declareParameter("Theta",coeff[0]);
      declareParameter("ScaleFactor",coeff[1]);
      declareParameter("AirSLD",coeff[2]);
      declareParameter("BulkSLD",coeff[3]);
      declareParameter("Roughness",coeff[4]);
      declareParameter("BackGround",coeff[5]);
      declareParameter("Resolution",coeff[6]);

      for(int i=0; i<m_nlayer; ++i)
      {
        std::string parName = "SLD_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[7+i*3]);
        parName = "d_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[8+i*3]);
        parName = "Rough_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[9+i*3]);
      }
    }
  }