Temperature Modelling in Python

Temperature Modelling in Python

How to automatically create and reference a dynamic array

Python is great for data science, the power of its arrays and functions make data modelling very accessible.

To produce a simple weather forecast we can create an array from a cosine wave where amplitude is the temperature range divided by 2, wavelength is the days in the year (366 in 2020), the Y offset is the hottest temperature divided by the amplitude and the X offset is the coldest day.

daily_temp = y_offset + amplitude * -1 * cos(2*pi * 1/wavelength * day - 2*pi*x_offset/wavelength)

According to wikipedia, the max for winter is 6.4 deg C, the max for summer is 20.4 deg C and the coldest day is 13th Jan.

This give us a forecast of 18.9 deg C for 22nd August. The temperature at the time was 19 deg C.

It works reasonably well for simple long-range forecasts because sin/cos are models for waves/rotational motion and seasons are a result of the earth tilting.

(click on the code below for the github repository)

No alt text provided for this image
No alt text provided for this image


Vas Rabani

Product Management | Agile Project Management | Lecturer @ UCD Professional Academy

4 年

Nice you have illustrated your example in coding - really straightforward to understand now ...

Tom Raymond

Credit & Risk Analyst delivering Data led insight and solutions using Lean, Agile and MECE methodologies

4 年

Nice! Thanks for sharing Phil ??

要查看或添加评论,请登录

Philip Blakeman的更多文章

社区洞察

其他会员也浏览了