<commit_before>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


// What's this file supposed to do ?
//
// (Pho)tometry (It)eration (Error) Update
//
// Equation:
//
// e = Sumk( Sumij( ((I - A*T*R)*S)^2 ))
//
// If there's no reflectance, don't multiply by it.

#include <vw/Image.h>
#include <asp/Core/Macros.h>
#include <asp/PhotometryTK/RemoteProjectFile.h>
#include <asp/PhotometryTK/ErrorAccumulators.h>
using namespace vw;
using namespace asp::pho;

#include <boost/program_options.hpp>
namespace po = boost::program_options;

using namespace std;

struct Options {
  Url ptk_url;

  // For spawning multiple jobs
  int job_id, num_jobs, level;
};

void update_error( Options& opt ) {
  RemoteProjectFile remote_ptk( opt.ptk_url );
  ProjectMeta project_info;
  remote_ptk.get_project( project_info );

  // Deciding what cameras
  int minidx, maxidx;
  minidx = float(project_info.num_cameras()*opt.job_id)/float(opt.num_jobs);
  maxidx = float(project_info.num_cameras()*(opt.job_id+1))/float(opt.num_jobs);

  // Load platefile
  boost::shared_ptr<PlateFile> drg_plate, albedo_plate, reflect_plate;
  remote_ptk.get_platefiles(drg_plate,albedo_plate,reflect_plate);

  if (opt.level < 0 )
    opt.level = drg_plate->num_levels() - 1;

  for(int j = minidx; j < maxidx; j++) {
    CameraMeta cam_info;
    remote_ptk.get_camera(j, cam_info);

    ErrorNRAccumulatorFunc<double,Vector2i> funcProto(opt.level, j+1, cam_info.exposure_t(), drg_plate, albedo_plate);
    
    std::cout << "Camera[" << j << "]         exposure time: "
              << cam_info.exposure_t() << "\n";

    int32 full = 1 << opt.level;
    int32 quarter = full/4;
    BBox2i affected_tiles(0,quarter,full-1,quarter*2-1);

    RecursiveBBoxAccumulator<ErrorNRAccumulatorFunc<double,Vector2i> > accum(32, funcProto);

    ErrorNRAccumulatorFunc<double,Vector2i> funcResult = accum(affected_tiles);

    std::cout << "cam[" << j << "] error=[" << funcResult.value() << "]\n";

    // Once I have the API, call funcResult.value() and 
    // add it to the existing value in the current camera
    if (project_info.current_iteration() == 0) {
      cam_info.set_init_error(funcResult.value());
    }
    else {
      cam_info.set_last_error(funcResult.value());
    }

    remote_ptk.set_camera(j, cam_info);
  }

  // Compare init error and most recent error:
  std::cout << "Init error=[" << remote_ptk.get_init_error() << "]\n";
  std::cout << "Last error=[" << remote_ptk.get_last_error() << "]\n";
}

void handle_arguments( int argc, char *argv[], Options& opt ) {<commit_msg>Changed phoiterror to use stderr for outputting informational messages and only use stdout for latest error value results (so we can parse it when it's called from phosolve.py).<commit_after>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


// What's this file supposed to do ?
//
// (Pho)tometry (It)eration (Error) Update
//
// Equation:
//
// e = Sumk( Sumij( ((I - A*T*R)*S)^2 ))
//
// If there's no reflectance, don't multiply by it.

#include <vw/Image.h>
#include <asp/Core/Macros.h>
#include <asp/PhotometryTK/RemoteProjectFile.h>
#include <asp/PhotometryTK/ErrorAccumulators.h>
using namespace vw;
using namespace asp::pho;

#include <boost/program_options.hpp>
namespace po = boost::program_options;

using namespace std;

struct Options {
  Url ptk_url;

  // For spawning multiple jobs
  int job_id, num_jobs, level;
};

void update_error( Options& opt ) {
  RemoteProjectFile remote_ptk( opt.ptk_url );
  ProjectMeta project_info;
  remote_ptk.get_project( project_info );

  // Save last error before we overwrite it
  float32 initError = remote_ptk.get_init_error();
  float32 lastError = remote_ptk.get_last_error();
  float32 currError = 0.0;

  // Deciding what cameras
  int minidx, maxidx;
  minidx = float(project_info.num_cameras()*opt.job_id)/float(opt.num_jobs);
  maxidx = float(project_info.num_cameras()*(opt.job_id+1))/float(opt.num_jobs);

  // Load platefile
  boost::shared_ptr<PlateFile> drg_plate, albedo_plate, reflect_plate;
  remote_ptk.get_platefiles(drg_plate,albedo_plate,reflect_plate);

  if (opt.level < 0 )
    opt.level = drg_plate->num_levels() - 1;

  for(int j = minidx; j < maxidx; j++) {
    CameraMeta cam_info;
    remote_ptk.get_camera(j, cam_info);

    ErrorNRAccumulatorFunc<double,Vector2i> funcProto(opt.level, j+1, cam_info.exposure_t(), drg_plate, albedo_plate);
    
    std::cerr << "Camera[" << j << "]         exposure time: "
              << cam_info.exposure_t() << "\n";

    int32 full = 1 << opt.level;
    int32 quarter = full/4;
    BBox2i affected_tiles(0,quarter,full-1,quarter*2-1);

    RecursiveBBoxAccumulator<ErrorNRAccumulatorFunc<double,Vector2i> > accum(32, funcProto);

    ErrorNRAccumulatorFunc<double,Vector2i> funcResult = accum(affected_tiles);

    std::cerr << "cam[" << j << "] error=[" << funcResult.value() << "]\n";

    // Once I have the API, call funcResult.value() and 
    // add it to the existing value in the current camera
    if (project_info.current_iteration() == 0) {
      cam_info.set_init_error(funcResult.value());
    }
    else {
      cam_info.set_last_error(funcResult.value());
    }

    remote_ptk.set_camera(j, cam_info);
  }

  currError = remote_ptk.get_last_error();

  // Compare init error and most recent error:
  std::cerr << "Init error=[" << initError << "]\n";
  std::cerr << "Last error=[" << lastError << "]\n";
  std::cerr << "Curr error=[" << currError << "]\n";

  std::cout << initError << " " << lastError << " " << currError << "\n";
}

void handle_arguments( int argc, char *argv[], Options& opt ) {
{'fraction_non_alphanumeric': 0.14189189189189189, 'fraction_numerical': 0.011486486486486487, 'mean_word_length': 3.9548117154811715, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2345113', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2044, 'n_words': 477}