Skip to content

Commit

Permalink
Merge commit 'f3dccf60f453b63445435ffdb22ffd236a163214'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Mar 12, 2024
2 parents dfe6b1b + f3dccf6 commit 903edae
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 66 deletions.
43 changes: 35 additions & 8 deletions agrolib/inOutDataXML/inOutDataXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ bool InOutDataXML::parserXML(QString *myError)
{
fileName_pragaName = secondChild.toElement().text();
}
else if (mySecondTag == "TEXT" || mySecondTag == "FIXEDTEXT")
else if (mySecondTag == "PREFIX" || mySecondTag == "FIXEDPREFIX")
{
fileName_fixedText.append(secondChild.toElement().text());
fileName_fixedPrefix.append(secondChild.toElement().text());
}
else if (mySecondTag == "SUFFIX" || mySecondTag == "FIXEDSUFFIX")
{
fileName_fixedSuffix.append(secondChild.toElement().text());
}
else if (mySecondTag == "NRCHAR" || mySecondTag == "NR_CHAR")
{
Expand Down Expand Up @@ -1141,11 +1145,32 @@ QString InOutDataXML::parseXMLPointCode(QString text)
{
if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED"))
{
QString substring = text.mid(0,pointCode.getNrChar());
if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s")
if (fileName_pragaName.isEmpty())
{
QString substring = text.mid(0,pointCode.getNrChar());
if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s")
{
// pointCode is a string
myPointCode = substring;
}
}
else
{
// pointCode is a string
myPointCode = substring;
// con questa casistica l'import funziona anche con gli xml di export che hanno il campo filename e prefissi o suffissi nel nome del file
QString substring = text;
for (int i = 0; i<fileName_fixedPrefix.size(); i++)
{
substring = substring.replace(fileName_fixedPrefix[i],"");
}
for (int i = 0; i<fileName_fixedSuffix.size(); i++)
{
substring = substring.replace(fileName_fixedSuffix[i],"");
}
if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s")
{
// pointCode is a string
myPointCode = substring;
}
}
}
else if (format_type == XMLFORMATDELIMITED)
Expand Down Expand Up @@ -1253,9 +1278,11 @@ QString InOutDataXML::parseXMLFilename(QString code)
{
return filename;
}
QString suffix = fileName_fixedText.join(",");
QString prefix = fileName_fixedPrefix.join(",");
prefix.replace(",","");
QString suffix = fileName_fixedSuffix.join(",");
suffix.replace(",","");
filename = fileName_path + code + suffix;
filename = fileName_path + prefix + code + suffix;
return filename;
}

Expand Down
3 changes: 2 additions & 1 deletion agrolib/inOutDataXML/inOutDataXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class InOutDataXML
QString format_decimalSeparator;
QString fileName_path;
QString fileName_pragaName;
QList<QString> fileName_fixedText;
QList<QString> fileName_fixedPrefix;
QList<QString> fileName_fixedSuffix;
int fileName_nrChar;
FieldXML time;
FieldXML pointCode;
Expand Down
20 changes: 0 additions & 20 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#include <vector>
#include <algorithm>

/*#include <fstream>
#include <chrono>
#include <iostream>
*/

#include "commonConstants.h"
#include "basicMath.h"
#include "furtherMathFunctions.h"
Expand Down Expand Up @@ -1517,25 +1512,10 @@ bool multipleDetrending(std::vector <Crit3DInterpolationDataPoint> &myPoints, Cr
std::vector<std::function<double(double, std::vector<double>&)>> myFunc;
setFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters);

//auto start2 = std::chrono::high_resolution_clock::now();

// multiple non linear fitting
/*interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 4, 3, parametersMin, parametersMax, parameters, parametersDelta,
20, 0.05, 0.02, predictors, predictands, false, weights);*/

interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 500, 5, parametersMin, parametersMax, parameters, parametersDelta,
100, 0.005, 0.01, predictors, predictands, false, weights);

/*auto end2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> tempo2 = end2 - start2;
std::ofstream csvfile("C:/Github/tempoBestFit.csv", std::ios::app);
if (!csvfile.is_open()) {
std::cerr << "Errore apertura file\n";
}
csvfile << tempo2.count() << std::endl;
csvfile.close();
*/
mySettings->setFittingFunction(myFunc);
mySettings->setFittingParameters(parameters);

Expand Down
19 changes: 1 addition & 18 deletions agrolib/mathFunctions/furtherMathFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
#include "commonConstants.h"
#include "furtherMathFunctions.h"

#include <iostream>
#include <fstream>
#include <cmath>

double lapseRateRotatedSigmoid(double x, std::vector <double> par)
{
Expand Down Expand Up @@ -1094,7 +1091,7 @@ namespace interpolation
R2 = computeR2(y,ySim);
else
R2 = computeWeighted_R2(y,ySim,weights);
//printf("%d R2 = %f\n",iRandom,R2);

if (R2 > (bestR2-deltaR2))
{
for (j=0;j<nrMinima-1;j++)
Expand All @@ -1121,18 +1118,9 @@ namespace interpolation
}
}*/
}
//iRandom++;
counter++;
} while( (counter < nrTrials) && (R2 < (1 - EPSILON)) && (fabs(R2Previous[0]-R2Previous[nrMinima-1]) > deltaR2) );

