Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ARPA-SIMC/PRAGA
Browse files Browse the repository at this point in the history
  • Loading branch information
voltAntonio committed Nov 8, 2024
2 parents 8d4a42e + a23519c commit d65312c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 99 deletions.
16 changes: 8 additions & 8 deletions interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,12 +1093,12 @@ void localSelection(vector <Crit3DInterpolationDataPoint> &inputPoints, vector <
for (unsigned long i = 0; i < inputPoints.size() ; i++)
inputPoints[i].distance = gis::computeDistance(x, y, float((inputPoints[i]).point->utm.x), float((inputPoints[i]).point->utm.y));

unsigned int nrValid = 0;
int nrValid = 0;
float stepRadius = 7500; // [m]
float r0 = 0; // [m]
float r1 = stepRadius; // [m]
unsigned int i;
unsigned int nrPrimaries = 0;
int nrPrimaries = 0;

int maxDistance = 0;
while ((!mySettings.getUseLapseRateCode() && nrValid < minPoints) || (mySettings.getUseLapseRateCode() && nrPrimaries < minPoints))
Expand Down Expand Up @@ -1514,7 +1514,7 @@ void calculateFirstGuessCombinations(Crit3DProxy* myProxy)
std::vector <double> tempFirstGuess;
int numSteps = 15;
std::vector <double> stepSize;
int nrParam = int(tempParam.size()/2);
unsigned nrParam = int(tempParam.size()/2);

double min_,max_;
for (unsigned j=0; j < nrParam; j++)
Expand Down Expand Up @@ -1801,13 +1801,13 @@ bool multipleDetrendingElevationFitting(int elevationPos, std::vector <Crit3DInt
// multiple non linear fitting
double R2 = NODATA;
if (isWeighted)
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 400, 4, parametersMin, parametersMax, parameters, parametersDelta,
stepSize, numSteps, 1000, 0.002, 0.005, predictors, predictands, weights,firstGuessCombinations);
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 4, parametersMin, parametersMax, parameters, parametersDelta,
1000, 0.002, 0.005, predictors, predictands, weights,firstGuessCombinations);
else
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 400, 4, parametersMin, parametersMax, parameters, parametersDelta,
stepSize, numSteps, 1000, 0.002, 0.005, predictors, predictands,firstGuessCombinations);
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 4, parametersMin, parametersMax, parameters, parametersDelta,
1000, 0.002, 0.005, predictors, predictands,firstGuessCombinations);

mySettings->getProxy(elevationPos)->setRegressionR2(R2);
mySettings->getProxy(elevationPos)->setRegressionR2(float(R2));

std::vector<std::vector<double>> newParameters;
newParameters.push_back(parameters);
Expand Down
6 changes: 2 additions & 4 deletions mathFunctions/furtherMathFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2477,10 +2477,9 @@ namespace interpolation
return norm;
}
double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&),
int nrTrials, int nrMinima,
int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
std::vector <double>& parameters, std::vector <double>& parametersDelta,
std::vector <double>& stepSize, int numSteps,
int maxIterationsNr, double myEpsilon, double deltaR2,
std::vector <double>& x ,std::vector<double>& y,
std::vector<double>& weights, std::vector<std::vector<double>> firstGuessCombinations)
Expand Down Expand Up @@ -2547,10 +2546,9 @@ namespace interpolation
}

double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&),
int nrTrials, int nrMinima,
int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
std::vector <double>& parameters, std::vector <double>& parametersDelta,
std::vector <double>& stepSize, int numSteps,
int maxIterationsNr, double myEpsilon, double deltaR2,
std::vector <double>& x ,std::vector<double>& y,
std::vector<std::vector<double>> firstGuessCombinations)
Expand Down
8 changes: 2 additions & 6 deletions mathFunctions/furtherMathFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,15 @@ enum estimatedFunction {FUNCTION_CODE_SPHERICAL, FUNCTION_CODE_LINEAR, FUNCTION_
std::vector<double> &parameters, std::vector<double> &parametersDelta,
int maxIterationsNr, double myEpsilon,
std::vector <double>& x, std::vector<double>& y);
double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&),
int nrTrials, int nrMinima,
double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&), int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
std::vector <double>& parameters, std::vector <double>& parametersDelta,
std::vector<double> &stepSize, int numSteps,
int maxIterationsNr, double myEpsilon, double deltaR2,
std::vector <double>& x , std::vector<double>& y,
std::vector<double>& weights, std::vector<std::vector<double> > firstGuessCombinations);
double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&),
int nrTrials, int nrMinima,
double bestFittingMarquardt_nDimension_singleFunction(double (*func)(double, std::vector<double>&), int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
std::vector <double>& parameters, std::vector <double>& parametersDelta,
std::vector<double> &stepSize, int numSteps,
int maxIterationsNr, double myEpsilon, double deltaR2,
std::vector <double>& x , std::vector<double>& y,
std::vector<std::vector<double> > firstGuessCombinations);
Expand Down
10 changes: 5 additions & 5 deletions meteo/meteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ void Crit3DMeteoGrid::fixDailyThermalConsistency(const Crit3DDate myDate)
{
if (tmin > tmax)
{
_meteoPoints[row][col]->setMeteoPointValueD(myDate, dailyAirTemperatureMin, tmax - 0.1);
_meteoPoints[row][col]->setMeteoPointValueD(myDate, dailyAirTemperatureMin, float(tmax - 0.1));
}
}
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ void Crit3DMeteoGrid::saveRowColfromZone(gis::Crit3DRasterGrid* zoneGrid, std::v
}


