Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Average grids #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/BasicGrids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void ClipBasicGrids(long x, long y, long search, const char *output) {
maxY = loc.y + search;
minY = loc.y - search;

FindIndBasins(-124.73, -66.95, 50.00, 24.5);
FindIndBasins(-180.0, 180.0, 90.0, -90.0);
//FindIndBasins(-84.84, -67.26, 44.17, 35.76);

printf("Search box is %ld, %ld, %ld, %ld, %ld, %ld\n", minX, maxX, minY, maxY, x, y);
Expand Down Expand Up @@ -726,6 +726,10 @@ void CarveBasin(BasinConfigSection *basin, std::vector<GridNode> *nodes, std::ma
gauge->SetLat(ref.y);
gauge->SetLon(ref.x);
}
if (g_DEM->data[loc->y][loc->x] == g_DEM->noData || g_FAM->data[loc->y][loc->x] == g_FAM->noData || g_FAM->data[loc->y][loc->x] < 0) {
ERROR_LOGF("Gauge \"%s\" is located in a no data grid cell!", gauge->GetName());
return;
}
gauge->SetFlowAccum(g_FAM->data[loc->y][loc->x]);
gauge->SetUsed(false);
INFO_LOGF("Gauge %s (%f, %f; %ld, %ld): FAM %ld", gauge->GetName(), gauge->GetLat(), gauge->GetLon(), loc->y, loc->x, gauge->GetFlowAccum());
Expand Down Expand Up @@ -844,6 +848,8 @@ void CarveBasin(BasinConfigSection *basin, std::vector<GridNode> *nodes, std::ma
}
currentN->area = g_Projection->GetArea(currentN->refLoc.x, currentN->refLoc.y);
currentN->contribArea = currentN->area;
currentN->relief = g_DEM->data[currentN->y][currentN->x];
currentN->riverLen = currentN->horLen;
currentN->fac = g_FAM->data[currentN->y][currentN->x];
walkNodes.push(currentN);

