# hp.gnomview(themaps[0],rot=[0,90],reso=10,title='Q')
# hp.gnomview(themaps[1],rot=[0,90],reso=10,title='U')

# hp.gnomview(themaps2[0],rot=[0,90],reso=10,title='Q')
# hp.gnomview(themaps2[1],rot=[0,90],reso=10,title='U')

covmap = np.identity(len(ipok) * len(themaps)) * signoise ** 2 * 0
guess = [0, binspec[:, 1], binspec[:, 2], binspec[:, 3], 0]
specout, error, invfisher, ds_dcb = qml.qml_cross_noiter(
    themaps,
    themaps2,
    mask,
    covmap,
    ellbins,
    fwhmrad,
    guess,
    ds_dcb,
    spectra,
    cholesky=False,
    temp=False,
    polar=True,
    plot=True,
)


#### MC
nbmc = 100
signoise = 0.2
allspec = []
allerr = []
for i in xrange(nbmc):

mapq_o = x0_convolved[:,1]
mapq_o[mask]=0
mapu_o = x0_convolved[:,2]
mapu_o[mask]=0
themaps_o = [mapq_o,mapu_o]
themaps2_o = [mapq_o,mapu_o]


### Likelihood
covmap=np.zeros(len(ipok)*2)
guess=[0,binspec[:,1],binspec[:,2],binspec[:,3],0]

specoutQ,errorQ,invfisherQ,ds_dcb=qml.qml_cross_noiter([themap_0_Q[:,1],themap_0_Q[:,2]] , 
    [themap_1_Q[:,1], themap_1_Q[:,2]],mask,covmap,ellbins,fwhmrad,guess,
    ds_dcb,spectra,cholesky=False,temp=False,polar=True,plot=True)

specoutQP,errorQP,invfisherQP,ds_dcb=qml.qml_cross_noiter([themap_0_QP[:,1],themap_0_QP[:,2]] , 
    [themap_1_QP[:,1], themap_1_QP[:,2]],mask,covmap,ellbins,fwhmrad,guess,
    ds_dcb,spectra,cholesky=False,temp=False,polar=True,plot=True)

specout_o,error_o,invfisher_o,ds_dcb=qml.qml_cross_noiter(themaps_o, themaps2_o,mask,covmap,ellbins,fwhmrad,guess,
    ds_dcb,spectra,cholesky=False,temp=False,polar=True,plot=True)


clf()
subplot(1,2,1)
xlim(0,np.max(ellmax)*1.2)
plot(ell,E,lw=3)
xlabel('$\ell$')