Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion Cell2Fire/Cell2Fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ inputs* df;
int currentSim = 0;
std::unordered_map<int, std::vector<float>> BBOFactors;
std::unordered_map<int, std::vector<int>> HarvestedCells;
std::vector<float> WeatherWeights;
std::vector<int> WeatherWeightIDs;
std::vector<int> NFTypesCells;
std::unordered_map<int, int> IgnitionHistory;
std::unordered_map<int, std::string> WeatherHistory;
Expand Down Expand Up @@ -218,6 +220,7 @@ Cell2Fire::Cell2Fire(arguments _args) : CSVForest(_args.InFolder + "fuels", " ")
// DEBUG
std::cout << "\n------------------Forest Data ----------------------\n" << std::endl;
std::vector<std::vector<std::string>> FDF = this->CSVForest.getData(_args.InFolder + "fuels");

// DEBUGthis->CSVForest.printData(FDF);
this->CSVForest.parseForestDF(&frdf, FDF);

Expand Down Expand Up @@ -327,6 +330,20 @@ Cell2Fire::Cell2Fire(arguments _args) : CSVForest(_args.InFolder + "fuels", " ")
}
}

/*
if (this->args.UseWeatherWeights)
{
cout << "use weather weights" << endl;
std::string sep = ",";
CSVReader CSVWeatherWeights(this->args.WeatherWeightsFile, sep);

std::vector<std::vector<std::string>> WeatherWeightsDF = CSVWeatherWeights.getData(this->args.WeatherWeightsFile);
cout << "ww df "<< WeatherWeightsDF[0][0] << endl;

CSVWeatherWeights.parseWeatherWeights(WeatherWeights, WeatherWeightIDs, WeatherWeightsDF, this->args.NWeatherFiles);

}*/

// Relevant sets: Initialization
this->availCells.clear();
this->nonBurnableCells.clear();
Expand Down Expand Up @@ -2246,6 +2263,7 @@ Cell2Fire::chooseWeather(const string& weatherOpt, int rnumber, int simExt)
{
// Random Weather
weatherFilename = this->args.InFolder + "Weathers" + separator() + "Weather" + std::to_string(rnumber) + ".csv";

// this->CSVWeather.setFilename(weatherFilename);

/* Weather DataFrame */
Expand Down Expand Up @@ -2336,6 +2354,16 @@ main(int argc, char* argv[])
{
initialize_coeff_p(args.scenario);
}
if (args.UseWeatherWeights)
{
std::string sep = ",";
CSVReader CSVWeatherWeights(args.WeatherWeightsFile, sep);

std::vector<std::vector<std::string>> WeatherWeightsDF = CSVWeatherWeights.getData(args.WeatherWeightsFile);

CSVWeatherWeights.parseWeatherWeights(WeatherWeights, WeatherWeightIDs, WeatherWeightsDF, args.NWeatherFiles);

}
cout << "\n-------Running simulations-------" << endl;
// Parallel zone
#pragma omp parallel num_threads(num_threads)
Expand Down Expand Up @@ -2371,7 +2399,12 @@ main(int argc, char* argv[])
boost::random::uniform_int_distribution<int> udistributionIgnition(1, Forest.nCells);

TID = omp_get_thread_num();
rnumber = udistribution(generator);
if (args.UseWeatherWeights) {
std::discrete_distribution<int> dist(std::begin(WeatherWeights), std::end(WeatherWeights));
int weatherWeightIndex = dist(generator);
rnumber = WeatherWeightIDs[weatherWeightIndex];
} else {
rnumber = udistribution(generator);}
rnumber2 = ndistribution(generator);
// Reset
Forest.reset(rnumber, rnumber2, ep);
Expand Down
16 changes: 16 additions & 0 deletions Cell2Fire/ReadArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ parseArgs(int argc, char* argv[], arguments* args_ptr)
else
input_hplan = &empty;

//--weather-weights
char* weather_weights_file = getCmdOption(argv, argv + argc, "--weather-weights");
if (weather_weights_file)
{
printf("WeatherWeightsFile: %s \n", weather_weights_file);
args_ptr->WeatherWeightsFile = weather_weights_file;
args_ptr->UseWeatherWeights = true;
input_weather = "random";
args_ptr->WeatherOpt = "random";
}
else {
args_ptr->WeatherWeightsFile = &empty;
args_ptr->UseWeatherWeights = false;
}


// Booleans
bool out_messages = false;
bool out_trajectories = false;
Expand Down
4 changes: 2 additions & 2 deletions Cell2Fire/ReadArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
typedef struct
{
std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator;
std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator, WeatherWeightsFile;
bool OutMessages, OutFl, OutIntensity, OutRos, OutCrown, OutCrownConsumption, OutSurfConsumption, Trajectories,
NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS;
NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS, UseWeatherWeights;
float ROSCV, ROSThreshold, CROSThreshold, HFIThreshold, HFactor, FFactor, BFactor, EFactor, FirePeriodLen;
float CBDFactor, CCFFactor, ROS10Factor, CROSActThreshold;
int MinutesPerWP, MaxFirePeriods, TotalYears, TotalSims, NWeatherFiles, IgnitionRadius, seed, nthreads, FMC,
Expand Down
49 changes: 26 additions & 23 deletions Cell2Fire/ReadCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <numeric>
/**
* Creates an instance of CSVReader.
* @param filename name of file to read
Expand Down Expand Up @@ -584,6 +584,31 @@ CSVReader::parseIgnitionDF(std::vector<int>& ig, std::vector<std::vector<std::st
}
}

/*
* Read weather weights
*/
void
CSVReader::parseWeatherWeights(std::vector<float>& WeatherWeights, std::vector<int>& WeatherWeightIDs, std::vector<std::vector<std::string>>& DF, int NumberOfWeatherFiles){
int i;
std::string::size_type sz; // alias of size_t
if (DF[0].size() > NumberOfWeatherFiles) {
throw std::runtime_error("Error: number of rows in weather weights file longer than number of weather files");
}
for (i = 0; i < DF.size(); i++)
{
int index = std::stoi(DF[i][0]);
WeatherWeights.push_back(std::stof(DF[i][1]));
WeatherWeightIDs.push_back(index);
if (index > NumberOfWeatherFiles) {
throw std::runtime_error("Error while parsing weather weights: ID not in Weathers folder");
}
}
double sum = std::accumulate(WeatherWeights.begin(), WeatherWeights.end(), 0.0);
if (sum > 1.000001 || sum < 0.9999999) {
throw std::runtime_error("Error: weather weights must add up to 1.0");
}
}

/*
* Populate HarvestedDF
*/
Expand Down Expand Up @@ -744,25 +769,3 @@ CSVReader::printWeatherDF(weatherDF wdf)
std::cout << " " << wdf.waz;
}

/*
int main()
{
// Creating an object of CSVWriter
CSVReader reader("example.csv");

// Get the data from CSV File
std::vector<std::vector<std::string> > dataList = reader.getData();

// Print the content of row by row on screen
for(std::vector<std::string> vec : dataList)
{
for(std::string data : vec)
{
std::cout<<data<< " ";
}
std::cout<<std::endl;
}
return 0;

}
*/
2 changes: 2 additions & 0 deletions Cell2Fire/ReadCSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class CSVReader
std::vector<std::vector<std::string>>& DF,
int NFTypes);

void parseWeatherWeights(std::vector<float>& WeatherWeights, std::vector<int>& WeatherWeightIDs, std::vector<std::vector<std::string>>& DF, int NumberOfWeatherFiles);

// Prints individual cell info
void printDF(inputs df);

Expand Down
Loading