Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PesticideMap Class Reference

#include <Pesticide.h>

Inheritance diagram for PesticideMap:
PesticideOutput

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 ()
 
virtual void Spray (LE *a_element_sprayed, TTypesOfPesticideCategory a_type)
 
- Public Member Functions inherited from PesticideOutput
 PesticideOutput (int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land)
 
 ~PesticideOutput ()
 

Protected Attributes

bool m_typeofmap
 true if using test pesticide, false for general pesticides More...
 
- Protected Attributes inherited from PesticideOutput
vector< double > * m_pmap_insecticides
 insecticide map/table data More...
 
vector< double > * m_pmap_fungicides
 herbicide map/table data More...
 
vector< double > * m_pmap_herbicides
 fungicide map/table 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...
 
Landscapem_OurLandscape
 pointer to the landscape
More...
 
RasterMapm_Rastermap
 pointer to the landscape map More...
 

Constructor & Destructor Documentation

◆ PesticideMap()

PesticideMap::PesticideMap ( int  a_startyear,
int  a_noyears,
int  a_cellsize,
Landscape a_landscape,
RasterMap a_land,
bool  a_typeofmap 
)
1786  : PesticideOutput(a_startyear, a_noyears, a_cellsize, a_landscape, a_land)
1787 {
1788  m_typeofmap = a_typeofmap;
1789 
1790  // Need to create the grid to fill. This grid is always used.
1791  m_pmap_insecticides = new vector<double>;
1793  fill(m_pmap_insecticides->begin(), m_pmap_insecticides->end(), 0);
1794  ofstream * m_PMap;
1795  m_PMap = new ofstream("ALMaSS_InsecticideMap.txt", ios::out);
1796  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
1797  m_PMap->close();
1798  // These two grids are used only if we want all three types recoreded.
1799  if (!m_typeofmap)
1800  {
1801  // We need all three in this case
1802  m_pmap_fungicides = new vector<double>;
1804  fill(m_pmap_fungicides->begin(), m_pmap_fungicides->end(), 0);
1805  m_PMap = new ofstream("ALMaSS_FungicideMap.txt", ios::out);
1806  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
1807  m_PMap->close();
1808  m_pmap_herbicides = new vector<double>;
1810  fill(m_pmap_herbicides->begin(), m_pmap_herbicides->end(), 0);
1811  m_PMap = new ofstream("ALMaSS_HerbicideMap.txt", ios::out);
1812  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
1813  m_PMap->close();
1814  }
1815  else
1816  {
1817  m_pmap_fungicides = NULL;
1818  m_pmap_herbicides = NULL;
1819  }
1820 }

References PesticideOutput::m_pmap_fungicides, PesticideOutput::m_pmap_height, PesticideOutput::m_pmap_herbicides, PesticideOutput::m_pmap_insecticides, PesticideOutput::m_pmap_width, and m_typeofmap.

◆ ~PesticideMap()

PesticideMap::~PesticideMap ( )
1823 {
1824  delete m_pmap_insecticides;
1825  if (!m_typeofmap)
1826  {
1827  // We need all three in this case
1828  delete m_pmap_fungicides;
1829  delete m_pmap_herbicides;
1830 
1831  }
1832 }

References PesticideOutput::m_pmap_fungicides, PesticideOutput::m_pmap_herbicides, PesticideOutput::m_pmap_insecticides, and m_typeofmap.

Member Function Documentation

◆ DumpPMap()

bool PesticideMap::DumpPMap ( vector< double > *  a_map)
1835 {
1836  string fname;
1837  if (a_map == m_pmap_insecticides) fname = "ALMaSS_InsecticideMap.txt";
1838  else if (a_map == m_pmap_fungicides) fname = "ALMaSS_FungicideMap.txt";
1839  else fname = "ALMaSS_HerbicideMap.txt";
1840  {
1841  ofstream* m_PMap = new ofstream(fname.c_str(), ios::app);
1842  if (!(*m_PMap).is_open())
1843  {
1844  g_msg->Warn(WARN_FILE, "PesticideMap::DumpMap Unable to open file for append: ", fname.c_str());
1845  exit(1);
1846  }
1847  // File is OK, save the map
1848  (*m_PMap) << "Year " << g_date->GetYear() << "Month " << g_date->GetMonth() << endl;
1849  for (int y = 0; y < m_pmap_height; y++)
1850  {
1851  for (int x = 0; x < m_pmap_width; x++)
1852  {
1853  (*m_PMap) << (*a_map)[y * m_pmap_width + x] << ' ';
1854  }
1855  }
1856  (*m_PMap) << endl;
1857  m_PMap->close();
1858  }
1859  fill(a_map->begin(), a_map->end(), 0);
1860  return true;
1861 }

