Skip to content

Commit

Permalink
Merge commit 'a4a578c582c4486090272b2253a02dae5b30e903'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jun 4, 2024
2 parents 4cf67b7 + a4a578c commit b09d5b4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 47 deletions.
31 changes: 11 additions & 20 deletions agrolib/weatherGenerator/parserXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,54 +52,44 @@ void XMLSeasonalAnomaly::printInfo()
qDebug() << "";
}


XMLScenarioAnomaly::XMLScenarioAnomaly()
{
this->initialize(); // chiedere a Fausto perché non fare initialize direttamente qui
this->initialize();
}


void XMLScenarioAnomaly::initialize()
{
/*
point.name = "";
point.code = "";
point.latitude = NODATA;
point.longitude = NODATA;
point.info = "";
forecast.clear();

climatePeriod.yearFrom = NODATA;
climatePeriod.yearTo = NODATA;

modelNumber = NODATA;
modelName.clear();
modelMember.clear();
models.type.clear();
models.value.clear();
models.number = 0;

repetitions = NODATA;
anomalyYear = NODATA;
anomalySeason = "";
*/
}


void XMLScenarioAnomaly::printInfo()
{
/*
qDebug() << "point.name = " << point.name;
qDebug() << "point.longitude = " << point.longitude;
qDebug() << "point.latitude = " << point.latitude;
//qDebug() << "point.longitude = " << point.longitude;
//qDebug() << "point.latitude = " << point.latitude;
qDebug() << "climate first year = " << climatePeriod.yearFrom;
qDebug() << "climate last year = " << climatePeriod.yearTo;
qDebug() << "number of models = " << modelNumber;
qDebug() << "models = " << modelName;
qDebug() << "number of members = " << modelMember;
qDebug() << "number of repetitions = " << repetitions;
qDebug() << "models = " << models.type;
qDebug() << "number of models = " << models.number;
qDebug() << "anomaly year = " << anomalyYear;
qDebug() << "anomaly season = " << anomalySeason;
qDebug() << "number of repetitions = " << repetitions;
qDebug() << "";
*/
}


Expand Down Expand Up @@ -399,6 +389,7 @@ bool parseXMLScenario(const QString &xmlFileName, XMLScenarioAnomaly &XMLAnomaly
{
models = child.toElement().text();
XMLAnomaly.models.value = models.split(",");
XMLAnomaly.models.number = XMLAnomaly.models.value.size();
nrTokens++;
}
child = child.nextSibling();
Expand Down
1 change: 1 addition & 0 deletions agrolib/weatherGenerator/parserXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{
QString type;
QStringList value;
int number;
};
struct TXMLScenarioClimateField
{
Expand Down
81 changes: 57 additions & 24 deletions agrolib/weatherGenerator/weatherGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ bool assignAnomalyPrec(float myAnomaly, int anomalyMonth1, int anomalyMonth2,
return true;
}


bool assignXMLAnomalyScenario(XMLScenarioAnomaly* XMLAnomaly,int modelIndex, int* anomalyMonth1, int* anomalyMonth2, TweatherGenClimate& wGenNoAnomaly, TweatherGenClimate &wGen)
{
//unsigned int i = 0;
Expand Down Expand Up @@ -779,10 +780,11 @@ bool makeSeasonalForecast(QString outputFileName, char separator, XMLSeasonalAno
isLastMember = true;
}
// compute seasonal prediction
std::vector<int> indexWg;
if (! computeSeasonalPredictions(dailyObsData, wGen,
myPredictionYear, myYear, nrRepetitions,
wgDoy1, wgDoy2, rainfallThreshold, isLastMember,
dailyPredictions, &outputDataLength ))
dailyPredictions, &outputDataLength, indexWg))
{
qDebug() << "Error in computeSeasonalPredictions";
return false;
Expand Down Expand Up @@ -958,7 +960,6 @@ bool makeSeasonalForecastWaterTable(QString outputFileName, char separator, XMLS
}
++myDate;
}

qDebug() << "Observed OK";
int outputDataLength = nrDaysBeforeWgDoy1;

Expand All @@ -985,45 +986,76 @@ bool makeSeasonalForecastWaterTable(QString outputFileName, char separator, XMLS
isLastMember = true;
}
// compute seasonal prediction
std::vector<int> indexWg;
if (! computeSeasonalPredictions(dailyObsData, wGen,
myPredictionYear, myYear, nrRepetitions,
wgDoy1, wgDoy2, rainfallThreshold, isLastMember,
dailyPredictions, &outputDataLength ))
dailyPredictions, &outputDataLength, indexWg))
{
qDebug() << "Error in computeSeasonalPredictions";
return false;
}

for (int tmp = 0; tmp <= daysWg; tmp++)
if (indexWg.size() != 0)
{
inputTMin[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[outputDataLength+tmp].minTemp;
inputTMax[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[outputDataLength+tmp].maxTemp;
inputPrec[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[outputDataLength+tmp].prec;
}
// calcola etp
waterTable.cleanAllMeteoVector();
waterTable.setInputTMin(inputTMin);
waterTable.setInputTMax(inputTMax);
waterTable.setInputPrec(inputPrec);
waterTable.computeETP_allSeries();
float myDepth;
float myDelta;
int myDeltaDays;
for (int tmp = 0; tmp <= daysWg; tmp++)
{
Crit3DDate myDate = dailyPredictions[outputDataLength+tmp].date;
if (waterTable.getWaterTableInterpolation(QDate(myDate.year, myDate.month, myDate.day), &myDepth, &myDelta, &myDeltaDays))
//qDebug() << "indexWg[0] " << indexWg[0];
//qDebug() << "indexWg [indexWg.size()-1] " << indexWg [indexWg.size()-1];
//int nWgDays = indexWg [indexWg.size()-1] - indexWg[0];
//qDebug() << "nWgDays " << nWgDays;
for (int tmp = 0; tmp < daysWg; tmp++)
{
inputTMin[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[indexWg[0]+tmp].minTemp;
inputTMax[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[indexWg[0]+tmp].maxTemp;
inputPrec[nrDaysBeforeWgDoy1 + tmp] = dailyPredictions[indexWg[0]+tmp].prec;
}
// calcola etp
waterTable.cleanAllMeteoVector();
waterTable.setInputTMin(inputTMin);
waterTable.setInputTMax(inputTMax);
waterTable.setInputPrec(inputPrec);
waterTable.computeETP_allSeries();
float myDepth;
float myDelta;
int myDeltaDays;
QDate myDate(seasonFirstDate.year, seasonFirstDate.month, seasonFirstDate.day);
for (int tmp = 0; tmp < daysWg; tmp++)
{
dailyPredictions[outputDataLength+tmp].waterTableDepth = myDepth;
if (waterTable.getWaterTableInterpolation(myDate, &myDepth, &myDelta, &myDeltaDays))
{
dailyPredictions[indexWg[0]+tmp].waterTableDepth = myDepth;
}
myDate = myDate.addDays(1);
}
}

// next model
myYear = myYear + nrRepetitions;
}

qDebug() << "\n>>> output:" << outputFileName;

int fixWgDoy1 = wgDoy1;
int fixWgDoy2 = wgDoy2;
int index = 0;
QDate firstDate(myPredictionYear,1,1);
QDate lastDate(lastYear,12,31);
qDebug() << "firstDate " << firstDate.toString();
qDebug() << "lastDate " << lastDate.toString();
int indexToBeCopyed = 0;
for (QDate myDate = firstDate; myDate <= lastDate; myDate=myDate.addDays(1))
{
setCorrectWgDoy(wgDoy1, wgDoy2, myPredictionYear, myDate.year(), fixWgDoy1, fixWgDoy2);
if ( !isWGDate(Crit3DDate(myDate.day(), myDate.month(), myDate.year()), fixWgDoy1, fixWgDoy2) && dailyPredictions[index].waterTableDepth == NODATA)
{
dailyPredictions[index].waterTableDepth = dailyPredictions[indexToBeCopyed].waterTableDepth;
indexToBeCopyed = indexToBeCopyed + 1;
}
else
{
indexToBeCopyed = 0;
}
index = index + 1;
}

writeMeteoDataCsv (outputFileName, separator, dailyPredictions, true);

dailyPredictions.clear();
Expand All @@ -1045,7 +1077,7 @@ bool makeSeasonalForecastWaterTable(QString outputFileName, char separator, XMLS
bool computeSeasonalPredictions(TinputObsData *dailyObsData, TweatherGenClimate &wgClimate,
int predictionYear, int firstYear, int nrRepetitions,
int wgDoy1, int wgDoy2, float rainfallThreshold, bool isLastMember,
std::vector<ToutputDailyMeteo>& outputDailyData, int *outputDataLength)
std::vector<ToutputDailyMeteo>& outputDailyData, int *outputDataLength, std::vector<int>& indexWg)

{
Crit3DDate myDate, obsDate;
Expand Down Expand Up @@ -1124,6 +1156,7 @@ bool computeSeasonalPredictions(TinputObsData *dailyObsData, TweatherGenClimate
outputDailyData[currentIndex].maxTemp = getTMax(myDoy, rainfallThreshold, wgClimate);
outputDailyData[currentIndex].minTemp = getTMin(myDoy, rainfallThreshold, wgClimate);
outputDailyData[currentIndex].prec = getPrecip(myDoy, rainfallThreshold, wgClimate);
indexWg.push_back(currentIndex);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion agrolib/weatherGenerator/weatherGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
bool computeSeasonalPredictions(TinputObsData *dailyObsData, TweatherGenClimate& wgClimate,
int predictionYear, int firstYear, int nrRepetitions,
int wgDoy1, int wgDoy2, float minPrec, bool isLastMember,
std::vector<ToutputDailyMeteo> &outputDailyData, int *outputDataLength);
std::vector<ToutputDailyMeteo> &outputDailyData, int *outputDataLength, std::vector<int> &indexWg);

bool computeClimate(TweatherGenClimate &wgClimate, int firstYear, int nrRepetitions,
float rainfallThreshold, std::vector<ToutputDailyMeteo> &outputDailyData);
Expand Down
4 changes: 2 additions & 2 deletions agrolib/weatherGenerator/wgClimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ bool computeWG2DClimate(int nrDays, Crit3DDate inputFirstDate, float *inputTMin,
/*!
* \brief Generates a climate starting from daily weather
*/
bool climateGenerator(int nrData, TinputObsData climateDailyObsData, Crit3DDate climateDateIni, Crit3DDate climateDateFin, float precThreshold, float minPrecData, TweatherGenClimate* wGen)

bool climateGenerator(int nrData, TinputObsData climateDailyObsData, Crit3DDate climateDateIni,
Crit3DDate climateDateFin, float precThreshold, float minPrecData, TweatherGenClimate* wGen)
{
unsigned int nrDays;
int startIndex;
Expand Down

0 comments on commit b09d5b4

Please sign in to comment.