Unverified Commit cabe50fc authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Improved error reporting and fixed a bug with the kaguyatc distortion model (#245)

* Improved error reporting and logging

* Fixed an error where kaguya mi distortion
parent 3fcf1ded
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1920,6 +1920,8 @@ void UsgsAstroLsSensorModel::losToEcf(
         m_startingSample, 0.0,
         m_iTransS, m_iTransL,
         distortedFocalPlaneX, distortedFocalPlaneY);
   MESSAGE_LOG(m_logger, "losToEcf: distorted focal plane coordinate {} {}",
                         distortedFocalPlaneX, distortedFocalPlaneY)

   // Remove lens
   double undistortedFocalPlaneX, undistortedFocalPlaneY;
@@ -1927,10 +1929,14 @@ void UsgsAstroLsSensorModel::losToEcf(
                    undistortedFocalPlaneX, undistortedFocalPlaneY,
                    m_opticalDistCoeffs,
                    m_distortionType);
   MESSAGE_LOG(m_logger, "losToEcf: undistorted focal plane coordinate {} {}",
                         undistortedFocalPlaneX, undistortedFocalPlaneY)

  // Define imaging ray (look vector) in camera space
   double cameraLook[3];
   createCameraLookVector(undistortedFocalPlaneX, undistortedFocalPlaneY, m_zDirection, m_focalLength, cameraLook);
   MESSAGE_LOG(m_logger, "losToEcf: uncorrected camera look vector {} {} {}",
                         cameraLook[0], cameraLook[1], cameraLook[2])

   // Apply attitude correction
   double attCorr[9];
+89 −16
Original line number Diff line number Diff line
@@ -119,9 +119,34 @@ bool UsgsAstroPlugin::canModelBeConstructedFromState(const std::string &modelNam
    csm::Model* model = constructModelFromState(modelState, warnings);
    return (bool)model;
  }
    catch(...) {
  catch(std::exception& e) {
    if(warnings) {
      std::string msg = "Could not create model [";
      msg += modelName;
      msg += "] with error [";
      msg += e.what();
      msg += "]";
      warnings->push_back(
        csm::Warning(
          csm::Warning::UNKNOWN_WARNING,
          msg,
          "UsgsAstroFrameSensorModel::canModelBeConstructedFromState()"));
    }
    return false;
  }
  catch(...) {
    if(warnings) {
      std::string msg = "Could not create model [";
      msg += modelName;
      msg += "] with an unknown error.";
      warnings->push_back(
        csm::Warning(
          csm::Warning::UNKNOWN_WARNING,
          msg,
          "UsgsAstroFrameSensorModel::canModelBeConstructedFromState()"));
    }
  }
  return false;
}


@@ -132,10 +157,34 @@ bool UsgsAstroPlugin::canModelBeConstructedFromISD(const csm::Isd &imageSupportD
    csm::Model* model = constructModelFromISD(imageSupportData, modelName, warnings);
    return (bool)model;
  }
  catch(std::exception& e) {
    if(warnings) {
      std::string msg = "Could not create model [";
      msg += modelName;
      msg += "] with error [";
      msg += e.what();
      msg += "]";
      warnings->push_back(
        csm::Warning(
          csm::Warning::UNKNOWN_WARNING,
          msg,
          "UsgsAstroFrameSensorModel::canModelBeConstructedFromISD()"));
    }
  }
  catch(...) {
    return false;
    if(warnings) {
      std::string msg = "Could not create model [";
      msg += modelName;
      msg += "] with an unknown error.";
      warnings->push_back(
        csm::Warning(
          csm::Warning::UNKNOWN_WARNING,
          msg,
          "UsgsAstroFrameSensorModel::canModelBeConstructedFromISD()"));
    }
  }
  return false;
}


// This function takes a csm::Isd which only has the image filename set. It uses this filename to
@@ -158,9 +207,13 @@ std::string UsgsAstroPlugin::loadImageSupportData(const csm::Isd &imageSupportDa
    jsonisd["image_identifier"] = filename;
    return jsonisd.dump();

  } catch (...) {
    std::string errorMessage = "Could not read metadata file associated with image: ";
    errorMessage.append(isdFilename);
  }
  catch (std::exception& e) {
    std::string errorMessage = "Could not read metadata file associated with image [";
    errorMessage += isdFilename;
    errorMessage += "] with error [";
    errorMessage += e.what();
    errorMessage += "]";
    throw csm::Error(csm::Error::FILE_READ, errorMessage,
                     "UsgsAstroPlugin::loadImageSupportData");
  }