/* std::ofstream csvfile("C:/Github/counterR2.csv", std::ios::app);
if (!csvfile.is_open()) {
std::cerr << "Errore apertura file\n";
}
csvfile << counter << "," << R2 << std::endl;
csvfile.close();
*/
for (i=0;i<nrPredictors;i++)
{
for (j=0; j<nrParameters[i]; j++)
Expand Down Expand Up @@ -1349,11 +1337,6 @@ namespace interpolation

parametersChange[nrPredictors - 1][nrParameters[nrPredictors-1]-1] = g[nrParametersTotal - 1] / a[nrParametersTotal - 1][nrParametersTotal - 1];

/*debugging
if (std::isnan(parametersChange[nrPredictors - 1][nrParameters[nrPredictors-1]-1]))
{
printf("nan trovato\n");
}*/

for (i = nrParametersTotal - 2; i >= 0; i--)
{
Expand Down
52 changes: 47 additions & 5 deletions agrolib/meteoWidget/meteoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ void Crit3DMeteoWidget::resetValues()
{
QLineSeries* line = new QLineSeries();
line->setName(getFormattedLabel(pointName, nameLines[i]));

//QColor lineColor = colorLine[i];
QColor lineColor = colorLines[i];
if (nMeteoPoints == 1)
{
Expand Down Expand Up @@ -2312,16 +2310,60 @@ void Crit3DMeteoWidget::on_actionDataAvailability()

void Crit3DMeteoWidget::on_actionDataSum()
{
// TO DO;
// Apre una finestra con l'elenco delle variabili attualmente visualizzate in modo che siano selezionabili quali vogliamo switchare sulla comulata
DialogVariableToSum varToSum(currentVariables);
QList<QString> varToSumList;
if (varToSum.result() == QDialog::Accepted)
{
varToSumList = varToSum.getSelectedVariable();
}
qDebug() << "varToSumList " << varToSumList.join(",");
else
{
return;
}
if (!varToSumList.isEmpty())
{
drawSum(varToSumList);
}
}

void Crit3DMeteoWidget::drawSum(QList<QString> varToSumList)
{
// TO DO
int nMeteoPoints = meteoPoints.size();
for (int i = 0; i < varToSumList.size(); i++)
{
qDebug() << "varToSumList: " << varToSumList[i];
if (!lineSeries.isEmpty())
{
for (int j = 0; j < nameLines.size(); j++)
{
qDebug() << "nameLines[j]: " << nameLines[j];
if (nameLines[j] == varToSumList[i])
{
qDebug() << "found: " << varToSumList[i];
for (int mp=0; mp<nMeteoPoints;mp++)
{
for (int n = 0; n<lineSeries[mp][j]->points().size(); n++)
{
qDebug() << "lineSeries[mp][j]->points()[n].x(): " << lineSeries[mp][j]->points()[n].x();
qDebug() << "lineSeries[mp][j]->points()[n].y(): " << lineSeries[mp][j]->points()[n].y();
}
}
}
}
}
if (! barSeries.isEmpty())
{
for (int j = 0; j < nameBar.size(); j++)
{
qDebug() << "nameBar[j]: " << nameBar[j];
if (nameBar[j] == varToSumList[i])
{
qDebug() << "found: " << varToSumList[i];
}
}
}
}
}


Expand Down
1 change: 1 addition & 0 deletions agrolib/meteoWidget/meteoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
void on_actionInfoPoint();
void on_actionDataAvailability();
void on_actionDataSum();
void drawSum(QList<QString> varToSumList);

private:
int meteoWidgetID;
Expand Down
1 change: 1 addition & 0 deletions agrolib/pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,7 @@ bool PragaProject::interpolationMeteoGrid(meteoVariable myVar, frequencyType myF
}
else
{

if (! interpolationGrid(myVar, myTime))
return false;
}
Expand Down
19 changes: 5 additions & 14 deletions agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include <QMessageBox>
#include <string>

/*#include <fstream>
#include <chrono>
*/

Project::Project()
{
Expand Down Expand Up @@ -2309,7 +2306,6 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT
float z = DEM.value[row][col];
if (! isEqual(z, myHeader.flag))
{
//auto start1 = std::chrono::high_resolution_clock::now();
gis::getUtmXYFromRowCol(myHeader, row, col, &x, &y);

std::vector <Crit3DInterpolationDataPoint> subsetInterpolationPoints;
Expand All @@ -2318,16 +2314,6 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT
getProxyValuesXY(x, y, &interpolationSettings, proxyValues);
myRaster->value[row][col] = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings,
myVar, x, y, z, proxyValues, true);

/*auto end1 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> tempo1 = end1 - start1;
std::ofstream csvfile("C:/Github/rowCol.csv", std::ios::app);
if (!csvfile.is_open()) {
std::cerr << "Errore apertura file\n";
}
csvfile << row << "," << col << "," << tempo1.count() << std::endl;
csvfile.close();*/
}
}
}
Expand Down Expand Up @@ -2598,6 +2584,10 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)

if (interpolationSettings.getUseLocalDetrending())
{
if (row == 80 && col == 67)
{
std::cout << "cella individuata" << std::endl;
}
std::vector <Crit3DInterpolationDataPoint> subsetInterpolationPoints;
localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, interpolationSettings);
preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime);
Expand All @@ -2606,6 +2596,7 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)
if (interpolatedValue > 9000)
{
std::cout << "valore sballato" << std::endl;
std::cout << "riga " << row << " colonna " << col << std::endl;
}
}
else
Expand Down

0 comments on commit 903edae

Please sign in to comment.