From 8506815d3e794d329d28d8c295261f7e3ed22fa1 Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 20 Aug 2024 16:01:52 +0200 Subject: [PATCH 1/2] fix regressionSimpleT --- interpolation/interpolation.cpp | 20 +++++++++++++------- meteo/meteo.cpp | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 7a531afbf..ec65485fe 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -39,6 +39,7 @@ #include "interpolationPoint.h" #include "interpolation.h" #include "interpolationSettings.h" +#include "meteo.h" #include @@ -347,32 +348,37 @@ bool regressionGeneric(std::vector &myPoints, Cri bool regressionSimpleT(std::vector &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; } diff --git a/meteo/meteo.cpp b/meteo/meteo.cpp index df096947e..258c479ef 100644 --- a/meteo/meteo.cpp +++ b/meteo/meteo.cpp @@ -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); @@ -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)); From 4410284d5932e6b2be7d74ff4a3ddd7016d77bc3 Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 20 Aug 2024 18:48:26 +0200 Subject: [PATCH 2/2] fix get point properties --- dbMeteoPoints/download.cpp | 25 +++++++++++++++---------- dbMeteoPoints/download.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dbMeteoPoints/download.cpp b/dbMeteoPoints/download.cpp index 3d8c85e1a..69e9afa48 100644 --- a/dbMeteoPoints/download.cpp +++ b/dbMeteoPoints/download.cpp @@ -21,9 +21,9 @@ DbArkimet* Download::getDbArkimet() return _dbMeteo; } -bool Download::getPointProperties(QList datasetList) -{ +bool Download::getPointProperties(const QList &datasetList, QString &errorString) +{ bool result = true; QEventLoop loop; @@ -43,7 +43,7 @@ bool Download::getPointProperties(QList datasetList) if (reply->error() != QNetworkReply::NoError) { - qDebug() << "Network Error: " << reply->error(); + errorString = "Network Error: " + reply->errorString(); result = false; } else @@ -56,7 +56,12 @@ bool Download::getPointProperties(QList 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(); @@ -68,21 +73,20 @@ bool Download::getPointProperties(QList 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; @@ -90,6 +94,7 @@ bool Download::getPointProperties(QList datasetList) return result; } + QMap Download::getArmiketIdList(QList datasetList) { diff --git a/dbMeteoPoints/download.h b/dbMeteoPoints/download.h index 06e77bc15..ab04e8acb 100644 --- a/dbMeteoPoints/download.h +++ b/dbMeteoPoints/download.h @@ -12,7 +12,7 @@ explicit Download(QString dbName, QObject* parent = nullptr); ~Download(); - bool getPointProperties(QList datasetList); + bool getPointProperties(const QList &datasetList, QString &errorString); bool getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp); QMap getArmiketIdList(QList datasetList); void downloadMetadata(QJsonObject obj);