FFSM++  1.1.0
French Forest Sector Model ++
Pixel Class Reference

Pixel-level class. More...

#include <Pixel.h>

Inheritance diagram for Pixel:
Collaboration diagram for Pixel:

Public Member Functions

 Pixel (double ID_h, ThreadManager *MTHREAD_h)
 
 ~Pixel ()
 
double getDoubleValue (const string &layerName_h, const bool &returnZeroForNoValue=false) const
 Return the value for a specific layer. More...
 
double getDoubleValue (const string &parName, const string &forName, const string &dClass, const int &year, const bool &returnZeroForNoValue=false)
 
double getMultiplier (const string &multiplierName, const string &forName, int year=DATA_NOW)
 
double getPathMortality (const string &forType, const string &dC, int year=DATA_NOW)
 Return the INCREASED mortality due to pathogen presence for a given ft and dc in a certain year (default the running year) More...
 
void correctInputMultiplier (const string &multiplierName, const string &forName, double coefficient=1)
 It apply a given coefficient to all the multipliers layers of a given ft. More...
 
void newYear ()
 
double getPastRegArea (const int &ft_idx, const int &year)
 
void setPastRegArea (const double &value, const int &ft_idx, const int &year)
 
ModelRegiongetMyRegion (const int &rLevel=2)
 
double getSTData (const string &parName, const string &forName, int year, const string &d2="", double naToReturn=RETNA)
 
double getID () const
 
int getX () const
 
int getY () const
 
vector< Pixel * > getPixelsAtDistLevel (int distLevel_h) const
 Return a vector of pixels at the specified distance (in levels, not in physical units) More...
 
string getPxComments () const
 
double getCachedDouble () const
 
void setValue (const string &layerName_h, const double &value_h)
 Insert a new layer and its value. More...
 
void changeValue (const string &layerName_h, const double &value_h, const bool &setNoValueForZero=false)
 Change the value of an existing layerMTHREAD->GIS->pack(parName, forName, dClass, year), value_h,. More...
 
void setCoordinates (int x_h, int y_h)
 
void setPxComments (std::string pxComments_h)
 
void setCachedDouble (double cachedDouble_h)
 
void clearCache ()
 
void setSpModifier (const double &value, const int &ftindex)
 
double getSpModifier (const string &ft)
 
void swap (const int &swap_what)
 Assign to the delayed value the current values, e.g. vol_l = vol. More...
 
void setMyRegion (ModelRegion *region_h)
 
- Public Member Functions inherited from BaseClass
 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
int s2i (const string &string_h) const
 string to integer conversion More...
 
double s2d (const string &string_h) const
 string to double conversion More...
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion More...
 
bool s2b (const string &string_h) const
 string to bool conversion More...
 
string i2s (const int &int_h) const
 integer to string conversion More...
 
string d2s (const double &double_h) const
 double to string conversion More...
 
string b2s (const bool &bool_h) const
 bool to string conversion More...
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector) More...
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector) More...
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector) More...
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector) More...
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector) More...
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector) More...
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More...
 
void refreshGUI () const
 Ping to periodically return the control to the GUI. More...
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space) More...
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key. More...
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value. More...
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one. More...
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs. More...
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int) More...
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map. More...
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector. More...
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops). More...
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once. More...
 
template<typename T >
std::string toString (const T &x) const
 

Public Attributes

vector< vector< double > > vol
 
vector< vector< double > > area
 
vector< vector< double > > deltaArea
 
vector< double > initialDc0Area
 
vector< vector< double > > hArea
 
vector< vector< double > > hVol
 
vector< vector< double > > hProductivity
 
vector< vector< vector< double > > > hVol_byPrd
 
map< int, vector< double > > regArea
 
vector< double > vReg
 
vector< vector< double > > vMort
 
vector< double > expectedReturns
 
vector< int > optDc
 
vector< int > optFtChosen
 
vector< int > optDcChosen
 
vector< double > expectedAnnualIncome_carbon
 
vector< double > expectedAnnualIncome_timber
 
vector< double > expectedReturnsNotCorrByRa
 by ft. Attenction, reported expReturns at "forest" level (compared with those at forest type level) do NOT include ra More...
 
vector< vector< double > > vol_l
 store the volumes of the previous year More...
 
vector< vector< double > > area_l
 store the areas of the previous year More...
 
vector< vector< double > > beta
 
vector< vector< double > > mort
 
vector< vector< double > > tp
 
vector< vector< double > > cumTp
 This is time of passage to REACH a diameter class (while the exogenous tp by diameter class is the time of passage to LEAVE to the next d class). By ft,dc. More...
 
vector< vector< double > > vHa
 Volume at hectar by each diameter class [m^3/ha]. More...
 
vector< vector< double > > cumAlive
 Cumulative prob of remaining alive at beginnin of a given diam class. More...
 
