Open sebastien-rosset opened 4 months ago
it was intentional... 0 means the boat is not moving. NaN means we do not know the boat speed.. but maybe it is still broken?
it was intentional... 0 means the boat is not moving. NaN means we do not know the boat speed.. but maybe it is still broken?
Thanks, the history is helpful. I will check again and get back.
Based on this code:
PARSE_WARNING(_("Warning: 0 values found in polar.\n"
"These measurements will be interpolated.\n"
"To specify interpolated, leave blank values.\n"
"To specify course as 'invalid' use 0.0 rather than 0\n"));
and:
** blank = Interpolate from nearby values, if at least one set of
values of tws/twd are entered in the column/row.
*** 0 = Not recognized by the program, will remove these it edited.
Sometimes a polar will contain 0's. They should be removed.
*** 0.0 = Specifies invalid (cannot be used). Boat won't move and can't
go there.
and:
<property name="label">Leave any cell blank to automatically interpolate from nearby values.
Use a value of 0.0 to specify invalid (cannot be used)

View the polar plot in the boat dialog while editing the polar.</property>
There are four possible values in a polar:
Value | Description |
---|---|
> 0 | Normal boat speed value |
0.0 | Boat speed is considered "invalid" |
empty | Value will be interpolated using neighboring cells |
0 | The first time "0" is found in the polar, the cell value is set to NaN . This means the value will be interpolated using neighboring cells. Subsequent "0" values in the polar are stored as 0.0 i.e. boat speed is zero. |
Values are interpolated only if either:
In other cases, the polar value is not interpolated and remains NaN
.
Once the polar values have been loaded and the plugin calculates a route, the value NaN
is considered invalid. I.e. the plugin will not use this path.
I'm wondering if this logic could be simplified.
NaN
. But if the wind angle is zero, it makes sense that the boat speed is 0.0, i.e. the boat speed is not "unknown".For case 3.i, the code hits this path: https://github.com/seandepagnier/weather_routing_pi/pull/302/files#diff-e6e0fa7dd681f90e3e13a71ae1102a4bb0c52ae1173eb1dad0865264df6ed903R673 and prints failure messages such as:
polar failed bad! 18.487259 7.997830 21.487259 nan
polar failed bad! 18.487259 7.997830 24.487259 nan
polar failed bad! 18.487259 7.997830 27.487259 nan
polar failed bad! 18.487259 7.997830 30.487259 nan
It the logic remains as is, then perhaps the values in .opencpn/plugins/weather_routing/polars/Example/Test-TWS-0-20+60.pol
for the first row should be changed from "0" to "0.0".
Problem statement
Polar::wind_speed
is set toNaN
. It seems it should be set to zero.Polar::wind_speed
is set toNaN
, thePolar::Speed
function may returnNan
, and a message is printed to stdout. It should probably have been logged to opencpn.log, which makes it easier to troubleshoot.Example print statements to
stdout
when polar contains NaN:Changes in this PR
When the plugin opens a polar and warning-level parse issues are found, log the parse warnings to
opencpn.log
. This is useful for troubleshooting route calculation issues. For example:When a polar contains the 0 value, initialize the first element of the
Polar::wind_speed
array with the0
value instead ofNaN
.Polar::wind_speed
array toNaN
was intentional?? See analysis below.When route calculation fails, use
wxLogMessage
instead ofprintf
to report the problem. Improve the message to make it easier to troubleshoot the issue.With this PR, the print statements are now written to
opencpn.log
:Analysis
When a polar is loaded, some warnings are generated with
PARSE_WARNING
, but these warnings are not necessarily displayed anywhere. The warnings are not logged in opencpn.log either. This can make route failure harder to understand.In particular, when a polar file contains a 0 value,
Polar::Open
adds theNaN
value to the first entry in thePolar::wind_speeds
array. For example, given the following polar:The
Polar::wind_speeds
array is populated as[NaN, 5.4, 5.6, 6, 6.1, 6, 5.6, 5.0, 4.3]
Relevant code: https://github.com/seandepagnier/weather_routing_pi/blob/97f2a08dfb06b4847d9790b11b6155d3bca5efd2/src/Polar.cpp#L299-L315The
NaN
value in thewind_speeds
array ends up causingPolar::Speed()
to returnVB=NaN
at https://github.com/seandepagnier/weather_routing_pi/blob/97f2a08dfb06b4847d9790b11b6155d3bca5efd2/src/Polar.cpp#L537