diff --git a/dbMeteoPoints/dbMeteoPointsHandler.cpp b/dbMeteoPoints/dbMeteoPointsHandler.cpp index 569c6b33a..ca9414369 100644 --- a/dbMeteoPoints/dbMeteoPointsHandler.cpp +++ b/dbMeteoPoints/dbMeteoPointsHandler.cpp @@ -224,7 +224,6 @@ QDateTime Crit3DMeteoPointsDbHandler::getFirstDate(frequencyType frequency) } } - QString tmp = firstDate.toString("yyyy-MM-dd"); return firstDate; } diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 35069f500..5a7cccd0d 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2017,9 +2017,33 @@ bool PragaProject::interpolationOutputPointsPeriod(QDate firstDate, QDate lastDa { if (getVarFrequency(myVar) == hourly) { - // TODO RH and other special variables + setComputeOnlyPoints(true); - if (! interpolationDemMain(myVar, getCrit3DTime(myDate, hour), getPragaMapFromVar(myVar))) + // TODO other special variables + + bool isOk; + if (myVar == airRelHumidity && interpolationSettings.getUseDewPoint()) + { + if (interpolationSettings.getUseInterpolatedTForRH()) + { + passInterpolatedTemperatureToHumidityPoints(getCrit3DTime(myDate, hour), meteoSettings); + } + + isOk = interpolationDemMain(airDewTemperature, getCrit3DTime(myDate, hour), hourlyMeteoMaps->mapHourlyTdew); + + if (isOk) + { + hourlyMeteoMaps->computeRelativeHumidityMap(hourlyMeteoMaps->mapHourlyRelHum); + } + } + else + { + isOk = interpolationDemMain(myVar, getCrit3DTime(myDate, hour), getPragaMapFromVar(myVar)); + } + + setComputeOnlyPoints(false); + + if (! isOk) return false; } } @@ -2037,9 +2061,15 @@ bool PragaProject::interpolationOutputPointsPeriod(QDate firstDate, QDate lastDa { if (getVarFrequency(myVar) == daily) { + setComputeOnlyPoints(true); + // TODO special variables - if (! interpolationDemMain(myVar, getCrit3DTime(myDate, 0), getPragaMapFromVar(myVar))) + bool isOk = interpolationDemMain(myVar, getCrit3DTime(myDate, 0), getPragaMapFromVar(myVar)); + + setComputeOnlyPoints(false); + + if (! isOk) return false; // fix daily temperatures consistency diff --git a/project/meteoMaps.cpp b/project/meteoMaps.cpp index d6a4b411d..f790088ac 100644 --- a/project/meteoMaps.cpp +++ b/project/meteoMaps.cpp @@ -295,10 +295,10 @@ bool Crit3DHourlyMeteoMaps::computeLeafWetnessMap() -bool Crit3DHourlyMeteoMaps::computeRelativeHumidityMap(gis::Crit3DRasterGrid* myGrid) +bool Crit3DHourlyMeteoMaps::computeRelativeHumidityMap(gis::Crit3DRasterGrid* myRaster) { float airT, dewT; - myGrid->emptyGrid(); + myRaster->emptyGrid(); for (long row = 0; row < mapHourlyRelHum->header->nrRows ; row++) { @@ -309,12 +309,12 @@ bool Crit3DHourlyMeteoMaps::computeRelativeHumidityMap(gis::Crit3DRasterGrid* my if (! isEqual(airT, mapHourlyTair->header->flag) && ! isEqual(dewT, mapHourlyTdew->header->flag)) { - myGrid->value[row][col] = relHumFromTdew(dewT, airT); + myRaster->value[row][col] = relHumFromTdew(dewT, airT); } } } - return gis::updateMinMaxRasterGrid(myGrid); + return gis::updateMinMaxRasterGrid(myRaster); } diff --git a/project/meteoMaps.h b/project/meteoMaps.h index 3ca912239..a8e3150a7 100644 --- a/project/meteoMaps.h +++ b/project/meteoMaps.h @@ -63,7 +63,7 @@ gis::Crit3DRasterGrid* getMapFromVar(meteoVariable myVar); bool computeET0PMMap(const gis::Crit3DRasterGrid &DEM, Crit3DRadiationMaps *radMaps); - bool computeRelativeHumidityMap(gis::Crit3DRasterGrid* myGrid); + bool computeRelativeHumidityMap(gis::Crit3DRasterGrid* myRaster); bool computeLeafWetnessMap(); void setComputed(bool value); bool getComputed(); diff --git a/project/project.cpp b/project/project.cpp index 6326cda33..deed22571 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2089,9 +2089,14 @@ bool Project::interpolationOutputPoints(std::vector getRowCol(x, y, row, col); if (! gis::isOutOfGridRowCol(row, col, *outputGrid)) { - if (getUseDetrendingVar(myVar)) getProxyValuesXY(x, y, &interpolationSettings, proxyValues); + if (getUseDetrendingVar(myVar)) + { + getProxyValuesXY(x, y, &interpolationSettings, proxyValues); + } + outputPoints[i].currentValue = interpolate(interpolationPoints, &interpolationSettings, - meteoSettings, myVar, x, y, z, proxyValues, true); + meteoSettings, myVar, x, y, z, proxyValues, true); + outputGrid->value[row][col] = outputPoints[i].currentValue; } } @@ -2100,6 +2105,7 @@ bool Project::interpolationOutputPoints(std::vector initialize(); @@ -2318,7 +2324,13 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRasterGrid *myRaster) { - this->radiationMaps->initialize(); + if (! radiationMaps->latMap->isLoaded || ! radiationMaps->lonMap->isLoaded) + return false; + + if (! radiationMaps->slopeMap->isLoaded || ! radiationMaps->aspectMap->isLoaded) + return false; + + radiationMaps->initialize(); std::vector interpolationPoints; @@ -2334,7 +2346,7 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste // TODO: add flag to parameters. Could be NOT wanted if (! computeTransmissivityFromTRange(meteoPoints, nrMeteoPoints, myTime)) { - logError("Function interpolateDemRadiation: cannot compute transmissivity."); + logError("Error in function interpolateDemRadiation: cannot compute transmissivity."); return false; } } @@ -2345,7 +2357,7 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste meteoSettings, &climateParameters, interpolationPoints, checkSpatialQuality); if (! result) { - logError("Function interpolateDemRadiation: not enough transmissivity data."); + logError("Error in function interpolateDemRadiation: not enough transmissivity data."); return false; } @@ -2355,7 +2367,6 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste // interpolate transmissivity if (getComputeOnlyPoints()) { - radiationMaps->transmissivityMap->initializeGrid(DEM); result = interpolationOutputPoints(interpolationPoints, radiationMaps->transmissivityMap, atmTransmissivity); } else @@ -2365,18 +2376,18 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste } if (! result) { - logError("Function interpolateDemRadiation: error interpolating transmissivity."); + logError("Function interpolateDemRadiation: error in interpolating transmissivity."); return false; } // compute radiation if (getComputeOnlyPoints()) { - result = radiation::computeRadiationOutputPoints(&radSettings, this->DEM, this->radiationMaps, outputPoints, myTime); + result = radiation::computeRadiationOutputPoints(&radSettings, DEM, radiationMaps, outputPoints, myTime); } else { - result = radiation::computeRadiationGrid(&radSettings, this->DEM, this->radiationMaps, myTime); + result = radiation::computeRadiationDEM(&radSettings, DEM, radiationMaps, myTime); } if (! result) { diff --git a/solarRadiation/solarRadiation.cpp b/solarRadiation/solarRadiation.cpp index 3c59b5683..6f3209526 100644 --- a/solarRadiation/solarRadiation.cpp +++ b/solarRadiation/solarRadiation.cpp @@ -824,7 +824,7 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur } - bool computeRadiationRSunGridPoint(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& dem, + bool computeRadiationDemPoint(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& myDem, Crit3DRadiationMaps* radiationMaps, TradPoint radPoint, int row, int col, const Crit3DTime& myTime) { @@ -839,8 +839,8 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur float transmissivity = radiationMaps->transmissivityMap->value[row][col]; TsunPosition sunPosition; - if (!computeRadiationRsun(radSettings, TEMPERATURE_DEFAULT, PRESSURE_SEALEVEL, myTime, - linke, albedo, radSettings->getClearSky(), transmissivity, &sunPosition, &radPoint, dem)) + if (! computeRadiationRsun(radSettings, TEMPERATURE_DEFAULT, PRESSURE_SEALEVEL, myTime, + linke, albedo, radSettings->getClearSky(), transmissivity, &sunPosition, &radPoint, myDem)) return false; /* @@ -857,6 +857,7 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur return true; } + bool computeRadiationPotentialRSunMeteoPoint(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& dem, Crit3DMeteoPoint* myMeteoPoint, float slope, float aspect, const Crit3DTime& myTime, TradPoint* radPoint) { @@ -905,27 +906,38 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur } - bool computeRadiationGridRsun(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& dem, - Crit3DRadiationMaps* radiationMaps, const Crit3DTime& myTime) + bool computeRadiationDEM(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& myDem, + Crit3DRadiationMaps* radiationMaps, const Crit3DTime& myTime) { + if (radSettings->getAlgorithm() != RADIATION_ALGORITHM_RSUN) + return false; + int row, col; TradPoint radPoint; - for (row = 0; row < dem.header->nrRows; row++ ) + for (row = 0; row < myDem.header->nrRows; row++ ) { - for (col = 0; col < dem.header->nrCols; col++) + for (col = 0; col < myDem.header->nrCols; col++) { - if(isGridPointComputable(radSettings, row, col, dem, radiationMaps)) + if(isGridPointComputable(radSettings, row, col, myDem, radiationMaps)) { - dem.getXY(row, col, radPoint.x, radPoint.y); - radPoint.height = dem.value[row][col]; + myDem.getXY(row, col, radPoint.x, radPoint.y); + radPoint.height = myDem.value[row][col]; - if (! computeRadiationRSunGridPoint(radSettings, dem, radiationMaps, radPoint, row, col, myTime)) + if (! computeRadiationDemPoint(radSettings, myDem, radiationMaps, radPoint, row, col, myTime)) return false; } } } + updateRadiationMaps(radiationMaps, myTime); + + return true; + } + + + void updateRadiationMaps(Crit3DRadiationMaps* radiationMaps, const Crit3DTime &myTime) + { gis::updateMinMaxRasterGrid(radiationMaps->sunElevationMap); gis::updateMinMaxRasterGrid(radiationMaps->transmissivityMap); gis::updateMinMaxRasterGrid(radiationMaps->beamRadiationMap); @@ -941,7 +953,6 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur radiationMaps->globalRadiationMap->setMapTime(myTime); radiationMaps->setComputed(true); - return true; } @@ -1080,37 +1091,10 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur } - bool preConditionsRadiationGrid(const Crit3DRadiationMaps& radiationMaps) - { - if (! radiationMaps.latMap->isLoaded || ! radiationMaps.lonMap->isLoaded) return false; - if (! radiationMaps.slopeMap->isLoaded || ! radiationMaps.aspectMap->isLoaded) return false; - - return true; - } - - - bool computeRadiationGrid(Crit3DRadiationSettings* radSettings, const gis::Crit3DRasterGrid& dem, - Crit3DRadiationMaps* radiationMaps, const Crit3DTime& myTime) - { - if (! preConditionsRadiationGrid(*radiationMaps)) - return false; - - if (radSettings->getAlgorithm() == RADIATION_ALGORITHM_RSUN) - { - return computeRadiationGridRsun(radSettings, dem, radiationMaps, myTime); - } - else - return false; - } - - bool computeRadiationOutputPoints(Crit3DRadiationSettings *radSettings, const gis::Crit3DRasterGrid& dem, Crit3DRadiationMaps* radiationMaps, std::vector &outputPoints, const Crit3DTime& myTime) { - if (! preConditionsRadiationGrid(*radiationMaps)) - return false; - if (radSettings->getAlgorithm() != RADIATION_ALGORITHM_RSUN) return false; @@ -1127,13 +1111,14 @@ bool computeRadiationRsun(Crit3DRadiationSettings* radSettings, float temperatur if(isGridPointComputable(radSettings, row, col, dem, radiationMaps)) { - if (! computeRadiationRSunGridPoint(radSettings, dem, radiationMaps, radPoint, row, col, myTime)) + if (! computeRadiationDemPoint(radSettings, dem, radiationMaps, radPoint, row, col, myTime)) return false; } } } - radiationMaps->setComputed(true); + updateRadiationMaps(radiationMaps, myTime); + return true; } diff --git a/solarRadiation/solarRadiation.h b/solarRadiation/solarRadiation.h index 75dc79cc2..e7b9c7af7 100644 --- a/solarRadiation/solarRadiation.h +++ b/solarRadiation/solarRadiation.h @@ -66,7 +66,10 @@ float myLinke, float myAlbedo, float myClearSkyTransmissivity, float transmissivity, TsunPosition* mySunPosition, TradPoint* myPoint, const gis::Crit3DRasterGrid& myDEM); - bool computeRadiationRSunGridPoint(Crit3DRadiationSettings* mySettings, const gis::Crit3DRasterGrid& myDEM, + bool computeRadiationDEM(Crit3DRadiationSettings *radSettings, const gis::Crit3DRasterGrid& myDem, + Crit3DRadiationMaps* radiationMaps, const Crit3DTime& myTime); + + bool computeRadiationDemPoint(Crit3DRadiationSettings* mySettings, const gis::Crit3DRasterGrid& myDem, Crit3DRadiationMaps* radiationMaps, TradPoint radPoint, int row, int col, const Crit3DTime& myTime); @@ -74,8 +77,7 @@ Crit3DRadiationMaps *radiationMaps, std::vector &outputPoints, const Crit3DTime& myCrit3DTime); - bool computeRadiationGrid(Crit3DRadiationSettings *radSettings, const gis::Crit3DRasterGrid& myDEM, - Crit3DRadiationMaps* radiationMaps, const Crit3DTime& myCrit3DTime); + void updateRadiationMaps(Crit3DRadiationMaps* radiationMaps, const Crit3DTime &myTime); float computePointTransmissivity(Crit3DRadiationSettings *mySettings, const gis::Crit3DPoint& myPoint, Crit3DTime myTime, float* measuredRad, int windowWidth, int timeStepSecond, const gis::Crit3DRasterGrid& myDEM);