Dataset: from www.ncei.noaa.gov
Order ID: 1520589
Email: lionboy589@gmail.com
Order ID: 1520617
Email: lionboy589@gmail.com
Order ID: 1520669
Email: lionboy589@gmail.com
Order ID: 1520741
Email: lionboy589@gmail.com
Link: github
Requirement:
- Python 3.4 or newer
- Matplotlib 2.2.3
- numpy 1.15.1
Important file:
- Main.py: main function
- StatFunction.py: function related to stat
- Data.py: read data file
- Piecewise.py: piecewise interpolation
- Projection.py: do projection
- LinearSystem.py: solve linear system of equation
- 1520741.csv: Raw data file
Setup: In python3 interactive shell
import Data
import Projection
import Piecewise
import LinearSystem
import StatFunction
To get data
# get whole data
(index, temp) = Data.getMin(startYear, startMonth, startDay, endYear, endMonth, endDate)
# get random data
(index, temp) = Data.getMinRandom(startYear, startMonth, startDay, endYear, endMonth, endDate, numberOfPoint)
# get every k-th point
(index, temp) = Data.getMin(startYear, startMonth, startDay, endYear, endMonth, endDate, k)
To run interpolation
# best fit polynomial
func = Projection.degreePolynomial(index, temp, degree)
f = lambda x: numpy.polyval(func)
# linear spline
(func, interval) = Piecewise.LinearSpline(index, temp, degree)
f = lambda x: piecewise.cal(interval, func, x)
# quadratic spline
(func, interval) = Piecewise.QuadraticSpline(index, temp, degree)
f = lambda x: Piecewise.cal(interval, func, x)
# cubic spline
(func, interval) = Piecewise.CubicSpline1(index, temp, degree)
f = lambda x: piecewise.cal(interval, func, x)
To visualize the interpolation:
(wholeIndex, wholeTemp) = Data.getMin(year, 1, 1, year+1, 1, 1)
Projection.graphProjection(wholeIndex, wholeTemp, f)
Other useful function
# To predict temperature on a date
# date = number of days from the startYear-startMonth-startDay
f(date)
# To calculate the mean of sum square error
Stat.sumOfSquareError(wholeTemp, list(map(f, wholeIndex)))