Polarizer - data logging based polar generation

hoektron

Member
234
126
Gulf Coast, TX
I was on an ocean passage recently and was a bit frustrated with Predictwind routing, not having accurate polars for our boat, and having to basically just guess and apply scaling factors to other pre-defined polars.  Well, I'm a data nerd and figured there's got to be a way to generate my own polars based on actual sailing conditions.  The boat I was on had B&G electronics and buried waaaaay deep in one of the menus is the NMEA0183 server information.  Now, this data format is older than I am, but it was easy enough to parse that I was able to whip something up while underway.

Long story short, I wrote a series of python scripts that will log NMEA0183 data, save it to files based on sail config, parse/bin/average it into TWA/TWS/BSP (or SOG), output that to CSV files, and then combine it all into a 'best sailset' file that you can then plug into Predictwind.

If this is interesting to anyone, I put up all the code as an open source project on Github: https://github.com/hoeken/Polarizer

This whole setup only works on a B&G system where you can connect over the local network.  Also only tested it on my Macbook.  The code is a bit sloppy since I didn't have access to Stack Overflow, but it does work.  There's not much documentation, but the scripts are all pretty straightforward so should be somewhat self explanatory.  I'll be crossing the Atlantic again later this year so hopefully will get another good chance to work on it again in the future.

Cheers!

 

ryley

Super Anarchist
5,578
709
Boston, MA
@hoektron, do you have any outputs you can share? I know others have developed things like this in the past and the data has seemed very "noisy." I'd be very interested to see how your outputs compare, and how you felt about them as a tool on your passage.

Cheers,

 

hoektron

Member
234
126
Gulf Coast, TX
@hoektron, do you have any outputs you can share? I know others have developed things like this in the past and the data has seemed very "noisy." I'd be very interested to see how your outputs compare, and how you felt about them as a tool on your passage.

Cheers,
Sure, hopefully I can attach them here.  Here are a series of intermediate .csv files that it will generate that helped me see whats going on under the hood.  The count file is obvious - how many datapoints for that particular twa/tws.  diff is the difference between main and mean, mean and median are just the mathematical mean and median of each twa/tws point.  vmg is projected vmg either upwind or downwind.

I tried a number of things, but settled on 2 methods that seemed to give answers that matched up what we were seeing pretty well.  The data updates at about 1hz over NMEA0183, and it seems to be instant values at that moment.  So I added a 10 second running average and plug that in every 1hz or so.  After it bins all the BSP numbers by twa/tws it also filters out any data outside of 1 standard deviation and then uses the average of the remainder as boat speed.

Honestly the hardest part was remembering to stop the datalogging script when we made any sail changes.

This data was logged on a crossing in fairly normal conditions on a Balance 526 "Stargazer".  I want to say it has a standard B&G WS310 wind meter, and an airmar dst810 for boat speed.  We didn't really do any calibration beyond 'yep, it seems to be right'.

View attachment jib and full main-count.csv
View attachment jib and full main-diff.csv
View attachment jib and full main-mean.csv
View attachment jib and full main-median.csv
View attachment jib and full main-stddev.csv
View attachment jib and full main-vmg.csv

 

hoektron

Member
234
126
Gulf Coast, TX
The way I have it setup is that you log data for each sail set configuration, which will generate you all those files above, and the 'mean' file is essentially your polar for that set.

I also wrote a script to combine all these files into a 'best of sailset' file which is best boat speed across all sailsets, with a 'legend' that shows what twa/tws combo should have what sailset.  you can also edit this legend file to you personal tastes or wind limit requirements and re-generate a final polar that way.  There is also a predictwind file in there that you can use to upload to predictwind routing.  This was a mostly downwind sail for us (SA to Grenada) so we don't really have any good data on upwind sailing.

View attachment combined-polars-legend.csv
View attachment combined-polars-predictwind.txt
View attachment combined-polars-sailset.csv
View attachment combined-polars-speed.csv
View attachment combined-polars-vmg.csv

 

Zonker

Super Anarchist
10,683
7,116
Canada
Good luck as well. I was watching an IACC sail testing day where the boffins were recording real time performance. Amazingly scattered data. Looked like somebody sneezed on the screen. I recall they were plotting VMG versus wind speed while sailing upwind. You'd expect much tighter grouping of the data but nope.

 

weightless

Super Anarchist
5,608
587

El Borracho

Meaty Coloso
6,959
2,901
Pacific Rim
IDK but I've been told that sensor integration is what smart folk do when they've totally mastered high frequency radio electronics and are looking for a more serious challenge.

FWIW, I'd be tempted to check the assumption that rolling average is the best filter. If you're post processing in python this example from the scipy signal library might be worth a look:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html#scipy.signal.filtfilt
Yes. Rolling average might be the worst possible processing algorithm. Perhaps passable with hundreds of data points over several minutes. With the processing power available today on the simplest computer there are far better filters. Even the theoretical ideal low pass filters are trivial to compute today.

Tip: Do not screw with the outliers. They are data. 

 

hoektron

Member
234
126
Gulf Coast, TX
IDK but I've been told that sensor integration is what smart folk do when they've totally mastered high frequency radio electronics and are looking for a more serious challenge.

FWIW, I'd be tempted to check the assumption that rolling average is the best filter. If you're post processing in python this example from the scipy signal library might be worth a look:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html#scipy.signal.filtfilt
Huh, that one looks interesting. I'm not really a data scientist or statistician but I can give it a try. 

 

hoektron

Member
234
126
Gulf Coast, TX
Yes. Rolling average might be the worst possible processing algorithm. Perhaps passable with hundreds of data points over several minutes. With the processing power available today on the simplest computer there are far better filters. Even the theoretical ideal low pass filters are trivial to compute today.

Tip: Do not screw with the outliers. They are data. 
Well rolling average really did clean up the numbers. Especially when the nmea0183 output was at a very low rate and was just the instantaneous value. Huge swings in tws/twa as our mast would swing and big ones as we would speed up/slow down in troughs of waves.

Sure, a few minutes of data is garbage. I didnt see good results until I had at least a few hours of data for each sail config. Realistically it took days of data before I had any confidence in the numbers.

Once we did get enough data though, the numbers really started to match the performance we were seeing, and lined up with what you would expect out of a particular sail combo.

The real test for me would be to put it back in to Predictwind and see how well the routing works. Ideally you wouldnt need to do any fudging of numbers and it would just be bang on accurate. Ideally.

 

weightless

Super Anarchist
5,608
587
Huh, that one looks interesting. I'm not really a data scientist or statistician but I can give it a try. 
Me neither and I don't want to lead anyone astray. I just wanted to point to some options that might be interesting to you. I have fiddled with this just a little and I suspect you might get a "better" impulse response with Butterworth than with a rolling average. For a given value of "better", of course. If the rolling average is good enough that's great.

 

El Borracho

Meaty Coloso
6,959
2,901
Pacific Rim
Well rolling average really did clean up the numbers. Especially when the nmea0183 output was at a very low rate and was just the instantaneous value. Huge swings in tws/twa as our mast would swing and big ones as we would speed up/slow down in troughs of waves.

Sure, a few minutes of data is garbage. I didnt see good results until I had at least a few hours of data for each sail config. Realistically it took days of data before I had any confidence in the numbers.

Once we did get enough data though, the numbers really started to match the performance we were seeing, and lined up with what you would expect out of a particular sail combo.

The real test for me would be to put it back in to Predictwind and see how well the routing works. Ideally you wouldnt need to do any fudging of numbers and it would just be bang on accurate. Ideally.
Whatever “clean up the numbers”means. If rolling average seemed good then some good filtering would be astounding.

For gathering the data you can certainly run the sampling for many minutes or miles. That delay does not matter. The problem will be that when you try to use that data while sailing you will need quality data only seconds old. Nobody can steer to a several minute rolling average display.

There exist very effective methods to greatly suppress effects of rolling, for one example, without greatly delaying the reporting as averages tend to do. 

 

hoektron

Member
234
126
Gulf Coast, TX
Whatever “clean up the numbers”means. If rolling average seemed good then some good filtering would be astounding.

For gathering the data you can certainly run the sampling for many minutes or miles. That delay does not matter. The problem will be that when you try to use that data while sailing you will need quality data only seconds old. Nobody can steer to a several minute rolling average display.

There exist very effective methods to greatly suppress effects of rolling, for one example, without greatly delaying the reporting as averages tend to do. 
I think we're talking about completely different things here.

What I'm talking about is that during the first phase of the processing of the raw logged data, I do a running average of the last 10 seconds of data.  Not the entire dataset, just the last 10 seconds of data.  That really smooths things out, which is important because the next step is to put those 3 data points (twa, tws, bsp) into 'bins' that match up with the eventual x / y axes of the polar that will be generated.  Phase 2 is to then take an average of all the 'binned' boat speeds for a given twa/tws combo.  Before I was doing that, I would get really wild numbers, not to mention that the wind and boat speed numbers are being reported at different times!  So really some level of averaging that input is necessary.

As for what I mean by clean numbers... well that's me sitting at the plotter staring at my laptop and seeing how well the numbers match up. It was a 28 day passage.  Lots of staring, lol.

It was also me taking the polars my script generated and seeing how well they matched up with the simulated polars that we got from the yacht designers, which were run with the assumption of a 'lightship' vessel and flat seas. We were not light, and we were in moderate Atlantic open ocean conditions. Keep in mind that my goal here is to get accurate polars for our particular usage... making ocean passages and getting accurate routing. The simulated polars were also run with an asym, and the owner of my boat opted for a symmetric spinnaker, which really was the genesis of this whole project ("Whats the best way to rig this spinnaker, and what is the best VMG?  Lets try math!")

 

hoektron

Member
234
126
Gulf Coast, TX
The problem will be that when you try to use that data while sailing you will need quality data only seconds old. Nobody can steer to a several minute rolling average display
That is also not my intention here.  The purpose of this script is to log tons of data, crunch those numbers, and generate a set of polars that I can plug into Predictwind to get accurate weather routing.  I suppose some high end plotters do support polars, but you would be putting the static output of my script in as the polar and using the numbers from the MFD to sail to it.

 

weightless

Super Anarchist
5,608
587
I do a running average of the last 10 seconds of data.  Not the entire dataset, just the last 10 seconds of data. 
Oh. I have not looked at your data, working is working, and it might not be helpful to get too deep into all of this -- I think it gets deep fast. Still, If I was to dive in I think that I'd be tempted to put each instrument's data into time series tables (maybe in pandas which provides nice features for working with them), smooth those series with a low pass filter, then do your derivations and binning using the smoothed data. Keeping everything in phase while smoothing can be a trick. On of the nice features of the running the filter both ways through the data (ie. fliltfilt) is that the results end up in phase. I was trying to hint at that above.

 
Last edited by a moderator:

hoektron

Member
234
126
Gulf Coast, TX
Oh. I have not looked at your data, working is working, and it might not be helpful to get too deep into all of this -- I think it gets deep fast. Still, If I was to dive in I think that I'd be tempted to put each instrument's data into time series tables (maybe in pandas which provides nice features for working with them), smooth those series with a low pass filter, then do your derivations and binning using the smoothed data. Keeping everything in phase while smoothing can be a trick. On of the nice features of the running the filter both ways through the data (ie. fliltfilt) is that the results end up in phase. I was trying to hint at that above.
definitely going to try this.  all of the code was written at sea, with only iridium go as an internet connection.  it was like having half my brain gone with no stack overflow or easy way to look up / install libraries. making some graphs would be great and would help build more confidence in the data too.

 
Awesome project. I'll be super keen to have a play with this later!

Out of interest, which auto pilot does this 526 have in it? I'm guessing it's a NAC-3 if there's no 3D motion correction for the wind data.

 

hoektron

Member
234
126
Gulf Coast, TX
Out of interest, which auto pilot does this 526 have in it? I'm guessing it's a NAC-3 if there's no 3D motion correction for the wind data.
Hard to say really, because its all based on the owners choice. This one was def an NAC-3.

If you give it a try, let me know.  Right now it only pulls data from nmea0183 over ip from a b&g, but plan on adding n2k support once I get my boat in October.

 

Zonker

Super Anarchist
10,683
7,116
Canada
Just thinking out load because most of this is over my head - but over a few hours won't your wind speed vary so much that the difference between 10 and 12 knots sort of smears the data into saying the wind speed for this time was 11 knots? Same with TWA kind of thing with the autopilot steering in waves and heading bouncing all over the place.

I think what you will get will be easily more than enough for input into Predictwind for routing decisions. If I sat down for 1/2 hour I could probably come within 5-10% of my last boat's performance just by thinking about it and write a set of polar curves. 

I wouldn't get too hung up on the polar results as an input into Predictwind. You're not sitting at the nav table 18 hrs a day poring over continuously changing routing decisions like a serious ocean racing boat. I kind of think you'd get more from the boat by actively trimming or steering the boat by hand (no autopilot) for several hours a day. OR spending more time looking at big picture weather and and doing longer term strategic routing. I'd be comparing Grib models and reviewing the results rather than rely on the routing of just one model. I know Predictwind can do that, but I'd also be trying to see which models were matching the weather I was in.

 

hoektron

Member
234
126
Gulf Coast, TX
Just thinking out load because most of this is over my head - but over a few hours won't your wind speed vary so much that the difference between 10 and 12 knots sort of smears the data into saying the wind speed for this time was 11 knots? Same with TWA kind of thing with the autopilot steering in waves and heading bouncing all over the place.
Ah, so here's where I'm bad at explaining stuff.  The way the script works is that for each TWA, TWS, BSP data point, it puts it in a 'bin'.  Those bins are the rows/columns of a polar.  For example on a broad reach its 140, 150, 160, etc.  For wind speeds its 10, 12, 14, 16, etc.  So as you're sailing along it will look at each data point, figure out which TWA/TWS is the closest, and will throw it in the appropriate bin.  At the end it will average all the points in each bin and that value is the target boat speed for that particular TWA/TWS.

If anything, getting a wide range of wind and angles is good - you need that to fill out all the different TWA/TWS pairs.  If you look at one of the "count" csv's I uploaded you can see that some bins have TONS of datapoints, and the ones on the edges don't have as many.  Mainly because we were just sitting on one point of sail for days on end, lol.

 
Top