@@ -191,7 +244,19 @@ bool UsgsAstroPlugin::canISDBeConvertedToModelState(const csm::Isd &imageSupport
  try {
       convertISDToModelState(imageSupportData, modelName, warnings);
  }
  catch(...) {
  catch(std::exception& e) {
    if(warnings) {
      std::string msg = "Could not create model [";
      msg += modelName;
      msg += "] state with error [";
      msg += e.what();
      msg += "]";
      warnings->push_back(
        csm::Warning(
          csm::Warning::UNKNOWN_WARNING,
          msg,
          "UsgsAstroFrameSensorModel::canISDBeConvertedToModelState()"));
    }
    return false;
  }
  return true;
@@ -227,9 +292,13 @@ csm::Model *UsgsAstroPlugin::constructModelFromISD(const csm::Isd &imageSupportD
          model->getLogger()->info("Constructed model: {}", modelName);
        }
      }
      catch (...) {
      catch (std::exception& e) {
        csm::Error::ErrorType aErrorType = csm::Error::SENSOR_MODEL_NOT_CONSTRUCTIBLE;
        std::string aMessage = "Invalid ISD for Model " + modelName + ": ";
        std::string aMessage = "Could not construct model [";
        aMessage += modelName;
        aMessage += "] with error [";
        aMessage += e.what();
        aMessage += "]";
        std::string aFunction = "UsgsAstroPlugin::constructModelFromISD()";
        throw csm::Error(aErrorType, aMessage, aFunction);
      }
@@ -240,9 +309,13 @@ csm::Model *UsgsAstroPlugin::constructModelFromISD(const csm::Isd &imageSupportD
      try {
        model->replaceModelState(model->constructStateFromIsd(stringIsd, warnings));
      }
      catch (...) {
      catch (std::exception& e) {
        csm::Error::ErrorType aErrorType = csm::Error::SENSOR_MODEL_NOT_CONSTRUCTIBLE;
        std::string aMessage = "Invalid ISD for Model " + modelName + ": ";
        std::string aMessage = "Could not construct model [";
        aMessage += modelName;
        aMessage += "] with error [";
        aMessage += e.what();
        aMessage += "]";
        std::string aFunction = "UsgsAstroPlugin::constructModelFromISD()";
        throw csm::Error(aErrorType, aMessage, aFunction);
      }
@@ -250,7 +323,7 @@ csm::Model *UsgsAstroPlugin::constructModelFromISD(const csm::Isd &imageSupportD
    }
    else {
      csm::Error::ErrorType aErrorType = csm::Error::SENSOR_MODEL_NOT_SUPPORTED;
      std::string aMessage = "Model" + modelName + " not supported: ";
      std::string aMessage = "Model [" + modelName + "] not supported: ";
      std::string aFunction = "UsgsAstroPlugin::constructModelFromISD()";
      throw csm::Error(aErrorType, aMessage, aFunction);
    }
+4 −4
Original line number Diff line number Diff line
@@ -843,11 +843,11 @@ std::vector<double> getDistortionCoeffs(json isd, csm::WarningList *list) {
    break;
    case DistortionType::KAGUYATC: {
      try {
        std::vector<double> coefficientsX(4,0);
        std::vector<double> coefficientsY(4,0);

        coefficientsX = isd.at("optical_distortion").at("kaguyatc").at("x").get<std::vector<double>>();
        coefficientsY = isd.at("optical_distortion").at("kaguyatc").at("y").get<std::vector<double>>();
        std::vector<double> coefficientsX = isd.at("optical_distortion").at("kaguyatc").at("x").get<std::vector<double>>();
        coefficientsX.resize(4, 0.0);
        std::vector<double> coefficientsY = isd.at("optical_distortion").at("kaguyatc").at("y").get<std::vector<double>>();
        coefficientsY.resize(4, 0.0);
        coefficientsX.insert(coefficientsX.end(), coefficientsY.begin(), coefficientsY.end());

        return coefficientsX;