void Crit3DMeteoGrid::computeHourlyDerivedVariables(Crit3DTime dateTime, std::vector<meteoVariable> variables, bool useNetRad)
void Crit3DMeteoGrid::computeHourlyDerivedVar(Crit3DTime dateTime, meteoVariable myVar, bool useNetRad)
{

for (unsigned row = 0; row < unsigned(gridStructure().header().nrRows); row++)
Expand All @@ -1068,13 +1068,13 @@ void Crit3DMeteoGrid::computeHourlyDerivedVariables(Crit3DTime dateTime, std::ve
{
if (_meteoPoints[row][col]->active)
{
_meteoPoints[row][col]->computeHourlyDerivedVariables(dateTime, variables, useNetRad);
_meteoPoints[row][col]->computeHourlyDerivedVar(dateTime, myVar, useNetRad);
}
}
}
}

void Crit3DMeteoGrid::computeDailyDerivedVariables(Crit3DDate date, std::vector<meteoVariable> variables, Crit3DMeteoSettings& meteoSettings)
void Crit3DMeteoGrid::computeDailyDerivedVar(Crit3DDate date, meteoVariable myVar, Crit3DMeteoSettings& meteoSettings)
{

for (unsigned row = 0; row < unsigned(gridStructure().header().nrRows); row++)
Expand All @@ -1083,7 +1083,7 @@ void Crit3DMeteoGrid::computeDailyDerivedVariables(Crit3DDate date, std::vector<
{
if (_meteoPoints[row][col]->active)
{
_meteoPoints[row][col]->computeDailyDerivedVariables(date, variables, meteoSettings);
_meteoPoints[row][col]->computeDailyDerivedVar(date, myVar, meteoSettings);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions meteo/meteoGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@
void computeRelativeHumidityFromTd(const Crit3DDate myDate, const int myHour);
void computeWindVectorHourly(const Crit3DDate myDate, const int myHour);
void fixDailyThermalConsistency(const Crit3DDate myDate);
void computeHourlyDerivedVariables(Crit3DTime dateTime, std::vector <meteoVariable> variables, bool useNetRad);
void computeDailyDerivedVariables(Crit3DDate date, std::vector <meteoVariable> variables, Crit3DMeteoSettings &meteoSettings);
void computeHourlyDerivedVar(Crit3DTime dateTime, meteoVariable myVar, bool useNetRad);
void computeDailyDerivedVar(Crit3DDate date, meteoVariable myVar, Crit3DMeteoSettings &meteoSettings);

private:

Expand Down
75 changes: 35 additions & 40 deletions meteo/meteoPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,63 +1218,58 @@ std::vector <double> Crit3DMeteoPoint::getProxyValues()
return myValues;
}

bool Crit3DMeteoPoint::computeHourlyDerivedVariables(Crit3DTime dateTime, std::vector <meteoVariable> variables, bool useNetRad)
bool Crit3DMeteoPoint::computeHourlyDerivedVar(Crit3DTime dateTime, meteoVariable myVar, bool useNetRad)
{
Crit3DDate myDate = dateTime.date;
int myHour = dateTime.getHour();
float value = NODATA;
short valueShort = NODATA;

for (auto var : variables)
if (myVar == leafWetness)
{
if (var == leafWetness)
if (computeLeafWetness(getMeteoPointValueH(myDate, myHour, 0, precipitation),
getMeteoPointValueH(myDate, myHour, 0, airRelHumidity), &valueShort))
setMeteoPointValueH(myDate, myHour, 0, leafWetness, float(valueShort));
}
else if (myVar == referenceEvapotranspiration)
{
if (useNetRad)
{
short leafW;
if (computeLeafWetness(getMeteoPointValueH(myDate, myHour, 0, precipitation),
getMeteoPointValueH(myDate, myHour, 0, airRelHumidity), &leafW))
setMeteoPointValueH(myDate, myHour, 0, leafWetness, leafW);
value = float(ET0_Penman_hourly_net_rad(double(point.z),
double(getMeteoPointValueH(myDate, myHour, 0, netIrradiance)),
double(getMeteoPointValueH(myDate, myHour, 0, airTemperature)),
double(getMeteoPointValueH(myDate, myHour, 0, airRelHumidity)),
double(getMeteoPointValueH(myDate, myHour, 0, windScalarIntensity))));

}
else if (var == referenceEvapotranspiration)
else
{
float et0;

if (useNetRad)
{
et0 = float(ET0_Penman_hourly_net_rad(double(point.z),
double(getMeteoPointValueH(myDate, myHour, 0, netIrradiance)),
double(getMeteoPointValueH(myDate, myHour, 0, airTemperature)),
double(getMeteoPointValueH(myDate, myHour, 0, airRelHumidity)),
double(getMeteoPointValueH(myDate, myHour, 0, windScalarIntensity))));

}
else
{
//da sistemare
et0 = ET0_Penman_hourly(double(point.z),
double(getMeteoPointValueH(myDate, myHour, 0, atmTransmissivity) / 0.75),
double(getMeteoPointValueH(myDate, myHour, 0, globalIrradiance)),
double(getMeteoPointValueH(myDate, myHour, 0, airTemperature)),
double(getMeteoPointValueH(myDate, myHour, 0, airRelHumidity)),
double(getMeteoPointValueH(myDate, myHour, 0, windScalarIntensity)));
}

setMeteoPointValueH(myDate, myHour, 0, referenceEvapotranspiration, et0);
//da sistemare
value = ET0_Penman_hourly(double(point.z),
double(getMeteoPointValueH(myDate, myHour, 0, atmTransmissivity) / float(0.75)),
double(getMeteoPointValueH(myDate, myHour, 0, globalIrradiance)),
double(getMeteoPointValueH(myDate, myHour, 0, airTemperature)),
double(getMeteoPointValueH(myDate, myHour, 0, airRelHumidity)),
double(getMeteoPointValueH(myDate, myHour, 0, windScalarIntensity)));
}
}

setMeteoPointValueH(myDate, myHour, 0, myVar, value);

return true;
}

bool Crit3DMeteoPoint::computeDailyDerivedVariables(Crit3DDate date, std::vector <meteoVariable> variables, Crit3DMeteoSettings& meteoSettings)
bool Crit3DMeteoPoint::computeDailyDerivedVar(Crit3DDate date, meteoVariable myVar, Crit3DMeteoSettings& meteoSettings)
{
for (auto var : variables)
float value;

if (myVar == dailyReferenceEvapotranspirationHS)
{
if (var == dailyReferenceEvapotranspirationHS)
{
float et0 = dailyEtpHargreaves(getMeteoPointValueD(date, dailyAirTemperatureMin),
getMeteoPointValueD(date, dailyAirTemperatureMax),
date, latitude, &meteoSettings);
value = dailyEtpHargreaves(getMeteoPointValueD(date, dailyAirTemperatureMin),
getMeteoPointValueD(date, dailyAirTemperatureMax),
date, latitude, &meteoSettings);

setMeteoPointValueD(date, dailyReferenceEvapotranspirationHS, et0);
}
setMeteoPointValueD(date, dailyReferenceEvapotranspirationHS, value);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions meteo/meteoPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
void setAltitude(double altitude);
void setLapseRateCode(std::string lapseRateCode);

bool computeHourlyDerivedVariables(Crit3DTime dateTime, std::vector<meteoVariable> variables, bool useNetRad);
bool computeDailyDerivedVariables(Crit3DDate date, std::vector<meteoVariable> variables, Crit3DMeteoSettings &meteoSettings);
bool computeHourlyDerivedVar(Crit3DTime dateTime, meteoVariable myVar, bool useNetRad);
bool computeDailyDerivedVar(Crit3DDate date, meteoVariable myVar, Crit3DMeteoSettings &meteoSettings);
bool computeMonthlyAggregate(Crit3DDate firstDate, Crit3DDate lastDate, meteoVariable dailyMeteoVar, Crit3DMeteoSettings *meteoSettings, Crit3DQuality *qualityCheck, Crit3DClimateParameters *climateParam);
TObsDataH *getObsDataH() const;
void initializeObsDataDFromMp(unsigned int numberOfDays, const Crit3DDate& firstDate, Crit3DMeteoPoint mp);
Expand Down
Loading

0 comments on commit d65312c

Please sign in to comment.