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)
Product Management | Agile Project Management | Lecturer @ UCD Professional Academy
4 年Nice you have illustrated your example in coding - really straightforward to understand now ...
Credit & Risk Analyst delivering Data led insight and solutions using Lean, Agile and MECE methodologies
4 年Nice! Thanks for sharing Phil ??