vector< vector< double > > cumTp_exp
 This is the expected version of cumTp, used for calculating profits. More...
 
vector< vector< double > > vHa_exp
 This is the expected version of vHa, used for calculating profits. More...
 
vector< vector< double > > cumAlive_exp
 This is the expected version of cumAlive, used for calculating profits. More...
 
double portfolioVarRa
 Sampling derived risk aversion on portfolio variance for of this agent. More...
 
double expType
 Sampling derived expectation types of this agent (forest bilogical parameters: growth, mortality) More...
 
double expTypePrices
 Sampling derived expectation types of this agent (prices) More...
 
bool usePortfolio
 Sampling derived usage of portfolio management (false/true) More...
 
vector< double > avalCoef
 Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces avaiability of wood resources to exploitation due to local reasons (protected area, altimetry..) More...
 

Private Attributes

map< string, double > values
 Map of values for each layer. More...
 
map< string, double >::const_iterator vIter
 
double ID
 
int pxX
 
int pxY
 
string pxComments
 
double cachedDouble
 Cachable double used in some optimized algorithms. More...
 
vector< double > spMods
 The sampled spatial modifiers (by forest type) More...
 
ModelRegionl2region
 Pointer to level 2 region where this pixel is. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseClass
ThreadManagerMTHREAD
 Pointer to the Thread manager. More...
 

Detailed Description

Pixel-level class.

This class manage the info at the pixel level. A vector of pixel objects is owned by the class Gis.

Author
Antonello Lobianco

Definition at line 47 of file Pixel.h.

Constructor & Destructor Documentation

Pixel ( double  ID_h,
ThreadManager MTHREAD_h 
)

Definition at line 27 of file Pixel.cpp.

27  : ID(ID_h)
28 {
29  MTHREAD=MTHREAD_h;
30  int nft = MTHREAD->MD->getForTypeIds().size();
31  vector<double> temp(nft,1);
32  //vector<double> temp2(nft,0);
33  spMods = temp;
34  avalCoef = temp;
35  //vMort = temp2;
36  //std::fill(v.begin(), v.end(), 0);
37 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
double ID
Definition: Pixel.h:151
vector< double > avalCoef
Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces ...
Definition: Pixel.h:146
vector< double > spMods
The sampled spatial modifiers (by forest type)
Definition: Pixel.h:156
vector< string > getForTypeIds(bool all=false)
By default it doesn&#39;t return forTypes used only as input.
Definition: ModelData.cpp:430

Here is the call graph for this function:

~Pixel ( )

Definition at line 39 of file Pixel.cpp.

40 {
41 }

Member Function Documentation

void changeValue ( const string &  layerName_h,
const double &  value_h,
const bool &  setNoValueForZero = false 
)

Change the value of an existing layerMTHREAD->GIS->pack(parName, forName, dClass, year), value_h,.

Definition at line 135 of file Pixel.cpp.

Referenced by Gis::applyForestReclassification(), ModelCoreSpatial::loadExogenousForestLayers(), Layers::randomShuffle(), and ModelCoreSpatial::updateMapAreas().

135  {
136  map<string, double>::iterator p;
137  p=values.find(layerName_h);
138  if(p != values.end()){
139  if(setNoValueForZero && value_h == 0){
140  p->second = MTHREAD->GIS->getNoValue();
141  } else {
142  p->second = value_h;
143  }
144  } else {
145  msgOut(MSG_ERROR, "Coud not change pixel value for layer "+layerName_h+". Layer don't found.");
146  }
147  return;
148 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
double getNoValue() const
Definition: Gis.h:133
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

void clearCache ( )
inline

Definition at line 86 of file Pixel.h.

86 {cachedDouble=0;};
double cachedDouble
Cachable double used in some optimized algorithms.
Definition: Pixel.h:155
void correctInputMultiplier ( const string &  multiplierName,
const string &  forName,
double  coefficient = 1 
)

It apply a given coefficient to all the multipliers layers of a given ft.

Definition at line 369 of file Pixel.cpp.

369  {
370  string search_for = multiplierName+"#"+forName+"#";
371  for (std::map<string,double>::iterator it=values.lower_bound(search_for); it!=values.end(); ++it){
372  if (it->first.compare(0, search_for.size(), search_for) == 0){
373  //cout << ID << ";" << forName << ";" << coefficient << endl;
374  it->second = it->second * coefficient;
375  }
376  }
377 }
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:149
double getCachedDouble ( ) const
inline

Definition at line 74 of file Pixel.h.

74 {return cachedDouble;};
double cachedDouble
Cachable double used in some optimized algorithms.
Definition: Pixel.h:155
double getDoubleValue ( const string &  layerName_h,
const bool &  returnZeroForNoValue = false 
) const

Return the value for a specific layer.

Definition at line 158 of file Pixel.cpp.

Referenced by Gis::applyForestReclassification(), ThreadManager::computeQuery(), Layers::countMyPixels(), getDoubleValue(), getPathMortality(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::loadExogenousForestLayers(), Layers::print(), Layers::printBinMap(), Layers::randomShuffle(), ModelCoreSpatial::runBiologicalModule(), ModelCoreSpatial::runManagementModule(), ModelRegion::setMyPixels(), ModelCoreSpatial::sumRegionalForData(), and ModelCoreSpatial::updateMapAreas().

158  {
159  vIter=values.find(layerName_h);
160  if(vIter != values.end()) {
161  if(returnZeroForNoValue && vIter->second==MTHREAD->GIS->getNoValue()){
162  return 0.0;
163  } else {
164  return vIter->second;
165  }
166  } else {
167  msgOut(MSG_WARNING, "No layer \""+layerName_h+"\" found on pixel ("+i2s(getX())+","+i2s(getY())+"). Sure you didn't mispelled it?");
168  if(returnZeroForNoValue){
169  return 0.0;
170  } else {
171  return MTHREAD->GIS->getNoValue();
172  }
173  }
174 }
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
int getX() const
Definition: Pixel.h:68
map< string, double >::const_iterator vIter
Definition: Pixel.h:150
double getNoValue() const
Definition: Gis.h:133
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
Print a WARNING message.
Definition: BaseClass.h:60
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:149
int getY() const
Definition: Pixel.h:69

Here is the call graph for this function:

Here is the caller graph for this function:

double getDoubleValue ( const string &  parName,
const string &  forName,
const string &  dClass,
const int &  year,
const bool &  returnZeroForNoValue = false 
)

Definition at line 380 of file Pixel.cpp.

380  {
381  return getDoubleValue(MTHREAD->GIS->pack(parName, forName, dClass, year), returnZeroForNoValue);
382 }
string pack(const string &parName, const string &forName, const string &dClass, const int &year) const
Definition: Gis.h:148
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Definition: Pixel.cpp:158

Here is the call graph for this function:

double getID ( ) const
inline
double getMultiplier ( const string &  multiplierName,
const string &  forName,
int  year = DATA_NOW 
)

getMultiplier() returns the value of the multiplier as memorized in the spatialDataSubfolder layers or in the forData table. It will looks for exact match or for lower years if available. If no layers are available or the usePixelData option is not used, it will return 1. If the tp_multiplier is asked for, it will adjusts for spatial variance coefficient. If the mortCoef_multiplier is used and we are in the table settings it will adjust it by mortCoef_link.

Definition at line 184 of file Pixel.cpp.

Referenced by ModelCoreSpatial::cachePixelExogenousData(), ModelCoreSpatial::computeCumulativeData(), and Output::printDebugPixelValues().

184  {
185 
186 
187  if(year==DATA_NOW){year = MTHREAD->SCD->getYear();}
188 
189 
190  double multiplierSpVar = (multiplierName == "tp_multiplier")?getSpModifier(forName):1.0;
191 
192  vector <string> modifiersFromTable = MTHREAD->MD->getStringVectorSetting("modifiersFromTable");
193 
194  if(std::find(modifiersFromTable.begin(), modifiersFromTable.end(), multiplierName) != modifiersFromTable.end()) {
195  // load multiplier from forData table..
196  int regId = getMyRegion()->getRegId();
197  double multiplier = MTHREAD->MD->getForData(multiplierName, regId, forName, "",year);
198  if (multiplierName == "mortCoef_multiplier"){
199  return pow(multiplier,MTHREAD->MD->getDoubleSetting("mortMultiplier_link",DATA_NOW))*multiplierSpVar; //Added to account that our multipliers are based on probability of presence and not on planted/managed forests, where mortality is somhow reduced
200  }
201  return multiplier*multiplierSpVar;
202 
203  } else {
204  // load multiplier from layer file..
205  return getSTData(multiplierName, forName, year, "", 1.0);
206 
207 // // return 1 if not using pixel mode
208 // if(!MTHREAD->MD->getBoolSetting("usePixelData")) return 1.0;
209 // string search_for = multiplierName+"#"+forName+"##"+i2s(year);
210 // map <string,double>::const_iterator i = values.upper_bound(search_for); //return the position always upper to the found one, even if it's an equal match.
211 // if(i!= values.begin()) i--; // this rewind the position to the one just before or equal
212 // const string& key = i->first;
213 // string search_base = search_for.substr(0,search_for.size()-4);
214 // if (key.compare(0, search_base.size(), search_base) == 0){
215 // //cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
216 // //if(i->second != 1){
217 // // cout << "NOT ONE: " << search_for <<", "<< i->first << ", " << i->second << endl;
218 // // exit(0);
219 // //}
220 // return i->second*multiplierSpVar;
221 // } else {
222 // //cout << "NOTM: " << search_for <<", "<< i->first << endl;
223 // return 1.0*multiplierSpVar;
224 // }
225 
226  }
227 }
The required data is for the current year.
Definition: BaseClass.h:73
double getSpModifier(const string &ft)
Definition: Pixel.cpp:437
int getRegId() const
Definition: ModelRegion.h:66
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
vector< string > getStringVectorSetting(const string &name_h, int reg=WORLD) const
Definition: ModelData.cpp:1129
ModelRegion * getMyRegion(const int &rLevel=2)
Definition: Pixel.cpp:449
double getSTData(const string &parName, const string &forName, int year, const string &d2="", double naToReturn=RETNA)
Definition: Pixel.cpp:246
const double getForData(const string &type_h, const int &regId_h, const string &forType_h, const string &freeDim_h, const int &year=DATA_NOW)
Definition: ModelData.cpp:1281
int getYear()
Definition: Scheduler.h:49
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1109

Here is the call graph for this function:

Here is the caller graph for this function:

ModelRegion * getMyRegion ( const int &  rLevel = 2)

Definition at line 449 of file Pixel.cpp.

Referenced by getMultiplier().

449  {
450  if(rLevel==2){
451  return l2region;
452  } else if (rLevel==1) {
453  return l2region->getParent();
454  } else {
455  msgOut(MSG_ERROR, "Requested a unknown level region code in getMyRegion().");
456  }
457 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
ModelRegion * l2region
Pointer to level 2 region where this pixel is.
Definition: Pixel.h:157
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
ModelRegion * getParent()
Definition: ModelRegion.h:72

Here is the call graph for this function:

Here is the caller graph for this function:

double getPastRegArea ( const int &  ft_idx,
const int &  year 
)

Definition at line 390 of file Pixel.cpp.

Referenced by ModelCoreSpatial::runBiologicalModule().

390  {
391  map <int,vector<double> >::const_iterator i=regArea.find(year);
392  if(i != regArea.end()) {
393  return i->second.at(ft_idx);
394  } else {
395  msgOut(MSG_ERROR, "Asking for a pastRegArea of a not-registered year. I don't have year "+i2s(year)+"!");
396  }
397 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
map< int, vector< double > > regArea
Definition: Pixel.h:114

Here is the call graph for this function:

Here is the caller graph for this function:

double getPathMortality ( const string &  forType,
const string &  dC,
int  year = DATA_NOW 
)

Return the INCREASED mortality due to pathogen presence for a given ft and dc in a certain year (default the running year)

The mortality returned is the increased yearly mortality due to any affecting pathogenes. The function load the relevant pathogen mortality rule(s), for each of them check for how many years the phatogen is present with concentrations above the threshold and returns the relavant increase in mortality (summing them in case of multiple pathogens).

Definition at line 329 of file Pixel.cpp.

Referenced by ModelCoreSpatial::cachePixelExogenousData(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::runManagementModule(), and ModelCoreSpatial::sumRegionalForData().

329  {
330  if(!MTHREAD->MD->getBoolSetting("usePathogenModule")) return 0.0;
331 
332  string debug=forType;
333  int initialOptYear = MTHREAD->MD->getIntSetting("initialOptYear");
334  int simulationYears = MTHREAD->MD->getIntSetting("simulationYears");
335 
336  int maxYear = initialOptYear + simulationYears;
337 
338  vector<pathRule*> pathRules = MTHREAD->MD->getPathMortalityRule(forType,dC);
339 
340  double pathMort = 0.0;
341  if(year==DATA_NOW){year = MTHREAD->SCD->getYear();}
342 
343  for(uint r=0;r<pathRules.size();r++){
344  string pathId=pathRules[r]->pathId;
345  double pres_min=pathRules[r]->pres_min;
346  vector<double> mortCoefficients=pathRules[r]->mortCoefficents;
347  double pathMort_thispath = 0.0;
348  for(uint y=year;y>(year-mortCoefficients.size());y--){
349  int i =year-y;
350  int y2 = y;
351  if(y>=maxYear){
352  y2=maxYear-1;
353  }
354 
355  string layerName="pathogen_pp#"+pathId+"#"+i2s(y2);
356  if(MTHREAD->GIS->layerExist(layerName)){
357  if (this->getDoubleValue(layerName,true)>= pres_min){
358  pathMort_thispath = mortCoefficients[i];
359  }
360  }
361  }
362  pathMort += pathMort_thispath;
363  }
364  return pathMort;
365 
366 }
The required data is for the current year.
Definition: BaseClass.h:73
int getIntSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1105
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
Forest types (struct)
Definition: ModelData.h:293
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
bool layerExist(const string &layerName_h, bool exactMatch=true) const
Return a pointer to a layer given its name.
Definition: Gis.cpp:552
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
vector< pathRule * > getPathMortalityRule(const string &forType, const string &dC)
Return the pathogen mortality rule(s) associated with a given ft and dc (plural as more than a single...
Definition: ModelData.cpp:2034
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
Definition: Pixel.cpp:158
int getYear()
Definition: Scheduler.h:49

Here is the call graph for this function:

Here is the caller graph for this function:

vector< Pixel * > getPixelsAtDistLevel ( int  distLevel_h) const

Return a vector of pixels at the specified distance (in levels, not in physical units)

The function return a vector of pointers to Pixels at the gived distance from the caller pixel.\ The list start with those on the Top, then add those on the right, those on the bottom and those on the left. Finally it had the corner pixels (that are more far).\ It takes into consideration borders correctly.

Fully tested on internal points as well semi-border cases, border cases and corner cases. ALL OK.

Parameters
distLevel_hDistance in number of adiacent pixels. It has to be at least 1 (the function return an error if it is 0).

Definition at line 53 of file Pixel.cpp.

53  {
54 
55  if (distLevel_h<1) {
56  msgOut(MSG_CRITICAL_ERROR, "getPixelsAtDistLevel() is defined for distances of at least 1 !");
57  }
58 
59  vector <Pixel *> toReturn;
60  int xNPixels = MTHREAD->GIS->getXNPixels();
61  int yNPixels = MTHREAD->GIS->getYNPixels();
62  int thisX = this->getX();
63  int thisY = this->getY();
64  int minX = max(0 , (thisX - distLevel_h)+1);
65  int maxX = min(xNPixels , thisX + distLevel_h);
66  int minY = max(0 , (thisY - distLevel_h)+1);
67  int maxY = min(yNPixels , thisY + distLevel_h);
68 
69  // getting the top pixels (corner exluded)...
70  if (thisY-distLevel_h >=0){
71  for(int i=minX;i<maxX;i++){
72  toReturn.push_back(MTHREAD->GIS->getPixel(i,thisY-distLevel_h));
73  }
74  }
75  // getting the right pixels (corner exluded)...
76  if (thisX+distLevel_h < xNPixels){
77  for(int i=minY;i<maxY;i++){
78  toReturn.push_back(MTHREAD->GIS->getPixel(thisX+distLevel_h,i));
79  }
80  }
81  // getting the bottom pixels (corner exluded)...
82  if (thisY+distLevel_h < yNPixels){
83  for(int i=minX;i<maxX;i++){
84  toReturn.push_back(MTHREAD->GIS->getPixel(i,thisY+distLevel_h));
85  }
86  }
87  // getting the left pixels (corner exluded)...
88  if (thisX-distLevel_h >= 0){
89  for(int i=minY;i<maxY;i++){
90  toReturn.push_back(MTHREAD->GIS->getPixel(thisX-distLevel_h,i));
91  }
92  }
93 
94  // getting the corners (correctly at the end, after already retrieved the other pixels..)...
95  // top-left..
96  if (thisX-distLevel_h >= 0 && thisY-distLevel_h >=0){
97  toReturn.push_back(MTHREAD->GIS->getPixel(thisX-distLevel_h,thisY-distLevel_h));
98  }
99  // top-right..
100  if (thisX+distLevel_h < xNPixels && thisY-distLevel_h >=0){
101  toReturn.push_back(MTHREAD->GIS->getPixel(thisX+distLevel_h,thisY-distLevel_h));
102  }
103  // bottom-right..
104  if (thisX+distLevel_h < xNPixels && thisY+distLevel_h <yNPixels){ // bug discovered 20070719
105  toReturn.push_back(MTHREAD->GIS->getPixel(thisX+distLevel_h,thisY+distLevel_h));
106  }
107  // bottom-left..
108  if (thisX-distLevel_h >= 0 && thisY+distLevel_h <yNPixels){
109  toReturn.push_back(MTHREAD->GIS->getPixel(thisX-distLevel_h,thisY+distLevel_h));
110  }
111  return toReturn;
112 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
int getX() const
Definition: Pixel.h:68
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Gis * GIS
GIS information and methods.
Definition: ThreadManager.h:73
int getYNPixels() const
Return the number of pixels on X.
Definition: Gis.h:130
Print an error message and stop the model.
Definition: BaseClass.h:62
Pixel * getPixel(int x_h, int y_h)
Definition: Gis.h:134
int getXNPixels() const
Definition: Gis.h:129
int getY() const
Definition: Pixel.h:69

Here is the call graph for this function:

string getPxComments ( ) const
inline

Definition at line 73 of file Pixel.h.

73 {return pxComments;};
string pxComments
Definition: Pixel.h:154
double getSpModifier ( const string &  ft)

Definition at line 437 of file Pixel.cpp.

Referenced by getMultiplier().

437  {
438  vector<string>ftypes = MTHREAD->MD->getForTypeIds();
439  for (int i=0;i<ftypes.size();i++){
440  if (ftypes[i] == ft){
441  return spMods.at(i);
442  }
443  }
444  msgOut(MSG_CRITICAL_ERROR,"Asked spatial modifier for a forest type that doesn't exist");
445 
446 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
vector< double > spMods
The sampled spatial modifiers (by forest type)
Definition: Pixel.h:156
vector< string > getForTypeIds(bool all=false)
By default it doesn&#39;t return forTypes used only as input.
Definition: ModelData.cpp:430

Here is the call graph for this function:

Here is the caller graph for this function:

double getSTData ( const string &  parName,
const string &  forName,
int  year,
const string &  d2 = "",
double  naToReturn = RETNA 
)

getSTData() (standing for "get spatial temporal data") returns the value memorized in a spatial layer whose name follows the above convention

parName::fType::dimension2::year

It queries the layer framework with the following logic:

Parameters
parNameParameter name (exact match)
forNameForest type (exact match or look for "")
yearYear (exact match or look for the highest lower value). Accept enum DATA_NOW
d2Optional dimension (exact match or look for "", string. Default = "")
naToReturnOptional value to return if no match (default to secnario-specific novalue)

Definition at line 246 of file Pixel.cpp.

Referenced by ModelCoreSpatial::cachePixelExogenousData(), ModelCoreSpatial::computeCumulativeData(), and getMultiplier().

246  {
247 
248  double defaultNoValue = MTHREAD->MD->getDoubleSetting("noValue");
249  if (naToReturn == RETNA) naToReturn = defaultNoValue;
250 
251  // return NA if not using pixel mode
252  if(!MTHREAD->MD->getBoolSetting("usePixelData")) return naToReturn;
253 
254  // If year is DATA_NOW get current year
255  if (year == DATA_NOW) year = MTHREAD->SCD->getYear();
256 
257  // Looking for an exact match in forName
258  string search_for = parName+"#"+forName+"#"+d2+"#"+i2s(year);
259  map <string,double>::const_iterator i = values.upper_bound(search_for); //return the position always upper to the found one, even if it's an equal match.
260  if(i!= values.begin()) i--; // this rewind the position to the one just before or equal
261  const string& key = i->first;
262  string search_base = search_for.substr(0,search_for.size()-4);
263  if (key.compare(0, search_base.size(), search_base) == 0){
264  //cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
265  //if(i->second != 1){
266  // cout << "NOT ONE: " << search_for <<", "<< i->first << ", " << i->second << endl;
267  // exit(0);
268  //}
269  return i->second == defaultNoValue ? naToReturn : i->second;
270  } else {
271  // An exact match in forName has not being found, look for no forName:
272  string search_for2 = parName+"#"+"#"+d2+"#"+i2s(year);
273  map <string,double>::const_iterator i2 = values.upper_bound(search_for2); //return the position always upper to the found one, even if it's an equal match.
274  if(i2!= values.begin()) i2--; // this rewind the position to the one just before or equal
275  const string& key2 = i2->first;
276  string search_base2 = search_for2.substr(0,search_for2.size()-4);
277  if (key2.compare(0, search_base2.size(), search_base2) == 0){
278  //cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
279  //if(i->second != 1){
280  // cout << "NOT ONE: " << search_for <<", "<< i->first << ", " << i->second << endl;
281  // exit(0);
282  //}
283  return i2->second == defaultNoValue ? naToReturn : i2->second;
284  } else {
285  // An exact match in forName or noforName has not being found, look for no dc:
286  string search_for2 = parName+"#"+forName+"#"+"#"+i2s(year);
287  map <string,double>::const_iterator i2 = values.upper_bound(search_for2); //return the position always upper to the found one, even if it's an equal match.
288  if(i2!= values.begin()) i2--; // this rewind the position to the one just before or equal
289  const string& key2 = i2->first;
290  string search_base2 = search_for2.substr(0,search_for2.size()-4);
291  if (key2.compare(0, search_base2.size(), search_base2) == 0){
292  //cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
293  //if(i->second != 1){
294  // cout << "NOT ONE: " << search_for <<", "<< i->first << ", " << i->second << endl;
295  // exit(0);
296  //}
297  return i2->second == defaultNoValue ? naToReturn : i2->second;
298  } else {
299  // An exact match, or partial match in forName or dc alones has not being found, look for no forName AND no dc:
300  string search_for2 = parName+"#"+"#"+"#"+i2s(year);
301  map <string,double>::const_iterator i2 = values.upper_bound(search_for2); //return the position always upper to the found one, even if it's an equal match.
302  if(i2!= values.begin()) i2--; // this rewind the position to the one just before or equal
303  const string& key2 = i2->first;
304  string search_base2 = search_for2.substr(0,search_for2.size()-4);
305  if (key2.compare(0, search_base2.size(), search_base2) == 0){
306  //cout << "MATCH: " << search_for <<", "<< i->first << ", " << i->second << endl;
307  //if(i->second != 1){
308  // cout << "NOT ONE: " << search_for <<", "<< i->first << ", " << i->second << endl;
309  // exit(0);
310  //}
311  return i2->second == defaultNoValue ? naToReturn : i2->second;
312  } else {
313  //cout << "NOTM: " << search_for <<", "<< i->first << endl;
314  return naToReturn;
315  }
316  }
317  }
318  }
319 }
The required data is for the current year.
Definition: BaseClass.h:73
bool getBoolSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1117
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Scheduler * SCD
the scheduler object (simulation-loops scheduler)
Definition: ThreadManager.h:75
int getYear()
Definition: Scheduler.h:49
Request the (scenario specific) NO VALUE to be returned.
Definition: BaseClass.h:79
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:149
double getDoubleSetting(const string &name_h, int position=0, int reg=WORLD) const
Definition: ModelData.cpp:1109

Here is the call graph for this function:

Here is the caller graph for this function:

int getX ( ) const
inline

Definition at line 68 of file Pixel.h.

Referenced by ThreadManager::computeQuery(), Gis::getDistance(), getDoubleValue(), getPixelsAtDistLevel(), and Output::printDebugPixelValues().

68 {return pxX;} ;
int pxX
Definition: Pixel.h:152

Here is the caller graph for this function:

int getY ( ) const
inline

Definition at line 69 of file Pixel.h.

Referenced by ThreadManager::computeQuery(), Gis::getDistance(), getDoubleValue(), getPixelsAtDistLevel(), and Output::printDebugPixelValues().

69 {return pxY;};
int pxY
Definition: Pixel.h:153

Here is the caller graph for this function:

void newYear ( )

Definition at line 385 of file Pixel.cpp.

Referenced by Scheduler::run().

385  {
386 
387 }

Here is the caller graph for this function:

void setCachedDouble ( double  cachedDouble_h)
inline

Definition at line 85 of file Pixel.h.

85 {cachedDouble=cachedDouble_h;};
double cachedDouble
Cachable double used in some optimized algorithms.
Definition: Pixel.h:155
void setCoordinates ( int  x_h,
int  y_h 
)
inline

Definition at line 83 of file Pixel.h.

Referenced by Gis::setSpace().

83 {pxX=x_h; pxY=y_h;};
int pxX
Definition: Pixel.h:152
int pxY
Definition: Pixel.h:153

Here is the caller graph for this function:

void setMyRegion ( ModelRegion region_h)
inline

Definition at line 90 of file Pixel.h.

Referenced by ModelRegion::setMyPixels().

90 {l2region = region_h;};
ModelRegion * l2region
Pointer to level 2 region where this pixel is.
Definition: Pixel.h:157

Here is the caller graph for this function:

void setPastRegArea ( const double &  value,
const int &  ft_idx,
const int &  year 
)

Definition at line 400 of file Pixel.cpp.

400  {
401  msgOut(MSG_CRITICAL_ERROR,"TODO");
402  /*map <int,vector<double> >::const_iterator i=regArea.find(year);
403  if(i != regArea.end()) {
404  // we already have this year, let's see if the vector is bif enough
405  int currsize = i->second.size();
406  for(j=0;j<ft_idx-currside;j++){
407 
408  }
409  return i->second.at(ft_idx);
410  } else {
411  // new year
412  }
413 
414 
415  pair<int,vector<double> newRegArea;
416  */
417 
418 
419 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62

Here is the call graph for this function:

void setPxComments ( std::string  pxComments_h)
inline

Definition at line 84 of file Pixel.h.

84 {pxComments = pxComments_h;};
string pxComments
Definition: Pixel.h:154
void setSpModifier ( const double &  value,
const int &  ftindex 
)
inline

Definition at line 87 of file Pixel.h.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols().

87 {spMods.at(ftindex)=value;};
vector< double > spMods
The sampled spatial modifiers (by forest type)
Definition: Pixel.h:156

Here is the caller graph for this function:

void setValue ( const string &  layerName_h,
const double &  value_h 
)
inline

Insert a new layer and its value.

Definition at line 78 of file Pixel.h.

78 {values.insert(pair<string, double>(layerName_h, value_h));}
map< string, double > values
Map of values for each layer.
Definition: Pixel.h:149
void swap ( const int &  swap_what)

Assign to the delayed value the current values, e.g. vol_l = vol.

Definition at line 422 of file Pixel.cpp.

Referenced by ModelCoreSpatial::resetPixelValues().

422  {
423  switch (swap_what){
424  case VAR_VOL:
425  vol_l = vol;
426  break;
427  case VAR_AREA:
428  area_l = area;
429  break;
430  default:
431  msgOut(MSG_CRITICAL_ERROR,"Don't know how to swap "+swap_what);
432  }
433 }
vector< vector< double > > area
Definition: Pixel.h:107
vector< vector< double > > vol_l
store the volumes of the previous year
Definition: Pixel.h:128
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
vector< vector< double > > vol
Definition: Pixel.h:90
vector< vector< double > > area_l
store the areas of the previous year
Definition: Pixel.h:129

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

vector<vector <double> > area_l
vector<double> avalCoef

Availability (of wood resources) coefficient. A [0,1] coefficient (new: by forest type) that reduces avaiability of wood resources to exploitation due to local reasons (protected area, altimetry..)

Definition at line 146 of file Pixel.h.

Referenced by ModelCoreSpatial::cachePixelExogenousData(), ModelCoreSpatial::computeInventary(), ModelData::getAvailableAliveTimber(), Pixel(), and ModelCoreSpatial::runBiologicalModule().

double cachedDouble
private

Cachable double used in some optimized algorithms.

Definition at line 155 of file Pixel.h.

vector<vector <double> > cumAlive

Cumulative prob of remaining alive at beginnin of a given diam class.

Definition at line 136 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData(), and ModelCoreSpatial::resetPixelValues().

vector<vector <double> > cumAlive_exp

This is the expected version of cumAlive, used for calculating profits.

Definition at line 139 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::resetPixelValues(), and ModelCoreSpatial::runManagementModule().

vector<vector <double> > cumTp

This is time of passage to REACH a diameter class (while the exogenous tp by diameter class is the time of passage to LEAVE to the next d class). By ft,dc.

Definition at line 134 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::getAvgAgeByDc(), and ModelCoreSpatial::resetPixelValues().

vector<vector <double> > cumTp_exp

This is the expected version of cumTp, used for calculating profits.

Definition at line 137 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::getVHaByYear(), ModelCoreSpatial::resetPixelValues(), and ModelCoreSpatial::runManagementModule().

vector<vector <double> > deltaArea
vector<double> expectedAnnualIncome_carbon
vector<double> expectedAnnualIncome_timber
vector<double> expectedReturnsNotCorrByRa

by ft. Attenction, reported expReturns at "forest" level (compared with those at forest type level) do NOT include ra

Definition at line 126 of file Pixel.h.

Referenced by Output::printDebugPixelValues(), ModelCoreSpatial::runManagementModule(), and ModelCoreSpatial::sumRegionalForData().

double expType

Sampling derived expectation types of this agent (forest bilogical parameters: growth, mortality)

Definition at line 143 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData().

double expTypePrices

Sampling derived expectation types of this agent (prices)

Definition at line 144 of file Pixel.h.

Referenced by ModelCoreSpatial::runManagementModule().

vector<vector <double> > hProductivity
vector< vector <vector <double> > > hVol_byPrd
double ID
private

Definition at line 151 of file Pixel.h.

vector<double> initialDc0Area

Definition at line 109 of file Pixel.h.

Referenced by ModelCoreSpatial::runBiologicalModule().

ModelRegion* l2region
private

Pointer to level 2 region where this pixel is.

Definition at line 157 of file Pixel.h.

Referenced by getMyRegion().

vector<int> optDc
vector<int> optDcChosen
vector<int> optFtChosen
double portfolioVarRa

Sampling derived risk aversion on portfolio variance for of this agent.

Definition at line 142 of file Pixel.h.

string pxComments
private

Definition at line 154 of file Pixel.h.

int pxX
private

Definition at line 152 of file Pixel.h.

int pxY
private

Definition at line 153 of file Pixel.h.

map<int, vector <double> > regArea
vector<double> spMods
private

The sampled spatial modifiers (by forest type)

Definition at line 156 of file Pixel.h.

Referenced by getSpModifier(), and Pixel().

bool usePortfolio

Sampling derived usage of portfolio management (false/true)

Definition at line 145 of file Pixel.h.

map<string, double> values
private

Map of values for each layer.

Definition at line 149 of file Pixel.h.

Referenced by changeValue(), correctInputMultiplier(), getDoubleValue(), and getSTData().

vector<vector <double> > vHa
vector<vector <double> > vHa_exp

This is the expected version of vHa, used for calculating profits.

Definition at line 138 of file Pixel.h.

Referenced by ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::getVHaByYear(), ModelCoreSpatial::resetPixelValues(), and ModelCoreSpatial::runManagementModule().

map<string, double>::const_iterator vIter
mutableprivate

Definition at line 150 of file Pixel.h.

Referenced by getDoubleValue().

vector<vector <double> > vol_l

The documentation for this class was generated from the following files: