ALMaSS Rabbit ODdox  1.1
The rabbit model description following ODdox protocol
PesticideMap Class Reference

#include <pesticide.h>

Public Member Functions

 PesticideMap (int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land, bool a_typeofmap)
 
 ~PesticideMap ()
 
bool DumpPMap (vector< double > *a_map)
 
bool DumpPMapI ()
 
bool DumpPMapH ()
 
bool DumpPMapF ()
 
void Spray (LE *a_element_sprayed, TTypesOfPesticideCategory a_type)
 

Protected Attributes

vector< double > * m_pmap_insecticides
 insecticide map data More...
 
vector< double > * m_pmap_fungicides
 herbicide map data More...
 
vector< double > * m_pmap_herbicides
 fungicide map data More...
 
int m_startyear
 first simultion year to record More...
 
int m_endyear
 last year of data to record More...
 
int m_cellsize
 the size of the cell for pesticide data in m More...
 
int m_pmap_width
 based on cellsize the width of the map More...
 
int m_pmap_height
 based on cellsize the height of the map More...
 
bool m_typeofmap
 true if using test pesticide, false for general pesticides More...
 
Landscapem_OurLandscape
 pointer to the landscape
More...
 
RasterMapm_Rastermap
 pointer to the landscape map More...
 

Detailed Description

Definition at line 369 of file pesticide.h.

Constructor & Destructor Documentation

◆ PesticideMap()

PesticideMap::PesticideMap ( int  a_startyear,
int  a_noyears,
int  a_cellsize,
Landscape a_landscape,
RasterMap a_land,
bool  a_typeofmap 
)

Definition at line 769 of file pesticide.cpp.

770 {
771  m_typeofmap = a_typeofmap;
772  m_startyear = a_startyear;
773  m_endyear = a_startyear + a_noyears;
774  m_cellsize = a_cellsize;
775  m_OurLandscape = a_landscape;
776  m_Rastermap = a_land;
779 
780  // Need to create the grid to fill. This grid is always used.
781  m_pmap_insecticides = new vector<double>;
783  fill(m_pmap_insecticides->begin(), m_pmap_insecticides->end(), 0);
784  ofstream * m_PMap;
785  m_PMap = new ofstream("ALMaSS_InsecticideMap.txt", ios::out);
786  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
787  m_PMap->close();
788  // These two grids are used only if we want all three types recoreded.
789  if (!m_typeofmap)
790  {
791  // We need all three in this case
792  m_pmap_fungicides = new vector<double>;
794  fill(m_pmap_fungicides->begin(), m_pmap_fungicides->end(), 0);
795  m_PMap = new ofstream("ALMaSS_FungicideMap.txt", ios::out);
796  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
797  m_PMap->close();
798  m_pmap_herbicides = new vector<double>;
800  fill(m_pmap_herbicides->begin(), m_pmap_herbicides->end(), 0);
801  m_PMap = new ofstream("ALMaSS_HerbicideMap.txt", ios::out);
802  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
803  m_PMap->close();
804  }
805  else
806  {
807  m_pmap_fungicides = NULL;
808  m_pmap_herbicides = NULL;
809  }
810 }

◆ ~PesticideMap()

PesticideMap::~PesticideMap ( )

Definition at line 812 of file pesticide.cpp.

813 {
814  delete m_pmap_insecticides;
815  if (!m_typeofmap)
816  {
817  // We need all three in this case
818  delete m_pmap_fungicides;
819  delete m_pmap_herbicides;
820 
821  }
822 }

Member Function Documentation

◆ DumpPMap()

bool PesticideMap::DumpPMap ( vector< double > *  a_map)

Definition at line 824 of file pesticide.cpp.

