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

TimeInDayLight - error when calculating local almanac #405

Open
quentin-guignard-pinoncely opened this issue May 2, 2024 · 2 comments
Open

Comments

@quentin-guignard-pinoncely
Copy link

quentin-guignard-pinoncely commented May 2, 2024

I'm trying to use the Time In Day Light tool, but the following error is raised (with the QGIS pluggin and the python interface) :

WhiteboxTools output:
*****************************
* Welcome to TimeInDaylight *
* Powered by WhiteboxTools *
* www.whiteboxgeo.com *
*****************************
Calculating the local almanac...
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ComponentRange { name: "ordinal", minimum: 1, maximum: 365, value: 366, conditional_range: true }', whitebox-tools-app\src\tools\terrain_analysis\time_in_daylight.rs:935:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Process returned error code 101

When i'm looking to the script, it seems that the script is triying to access to the 366 day of 2023, which it not exists.

https://github.com/jblindsay/whitebox-tools/blob/master/whitebox-tools-app/src/tools/terrain_analysis/time_in_daylight.rs#L935

@wiesehahn
Copy link

I got the same error via R, it was reported here opengeos/whiteboxR#74

@brownag
Copy link
Contributor

brownag commented Jul 31, 2024

Copying response from end of opengeos/whiteboxR#74

Originally posted by @brownag in opengeos/whiteboxR#74 (reply in thread)

I can confirm I get the same error on Linux. Via the R interface or via the command line. I tinkered with some of the parameters and same result.

I notice there were some changes (NaiveTime -> Time, NaiveDate -> Date) in how time is handled in this tool for WhiteboxTools v2.3: 4208336#diff-4c6d03f9fd598a5f68bf881cd140eedc9642af3e07fa7bdc0d062f291adba587

Based on the error output thread 'main' panicked at 'called Result::unwrap() on an Err value: ComponentRange { name: "ordinal", minimum: 1, maximum: 365, value: 366, conditional_range: true }', whitebox-tools-app\src\tools\terrain_analysis\time_in_daylight.rs:935:30 I would guess that this is an issue related to leap years.

2024 is a leap year, 2023 is not. Previous code used 2020. It looks like the code (Line 934 in time_in_daylight.rs) might be hard-coded to use 2023, but is iterating over day of year 1 to 366.

let midnight = Date::from_ordinal_date(2023, doy as u16)
.unwrap()
.with_hms(0, 0, 0)
.unwrap()
.assume_offset(
UtcOffset::from_hms(utc_offset as i8, 0, 0)
.unwrap()
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants