Python Create Colourised Tide Tables & Automate Process

This is the next part of daily download data via email, to do with tides on the beach that I regularly walk the dog.

Using Bing crosby (aka Bing Chat) to find the solution

This was a bit of a challenge as I was doing an experiment with Bing Crosby (aka Bing Chat) to see how wel it did. I kept on trying to get bing to do al the work but found it started to cycle the same answers again and again. Even starting new instances of bing it would come up with the same coding solution even if it didn’t meet the criteria.

Another test I did with Bing Crosby (aka Bing Chat) was to use the black box approach, I’d give it the input CSV data and the output CSV data and asked it to modify the one dataset to the other using python.

This was interesting as it used 3 different approaches to try and make a solution, the first using pandas, the second series and the third a very long iterative approach. I chose to stay with the pandas solution.

In the end I think bing was not that great with the logic part of the code or else I did not explain my requirements very well.

Another thing that happened is that I used up all my Bing Crosby (aka Bing Chat) points for the day, although I’d been using it most of the day, and it told me it was worn out and come back tomorrow, so I had to mess around and create another account so I could continue to use it. So it does have its limits for free use as well as the chat GPT program.

After fixing the code I’d a table with the date column and 10 tide columns, two for each tide one for time and one for height. I asked bing to reduce it to one column each (total of 5) with the time above and the height beneath for each tide and it came up with an elegant solution using a ‘/n’ new line in the middle of the string, this worked great in the PDF table (at this point I fed bing the whole code including making the PDF table with a Class). It would not have been a solution that I would have come up with and I was impressed with its simplicity and elegance.

Completing the code

I found that after using Bing Crosby (aka Bing Chat) I had a few examples so was able to follow the logic of the code. So it was easier to find where the problem was and find a solution using the interwongle to ask the right questions and get results on Stack Overflow.

With the previous examples I managed to resolve the code logic quite quickly, but in some ways that is because I spent a long time on Bing. If I’d tried to solve it earlier I may have done it faster. But it was a learning process

Tides Plot

I did an initial plot with Bing and looked around for examples and libraries that could make a sine wave for to fit the high and low tide points and spent an hour or 2 getting nowhere. I left off doing the plot and came back to it later and just accepted a straight line between 2 points for high/low tides and it conveys just as much information as the sine wave curve but doesn’t look as pretty.

Bing was pretty great at adding features such as amplitude between high/low tides, heights of peaks/troughs and x axis formatting for date/time and grids. This really speeds up my embellishments of charts.

In one way, it dumbs down the process, so I don’t learn how its done, in another way it gives me lots of examples so I know what I can do and the rough method to achieve the outcome that I want.

The enhancement of the charts does give visual clarity to help convey the information, and as a designer I’m a very visual person, and prefer to consume information in a plot rather than a table, although the table is good for reference data. But there is a fiddle factor that goes with adding detail to plots and this can be a time consuming and subjective process,and I can be a bit intolerant of it as it can take up so much of your time , just to add ‘ a slightly different shade of mauve perhaps?’ that then you fiddle with for 2 hours and don’t produce anything relevant.

Table Background Colourisation

When I asked Bing Crosby (aka Bing Chat) to write the code I asked it to write a class for creating the table using the fpdf2 library. On reflection using a class for this may not have been the best way, as I was reliant on bing to rewrite the code snippets from the fpdf2 documents to be able to be used in a class.

I initially thought by using classes I’d start to learn a bit more about them but in this case it was not of that much help.

I found that I could either colourise rows, or columns but not both , as my experiments with trying to use both ended up with a checkerboard pattern, and I ended up having to choose with colourising either rows or columns, and for this instance chose columns. I also played with colouring headers and also the Title backgrounds as well.

In the moon phase table I was a bit disappointed with the emoji icons, coloured on web page, only showing up as black/white in the table, and it seems that the Unicode only comes into the PDF as black/white. But there is an alternative approach where you can bring I images so maybe for future ones I can add images into a column with coloured phases of the moon.


Overall I was happy with the process and doing:

1/ API call and configuring the json output to add extra columns by splitting the datetime stamp into a date and time column and adding a tide column for high/low tides as one script and process

2/ Then creating the script for the tide table, using the csv output from the csv created in the first step, and in this case also combining the PDF output script in it as well, it also called in the jpg from step 3 to add tide plot to the pdf

3/ Another script using the csv output from first step to create the plot to a .jpg file.

When I came to incorporate this into my PDF automation for the Epheremis email it was easy to add these scripts inas discrete steps, although in the following order 1,3 then 2 to crate final pdf, then this was incorporated into the script that merges all the separate pdf’s (epheremis, skyplot, moon phase/sun rise/set & tides pdf) into one document.

After that the email that sent the combined pdf just needed the subject heading to reflect the additional tide information

End comment

A good bit of learning using Bing Crosby (aka Bing Chat), hopefully I’ll be able to use it more effectively in future to be more productive with it.

I’m pleased with the results of all the things I set out to do in this project & I learned a lot about tides that I was not aware of before.

I would have liked a sinewave on my plot but I’m not prepared, at this time to put a massive amount of effort into something that is not that critical, it’s a nice to have rather than an important feature.

The scaling of the tide plot to the text size of the table is wrong, maybe I should split the plot into 2 so txt size more consistent, but that is for a future iteration.