825 {
826  string fname;
827  if (a_map == m_pmap_insecticides) fname = "ALMaSS_InsecticideMap.txt";
828  else if (a_map == m_pmap_fungicides) fname = "ALMaSS_FungicideMap.txt";
829  else fname = "ALMaSS_HerbicideMap.txt";
830  {
831  ofstream* m_PMap = new ofstream(fname.c_str(), ios::app);
832  if (!(*m_PMap).is_open())
833  {
834  g_msg->Warn(WARN_FILE, "PesticideMap::DumpMap Unable to open file for append: ", fname.c_str());
835  exit(1);
836  }
837  // File is OK, save the map
838  (*m_PMap) << "Year " << g_date->GetYear() << "Month " << g_date->GetMonth() << endl;
839  for (int y = 0; y < m_pmap_height; y++)
840  {
841  for (int x = 0; x < m_pmap_width; x++)
842  {
843  (*m_PMap) << (*a_map)[y*m_pmap_width + x] << ' ';
844  }
845  }
846  (*m_PMap) << endl;
847  m_PMap->close();
848  }
849  fill(a_map->begin(), a_map->end(), 0);
850  return true;
851 }

References g_date, g_msg, Calendar::GetMonth(), Calendar::GetYear(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by DumpPMapF(), DumpPMapH(), and DumpPMapI().

◆ DumpPMapF()

bool PesticideMap::DumpPMapF ( )
inline

Definition at line 405 of file pesticide.h.

405 { return DumpPMap(m_pmap_fungicides); }

References DumpPMap(), and m_pmap_fungicides.

◆ DumpPMapH()

bool PesticideMap::DumpPMapH ( )
inline

Definition at line 404 of file pesticide.h.

404 { return DumpPMap(m_pmap_herbicides); }

References DumpPMap(), and m_pmap_herbicides.

◆ DumpPMapI()

bool PesticideMap::DumpPMapI ( )
inline

Definition at line 403 of file pesticide.h.

403 { return DumpPMap(m_pmap_insecticides); }

References DumpPMap(), and m_pmap_insecticides.

◆ Spray()

void PesticideMap::Spray ( LE a_element_sprayed,
TTypesOfPesticideCategory  a_type 
)

This records a 1 in the map for every m2 where pesticide is applied. This does not record drift.

Going through the whole landscape is very slow and unnecessary for small polygons. Since our polygons do not extend beyond the edge of the map ie do not wrap round, then we only need a measure of minx, maxx, miny, maxy. This is set up at the start of the simulation.

This method first determines what type of pesticide and selects the correct map to record on.

Definition at line 854 of file pesticide.cpp.

855 {
867  vector<double>* ourmap = m_pmap_insecticides; ;
868  if (a_type == fungicide) ourmap = m_pmap_fungicides;
869  else if (a_type == herbicide) ourmap = m_pmap_herbicides;
870  int l_large_map_index = a_element_sprayed->GetMapIndex();
871  int minx = a_element_sprayed->GetMinX();
872  int miny = a_element_sprayed->GetMinY();
873  int maxx = a_element_sprayed->GetMaxX();
874  int maxy = a_element_sprayed->GetMaxY();
875  for (int y = miny; y <= maxy; y++) {
876  for (int x = minx; x <= maxx; x++) {
877  if (m_Rastermap->Get(x, y) == l_large_map_index)
878  {
879  // Add one m spray value of 1.0 per m
880  (*ourmap)[(x/m_cellsize)+(y/m_cellsize)*m_pmap_width]++;
881  }
882  }
883  }
884 }

References fungicide, LE::GetMapIndex(), LE::GetMaxX(), LE::GetMaxY(), LE::GetMinX(), LE::GetMinY(), and herbicide.

Member Data Documentation

◆ m_cellsize

int PesticideMap::m_cellsize
protected

the size of the cell for pesticide data in m

Definition at line 387 of file pesticide.h.

◆ m_endyear

int PesticideMap::m_endyear
protected

last year of data to record

Definition at line 385 of file pesticide.h.

◆ m_OurLandscape

Landscape* PesticideMap::m_OurLandscape
protected

pointer to the landscape

Definition at line 395 of file pesticide.h.

◆ m_pmap_fungicides

vector<double>* PesticideMap::m_pmap_fungicides
protected

herbicide map data

Definition at line 379 of file pesticide.h.

Referenced by DumpPMapF().

◆ m_pmap_height

int PesticideMap::m_pmap_height
protected

based on cellsize the height of the map

Definition at line 391 of file pesticide.h.

◆ m_pmap_herbicides

vector<double>* PesticideMap::m_pmap_herbicides
protected

fungicide map data

Definition at line 381 of file pesticide.h.

Referenced by DumpPMapH().

◆ m_pmap_insecticides

vector<double>* PesticideMap::m_pmap_insecticides
protected

insecticide map data

PesticideMap is a class for handling pesticide mapping output. This can be used to sum up pesticide concentrations over time. It works currently for general pesticides split into insecticides, herbicides, and fungicides, but also for the primary test pesticide if one is being used.

Definition at line 377 of file pesticide.h.

Referenced by DumpPMapI().

◆ m_pmap_width

int PesticideMap::m_pmap_width
protected

based on cellsize the width of the map

Definition at line 389 of file pesticide.h.

◆ m_Rastermap

RasterMap* PesticideMap::m_Rastermap
protected

pointer to the landscape map

Definition at line 397 of file pesticide.h.

◆ m_startyear

int PesticideMap::m_startyear
protected

first simultion year to record

Definition at line 383 of file pesticide.h.

◆ m_typeofmap

bool PesticideMap::m_typeofmap
protected

true if using test pesticide, false for general pesticides

Definition at line 393 of file pesticide.h.


The documentation for this class was generated from the following files:
PesticideMap::m_cellsize
int m_cellsize
the size of the cell for pesticide data in m
Definition: pesticide.h:387
LE::GetMinX
int GetMinX(void)
Definition: elements.h:335
Calendar::GetYear
int GetYear(void)
Definition: calendar.h:67
PesticideMap::m_endyear
int m_endyear
last year of data to record
Definition: pesticide.h:385
LE::GetMaxX
int GetMaxX(void)
Definition: elements.h:333
PesticideMap::m_pmap_width
int m_pmap_width
based on cellsize the width of the map
Definition: pesticide.h:389
RasterMap::Get
int Get(int a_x, int a_y)
Definition: rastermap.h:81
fungicide
Definition: landscape.h:63
Calendar::GetMonth
int GetMonth(void)
Definition: calendar.h:69
LE::GetMinY
int GetMinY(void)
Definition: elements.h:336
PesticideMap::m_pmap_fungicides
vector< double > * m_pmap_fungicides
herbicide map data
Definition: pesticide.h:379
herbicide
Definition: landscape.h:63
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
PesticideMap::m_startyear
int m_startyear
first simultion year to record
Definition: pesticide.h:383
PesticideMap::m_Rastermap
RasterMap * m_Rastermap
pointer to the landscape map
Definition: pesticide.h:397
Landscape::SupplySimAreaHeight
int SupplySimAreaHeight(void)
Definition: landscape.h:1637
Landscape::SupplySimAreaWidth
int SupplySimAreaWidth(void)
Definition: landscape.h:1632
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
PesticideMap::m_OurLandscape
Landscape * m_OurLandscape
pointer to the landscape
Definition: pesticide.h:395
PesticideMap::m_pmap_insecticides
vector< double > * m_pmap_insecticides
insecticide map data
Definition: pesticide.h:377
WARN_FILE
Definition: maperrormsg.h:37
PesticideMap::m_typeofmap
bool m_typeofmap
true if using test pesticide, false for general pesticides
Definition: pesticide.h:393
g_date
class Calendar * g_date
Definition: calendar.cpp:38
PesticideMap::DumpPMap
bool DumpPMap(vector< double > *a_map)
Definition: pesticide.cpp:824
LE::GetMaxY
int GetMaxY(void)
Definition: elements.h:334
PesticideMap::m_pmap_height
int m_pmap_height
based on cellsize the height of the map
Definition: pesticide.h:391
PesticideMap::m_pmap_herbicides
vector< double > * m_pmap_herbicides
fungicide map data
Definition: pesticide.h:381
LE::GetMapIndex
int GetMapIndex(void)
Definition: elements.h:190