Expand Down Expand Up @@ -916,7 +922,8 @@ void CarveBasin(BasinConfigSection *basin, std::vector<GridNode> *nodes, std::ma
//We compute slope here too!
if (keepGoing) {
for (int i = 1; i < FLOW_QTY; i++) {
if (TestUpstream(currentN, (FLOW_DIR)i, &nextNode)) {
if (TestUpstream(currentN, (FLOW_DIR)i, &nextNode) && currentNode < totalAccum) {
//printf("currentNode is %li\n", currentNode);
GridNode *nextN = &(*nodes)[currentNode];
nextN->index = currentNode;
currentNode++;
Expand All @@ -934,6 +941,8 @@ void CarveBasin(BasinConfigSection *basin, std::vector<GridNode> *nodes, std::ma
nextN->slope = ((DEMDiff < 1.0) ? 1.0 : DEMDiff) / nextN->horLen;
nextN->area = g_Projection->GetArea(nextN->refLoc.x, nextN->refLoc.y);
nextN->contribArea = nextN->area;
nextN->relief = g_DEM->data[nextN->y][nextN->x];
nextN->riverLen = nextN->horLen;
//printf("Pushing node %i %i (%i, %i) from %i %i (%i, %i) %i %i\n", nextN->x, nextN->y, g_DDM->data[nextN->y][nextN->x], g_FAM->data[nextN->y][nextN->x], currentN->x, currentN->y, g_DDM->data[currentN->y][currentN->x], g_FAM->data[currentN->y][currentN->x], currentNode, nodes->size());
walkNodes.push(nextN);
}
Expand All @@ -951,6 +960,10 @@ void CarveBasin(BasinConfigSection *basin, std::vector<GridNode> *nodes, std::ma
GridNode *node = &nodes->at(i);
if (node->downStreamNode != INVALID_DOWNSTREAM_NODE) {
nodes->at(node->downStreamNode).contribArea += node->contribArea;
nodes->at(node->downStreamNode).riverLen += node->riverLen;
if (nodes->at(node->downStreamNode).relief < node->relief) {
nodes->at(node->downStreamNode).relief = node->relief;
}
}
}

Expand Down Expand Up @@ -1063,7 +1076,7 @@ bool TestUpstream(long nextX, long nextY, FLOW_DIR dir, GridLoc *loc) {
return false;
}

if (nextX >= 0 && nextY >= 0 && nextX < g_DDM->numCols && nextY < g_DDM->numRows && g_DDM->data[nextY][nextX] == wantDir) { // && g_FAM->data[nextY][nextX] <= currentFAC) {
if (nextX >= 0 && nextY >= 0 && nextX < g_DDM->numCols && nextY < g_DDM->numRows && g_DDM->data[nextY][nextX] == wantDir && g_DEM->data[nextY][nextX] != g_DEM->noData && g_FAM->data[nextY][nextX] != g_FAM->noData) { // && g_FAM->data[nextY][nextX] <= currentFAC) {
loc->x = nextX;
loc->y = nextY;
return true;
Expand Down Expand Up @@ -1259,6 +1272,9 @@ void ReclassifyDDM() {
case 32:
g_DDM->data[row][col] = FLOW_NORTHWEST;
break;
default:
g_DDM->data[row][col] = g_DDM->noData;
break;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/GridNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct GridNode {
float area;
float contribArea;
float horLen;
float riverLen;
float relief;
bool channelGridCell;
GaugeConfigSection *gauge;
unsigned long downStreamNode;
Expand Down
2 changes: 2 additions & 0 deletions src/GriddedOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const char *GriddedOutputText[] = {
"maxthresholdexceedance",
"maxthresholdexceedancep",
"precipaccum",
"maxinundation",
};

const int GriddedOutputFlags[] = {
Expand All @@ -45,4 +46,5 @@ const int GriddedOutputFlags[] = {
OG_MAXTHRES,
OG_MAXTHRESP,
OG_PRECIPACCUM,
OG_MAXDEPTH,
};
3 changes: 2 additions & 1 deletion src/GriddedOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ enum SUPPORTED_OUTPUT_GRIDS {
OG_MAXTHRES = 32768,
OG_MAXTHRESP = 65536,
OG_PRECIPACCUM = 131072,
OG_MAXDEPTH = 262144,
};

#define OG_QTY 19
#define OG_QTY 20

extern const char *GriddedOutputText[];
extern const int GriddedOutputFlags[];
Expand Down
45 changes: 13 additions & 32 deletions src/KinematicRoute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,6 @@ float KWRoute::SetObsInflow(long index, float inflow) {
cNode->incomingWaterOverland = inflow / node->horLen;
} else {
prev = cNode->states[STATE_KW_PQ];
float diff = 0.0;
if (inflow > 1.0 && prev > 1.0) {
diff = inflow/prev - 1.0;
}
GaugeConfigSection *thisGauge = node->gauge;
float multiplier = 1.0;
if (diff > 0.2) {
multiplier = 0.5;
} else if (diff < -0.2) {
multiplier = 2.0;
}
printf(" Multiplier %f,%f,%f,%f ", multiplier, diff, inflow, prev);
if (multiplier != 1.0) {
size_t numNodes = nodes->size();
for (size_t i = 0; i < numNodes; i++) {
node = &nodes->at(i);
if (node->gauge == thisGauge) {
KWGridNode *cNode = &(kwNodes[i]);
cNode->params[PARAM_KINEMATIC_ALPHA] *= multiplier;
if (cNode->params[PARAM_KINEMATIC_ALPHA] < 0.01) {
cNode->params[PARAM_KINEMATIC_ALPHA] = 0.01;
} else if (cNode->params[PARAM_KINEMATIC_ALPHA] > 200.0) {
cNode->params[PARAM_KINEMATIC_ALPHA] = 200.0;
}
}
}

}
cNode->states[STATE_KW_PQ] = inflow;
cNode->incomingWaterChannel = inflow;
}
Expand Down Expand Up @@ -387,6 +359,15 @@ void KWRoute::InitializeParameters(std::map<GaugeConfigSection *, float *> *para
//This pass distributes parameters
size_t numNodes = nodes->size();
size_t unused = 0;

if (paramGrids->at(PARAM_KINEMATIC_ALPHA) && g_DEM->IsSpatialMatch(paramGrids->at(PARAM_KINEMATIC_ALPHA))) {
printf("Alpha grid is match!\n");
}

if (paramGrids->at(PARAM_KINEMATIC_BETA) && g_DEM->IsSpatialMatch(paramGrids->at(PARAM_KINEMATIC_BETA))) {
printf("Beta grid is match!\n");
}

for (size_t i = 0; i < numNodes; i++) {
GridNode *node = &nodes->at(i);
KWGridNode *cNode = &(kwNodes[i]);
Expand All @@ -402,8 +383,8 @@ void KWRoute::InitializeParameters(std::map<GaugeConfigSection *, float *> *para
}
cNode->incomingWater[KW_LAYER_INTERFLOW] = 0.0;
cNode->incomingWater[KW_LAYER_FASTFLOW] = 0.0;
// Deal with the distributed parameters here
// Deal with the distributed parameters here
GridLoc pt;
for (size_t paramI = 0; paramI < PARAM_KINEMATIC_QTY; paramI++) {
FloatGrid *grid = paramGrids->at(paramI);
Expand All @@ -430,7 +411,7 @@ void KWRoute::InitializeParameters(std::map<GaugeConfigSection *, float *> *para
}

if (cNode->params[PARAM_KINEMATIC_ALPHA] < 0.0) {
//printf("Node Alpha(%f) is less than 0, setting to 1.\n", cNode->params[PARAM_KINEMATIC_ALPHA]);
printf("Node Alpha(%f) is less than 0, setting to 1.\n", cNode->params[PARAM_KINEMATIC_ALPHA]);
cNode->params[PARAM_KINEMATIC_ALPHA] = 1.0;
}

Expand All @@ -446,7 +427,7 @@ void KWRoute::InitializeParameters(std::map<GaugeConfigSection *, float *> *para



if (node->fac > cNode->params[PARAM_KINEMATIC_TH]) {
if (node->contribArea > cNode->params[PARAM_KINEMATIC_TH]) {
node->channelGridCell = true;
cNode->channelGridCell = true;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/LAEAProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "LAEAProjection.h"

LAEAProjection::LAEAProjection() {
stan_par = TORADIANS(45.0);
cent_lon = TORADIANS(-100.0);
a = 6370997.0;
stan_par = TORADIANS(48.0); // TORADIANS(45.0);
cent_lon = TORADIANS(9.0); //TORADIANS(-100.0);
a = 6378388.0; //6370997.0;
}

LAEAProjection::~LAEAProjection() {
Expand Down
Loading