Cell2Fire
A large-scale forest fire simulator.
Loading...
Searching...
No Matches
DataGenerator.cpp File Reference
#include "DataGenerator.h"
#include "tiffio.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <limits>
#include <memory>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
Include dependency graph for DataGenerator.cpp:

Functions

char separator ()
 
std::tuple< std::unordered_map< std::string, std::string >, std::unordered_map< std::string, std::tuple< float, float, float, float > > > Dictionary (const std::string &filename)
 Reads the model lookup table and creates dictionaries for the fuel types and cell's ColorsDict.
 
std::tuple< std::vector< int >, std::vector< std::string >, int, int, float > ForestGrid (const std::string &filename, const std::unordered_map< std::string, std::string > &Dictionary)
 Reads fuels from ASCII raster file and creates a list of cells.
 
bool fileExists (const std::string &filename)
 checks if a file exists.
 
void DataGrids (const std::string &filename, std::vector< float > &data, int nCells)
 Read grid data from ASCII file into a vector.
 
std::tuple< std::vector< int >, std::vector< std::string >, int, int, float > ForestGridTif (const std::string &filename, const std::unordered_map< std::string, std::string > &Dictionary)
 Reads fuels raster file in tif format and creates a list of cells.
 
void DataGridsTif (const std::string &filename, std::vector< float > &data, int nCells)
 This functionality is not currently available.
 
std::vector< std::vector< std::unique_ptr< std::string > > > GenerateDat (const std::vector< std::string > &GFuelType, const std::vector< int > &GFuelTypeN, const std::vector< float > &Elevation, const std::vector< float > &PS, const std::vector< float > &SAZ, const std::vector< float > &Curing, const std::vector< float > &CBD, const std::vector< float > &CBH, const std::vector< float > &CCF, const std::vector< float > &PY, const std::vector< float > &FMC, const std::vector< float > &TreeHeight, const std::string &InFolder)
 Create input data matrix.
 
void writeDataToFile (const std::vector< std::vector< std::unique_ptr< std::string > > > &dataGrids, const std::string &InFolder)
 Save data matrix into a CSV file called Data.csv.
 
void GenDataFile (const std::string &InFolder, const std::string &Simulator)
 Reads all available input raster files and generates a new file called 'Data.csv' in which each row contains the input data for a cell.
 

Function Documentation

◆ DataGrids()

void DataGrids ( const std::string &  filename,
std::vector< float > &  data,
int  nCells 
)

Read grid data from ASCII file into a vector.

Transforms a raster layer into an array of information.

Parameters
filenamename of file to read
datavector where information will be stored
nCellsnumber of cells
Here is the caller graph for this function:

◆ DataGridsTif()

void DataGridsTif ( const std::string &  filename,
std::vector< float > &  data,
int  nCells 
)

This functionality is not currently available.

Read grid data from Tif file into a vector. Transforms a raster layer into an array of information.

Parameters
filenamename of file to read
datavector where information will be stored
nCellsnumber of cells

◆ Dictionary()

std::tuple< std::unordered_map< std::string, std::string >, std::unordered_map< std::string, std::tuple< float, float, float, float > > > Dictionary ( const std::string &  filename)

Reads the model lookup table and creates dictionaries for the fuel types and cell's ColorsDict.

The function will look for either spain_lookup_table.csv, kitral_lookup_table.csv or fbp_lookup_table.csv in the input instance directory, depending on the chosen model.

This file should have the following columns:

  • grid_value: numeric id for fuel type within grid
  • export_value: numeric id for fuel type
  • descriptive_name: description of fuel type
  • fuel_type: code for fuel type
  • r: red
  • g: green
  • b: blue
  • h: hue
  • s: saturation
  • l: lightness

The function creates a fuel type map <grid_value, fuel_type> and a color map <grid_value, r, g, b, 1.0>

Parameters
filenameName of file containing the lookup table for the chosen simulation model
Returns
a tuple with a mapping of fuel code per fuel numeric id, and a mapping of color per fuel numeric id.
Here is the caller graph for this function:

◆ fileExists()

bool fileExists ( const std::string &  filename)

checks if a file exists.

Parameters
filenameName of file
Returns
True if file can be opened, False if not.
Here is the caller graph for this function:

◆ ForestGrid()

std::tuple< std::vector< int >, std::vector< std::string >, int, int, float > ForestGrid ( const std::string &  filename,
const std::unordered_map< std::string, std::string > &  Dictionary 
)

Reads fuels from ASCII raster file and creates a list of cells.

Parameters
filenameName of file containing raster of fuel type per cell
DictionaryMap of fuel numeric ID in raster grid to fuel model code.
Returns
A tuple with an array of the cells' fuel type numeric ID and an array of the cells' fuel type code, the number of rows, the number of columns and the size of a cell.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForestGridTif()

std::tuple< std::vector< int >, std::vector< std::string >, int, int, float > ForestGridTif ( const std::string &  filename,
const std::unordered_map< std::string, std::string > &  Dictionary 
)

Reads fuels raster file in tif format and creates a list of cells.

Parameters
filenameName of fuel data file.
DictionaryMapping of fuel type numeric ID to fuel type code.
Returns
A tuple containing: vector of fuel type per cell as numeric ID, vector of fuel type per cell as model code, number of rows in grid, number of columns in grid, cell size.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenDataFile()

void GenDataFile ( const std::string &  InFolder,
const std::string &  Simulator 
)

Reads all available input raster files and generates a new file called 'Data.csv' in which each row contains the input data for a cell.

If the 'fuels' raster file is in tif format, then it assumes all other rasters are also in that format. Otherwise, it assumes ascii format.

The function looks for the following files in InFolder:

  • elevation: terrain elevation [m]
  • saz: slope azimuth
  • slope: terrain slope
  • cur: curing level
  • cbd: canopy bulk density [km/m²]
  • cbh: canopy base height [m]
  • ccf: canopy cover fraction
  • py: ignition probability map [%]
  • fmc: foliage moisture content
  • hm: tree height [m]

The generated file contains the following columns: fuel type, latitude, longitude, elevation, wind speed (always blank), wind direction (always blank), slope, slope azimuth, curing level, canopy bulk density, canopy base height, canopy cover fraction, fuel type number ,foliage moisture content, ignition probability.

Parameters
InFolderInput data directory
SimulatorSimulation model code
Here is the call graph for this function:

◆ GenerateDat()

std::vector< std::vector< std::unique_ptr< std::string > > > GenerateDat ( const std::vector< std::string > &  GFuelType,
const std::vector< int > &  GFuelTypeN,
const std::vector< float > &  Elevation,
const std::vector< float > &  PS,
const std::vector< float > &  SAZ,
const std::vector< float > &  Curing,
const std::vector< float > &  CBD,
const std::vector< float > &  CBH,
const std::vector< float > &  CCF,
const std::vector< float > &  PY,
const std::vector< float > &  FMC,
const std::vector< float > &  TreeHeight,
const std::string &  InFolder 
)

Create input data matrix.

Parameters
GFuelTypeArray of fuel model codes
GFuelTypeNArray of fuel model ids
ElevationArray of terrain elevations
PSArray of slope
SAZArray of slope azimuth
CuringArray of curing levels
CBDArray of canopy bulk densities
CBHArray of canopy base heights
CCFArray of canopy cover fractions
PYArray of ignition probabilities
FMCArray of foliage moisture content
TreeHeightArray of tree heights
InFolderInput data directory
Returns
An array of arrays representing a cell.
Here is the caller graph for this function:

◆ writeDataToFile()

void writeDataToFile ( const std::vector< std::vector< std::unique_ptr< std::string > > > &  dataGrids,
const std::string &  InFolder 
)

Save data matrix into a CSV file called Data.csv.

Parameters
dataGridsArray of arrays storing each cell's input data
InFolderDirectory where the CSV file will be created.
Here is the caller graph for this function: