Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ARPA-SIMC/agroTools
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Feb 7, 2024
2 parents d8a95c0 + ab9287f commit c6d894a
Show file tree
Hide file tree
Showing 9 changed files with 1,021 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ utm_zone=32
[project]
csvPath=./outputData/
id=10, 2303, 4, 6257, 6265
meteoGrid=../../METEOGRID/DBGridXML_ERG5_forecast.xml
meteo_points=../../METEOPOINT/frost.db
name=testFrostForecast
var=TAVG, RHAVG, W_SCAL_INT, W_VEC_DIR, PREC, RAD
Expand Down
428 changes: 324 additions & 104 deletions agrolib/homogeneityWidget/homogeneityWidget.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions agrolib/homogeneityWidget/homogeneityWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
void addFoundStationClicked();
void deleteFoundStationClicked();
void executeClicked();
void checkValueAndMerge(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet, QDate myDate);

private:
Crit3DMeteoPointsDbHandler* meteoPointsDbHandler;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/mathFunctions/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ namespace statistics
{
X[i]= (double*)calloc(nrPredictors+1, sizeof(double));
}
printf("transposed matrix\n");

for (int j=0;j<nrPredictors+1;j++)
{
for (int i=0;i<nrItems;i++)
Expand Down
840 changes: 643 additions & 197 deletions agrolib/pointStatisticsWidget/pointStatisticsWidget.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions agrolib/pointStatisticsWidget/pointStatisticsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
void saveToDbClicked();
void updateYears();
void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint *meteoPointSet, QDate myDate);
void checkValueAndMerge(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet, QDate myDate);


private:
bool isGrid;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,7 @@ void PragaProject::showPointStatisticsWidgetPoint(std::string idMeteoPoint)
{
if (meteoPoints[i].id != idMeteoPoint)
{
if (meteoPoints[i].active && (meteoPoints[i].nrObsDataDaysD != 0 || meteoPoints[i].nrObsDataDaysH != 0))
if (meteoPoints[i].nrObsDataDaysD != 0 || meteoPoints[i].nrObsDataDaysH != 0)
{
double utmX = meteoPoints[i].point.utm.x;
double utmY = meteoPoints[i].point.utm.y;
Expand Down
13 changes: 9 additions & 4 deletions bin/frostForecast/frost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ void Frost::saveParameters()
projectSettings->setValue("SE_parTss", FloatVectorToStringList(SE_parTss));
projectSettings->setValue("SE_parRHss", FloatVectorToStringList(SE_parRHss));
projectSettings->endGroup();

projectSettings->sync();

}

int Frost::readSettings()
Expand Down Expand Up @@ -619,7 +622,6 @@ void fitCoolingCoefficient(std::vector <std::vector <float>>& hourly_series, int
myMin = minValue;
myMax = maxValue;
iteration = 0;
time = 0;
do {

mySum1 = 0;
Expand Down Expand Up @@ -663,6 +665,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo

TObsDataH* hourlyData = point->getObsDataH();

const unsigned MIN_DATA = 5;
Crit3DDate today;
TsunPosition sunPosition;
float temperature = 25;
Expand All @@ -678,7 +681,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo
std::vector <float> hourlyT;
float T;
float minT, maxT;
bool dataPresent;
bool dataPresent, dataSunsetPresent;
std::vector <float> ssData;
float RH_SS;
bool isSunRise, isSunset;
Expand Down Expand Up @@ -717,6 +720,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo
minT = NODATA;
maxT = NODATA;
dataPresent = false;
dataSunsetPresent = false;
hourlyT.clear();

while (! isSunRise)
Expand Down Expand Up @@ -749,6 +753,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo
{
ssData.push_back(T);
ssData.push_back(RH_SS);
dataSunsetPresent = true;
}
}

Expand All @@ -770,7 +775,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo
if (h == hourSunRiseUtc && d == dateIndexSunRiseUtc)
{
isSunRise = true;
if (dataPresent && minT < thresholdTmin && (maxT - minT >= thresholdTrange))
if (dataPresent && dataSunsetPresent && minT < thresholdTmin && (maxT - minT >= thresholdTrange))
{
outData.push_back(hourlyT);
sunsetData.push_back(ssData);
Expand All @@ -785,7 +790,7 @@ bool Frost::getRadiativeCoolingHistory(unsigned pos, std::vector<std::vector<flo
}
}

return (outData.size() > 0);
return (outData.size() > MIN_DATA);
}

bool Frost::calibrateModel(int idPos)
Expand Down
78 changes: 40 additions & 38 deletions bin/frostForecast/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <QCoreApplication>
#include <QDir>
#include <iostream>
#include "utilities.h"
#include "frost.h"

// uncomment to execute test
// #define TEST
// #define TEST_CALIBRATE

void usage()
{
std::cout << "frostForecast" << std::endl
<< "Usage: frostForecast <project.ini> [date] [-calibrate]" << std::endl;
<< "Usage: frostForecast <project.ini> [-calibrate] [-date]" << std::endl;
std::cout << std::flush;
}

Expand All @@ -36,10 +34,6 @@ int main(int argc, char *argv[])
usage();
return ERROR_MISSINGFILE;
#endif

#ifdef TEST_CALIBRATE
calibrateModel = true;
#endif
}
else
{
Expand All @@ -50,60 +44,68 @@ int main(int argc, char *argv[])
usage();
return ERROR_MISSINGFILE;
}
runDateStr = argv[2];

if (argc == 3 && strcmp(argv[3], "-calibrate") == 0)
if (strcmp(argv[2], "-calibrate") == 0)
calibrateModel = true;
}

// check date
QDate runDate = QDate::fromString(runDateStr, "yyyy-MM-dd");
if (! runDate.isValid())
{
frost.logger.writeError("Wrong date format. Requested format is: YYYY-MM-DD");
return ERROR_WRONGDATE;
else
runDateStr = argv[2];
}

frost.initialize();
frost.setSettingsFileName(settingsFileName);
frost.setRunDate(runDate);

frost.logger.writeInfo ("settingsFileName: " + settingsFileName);

int result = frost.readSettings();
if (result!=FROSTFORECAST_OK) return result;

/*
result = frost.downloadMeteoPointsData();
if (result!=FROSTFORECAST_OK)
{
return result;
}*/

int i = 0;
bool calibrationOk = false;

bool calibrationOk = false;
if (calibrateModel)
{
QList<Crit3DMeteoPoint> pointList = frost.getMeteoPointsList();

frost.initializeFrostParam();

for (int i=0; i < frost.getMeteoPointsList().size(); i++)
calibrationOk = (frost.calibrateModel(i) || calibrationOk);
for (int i=0; i < pointList.size(); i++)
{
if (frost.calibrateModel(i))
{
calibrationOk = true;
frost.logger.writeInfo ("calibration done for point: " + QString::fromStdString(pointList[i].id));
}
}

if (calibrationOk) frost.saveParameters();
}
else
{
// check date
QDate runDate = QDate::fromString(runDateStr, "yyyy-MM-dd");
if (! runDate.isValid())
{
frost.logger.writeError("Wrong date format. Requested format is: YYYY-MM-DD");
return ERROR_WRONGDATE;
}

result = frost.readParameters();
if (result != FROSTFORECAST_OK) return result;
result = frost.readParameters();
if (result != FROSTFORECAST_OK) return result;

QList<QString> idList = frost.getIdList();
QList<QString> idList = frost.getIdList();
frost.setRunDate(runDate);

for (i=0; i < idList.size(); i++)
{
result = frost.getForecastData(i);
if (result == FROSTFORECAST_OK)
frost.createCsvFile(idList[i]);
else
return result;
result = frost.downloadMeteoPointsData();
if (result != FROSTFORECAST_OK) return result;

for (i=0; i < idList.size(); i++)
{
result = frost.getForecastData(i);
if (result == FROSTFORECAST_OK)
frost.createCsvFile(idList[i]);
else
return result;
}
}

return FROSTFORECAST_OK;
Expand Down

0 comments on commit c6d894a

Please sign in to comment.