References g_date, g_msg, Calendar::GetMonth(), Calendar::GetYear(), PesticideOutput::m_pmap_fungicides, PesticideOutput::m_pmap_height, PesticideOutput::m_pmap_insecticides, PesticideOutput::m_pmap_width, MapErrorMsg::Warn(), and WARN_FILE.

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

◆ DumpPMapF()

bool PesticideMap::DumpPMapF ( )
inline

◆ DumpPMapH()

bool PesticideMap::DumpPMapH ( )
inline

◆ DumpPMapI()

bool PesticideMap::DumpPMapI ( )
inline

◆ Spray()

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

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.

Reimplemented from PesticideOutput.

1864 {
1876  vector<double>* ourmap = m_pmap_insecticides; ;
1877  if (a_type == fungicide) ourmap = m_pmap_fungicides;
1878  else if (a_type == herbicide) ourmap = m_pmap_herbicides;
1879  int l_large_map_index = a_element_sprayed->GetMapIndex();
1880  int minx = a_element_sprayed->GetMinX();
1881  int miny = a_element_sprayed->GetMinY();
1882  int maxx = a_element_sprayed->GetMaxX();
1883  int maxy = a_element_sprayed->GetMaxY();
1884  for (int y = miny; y <= maxy; y++) {
1885  for (int x = minx; x <= maxx; x++) {
1886  if (m_Rastermap->Get(x, y) == l_large_map_index)
1887  {
1888  // Add one m spray value of 1.0 per m
1889  (*ourmap)[(x / m_cellsize) + (y / m_cellsize) * m_pmap_width]++;
1890  }
1891  }
1892  }
1893 }

References fungicide, RasterMap::Get(), LE::GetMapIndex(), LE::GetMaxX(), LE::GetMaxY(), LE::GetMinX(), LE::GetMinY(), herbicide, PesticideOutput::m_cellsize, PesticideOutput::m_pmap_fungicides, PesticideOutput::m_pmap_herbicides, PesticideOutput::m_pmap_insecticides, PesticideOutput::m_pmap_width, and PesticideOutput::m_Rastermap.

Member Data Documentation

◆ m_typeofmap

bool PesticideMap::m_typeofmap
protected

true if using test pesticide, false for general pesticides

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.

Referenced by PesticideMap(), and ~PesticideMap().


The documentation for this class was generated from the following files:
PesticideOutput::m_cellsize
int m_cellsize
the size of the cell for pesticide data in m
Definition: Pesticide.h:764
PesticideOutput::m_Rastermap
RasterMap * m_Rastermap
pointer to the landscape map
Definition: Pesticide.h:772
LE::GetMinX
int GetMinX(void)
Definition: Elements.h:399
WARN_FILE
Definition: MapErrorMsg.h:37
Calendar::GetYear
int GetYear(void)
Definition: Calendar.h:71
LE::GetMaxX
int GetMaxX(void)
Definition: Elements.h:397
RasterMap::Get
int Get(int a_x, int a_y)
Definition: Rastermap.h:82
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Calendar::GetMonth
int GetMonth(void)
Definition: Calendar.h:73
LE::GetMinY
int GetMinY(void)
Definition: Elements.h:400
PesticideOutput::m_pmap_width
int m_pmap_width
based on cellsize the width of the map
Definition: Pesticide.h:766
PesticideOutput::m_pmap_insecticides
vector< double > * m_pmap_insecticides
insecticide map/table data
Definition: Pesticide.h:754
fungicide
Definition: LandscapeFarmingEnums.h:1050
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
herbicide
Definition: LandscapeFarmingEnums.h:1050
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
PesticideMap::m_typeofmap
bool m_typeofmap
true if using test pesticide, false for general pesticides
Definition: Pesticide.h:812
PesticideOutput::m_pmap_height
int m_pmap_height
based on cellsize the height of the map
Definition: Pesticide.h:768
PesticideOutput::m_pmap_herbicides
vector< double > * m_pmap_herbicides
fungicide map/table data
Definition: Pesticide.h:758
PesticideOutput::PesticideOutput
PesticideOutput(int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land)
Definition: Pesticide.cpp:1774
PesticideOutput::m_pmap_fungicides
vector< double > * m_pmap_fungicides
herbicide map/table data
Definition: Pesticide.h:756
PesticideMap::DumpPMap
bool DumpPMap(vector< double > *a_map)
Definition: Pesticide.cpp:1834
LE::GetMaxY
int GetMaxY(void)
Definition: Elements.h:398
LE::GetMapIndex
int GetMapIndex(void)
Definition: Elements.h:239