Cell2Fire
A large-scale forest fire simulator.
Loading...
Searching...
No Matches
CSVReader Class Reference

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
 

Constructor & Destructor Documentation

◆ CSVReader()

CSVReader::CSVReader ( std::string  filename,
std::string  delm = "," 
)

Creates an instance of CSVReader.

Parameters
filenamename of file to read
delmdelimiter of columns in file.

Member Function Documentation

◆ getData()

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.

Returns
A 2D vector of strings containing the parsed data.
  • For ASC and CSV files, each row is stored as a vector of strings.
  • For TIFF files, metadata is stored in the first few rows, followed by pixel values.
Exceptions
std::runtime_errorIf the file type is unsupported, memory allocation fails, or an error occurs during file reading.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseBBODF()

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.

Parameters
bboOutput map that will store BBO factors for each fuel type. Key: fuel type ID, Value: vector of BBO factors.
DF2D string vector representing the parsed CSV file (first column: fuel type, next four columns: BBO factors).
NFTypesNumber of fuel types (i.e., number of rows in the input table, excluding headers).
Here is the caller graph for this function:

◆ parseDF()

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.

Parameters
df_ptrpointer to inputs object
DF2D vector with input data
args_ptrarray of inputted command line arguments
NCellsnumber of cells
Here is the caller graph for this function:

◆ parseForestDF()

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.

Parameters
frt_ptrPointer to the forestDF structure to populate with parsed metadata and cell coordinates.
DFInput data frame containing the forest metadata and layout information.

Expected DF format:

  • Row 0: ["ncols", <int>]
  • Row 1: ["nrows", <int>]
  • Row 2: ["xllcorner", <double>]
  • Row 3: ["yllcorner", <double>]
  • Row 4: ["cellsize", <int>]
  • Rows 5+: Actual cell data (not parsed in this function).
Here is the caller graph for this function:

◆ parseHarvestedDF()

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.

Parameters
hcOutput map linking each year to the list of harvested cell indices.
DFInput data frame containing harvested cell information.
HPeriodsNumber of harvest periods to parse (i.e., rows excluding the header).
Here is the caller graph for this function:

◆ parseIgnitionDF()

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.

Parameters
igReference to the vector that will be populated with ignition cell indices.
DFString vector representing the input ignition data table.
IgPeriodsNumber of ignition periods (rows) to parse in the data frame.
Here is the caller graph for this function:

◆ parseNDF()

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.

Parameters
NFTypesvector of fuel type per cell
DF2D vector of input data
NCellsnumber of cells
Here is the caller graph for this function:

◆ parsePROB()

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.

Parameters
probabilitiesvector of ignition probability per cell
DF2D vector of input data
NCellsnumber of cells
Here is the caller graph for this function:

◆ parseWeatherDF()

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.

Parameters
wdf_ptrpointer to the array with weather data to be populated
args_ptrpointer to the array of inputted command line arguments, including the simulation model code
DFvector of weather data extracted from CSV file
WPeriodsnumber of weather periods (rows)
Here is the caller graph for this function:

◆ printData()

void CSVReader::printData ( std::vector< std::vector< std::string > > &  DF)

print data contained in 2D vector to console row by row

Parameters
DF2D vector of strings
Here is the caller graph for this function:

◆ printDF()

void CSVReader::printDF ( inputs  df)

Prints input data.

Parameters
dfStructure containing input data.

◆ printWeatherDF()

void CSVReader::printWeatherDF ( weatherDF  wdf)

Prints windspeed and wind direction

Parameters
wdfstructure with weather data
Here is the caller graph for this function:

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