![]() |
Cell2Fire
A large-scale forest fire simulator.
|
Public Member Functions | |
CSVReader (std::string filename, std::string delm=",") | |
std::vector< std::vector< std::string > > | getData () |
Reads and parses data from a CSV, ASCII or TIFF file into a 2D vector. | |
void | printData (std::vector< std::vector< std::string > > &DF) |
print data contained in 2D vector to console row by row | |
void | parseDF (inputs *df_ptr, std::vector< std::vector< std::string > > &DF, arguments *args_ptr, int NCells) |
Populates an instance of inputs using information contained in a 2D vector. | |
void | parseNDF (std::vector< int > &NFTypes, std::vector< std::vector< std::string > > &DF, int NCells) |
Populates a vector of size NCells with fuel type number per cell. | |
void | parsePROB (std::vector< float > &probabilities, std::vector< std::vector< std::string > > &DF, int NCells) |
Not currently supported. Populates a vector of size NCells with ignition probability per cell. | |
void | parseWeatherDF (weatherDF *wt_ptr, arguments *args_ptr, std::vector< std::vector< std::string > > &DF, int WPeriods) |
copy weather "dataframe" into array Reads a string vector representing a weather data frame (DF ), extracts and converts relevant weather values based on the simulation model selected (Kitral or FBP), and stores them into a weatherDF array. | |
void | parseIgnitionDF (std::vector< int > &ig, std::vector< std::vector< std::string > > &DF, int IgPeriods) |
Parses the ignition data frame and populates ignition cell indices. | |
void | parseForestDF (forestDF *frt_ptr, std::vector< std::vector< std::string > > &DF) |
Parses forest structure and spatial metadata from a data frame and populates a forestDF object. | |
void | parseHarvestedDF (std::unordered_map< int, std::vector< int > > &hc, std::vector< std::vector< std::string > > &DF, int HPeriods) |
Parses harvested cell data and maps them to simulation periods for firebreak designation. | |
void | parseBBODF (std::unordered_map< int, std::vector< float > > &bbo, std::vector< std::vector< std::string > > &DF, int NFTypes) |
Parses a Black Box Optimization (BBO) configuration table for forest fuel types. | |
void | printDF (inputs df) |
Prints input data. | |
void | printWeatherDF (weatherDF wdf) |
Public Attributes | |
std::string | fileName |
std::string | delimeter |
CSVReader::CSVReader | ( | std::string | filename, |
std::string | delm = "," |
||
) |
Creates an instance of CSVReader.
filename | name of file to read |
delm | delimiter of columns in file. |
std::vector< std::vector< std::string > > CSVReader::getData | ( | ) |
Reads and parses data from a CSV, ASCII or TIFF file into a 2D vector.
Checks for the existence of the input file with either a .tif
or .asc
extension and processes it accordingly. If the file is in CSV format, it is read line by line and split using the specified delimiter. If the file is in ASCII format, the function reads the header separately before parsing the data. If the file is in TIFF format, it extracts metadata (e.g., grid dimensions, cell size, and coordinates) and reads raster data row by row.
std::runtime_error | If the file type is unsupported, memory allocation fails, or an error occurs during file reading. |
void CSVReader::parseBBODF | ( | std::unordered_map< int, std::vector< float > > & | bbo, |
std::vector< std::vector< std::string > > & | DF, | ||
int | NFTypes | ||
) |
Parses a Black Box Optimization (BBO) configuration table for forest fuel types.
This function reads a table (data frame) containing BBO tuning factors associated with each forest fuel type. Each row in the table corresponds to a specific fuel type and includes four BBO factors used to guide fire behavior modeling or simulation tuning.
The resulting data structure is an unordered map where the key is the fuel type ID, and the value is a vector of four floating-point BBO factors.
bbo | Output map that will store BBO factors for each fuel type. Key: fuel type ID, Value: vector of BBO factors. |
DF | 2D string vector representing the parsed CSV file (first column: fuel type, next four columns: BBO factors). |
NFTypes | Number of fuel types (i.e., number of rows in the input table, excluding headers). |
void CSVReader::parseDF | ( | inputs * | df_ptr, |
std::vector< std::vector< std::string > > & | DF, | ||
arguments * | args_ptr, | ||
int | NCells | ||
) |
Populates an instance of inputs using information contained in a 2D vector.
Populates the inputs object df_ptr
with the information found in DF
. If no value is provided for a variable, then a default one is used.
df_ptr | pointer to inputs object |
DF | 2D vector with input data |
args_ptr | array of inputted command line arguments |
NCells | number of cells |
void CSVReader::parseForestDF | ( | forestDF * | frt_ptr, |
std::vector< std::vector< std::string > > & | DF | ||
) |
Parses forest structure and spatial metadata from a data frame and populates a forestDF object.
Reads metadata from the input data frame DF
, including the number of columns and rows in the grid, cell size, and lower-left corner coordinates (xllcorner, yllcorner). It uses this information to initialize the geometry of the forest grid.
The function also computes and stores the (x, y) grid coordinates for each cell in row-major order, assuming the origin (0,0) is at the lower-left and that Y increases upwards.
frt_ptr | Pointer to the forestDF structure to populate with parsed metadata and cell coordinates. |
DF | Input data frame containing the forest metadata and layout information. |
Expected DF
format:
void CSVReader::parseHarvestedDF | ( | std::unordered_map< int, std::vector< int > > & | hc, |
std::vector< std::vector< std::string > > & | DF, | ||
int | HPeriods | ||
) |
Parses harvested cell data and maps them to simulation periods for firebreak designation.
Reads a string vector (DF
) containing harvested (firebreak) cell indices and populates an unordered map (hc
), where each key represents a simulation year (starting from 1) and the value is a vector of cell indices harvested in that year. A year is a "fire season".
This data is later used to mark harvested cells as firebreaks by updating their fuel type and status in the simulation (e.g., making them non-burnable).
Assumes the first row of DF
contains headers and skips it. Each subsequent row corresponds to one year, and columns (from index 1 onward) contain harvested cell indices.
hc | Output map linking each year to the list of harvested cell indices. |
DF | Input data frame containing harvested cell information. |
HPeriods | Number of harvest periods to parse (i.e., rows excluding the header). |
void CSVReader::parseIgnitionDF | ( | std::vector< int > & | ig, |
std::vector< std::vector< std::string > > & | DF, | ||
int | IgPeriods | ||
) |
Parses the ignition data frame and populates ignition cell indices.
Reads ignition cell indices from a string vector (DF
) and stores them in the provided integer vector ig
. It assumes the ignition cell index is located in the second column (DF[i][1]
) of each row.
ig | Reference to the vector that will be populated with ignition cell indices. |
DF | String vector representing the input ignition data table. |
IgPeriods | Number of ignition periods (rows) to parse in the data frame. |
void CSVReader::parseNDF | ( | std::vector< int > & | NFTypes, |
std::vector< std::vector< std::string > > & | DF, | ||
int | NCells | ||
) |
Populates a vector of size NCells with fuel type number per cell.
NFTypes | vector of fuel type per cell |
DF | 2D vector of input data |
NCells | number of cells |
void CSVReader::parsePROB | ( | std::vector< float > & | probabilities, |
std::vector< std::vector< std::string > > & | DF, | ||
int | NCells | ||
) |
Not currently supported. Populates a vector of size NCells with ignition probability per cell.
This is not currently supported because ignition probability is not stored in DF
.
probabilities | vector of ignition probability per cell |
DF | 2D vector of input data |
NCells | number of cells |
void CSVReader::parseWeatherDF | ( | weatherDF * | wdf_ptr, |
arguments * | args_ptr, | ||
std::vector< std::vector< std::string > > & | DF, | ||
int | WPeriods | ||
) |
copy weather "dataframe" into array Reads a string vector representing a weather data frame (DF
), extracts and converts relevant weather values based on the simulation model selected (Kitral or FBP), and stores them into a weatherDF
array.
For the Kitral model ("K"), it reads temperature and relative humidity. For the FBP model ("C"), it reads precipitation, temperature, RH, wind speed, wind direction, and FWI components (FFMC, DMC, DC, ISI, BUI, FWI).
Missing or empty fields are defaulted to 0.
wdf_ptr | pointer to the array with weather data to be populated |
args_ptr | pointer to the array of inputted command line arguments, including the simulation model code |
DF | vector of weather data extracted from CSV file |
WPeriods | number of weather periods (rows) |
void CSVReader::printData | ( | std::vector< std::vector< std::string > > & | DF | ) |
print data contained in 2D vector to console row by row
DF | 2D vector of strings |
void CSVReader::printDF | ( | inputs | df | ) |
Prints input data.
df | Structure containing input data. |
void CSVReader::printWeatherDF | ( | weatherDF | wdf | ) |
Prints windspeed and wind direction
wdf | structure with weather data |