Example #1
0
def calculateOneStation(id):
	item0 = list[id]
	station_0 = list_station_all[id]
	for x in xrange(1,size):
		print x
		item = list_station_all[x]
		leng = len(item)
		#print leng
		#cov =np.cov(station_0,item)[0][1]
		
		#correlate = np.corrcoef(station_0, item)[0,1]
		semi = semivariance(station_0, item)
		#list_corr_tuple.append((id, x, correlate))
		list_corr_tuple.append((id, x, semi))
		
		#print correlate
		#correlate =  corr(station_0, item)
		#value = 0
		#for y in xrange(0, leng):
		#	value = value + abs(station_0[y] - item[y])
		#value = value/leng
		#print value
		list_index.append(x)
		list_value.append(semi)
		list_h.append(haversine(item0[2], item0[1], list[x][2], list[x][1]))
def generateGlobalMatrix( date_from, date_to, list_all_station):
	global trend_curve
	list_station = list_all_station
	#print list_station
	meteo_size = len(list_station)
	list_mean = []
	for i in xrange(0,meteo_size):
		#print list_station[i][0]
		item = getTempOfAAtationFromTo( list_station[i][3],date_from, date_to)
		list_all = zip(*item)
		#3 for temp, 4 for humid, 5 for rain
		list_temp = list_all[3]
		#print list_temp
		list_data.append(list_temp)
		mean_item = (list_all[1][0],list_all[2][0], sum(list_all[3])/len(list_all[3]))
		print mean_item
		list_mean.append(mean_item)
	f.write('MEAN: ' + str(list_mean) + '\n')
	trend_curve = curveFitting(list_mean)
	print trend_curve
	#plotSurface(trend_curve, list_mean)
	#print len(list_mean)
	#print list_data[0]
	#G = np.zeros([meteo_size, meteo_size])
	for x in xrange(0,meteo_size):#x 0->97 is Meteo_id 1->98
		for y in xrange(0,meteo_size):#0->97 is Meteo_id 1->98
			#gen covariance for [x][y]
			a = list_data[x]
			b = list_data[y]
			#cov =np.cov(a,b)[0][1]
			semi = semivariance( a, b)
			cov = covariance(a,b)
			#print 'a: ', a
			#print 'b: ',b
			#print 'cov a b = ', str(cov)
			#print covariance(a,b)
			G[x][y]= semi
			G_COV[x][y] = cov
	'''
	f.write('G_SEMI ----------------------------------------- \n')
	for item in G:
		f.write(str(item) + '\n')
	f.write('G_COV  ----------------------------------------- \n')
	for item in G_COV:
		f.write(str(item) + '\n')
	'''
	#print G[0:5,0:5]
	return trend_curve