I am trying to interpolate time series data for a variable at many locations (suppose at 6 points - lat and lon values are available) based on the available data sets (4 points with lat, long and corresponding time series daily values are available). However, when I am doing the interpolation as per my codes, it is given only one value instead of time series values. Please help me in this regarding.
import math
import numpy as np
# Distance calculation, degree to km (Haversine method)
def harvesine(lon1, lat1, lon2, lat2):
rad = math.pi / 180 # degree to radian
R = 6378.1 # earth average radius at equador (km)
dlon = (lon2 - lon1) * rad
dlat = (lat2 - lat1) * rad
a = (math.sin(dlat / 2)) ** 2 + math.cos(lat1 * rad) *
math.cos(lat2 * rad) * (math.sin(dlon / 2)) ** 2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = R * c
return(d)
# ------------------------------------------------------------
# Prediction
def idwr(x, y, z, xi, yi):
lstxyzi = []
for p in range(len(xi)):
lstdist = []
for s in range(len(x)):
d = (harvesine(x[s], y[s], xi[p], yi[p]))
lstdist.append(d)
sumsup = list((1 / np.power(lstdist, 2)))
suminf = np.sum(sumsup)
sumsup = np.sum(np.array(sumsup) * np.array(z))
u = sumsup / suminf
xyzi = [xi[p], yi[p], u]
lstxyzi.append(xyzi)
return(lstxyzi)
#known points (lat & long) and data
x = np.loadtxt('LON1_425.csv', delimiter=',')
y = np.loadtxt('LAT1_425.csv', delimiter=',')
z = np.loadtxt('DATA.csv', delimiter=',')
#Unknown Points
xi = np.loadtxt('LON_DGAPS.csv', delimiter=',')
yi = np.loadtxt('LAT_DGAPS.csv', delimiter=',')
# running the function
out=idwr(x,y,z(i),xi(i),yi(i))
np.savetxt('data11.csv', out, delimiter=',')
My datasets are given here:
https://drive.google.com/drive/folders/1fgt5XfTHTzHiPrQtiJAaoRNmHlH1G1uo?usp=sharing
Thanks
question from:
https://stackoverflow.com/questions/65713756/problem-in-idw-interpolation-for-time-series-datasets 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…