Beispiel #1
0
predictand_data = field.variables[0][slices]
print "predictand_data.shape = ", predictand_data.shape

locations = predictands["sources"][predictands["sources"].keys()[0]]["fields"]["tasmax"].features()
# print locations

# for location in locations['features']:
# 	print location

locations = locations["features"][20:22]

pca = PCA_sklearn()
pca.fit(predictors, locations, startdate=startdate, enddate=enddate)
# pca.save('pca.nc')
# pca.load('pca.nc')
reduced_predictors = pca.transform(predictors, startdate=startdate, enddate=enddate)

vmin = 0
vmax = 50
mappable = ScalarMappable(cmap="Blues")
mappable.set_array(np.arange(vmin, vmax, 0.1))
mappable.set_clim((vmin, vmax))

id = 20
for pred in reduced_predictors:

    tree = BinaryTree(pred, maxdepth=10)

    fig = plt.fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111)
    # 	ax.scatter(np.array(tree.samples)[:,0], np.array(tree.samples)[:,1], s=1, alpha=0.4, color='black')
locations = predictands['sources'][predictands['sources'].keys()[0]]['fields']['pr'].features()

locations = locations['features'][20:22]

if method == 'pls':
	pls = PLS_sklearn()
	pls.fit(predictors, predictand_data, locations, log=True, startdate=startdate, enddate=enddate)
	reduced_predictors = pls.transform(predictors, startdate=startdate, enddate=enddate)
	reduced_predictors_subset1 = pls.transform(predictors, startdate=startdate, enddate=enddate, months=[6,7,8])
	reduced_predictors_subset2 = pls.transform(predictors, startdate=startdate, enddate=enddate, months=[12,1,2])

if method == 'pca':
	pca = PCA_sklearn()
	pca.fit(predictors, locations, startdate=startdate, enddate=enddate)
	reduced_predictors = pca.transform(predictors, startdate=startdate, enddate=enddate)
	reduced_predictors_subset1 = pca.transform(predictors, startdate=startdate, enddate=enddate, months=[6,7,8])
	reduced_predictors_subset2 = pca.transform(predictors, startdate=startdate, enddate=enddate, months=[12,1,2])



id = 20
for pred in reduced_predictors:

	ranges = zip(np.min(pred, axis=0), np.max(pred, axis=0))

	tree = BinaryTree(pred, ranges=ranges, maxdepth=10)
	tree_subset1 = BinaryTree(reduced_predictors_subset1[id-20], ranges=ranges, maxdepth=10)
	tree_subset2 = BinaryTree(reduced_predictors_subset2[id-20], ranges=ranges, maxdepth=10)
	print "this location is at ", locations[id-20]