Skip to content

Commit

Permalink
Merge commit '4410284d5932e6b2be7d74ff4a3ddd7016d77bc3'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Aug 21, 2024
2 parents 93f0e14 + 4410284 commit 0ec730c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
25 changes: 15 additions & 10 deletions agrolib/dbMeteoPoints/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ DbArkimet* Download::getDbArkimet()
return _dbMeteo;
}

bool Download::getPointProperties(QList<QString> datasetList)
{

bool Download::getPointProperties(const QList<QString> &datasetList, QString &errorString)
{
bool result = true;
QEventLoop loop;

Expand All @@ -43,7 +43,7 @@ bool Download::getPointProperties(QList<QString> datasetList)

if (reply->error() != QNetworkReply::NoError)
{
qDebug() << "Network Error: " << reply->error();
errorString = "Network Error: " + reply->errorString();
result = false;
}
else
Expand All @@ -56,7 +56,12 @@ bool Download::getPointProperties(QList<QString> datasetList)
qDebug() << "err: " << error->errorString() << " -> " << error->offset;

// check validity of the document
if(! doc.isNull() && doc.isArray() )
if(doc.isNull() || ! doc.isArray())
{
errorString = "Invalid JSON";
result = false;
}
else
{
QJsonArray jsonArr = doc.array();

Expand All @@ -68,28 +73,28 @@ bool Download::getPointProperties(QList<QString> datasetList)

if (jsonDataset.isUndefined())
qDebug() << "jsonDataset: key id does not exist";
else if (!jsonDataset.isString())
else if (! jsonDataset.isString())
qDebug() << "jsonDataset: value is not string";
else
{
foreach(QString item, _datasetsList)
{
if (jsonDataset.toString().toUpper() == item.toUpper())
{
this->downloadMetadata(obj);
}
}
}
}
}
else
{
qDebug() << "Invalid JSON...\n";
result = false;
}
}

delete reply;
delete manager;
return result;
}


QMap<QString, QString> Download::getArmiketIdList(QList<QString> datasetList)
{

Expand Down
2 changes: 1 addition & 1 deletion agrolib/dbMeteoPoints/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
explicit Download(QString dbName, QObject* parent = nullptr);
~Download();

bool getPointProperties(QList<QString> datasetList);
bool getPointProperties(const QList<QString> &datasetList, QString &errorString);
bool getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp);
QMap<QString,QString> getArmiketIdList(QList<QString> datasetList);
void downloadMetadata(QJsonObject obj);
Expand Down
20 changes: 13 additions & 7 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "interpolationPoint.h"
#include "interpolation.h"
#include "interpolationSettings.h"
#include "meteo.h"

#include <functional>

Expand Down Expand Up @@ -347,32 +348,37 @@ bool regressionGeneric(std::vector <Crit3DInterpolationDataPoint> &myPoints, Cri
bool regressionSimpleT(std::vector <Crit3DInterpolationDataPoint> &myPoints, Crit3DInterpolationSettings* mySettings, Crit3DClimateParameters* myClimate,
Crit3DTime myTime, meteoVariable myVar, unsigned orogProxyPos)
{
float q, m, r2;
float slope, t0, r2;

Crit3DProxy* myProxyOrog = mySettings->getProxy(orogProxyPos);
myProxyOrog->initializeOrography();

if (! regressionSimple(myPoints, mySettings, orogProxyPos, false, &m, &q, &r2))
if (! regressionSimple(myPoints, mySettings, orogProxyPos, false, &slope, &t0, &r2))
return false;

if (r2 < mySettings->getMinRegressionR2())
return false;

myProxyOrog->setRegressionSlope(m);
myProxyOrog->setRegressionSlope(slope);
myProxyOrog->setLapseRateT0(t0);
myProxyOrog->setRegressionR2(r2);
myProxyOrog->setLapseRateT0(q);

// only pre-inversion data
if (m > 0)
if (slope > 0 && myVar != elaboration)
{
myProxyOrog->setInversionLapseRate(m);
myProxyOrog->setInversionLapseRate(slope);

float maxZ = MINVALUE(getMaxHeight(myPoints, mySettings->getUseLapseRateCode()), mySettings->getMaxHeightInversion());
myProxyOrog->setLapseRateT1(q + m * maxZ);
myProxyOrog->setLapseRateT1(t0 + slope * maxZ);
myProxyOrog->setLapseRateH1(maxZ);
myProxyOrog->setRegressionSlope(myClimate->getClimateLapseRate(myVar, myTime));
myProxyOrog->setInversionIsSignificative(true);
}
else
{
myProxyOrog->setInversionIsSignificative(false);
myProxyOrog->setInversionLapseRate(NODATA);
}

return true;
}
Expand Down
6 changes: 4 additions & 2 deletions agrolib/meteo/meteo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ float computeTminHourlyWeight(int myHour)

float Crit3DClimateParameters::getClimateLapseRate(meteoVariable myVar, Crit3DTime myTime)
{
const float DEFAULT_LAPSERATE = -0.006f;

Crit3DDate myDate = myTime.date;
int myHour = myTime.getNearestHour();

// TODO improve!
if (myDate.isNullDate() || myHour == NODATA)
return -0.006f;
return DEFAULT_LAPSERATE;

unsigned int indexMonth = unsigned(myDate.month - 1);

Expand All @@ -208,7 +210,7 @@ float Crit3DClimateParameters::getClimateLapseRate(meteoVariable myVar, Crit3DTi
lapseTmax = tdMaxLapseRate[indexMonth];
}
else
return NODATA;
return DEFAULT_LAPSERATE;

float tminWeight = computeTminHourlyWeight(myHour);
return (lapseTmin * tminWeight + lapseTmax * (1 - tminWeight));
Expand Down

0 comments on commit 0ec730c

Please sign in to comment.