Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cate-to committed Dec 18, 2024
1 parent aeb92d8 commit 51194a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
17 changes: 14 additions & 3 deletions interpolation/interpolationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,19 @@ int Crit3DInterpolationSettings::getProxyPosFromName(TProxyVar name)
return NODATA;
}

bool Crit3DInterpolationSettings::isGlocalReady()
bool Crit3DInterpolationSettings::isGlocalReady(bool isGrid)
{
return (getMacroAreasMap() != nullptr && getMacroAreas().size() > 0);
if (getMacroAreasMap() != nullptr && getMacroAreas().size() > 0)
{
for (int i = 0; i < getMacroAreas().size(); i++)
{
if ((isGrid && getMacroAreas()[i].getAreaCellsGrid().size() > 0) ||
(!isGrid && getMacroAreas()[i].getAreaCellsDEM().size() > 0))
return true;
}
}

return false;
}

std::string Crit3DProxy::getName() const
Expand Down Expand Up @@ -1023,7 +1033,8 @@ Crit3DMacroArea::Crit3DMacroArea()

void Crit3DMacroArea::clear()
{
areaCells.clear();
areaCellsDEM.clear();
areaCellsGrid.clear();
areaParameters.clear();
areaCombination.clear();
meteoPoints.clear();
Expand Down
12 changes: 8 additions & 4 deletions interpolation/interpolationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
Crit3DProxyCombination areaCombination;
std::vector<std::vector<double>> areaParameters;
std::vector<int> meteoPoints;
std::vector<float> areaCells;
std::vector<float> areaCellsDEM;
std::vector<float> areaCellsGrid;

public:
Crit3DMacroArea();
Expand All @@ -152,8 +153,11 @@
void setMeteoPoints (std::vector<int> myMeteoPoints) { meteoPoints = myMeteoPoints; }
std::vector<int> getMeteoPoints() { return meteoPoints; }

void setAreaCells (std::vector<float> myCells) { areaCells = myCells; }
std::vector<float> getAreaCells() { return areaCells; }
void setAreaCellsDEM (std::vector<float> myCells) { areaCellsDEM = myCells; }
std::vector<float> getAreaCellsDEM() { return areaCellsDEM; }

void setAreaCellsGrid (std::vector<float> myCells) { areaCellsGrid = myCells; }
std::vector<float> getAreaCellsGrid() { return areaCellsGrid; }

void setParameters (std::vector<std::vector<double>> myParameters) { areaParameters = myParameters; }
std::vector<std::vector<double>> getParameters() { return areaParameters; }
Expand Down Expand Up @@ -241,7 +245,7 @@
void setUseLocalDetrending(bool myValue);
bool getUseLocalDetrending();

bool isGlocalReady();
bool isGlocalReady(bool isGrid);
void setUseGlocalDetrending(bool myValue);
bool getUseGlocalDetrending();
void setMacroAreasMap(gis::Crit3DRasterGrid *value);
Expand Down
4 changes: 2 additions & 2 deletions pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ bool PragaProject::interpolationMeteoGrid(meteoVariable myVar, frequencyType myF
}

// check glocal
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady())
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady(!interpolationSettings.getMeteoGridUpscaleFromDem()))
{
if (! loadGlocalAreasMap()) return false;
if (! loadGlocalStationsAndCells(!interpolationSettings.getMeteoGridUpscaleFromDem())) return false;
Expand Down Expand Up @@ -2805,7 +2805,7 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL
return false;
}

if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady())
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady(!interpolationSettings.getMeteoGridUpscaleFromDem()))
{
if (! loadGlocalAreasMap()) return false;
if (! loadGlocalStationsAndCells(!interpolationSettings.getMeteoGridUpscaleFromDem())) return false;
Expand Down
24 changes: 19 additions & 5 deletions project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,8 @@ bool Project::loadGlocalWeightMaps(std::vector<Crit3DMacroArea> &myAreas, bool i
gis::Crit3DRasterGrid* macroAreasGrid = new gis::Crit3DRasterGrid();
std::string fileName = mapsFolder.toStdString() + "glocalWeight_";

std::vector<Crit3DMacroArea> existingAreas = interpolationSettings.getMacroAreas();

std::vector<float> areaCells;
int nrCols, nrRows;
double myX, myY;
Expand All @@ -2384,6 +2386,13 @@ bool Project::loadGlocalWeightMaps(std::vector<Crit3DMacroArea> &myAreas, bool i

for (int i = 0; i < myAreas.size(); i++)
{
//se ci sono già celle caricate di DEM o grid, salvale
if (existingAreas.size() > i)
{
myAreas[i].setAreaCellsDEM(existingAreas[i].getAreaCellsDEM());
myAreas[i].setAreaCellsGrid(existingAreas[i].getAreaCellsGrid());
}

if (QFile::exists(QString::fromStdString(fileName) + QString::number(i) + ".flt"))
{
if (readEsriGrid(fileName + std::to_string(i), macroAreasGrid, myError))
Expand All @@ -2410,7 +2419,12 @@ bool Project::loadGlocalWeightMaps(std::vector<Crit3DMacroArea> &myAreas, bool i
}
}
if (areaCells.size() > 0) nrAreasWithCells++;
myAreas[i].setAreaCells(areaCells);

if (isGrid)
myAreas[i].setAreaCellsGrid(areaCells);
else
myAreas[i].setAreaCellsDEM(areaCells);

areaCells.clear();
}
else
Expand Down Expand Up @@ -2984,7 +2998,7 @@ bool Project::interpolationDemGlocalDetrending(meteoVariable myVar, const Crit3D
{
// load macro area and its cells
Crit3DMacroArea myArea = interpolationSettings.getMacroAreas()[areaIndex];
areaCells = myArea.getAreaCells();
areaCells = myArea.getAreaCellsDEM();
std::vector<Crit3DInterpolationDataPoint> subsetInterpolationPoints;
double interpolatedValue = NODATA;

Expand Down Expand Up @@ -3160,7 +3174,7 @@ bool Project::interpolationDemMain(meteoVariable myVar, const Crit3DTime& myTime
return false;

// check glocal
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady())
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady(false))
{
if (! loadGlocalAreasMap()) return false;
if (! loadGlocalStationsAndCells(false)) return false;
Expand Down Expand Up @@ -3382,7 +3396,7 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)
{
//load macro area and its cells
Crit3DMacroArea myArea = interpolationSettings.getMacroAreas()[areaIndex];
areaCells = myArea.getAreaCells();
areaCells = myArea.getAreaCellsGrid();
std::vector<Crit3DInterpolationDataPoint> subsetInterpolationPoints;

if (!areaCells.empty())
Expand Down Expand Up @@ -4461,7 +4475,7 @@ void Project::showLocalProxyGraph(gis::Crit3DGeoPoint myPoint)
myZDEM = DEM.value[row][col];
}

if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady())
if (interpolationSettings.getUseGlocalDetrending() && ! interpolationSettings.isGlocalReady(false))
{
if (! loadGlocalAreasMap() || ! loadGlocalStationsAndCells(false))
{
Expand Down

0 comments on commit 51194a6

Please sign in to comment.