int Sisim::median_ik( Progress_notifier* progress_notifier ) { // set up the sampler Random_number_generator gen; Monte_carlo_sampler_t< Random_number_generator > sampler( gen ); // loop on all realizations for( int nreal = 0; nreal < nb_of_realizations_ ; nreal ++ ) { // update the progress notifier progress_notifier->message() << "working on realization " << nreal << gstlIO::end; if( !progress_notifier->notify() ) return 1; // Create a new property to hold the realization and tell the simulation // grid to use it as the current property appli_message( "Creating new realization" ); GsTLGridProperty* prop; if(is_categorical_) prop = multireal_property_->new_categorical_realization(); else prop = multireal_property_->new_realization(); simul_grid_->select_property( prop->name() ); neighborhood_->select_property( prop->name() ); // initialize the new realization with the hard data if( property_copier_ ) { property_copier_->copy( harddata_grid_, harddata_property_, simul_grid_, prop ); } // do the simulation appli_message( "Doing simulation" ); int status = sequential_simulation( simul_grid_->random_path_begin(), simul_grid_->random_path_end(), *(neighborhood_.raw_ptr()), *ccdf_, *cdf_estimator_, *marginal_, sampler, progress_notifier ); if( status == -1 ) { simul_grid_->remove_property( prop->name() ); return 1; } } return 0; }
bool GsTL_project::execute( std::string action, std::string param, Error_messages_handler* errors ) { if( action.empty() ) return false; SmartPtr<Named_interface> ni = Root::instance()->new_interface( action, actions_manager + "/" ); Action* act = dynamic_cast<Action*>( ni.raw_ptr() ); if( !act ) { appli_warning( action << ": no such action " ); return false; } // before logging the action, we replace all newline characters // by a "\". This is because a script is interpreted line by line, // and to make it easy to copy from the logs, we write to the logs with the // correct syntax (ie use "\" to say that the line is not over) String_Op::replace( param, "\n", " " ); GsTLlog << action << " " << param << gstlIO::end; // if no error handler was provided, just create a temporary one that // we will discard later. bool tmp_handler = false; if( !errors ) { tmp_handler = true; errors = new Error_messages_handler; } QTime clock; clock.start(); // initialize the action. Check if not successful, return if( ! act->init( param, this, errors ) ) return false; appli_message( action << " took " << clock.elapsed() << "ms to initialize" ); // run clock.restart(); bool ok = act->exec(); appli_message( action << " took " << clock.elapsed() << "ms to run" ); GsTLcout << "completing " << action << " took " << clock.elapsed() << "ms" << gstlIO::end; if( tmp_handler ) delete errors; return ok; }
void Oinv_pointset::refresh() { if( cmap_ && current_property_ ) { int S; if (grid_) S = grid_->size(); else S = redgrid_->size(); float (*colors)[3] = new float[ S][3]; for( int i=0; i< int( S ); i++ ) { if( current_property_->is_informed( i ) ) { float r,g,b; cmap_->color( current_property_->get_value( i ), r,g,b ); colors[i][0] = r; colors[i][1] = g; colors[i][2] = b; } else { appli_message("uninformed at " << i); colors[i][0] = Oinv::nodata_color.red(); colors[i][1] = Oinv::nodata_color.green(); colors[i][2] = Oinv::nodata_color.blue(); } } colors_node_->diffuseColor.setValues(0, S, colors); delete [] colors; } }
int Cosisim::execute( GsTL_project* ) { // Initialize the global random number generator Global_random_number_generator::instance()->seed( seed_ ); // Set up a progress notifier int total_steps = simul_grid_->size() * (nb_of_realizations_); int frequency = std::max( total_steps / 20, 1 ); SmartPtr<Progress_notifier> progress_notifier = utils::create_notifier( "Running CoSisim", total_steps, frequency ); simul_grid_->init_random_path(); // loop on all realizations for( int nreal = 0; nreal < nb_of_realizations_ ; nreal ++ ) { // update the progress notifier progress_notifier->message() << "working on realization " << nreal+1 << gstlIO::end; if( !progress_notifier->notify() ) return 1; // Create a new property to hold the realization and tell the simulation // grid to use it as the current property appli_message( "Creating new realization" ); Grid_continuous_property* prop = multireal_property_->new_realization(); prop->set_parameters(parameters_); simul_grid_->select_property( prop->name() ); typedef Geostat_grid::random_path_iterator RandomPathIterator; RandomPathIterator path_begin = simul_grid_->random_path_begin(); RandomPathIterator path_end = simul_grid_->random_path_end(); int status = 0; if( do_median_ik_ ) status = median_ik( path_begin, path_end, progress_notifier.raw_ptr() ); else status = full_ik( path_begin, path_end, progress_notifier.raw_ptr() ); reset_indicator_properties(); // check if the simulation was aborted if( status == 1 ) { clean( prop ); return 1; } } // end loop on realizations remove_temporary_properties(); return 0; }
bool QTable_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); // QDomNode node = doc.firstChild(); // QDomElement elem = node.toElement(); // In string "value", each row is separated by a new line and each // element of a row is separated by a tab appli_message( "value= " << elem.attribute( "value" ) ); std::string value( elem.attribute( "value" ).latin1() ) ; String_Op::string_vector rows = String_Op::decompose_string( value, row_sep, false ); for( int i=0; i < rows.size() ; i++ ) { String_Op::string_vector row_elements = String_Op::decompose_string( rows[i], col_sep, false ); for( int j=0; j < row_elements.size(); j++ ) { QComboTableItem* item = dynamic_cast<QComboTableItem*>( table_->item(i,j) ); if( item ) item->setCurrentItem( row_elements[j].c_str() ); else table_->setText( i,j, row_elements[j].c_str() ); } } return true; }
Data_analysis_gui::~Data_analysis_gui() { appli_message( "data analysis dialog deleted" ); }
int dssim::execute( GsTL_project* ) { // Initialize the global random number generator Global_random_number_generator::instance()->seed( seed_ ); // Set up a progress notifier int total_steps = simul_grid_->size() * (nb_of_realizations_); int frequency = std::max( total_steps / 20, 1 ); SmartPtr<Progress_notifier> progress_notifier = utils::create_notifier( "Running dssim", total_steps, frequency ); // Initialize the marginal cdf for the direct sequential simulation // LogNormal_cdf marginal( 0.1, 1.0 ); // LogNormal_cdf ccdf; // work on the fine grid if( dynamic_cast<Strati_grid*>( simul_grid_ ) ) { Strati_grid* sgrid = dynamic_cast<Strati_grid*>( simul_grid_ ); sgrid->set_level( 1 ); } // set up the cdf-estimator typedef First2_moments_cdf_Kestimator< Covariance<Location>, Neighborhood, geostat_utils::KrigingConstraints > Kriging_cdf_estimator; Kriging_cdf_estimator cdf_estimator( covar_, *Kconstraints_, *combiner_ ); // set up the sampler Random_number_generator gen; Monte_carlo_sampler_t< Random_number_generator > sampler( gen ); // compute the random path simul_grid_->init_random_path(); // loop on all realizations for( int nreal = 0; nreal < nb_of_realizations_ ; nreal ++ ) { // update the progress notifier progress_notifier->message() << "working on realization " << nreal+1 << gstlIO::end; if( !progress_notifier->notify() ) return 1; // Create a new property to hold the realization and tell the simulation // grid to use it as the current property appli_message( "Creating new realization" ); GsTLGridProperty* prop = multireal_property_->new_realization(); simul_grid_->select_property( prop->name() ); neighborhood_->select_property( prop->name() ); // initialize the new realization with the hard data, if that was requested if( property_copier_ ) { property_copier_->copy( harddata_grid_, harddata_property_, simul_grid_, prop ); //initializer_->assign( prop, harddata_grid_, harddata_property_->name() ); } appli_message( "Doing simulation" ); // do the simulation int status = sequential_simulation( simul_grid_->random_path_begin(), simul_grid_->random_path_end(), *(neighborhood_.raw_ptr()), *ccdf_, cdf_estimator, *marginal_, sampler, progress_notifier.raw_ptr() ); if( status == -1 ) { clean( prop ); return 1; } } clean(); return 0; }
Geostat_grid* Csv_grid_infilter::read( std::ifstream& infile ) { int nx = dialog_->nx(); int ny = dialog_->ny(); int nz = dialog_->nz(); float x_size = dialog_->x_size(); float y_size = dialog_->y_size(); float z_size = dialog_->z_size(); float Ox = dialog_->Ox(); float Oy = dialog_->Oy(); float Oz = dialog_->Oz(); bool use_no_data_value = dialog_->use_no_data_value(); float no_data_value = GsTLGridProperty::no_data_value; QString no_data_value_str = QString().arg(no_data_value); if( dialog_->use_no_data_value() ) { no_data_value = dialog_->no_data_value(); no_data_value_str = QString::number(no_data_value); } QByteArray tmp = dialog_->name().simplified().toLatin1(); std::string name( tmp.constData() ); // ask manager to get a new grid and initialize it SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager + "/" + name ); if( ni.raw_ptr() != 0 ) { GsTLcerr << "object " << name << " already exists\n" << gstlIO::end; return 0; } appli_message( "creating new grid '" << name << "'" << " of dimensions: " << nx << "x" << ny << "x" << nz); ni = Root::instance()->new_interface( "cgrid", gridModels_manager + "/" + name ); Cartesian_grid* grid = dynamic_cast<Cartesian_grid*>( ni.raw_ptr() ); appli_assert( grid != 0 ); grid->set_dimensions( nx, ny, nz, x_size, y_size, z_size); grid->origin( GsTLPoint( Ox,Oy,Oz) ); appli_message( "grid resized to " << nx << "x" << ny << "x" << nz << " total=: " << grid->size() ); std::string buffer; //------------------------- // now, read the file std::getline( infile, buffer, '\n'); QStringList property_names = QString(buffer.c_str()).split(","); //Read one column at a time std::streampos start_data = infile.tellg(); for(unsigned int j = 0; j< property_names.size(); j++) { infile.clear(); infile.seekg( start_data ); // Check if property j is categorical bool is_categ = false; for(unsigned int i=0; i<30 ; i++ ) { bool ok; if( std::getline(infile, buffer) ) break; QString qstr(buffer.c_str()); QStringList values_str = qstr.split(","); values_str[j].toFloat(&ok); if(!ok) { is_categ = true; break; } } infile.clear(); infile.seekg( start_data ); if(is_categ) { GsTLGridCategoricalProperty* prop = grid->add_categorical_property(property_names[j].toStdString()); ni = Root::instance()->new_interface( categoricalDefinition_manager, name+"-"+property_names[j].toStdString()); CategoricalPropertyDefinitionName* cat_def = dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr()); while( std::getline(infile, buffer) ) { QString qstr(buffer.c_str()); QStringList values_qstr = qstr.split(","); cat_def->add_category(values_qstr[j].toStdString()); } prop->set_category_definition(cat_def->name()); infile.clear(); infile.seekg( start_data ); int node_id=0; while( std::getline(infile, buffer) ) { QString qstr(buffer.c_str()); QStringList values_qstr = qstr.split(","); QString val = values_qstr[j]; if(use_no_data_value && val == no_data_value_str) { prop->set_value( GsTLGridProperty::no_data_value, node_id ); } else { prop->set_value( val.toStdString(), node_id ); } node_id++; } } else { GsTLGridProperty* prop = grid->add_property(property_names[j].toStdString()); int node_id=0; while( std::getline(infile, buffer) ) { QString qstr(buffer.c_str()); QStringList values_qstr = qstr.split(","); if(!values_qstr[j].isEmpty()) { bool ok; float val = values_qstr[j].toFloat(&ok); if(ok && val != no_data_value) prop->set_value(val,node_id); } node_id++; } } } return grid; }
int KrigingMean::execute( GsTL_project* ) { // those flags will be used to signal if some of the nodes could not be // informed bool issue_singular_system_warning = false; bool issue_no_conditioning_data_warning = false; // Set up a progress notifier int total_steps = simul_grid_->size(); int frequency = std::max( total_steps / 20, 1 ); SmartPtr<Progress_notifier> progress_notifier = utils::create_notifier( "Running Kriging", total_steps, frequency ); // create the property appli_message("creating new property: " << property_name_ << "..." ); GsTLGridProperty* prop = geostat_utils::add_property_to_grid( simul_grid_, property_name_ ); simul_grid_->select_property( prop->name() ); typedef Geostat_grid::iterator iterator; iterator begin = simul_grid_->begin(); iterator end = simul_grid_->end(); for( ; begin != end; ++begin ) { if( !progress_notifier->notify() ) { clean( property_name_ ); return 1; } if( begin->is_informed() ) continue; neighborhood_->find_neighbors( *begin ); if( neighborhood_->size() < min_neigh_ ) continue; if(!neighborhood_->is_valid()) continue; double variance; int status; status = kriging_weights_2( kriging_weights_, variance, begin->location(), *(neighborhood_.raw_ptr()), covar_,*rhs_covar_, *Kconstraints_ ); if(status == 0) { // the kriging system could be solved double estimate = (*combiner_)( kriging_weights_.begin(), kriging_weights_.end(), *(neighborhood_.raw_ptr()) ); begin->set_property_value( estimate ); } else { // the kriging system could not be solved, issue a warning and skip the // node issue_singular_system_warning = true; } } /* This pop-up windows breaks script if( issue_singular_system_warning ) GsTLcerr << "Kriging could not be performed at some locations because\n" << "the kriging system was singular\n" << gstlIO::end; if( issue_no_conditioning_data_warning ) GsTLcerr << "Kriging could not be performed at some locations because\n" << "the neighborhood of those locations was empty.\n" << "Try increasing the size of the search ellipsoid.\n" << gstlIO::end; */ return 0; }
Geostat_grid* Csv_poinset_infilter::read( std::ifstream& infile ) { QByteArray tmp = dialog_->name().simplified().toLatin1(); std::string name( tmp.constData() ); int X_col_id = dialog_->X_column_index(); int Y_col_id = dialog_->Y_column_index(); int Z_col_id = dialog_->Z_column_index(); if( X_col_id == Y_col_id || X_col_id == Z_col_id || Y_col_id == Z_col_id ) { GsTLcerr << "The same column was selected for multiple coordinates \n" << gstlIO::end; return 0; } bool use_no_data_value = dialog_->use_no_data_value(); float no_data_value = GsTLGridProperty::no_data_value; if( dialog_->use_no_data_value() ) { no_data_value = dialog_->no_data_value(); } std::string str; std::getline(infile, str); QString qstr(str.c_str()); QStringList property_names = qstr.split(","); bool is_x_provided = dialog_->X_column_name() != "None"; bool is_y_provided = dialog_->Y_column_name() != "None"; bool is_z_provided = dialog_->Z_column_name() != "None"; if(is_x_provided) property_names.removeOne(dialog_->X_column_name()); if(is_y_provided) property_names.removeOne(dialog_->Y_column_name()); if(is_z_provided) property_names.removeOne(dialog_->Z_column_name()); std::vector< std::vector< QString > > property_values( property_names.size() ); std::vector< Point_set::location_type > point_locations; // For a csv file no data value is indicated by an empty field e.g. {34,,5.5} while( std::getline(infile, str) ) { qstr = str.c_str(); QStringList fields = qstr.split(","); Point_set::location_type loc; if(is_x_provided) loc[0] = fields[X_col_id].toDouble(); if(is_y_provided) loc[1] = fields[Y_col_id].toDouble(); if(is_z_provided) loc[2] = fields[Z_col_id].toDouble(); point_locations.push_back(loc); unsigned int i=0; for(unsigned int j=0;j<fields.size();j++) { if(j==0) i=0; if(j != X_col_id && j != Y_col_id && j != Z_col_id) { property_values[i].push_back(fields[j]); i++; } } } // done reading file //---------------------------- int point_set_size = point_locations.size(); appli_message( "read " << point_set_size << " points" ); // We now have a vector containing all the locations and another one with // all the property values. // Create a pointset, initialize it with the data we collected, and we're done // ask manager to get a new pointset and initialize it SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager + "/" + name ); if( ni.raw_ptr() != 0 ) { GsTLcerr << "object " << name << " already exists\n" << gstlIO::end; return 0; } std::string size_str = String_Op::to_string( point_set_size ); ni = Root::instance()->new_interface( "point_set://" + size_str, gridModels_manager + "/" + name ); Point_set* pset = dynamic_cast<Point_set*>( ni.raw_ptr() ); appli_assert( pset != 0 ); pset->point_locations( point_locations ); for( unsigned int k= 0; k < property_names.size(); k++ ) { // Need to find out if property is categorical unsigned int check_size = std::min(30,static_cast<int>(property_values[k].size())); bool is_categ = false; for(unsigned int i=0; i<check_size ; i++ ) { bool ok; property_values[k][i].toFloat(&ok); if(!ok) { is_categ = true; break; } } if(!is_categ) { GsTLGridProperty* prop = pset->add_property( property_names[k].toStdString() ); for( int l=0; l < point_set_size; l++ ) { float val = property_values[k][l].toFloat(); if(use_no_data_value && val == no_data_value) val = GsTLGridProperty::no_data_value; prop->set_value( val, l ); } } else { //Create categorical definition // by default it is named: grid-propertyName std::string catdef_name = name+"-"+property_names[k].toStdString(); ni = Root::instance()->new_interface( "categoricaldefinition://"+catdef_name,categoricalDefinition_manager +"/"+catdef_name ); CategoricalPropertyDefinitionName* cat_def = dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr()); for( int i=0; i < point_set_size; i++ ) { cat_def->add_category(property_values[k][i].toStdString()); } GsTLGridCategoricalProperty* prop = pset->add_categorical_property( property_names[k].toStdString(),cat_def->name() ); // prop->set_category_definition(cat_def->name()); QString no_data_value_str = QString().arg( no_data_value); for( int i=0; i < point_set_size; i++ ) { QString val = property_values[k][i]; if(use_no_data_value && val == no_data_value_str) { prop->set_value( GsTLGridProperty::no_data_value, i ); } else prop->set_value( val.toStdString(), i ); } } } return pset; }
bool Save_histogram::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); // TL modified if( params.size() < 3 ) { errors->report( "Usage: SaveHistogram grid prop file [format #bins " "logscaling_flag show_stats_flag show_grid_flag cdf_flag]" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } GsTLGridProperty* prop = grid->property( params[1] ); if( !prop ) { std::ostringstream message; message << "Grid \"" << params[0] << "\" has no property called \"" << params[1] << "\""; errors->report( message.str() ); return false; } // check if we can write to the requested file QFile file( params[2].c_str() ); if( !file.open( IO_WriteOnly ) ) { std::ostringstream message; message << "Can't open file " << params[2]; errors->report( message.str() ); return false; } file.close(); //TL modified bool cdf_flag = true; if (params.size() == 9) { if (params[8] == "0") { appli_message("Turning off cdf"); cdf_flag = false; } } Histogram_gui* histog = new Histogram_gui( proj, 0 ); //TL modified if (cdf_flag) histog->changeCurve("pdf+cdf"); else histog->changeCurve("pdf"); histog->get_data_from( prop ); std::string format = "PNG"; bool show_stats = true; bool show_grid = false; // check if other options were input if( params.size() >= 4 ) { format = params[3] ; } if( params.size() >= 5 ) { int bins = String_Op::to_number<int>( params[4] ); histog->update_bins( bins ); } if( params.size() >= 6 ) { bool logscale = String_Op::to_number<bool>( params[5] ); histog->set_x_axis_logscale( logscale ); } if( params.size() >= 7 ) { show_stats = String_Op::to_number<bool>( params[6] ); } if( params.size() >= 8 ) { show_grid = String_Op::to_number<bool>( params[7] ); } histog->show(); histog->save_as_image( params[2].c_str(), format.c_str(), show_stats, show_grid ); histog->hide(); delete histog; return true; }
bool Show_histogram::init( std::string& parameters, GsTL_project* proj, Error_messages_handler* errors ) { std::vector< std::string > params = String_Op::decompose_string( parameters, Actions::separator, Actions::unique ); if( params.size() < 2 ) { // TL modified errors->report( "Usage: ShowHistogram grid prop [#bins " "logscaling_flag cdf_flag]" ); return false; } SmartPtr<Named_interface> grid_ni = Root::instance()->interface( gridModels_manager + "/" + params[0] ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() ); if( !grid ) { std::ostringstream message; message << "No grid called \"" << params[0] << "\" was found"; errors->report( message.str() ); return false; } GsTLGridProperty* prop = grid->property( params[1] ); if( !prop ) { std::ostringstream message; message << "Grid \"" << params[0] << "\" has no property called \"" << params[1] << "\""; errors->report( message.str() ); return false; } //TL modified bool cdf_flag = true; if (params.size() == 5) { if (params[4] == "0") { appli_message("Turning off cdf"); cdf_flag = false; } } Histogram_gui* histog = new Histogram_gui( proj, 0 ); if (cdf_flag) histog->changeCurve("pdf+cdf"); else histog->changeCurve("pdf"); histog->get_data_from( prop ); // check if other options were input if( params.size() >= 3 ) { int bins = String_Op::to_number<int>( params[2] ); histog->update_bins( bins ); if( params.size() >= 4 ) { bool logscale = String_Op::to_number<bool>( params[3] ); histog->set_x_axis_logscale( logscale ); } } histog->show(); return true; }
bool initialize( Kriging_type ktype, KrigingCombiner*& Kcombiner, KrigingConstraints*& Kconstraints, KrigTagMap& tags_map, const Parameters_handler* parameters, Error_messages_handler* errors, Geostat_grid* simulation_grid, KrigDefaultsMap defaults ) { typedef Kriging_constraints_impl<Neighborhood, Location> KrigingConstraintsImpl; typedef Kriging_combiner_impl<WeightIterator, Neighborhood> KCombinerImpl; switch( ktype ) { case geostat_utils::SK : { appli_message( "doing SK" ); double skmean; KrigDefaultsMap::const_iterator defaults_it = defaults.find( geostat_utils::SK ); if( defaults_it != defaults.end() ) { skmean = String_Op::to_number<double>( defaults_it->second ); } else { // Retrieve the SK mean: std::string sk_tag = tags_map[SK]; std::string skmean_str = parameters->value( sk_tag ); if( skmean_str.empty() ) { errors->report( sk_tag, "No SK mean supplied" ); return false; } skmean = String_Op::to_number<double>( skmean_str ); } KrigingConstraintsImpl* constraints = new SKConstraints_impl<Neighborhood, Location>; Kconstraints = new KrigingConstraints( constraints ); KCombinerImpl* comb = new SK_combiner<WeightIterator, Neighborhood>( skmean ); Kcombiner = new KrigingCombiner( comb ); delete comb; delete constraints; return true; } case geostat_utils::OK : { appli_message( "doing OK " ); KrigingConstraintsImpl* constraints = new OKConstraints_impl<Neighborhood, Location>; Kconstraints = new KrigingConstraints( constraints ); KCombinerImpl* comb = new KCombinerImpl; Kcombiner = new KrigingCombiner( comb ); delete comb; delete constraints; return true; } case geostat_utils::KT : { appli_message( "doing KT " ); // Retrieve the trend components and store them into a vector<bool> std::vector<bool> flags; std::string kt_tag = tags_map[ geostat_utils::KT ]; std::string trend = parameters->value( kt_tag ); if( trend.empty() ) { errors->report( kt_tag, "No trend components supplied" ); return false; } // convert the trend string into a vector of bool std::istringstream input( trend.c_str() ); std::copy( std::istream_iterator<bool>( input ), std::istream_iterator<bool>(), std::back_inserter( flags ) ); std::vector<Trend_functor> trend_components; trend_components.push_back( Trend_functor( Trend_functions::id ) ); if( flags[0] ) trend_components.push_back( Trend_functor( Trend_functions::x ) ); if( flags[1] ) trend_components.push_back( Trend_functor( Trend_functions::y ) ); if( flags[2] ) trend_components.push_back( Trend_functor( Trend_functions::z ) ); if( flags[3] ) trend_components.push_back( Trend_functor( Trend_functions::x2 ) ); if( flags[4] ) trend_components.push_back( Trend_functor( Trend_functions::y2 ) ); if( flags[5] ) trend_components.push_back( Trend_functor( Trend_functions::z2 ) ); if( flags[6] ) trend_components.push_back( Trend_functor( Trend_functions::xy ) ); if( flags[7] ) trend_components.push_back( Trend_functor( Trend_functions::xz ) ); if( flags[8] ) trend_components.push_back( Trend_functor( Trend_functions::yz ) ); appli_warning( "number of components: " << trend_components.size() ); KrigingConstraintsImpl* constraints = new KTConstraints_impl<Trend_functor,Neighborhood, Location>( trend_components ); Kconstraints = new KrigingConstraints( constraints ); KCombinerImpl* comb = new KCombinerImpl; Kcombiner = new KrigingCombiner( comb ); delete comb; delete constraints; return true; } case geostat_utils::LVM : { appli_message( "doing LVM" ); appli_assert( simulation_grid ); std::string lvm_tag = tags_map[ geostat_utils::LVM ]; std::string mean_prop = parameters->value( lvm_tag ); if( simulation_grid->property( mean_prop ) == 0 ) { errors->report( String_Op::split_string( lvm_tag, "/" ).first, "No valid property specified" ); return false; } typedef SK_local_mean_combiner<WeightIterator, Neighborhood, Colocated_neighborhood> LVM_combiner; Colocated_neighborhood* coloc_neigh = dynamic_cast<Colocated_neighborhood*>( simulation_grid->colocated_neighborhood( mean_prop ) ); KCombinerImpl* comb = new LVM_combiner( *coloc_neigh ); Kcombiner = new KrigingCombiner( comb ); KrigingConstraintsImpl* constraints = new SKConstraints_impl<Neighborhood, Location>; Kconstraints = new KrigingConstraints( constraints ); delete comb; delete constraints; return true; } } //end of switch // Why did we get here ???? appli_warning( "No valid kriging type provided" ); errors->report( "Kriging_Type", "No valid kriging type provided" ); return false; }
void Histogram_gui::changeCurve(const QString & s) { std::map<float,int>::iterator itr; int total = histogram_->rawDataSize(); int i = 0; QwtText tfp("Probability"); tfp.setFont(plot_->axisFont(QwtPlot::yLeft)); QwtText tff("Frequency"); tff.setFont(plot_->axisFont(QwtPlot::yLeft)); QColor blueColor(Qt::blue); const QPen pen(blueColor); std::pair<double*,double*> curve = histogram_->plotting_data(); if (!curve.first) { appli_message("No data present"); return; } if (s == "cdf") { std::map<float, int> freqCount = histogram_->frequency(); _cdfCurve->setAxis(QwtPlot::xBottom, QwtPlot::yLeft); plot_->setAxisTitle(QwtPlot::yLeft, tfp); plot_->enableAxis(QwtPlot::yRight,false); curve_grid_->enableY(true); curve_grid_->setYAxis(QwtPlot::yLeft); plot_->enableAxis(QwtPlot::yLeft); curve_id_->setStyle(QwtPlotCurve::NoCurve); _cdfCurve->setStyle(QwtPlotCurve::Lines); double * x = new double[freqCount.size()+1]; double * y = new double[freqCount.size()+1]; y[0] = 0; for (itr = freqCount.begin(); itr != freqCount.end(); ++itr,++i) { x[i+1] = itr->first; y[i+1] = y[i]+(double)(itr->second)/(double)(total); } x[0] = x[1]; _cdfCurve->setPen(pen); _cdfCurve->setData( x, y, freqCount.size()+1 ); refresh_plot( _cdfCurve, std::make_pair( x,y ), freqCount.size()+1 ); refresh_stats(); delete []x; delete []y; } else if (s == "pdf") { //_cdfCurve->detach(); plot_->enableAxis(QwtPlot::yRight, false); plot_->setAxisTitle(QwtPlot::yLeft, tff); plot_->enableAxis(QwtPlot::xBottom); curve_id_->setAxis(QwtPlot::xBottom, QwtPlot::yLeft); curve_grid_->setYAxis(QwtPlot::yLeft); curve_grid_->enableY(true); curve_grid_->setXAxis(QwtPlot::xBottom); curve_grid_->enableX(true); _cdfCurve->setStyle(QwtPlotCurve::NoCurve); curve_id_->setStyle(QwtPlotCurve::Histogram); int size = histogram_->bins()+1; double* x = new double[size+1]; double* y = new double[size+1]; for( int i =0 ; i < size ; i++ ) { x[i+1] = curve.first[i]; y[i+1] = curve.second[i]; } x[0] = x[1]; y[0] = 0.0; refresh_plot( std::make_pair( x,y ), size+1 ); refresh_stats(); delete []x; delete []y; } else { std::map<float, int> freqCount = histogram_->frequency(); _cdfCurve->setAxis(QwtPlot::xBottom, QwtPlot::yRight); plot_->enableAxis(QwtPlot::yRight, true); plot_->enableAxis(QwtPlot::yLeft, true); curve_grid_->setYAxis(QwtPlot::yLeft); plot_->setAxisTitle(QwtPlot::yLeft, tff); plot_->setAxisTitle(QwtPlot::yRight, tfp); _cdfCurve->setStyle(QwtPlotCurve::Lines); curve_id_->setStyle(QwtPlotCurve::Histogram); double * x = new double[freqCount.size()+1]; double * y = new double[freqCount.size()+1]; y[0] = 0; for (itr = freqCount.begin(); itr != freqCount.end(); ++itr,++i) { x[i+1] = itr->first; y[i+1] = y[i]+(double)(itr->second)/(double)(total); } x[0] = x[1]; _cdfCurve->setPen(pen); _cdfCurve->setData( x, y, freqCount.size()+1 ); refresh_plot( _cdfCurve, std::make_pair( x,y ), freqCount.size()+1 ); //refresh_stats(); int size = histogram_->bins()+1; double* x1 = new double[size+1]; double* y1 = new double[size+1]; for( int i =0 ; i < size ; i++ ) { x1[i+1] = curve.first[i]; y1[i+1] = curve.second[i]; } x1[0] = x1[1]; y1[0] = 0.0; refresh_plot( std::make_pair( x1,y1 ), size+1 ); refresh_stats(); delete []x1; delete []y1; delete []x; delete []y; } //plot_->replot(); }
void Lib_initializer::load_filters_plugins() { SmartPtr<Named_interface> ni = Root::instance()->interface(topLevelInputFilters_manager); Manager* mng = dynamic_cast<Manager*> (ni.raw_ptr()); appli_assert( mng ); std::string filters_plugin_path(mng->plugin_path()); QString path(filters_plugin_path.c_str()); // Loop on all the library files (.so or .dll) in directory "path" QDir dir(path); if (!dir.exists()) return; QStringList filters; filters << "*.so" << "*.dll"; dir.setNameFilters(filters); dir.setFilter(QDir::Files); const QFileInfoList list = dir.entryInfoList(); if (list.empty()) { GsTLlog << "No filter plugins found.\n" << gstlIO::end; return; } QFileInfoList::const_iterator it = list.begin(); const QFileInfo* f_info; for (; it != list.end(); ++it) { f_info = &(*it); // QLibrary wants the absolute path QString tmp = path + "/" + f_info->fileName(); QByteArray tmps = tmp.toLatin1(); appli_message( "loading file: " << tmps.constData()); QLibrary lib(path + "/" + f_info->fileName()); //lib.setAutoUnload( false ); lib.load(); if (!lib.isLoaded()) { appli_warning( "library not loaded " << std::endl ); continue; } typedef int (*Init_func_prototype)(void); // The function must be called [filename]_init() // QString init_func_name( f_info->baseName() + "_init" ); // The function must be called plugin_init() QString init_func_name = "plugin_init"; QByteArray tmp1 = init_func_name.toLatin1(); Init_func_prototype init_func = (Init_func_prototype) lib.resolve(tmp1.constData()); if (init_func) init_func(); else { QByteArray s = init_func_name.toLatin1(); appli_warning( "unable to resolve symbol " << s.constData() ); } } }
int LU_sim::execute( GsTL_project* ) { // Initialize the global random number generator Global_random_number_generator::instance()->seed( seed_ ); // Set up a progress notifier int total_steps = simul_grid_->size() * (nb_of_realizations_); int frequency = std::max( total_steps / 20, 1 ); SmartPtr<Progress_notifier> progress_notifier = utils::create_notifier( "Running LU_sim", total_steps, frequency ); // In LU simulation, the marginal is a Gaussian cdf, // with mean 0 and variance 1. Gaussian_cdf marginal( 0.0, 1.0 ); //typedef Geostat_grid::random_path_iterator iterator; typedef Gval_iterator< TabularMapIndex > iterator; std::vector< int > id_unknown; std::vector< int > id_data; //harddata_grid_->select_property(harddata_property_->name()); if( harddata_grid_ ) { for( int i=0; i< harddata_property_->size(); i++ ) { if(!harddata_property_->is_informed(i) ) continue; id_data.push_back( i ); } } for( int i=0; i< simul_grid_->size(); i++ ) { if( simul_grid_ == harddata_grid_ && harddata_property_->is_informed(i) ) continue; id_unknown.push_back( i ); } iterator begin_d( harddata_grid_, harddata_property_ ,0, id_data.size(), TabularMapIndex(&id_data) ); iterator end_d( harddata_grid_, harddata_property_ ,id_data.size(), id_data.size(), TabularMapIndex(&id_data) ); Grid_continuous_property* prop = multireal_property_->new_realization(); iterator begin_u( simul_grid_, prop ,0, id_unknown.size(), TabularMapIndex(&id_unknown) ); iterator end_u( simul_grid_, prop ,id_unknown.size(), id_unknown.size(), TabularMapIndex(&id_unknown) ); Random_number_generator gen; LU_simulator< Covariance<Location>, Random_number_generator, Geostat_grid> lu_sim( covar_,gen, simul_grid_ ); lu_sim.initialize_matrix(begin_u, end_u, begin_d, end_d); // loop on all realizations for( int nreal = 0; nreal < nb_of_realizations_ ; nreal ++ ) { // update the progress notifier progress_notifier->message() << "working on realization " << nreal+1 << gstlIO::end; if( !progress_notifier->notify() ) return 1; // Create a new property to hold the realization and tell the simulation // grid to use it as the current property appli_message( "Creating new realization" ); //Grid_continuous_property* prop = multireal_property_->new_realization(); if(nreal>0) prop = multireal_property_->new_realization(); prop->set_parameters(parameters_); simul_grid_->select_property( prop->name() ); // initialize the new realization with the hard data, if that was requested if( property_copier_ ) { property_copier_->copy( harddata_grid_, harddata_property_, simul_grid_, prop ); } iterator begin_unk( simul_grid_, prop ,0, id_unknown.size(), TabularMapIndex(&id_unknown) ); iterator end_unk( simul_grid_, prop ,id_unknown.size(), id_unknown.size(), TabularMapIndex(&id_unknown) ); int status = lu_sim(begin_unk,end_unk,marginal); // initialize the new realization with the hard data, if that was requested // if( property_copier_ ) { // property_copier_->copy( harddata_grid_, harddata_property_, // simul_grid_, prop ); //initializer_->assign( prop, harddata_grid_, harddata_property_->name() ); // } if( status == -1 ) { clean( prop ); return 1; } // back-transform if needed if( use_target_hist_ ) { cdf_transform( prop->begin(), prop->end(), marginal, *target_cdf_.raw_ptr() ); } } clean(); return 0; }
Geostat_grid* Gslib_grid_infilter::read( std::ifstream& infile ) { int nx = dialog_->nx(); int ny = dialog_->ny(); int nz = dialog_->nz(); float x_size = dialog_->x_size(); float y_size = dialog_->y_size(); float z_size = dialog_->z_size(); float Ox = dialog_->Ox(); float Oy = dialog_->Oy(); float Oz = dialog_->Oz(); QByteArray tmp = dialog_->name().simplified().toLatin1(); std::string name( tmp.constData() ); // ask manager to get a new grid and initialize it SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager + "/" + name ); if( ni.raw_ptr() != 0 ) { GsTLcerr << "object " << name << " already exists\n" << gstlIO::end; return 0; } appli_message( "creating new grid '" << name << "'" << " of dimensions: " << nx << "x" << ny << "x" << nz); ni = Root::instance()->new_interface( "cgrid", gridModels_manager + "/" + name ); Cartesian_grid* grid = dynamic_cast<Cartesian_grid*>( ni.raw_ptr() ); appli_assert( grid != 0 ); grid->set_dimensions( nx, ny, nz, x_size, y_size, z_size); grid->origin( GsTLPoint( Ox,Oy,Oz) ); appli_message( "grid resized to " << nx << "x" << ny << "x" << nz << " total=: " << grid->size() ); std::string buffer; //------------------------- // now, read the file // read title std::getline( infile, buffer, '\n'); // read nb of properties int property_count; infile >> property_count; std::getline( infile, buffer, '\n'); // check whether the file contains multiple realizations bool has_multi_real = false; int lines_to_skip = grid->size() + property_count; for( int pos=0; pos < lines_to_skip ; pos++ ) std::getline( infile, buffer, '\n'); float val; if( infile >> val ) has_multi_real = true; // reposition the stream infile.clear(); infile.seekg( 0 ); std::getline( infile, buffer, '\n'); std::getline( infile, buffer, '\n'); if( has_multi_real ) { std::vector<MultiRealization_property*> properties; for( int i=0; i<property_count; i++ ) { std::getline( infile, buffer, '\n'); QString prop_name( buffer.c_str() ); MultiRealization_property* prop; QByteArray tmp = prop_name.simplified().toAscii(); prop = grid->add_multi_realization_property( tmp.constData() ); if( !prop ) { GsTLcerr << "Several properties share the same name " << gstlIO::end; return 0; } properties.push_back( prop ); } while( infile ) { if( !infile ) break; char c = infile.peek(); if( !std::isdigit(c) ) break; std::vector<GsTLGridProperty*> props; int index = 0; for( unsigned int ii=0; ii < property_count; ii++) { GsTLGridProperty* prop = properties[index]->new_realization(); props.push_back( prop ); ++index; } read_one_realization( infile, props, grid->size() ); } } else { std::vector<GsTLGridProperty*> properties; for( int i=0; i<property_count; i++ ) { std::getline( infile, buffer, '\n'); QString prop_name( buffer.c_str() ); QByteArray tmp =prop_name.simplified().toAscii(); GsTLGridProperty* prop = grid->add_property( tmp.constData() ); properties.push_back( prop ); } read_one_realization( infile, properties, grid->size() ); } return grid; }