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] pls = PLS_sklearn() pls.fit(predictors, predictand_data, locations, startdate=startdate, enddate=enddate) #pca.save('pca.nc') #pca.load('pca.nc') reduced_predictors = pls.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')
field = config['fields']['pr'] slices = [slice(None)]*2 start_index = field.reversemap(time=startdate)[field.time_dim].start end_index = field.reversemap(time=enddate)[field.time_dim].start slices[field.time_dim] = slice(start_index, end_index+1) predictand_data = field.variables[0][slices] print 'predictand_data.shape = ', predictand_data.shape 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: