Skip to content

i.eb.hsebal01: fix manual pixel handling #6004

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

Merged
merged 3 commits into from
Jul 2, 2025

Conversation

jayneel-shah18
Copy link
Contributor

This PR fixes issues mentioned in #6003 that prevent the module from working properly when manual wet/dry pixels are specified:

  • Missing initialization of raster arrays:
    • In manual mode, d_t0dem, d_z0m, and d_eact arrays were never populated before iteration loops. This caused all pixel values to remain zero, leading to invalid d_rah_dry and d_roh_dry, NaN results, and premature failure with Delta T Convergence failed.
    • Fix: Added this loop after raster input buffers are allocated:
/* Always read t0dem, z0m, and eact into the arrays */
for (row = 0; row < nrows; row++) {
    Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
    Rast_get_d_row(infd_z0m, inrast_z0m, row);
    Rast_get_d_row(infd_eact, inrast_eact, row);

    for (col = 0; col < ncols; col++) {
        d_t0dem[row][col] = ((DCELL *)inrast_t0dem)[col];
        d_z0m[row][col] = ((DCELL *)inrast_z0m)[col];
        d_eact[row][col] = ((DCELL *)inrast_eact)[col];
    }
}
  • Row/column assignment for manual coordinates:
    • When using manual mode without the -c flag, the provided wet/dry pixel coordinates must be interpreted as row/col indices. These were not assigned properly to rowWet, colWet, rowDry, colDry, leading to uninitialized or stale values.
    • Fix: Added this logic:
/* If -c flag is not set, interpret inputs as integer row/col indices */
if (!flag3->answer) {
    rowWet = (int)m_row_wet;
    colWet = (int)m_col_wet;
    rowDry = (int)m_row_dry;
    colDry = (int)m_col_dry;
}
  • Verbosity cleanup:
    • The verbosity messages for projection coordinates were displayed regardless of whether -c was specified, causing confusion.
    • Fix: Indented the messages so they only print if flag3->answer is true:
/* If pixels locations are in projected coordinates */
if (flag3->answer) {
    G_verbose_message(_("Manual wet/dry pixels in image coordinates"));
    G_verbose_message(_("Wet Pixel=> x:%f y:%f"), m_col_wet, m_row_wet);
    G_verbose_message(_("Dry Pixel=> x:%f y:%f"), m_col_dry, m_row_dry);
}

The changes in the module have been verified to run successfully in all modes:

  • Automatic pixel selection (-a)
  • Manual row/col pixel input (without -c)
  • Manual projected coordinates (with -c)

The results matched the expected output rasters in each mode.

A test suite for the module will be added once these changes are merged.

Closes #6003

@github-actions github-actions bot added C Related code is in C module imagery labels Jul 1, 2025
@petrasovaa petrasovaa merged commit 069ec85 into OSGeo:main Jul 2, 2025
27 checks passed
@jayneel-shah18 jayneel-shah18 deleted the i_eb_hsebal01_fix branch July 2, 2025 15:19
@github-actions github-actions bot added this to the 8.5.0 milestone Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C imagery module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] i.eb.hsebal01: Manual pixel selection fails due to uninitialized rasters and inconsistent pixel index handling
2 participants