########### Aggregate user data to get nImages*nMeasures*nSamples
# aggregate users by bootstrapping with number of users in original dataset
print ("*** User Aggregation ***")
aggrUser = ihc.bootstrap_consensus(datUser, nUsersPerSample=np.ma.size(datUser, axis=2))
# just get user data without sampling
# aggrUser = ihc.bootstrap_consensus(datUser, nUsersPerSample=np.ma.size(datUser,axis=2), nSamples=1, replace=False)

########### Print information about user data for individual tasks
# ihc.data_print([2659, 2667, 2674, 2662], imIDs=imIDs, datUser=datUser, aggrUser=aggrUser, aggrExp=aggrExp)

########### Describe/plot comparison between expert and user (individual users or consensus or both)
## plot median+-95CI of all users (raw, no corrections applied) against individual expert points
# ihc.plot_image_results_all_users_vs_expert(datExp,datUser,imIDs=imIDs)
## plot median+-95CI of aggrUser against individual expert points
ihc.plot_image_results_aggregated_users_vs_expert(datExp, aggrUser, imIDs=imIDs)
## plot median+-95CI for a range of users compared to expert, using aggregation settings
ihc.plot_performance_for_range_of_users(
    aggrExp=aggrExp, datUser=datUser, measure=s["measure"], errorFun="sss.spearmanr"
)
## plot performance of each user separately
# ihc.plot_performance_for_individual_users(aggrExp=aggrExp, datUser=datUser, userIDs=userIDs, measure='p*i', plotCorrected=False)

# some quick code to calculate a few measures
print "Aggregated users sampled, correlation with expert:", sss.spearmanr(
    aggrExp[:, 2], np.nanmedian(aggrUser[:, 2, :], axis=1)
)
print "Median of all users, correlation with expert:", sss.spearmanr(
    aggrExp[:, 2], np.nanmedian(datUser[:, 2, :], axis=1)
)
print "\tCI", bootstrap.ci(