93
94
PyObject *DATAPy, *A1Py, *A2Py, *COMPSPy, *EPAsPy, *EMAsPy, *PSouPy, *VARSPy, *FluxPy;
94
PyObject *PAntRPy, *PAntLPy, *WgtPy, *VSouPy, *VAntRPy, *VAntLPy, *HessianPy, *ResVecPy;
95
PyObject *PAntRPy, *PAntLPy, *WgtPy, *WgtCorrPy, *VSouPy, *VAntRPy, *VAntLPy, *HessianPy, *ResVecPy;
100
if (!PyArg_ParseTuple(args,"OOOOOOOOOOOOOOOOObb", &DATAPy, &WgtPy, &A1Py, &A2Py, &COMPSPy, &EPAsPy, &EMAsPy, &PSouPy, &PAntRPy, &PAntLPy, &VSouPy, &VAntRPy, &VAntLPy, &VARSPy, &HessianPy, &ResVecPy,&FluxPy, &doCirc, &doOrd1))
101
if (!PyArg_ParseTuple(args,"OOOOOOOOOOOOOOOOOObb", &DATAPy, &WgtPy, &WgtCorrPy, &A1Py, &A2Py, &COMPSPy, &EPAsPy, &EMAsPy, &PSouPy, &PAntRPy, &PAntLPy, &VSouPy, &VAntRPy, &VAntLPy, &VARSPy, &HessianPy, &ResVecPy,&FluxPy, &doCirc, &doOrd1))
101
102
{printf("Failed setData! Wrong arguments!\n"); fflush(stdout); Err = Py_BuildValue("i",-1); return Err;};
103
104
// delete NSou, Nvis;
144
146
if(DEBUG){printf(" %i visibilities; %i subcomponents. \n",Nvis[i],NSou[i]); fflush(stdout);};
146
149
DATA[i] = (cplx64d *)PyArray_DATA(PyList_GetItem(DATAPy,i));
147
150
A1[i] = (int *)PyArray_DATA(PyList_GetItem(A1Py,i));
148
151
A2[i] = (int *)PyArray_DATA(PyList_GetItem(A2Py,i));
268
273
}; // Relative weights for RR, RL, LR, LL / XX, XY, YX, YY
271
double currWgt[4], ord2;
276
double currWgt[4], ord2, Pf2Abs, PfAbs, ItotAbs;
274
279
// Turn on/off 2nd order corrections:
281
286
int iaux1, iaux2, iaux3, iaux4;
282
287
int printedGood = 0;
284
if (!PyArg_ParseTuple(args,"b", &doDeriv))
289
if (!PyArg_ParseTuple(args,"bbb", &doDeriv, &doResid, &doWgt))
285
290
{printf("Failed getHessian! Wrong arguments!\n");
286
291
Err = Py_BuildValue("i",-1); fflush(stdout); return Err;};
303
308
cplx64d RRc, RLc, LRc, LLc;
304
309
cplx64d Im = cplx64d(0.,1.);
306
313
cplx64d RR, RL, LR, LL, auxC;
307
314
cplx64d resid[4];
308
315
cplx64d AllDer[NPar][4];
442
449
// Apply leakage to model visibilities:
443
450
RR = (RRc + RLc*std::conj(DR[A2[s][i]]) + LRc*DR[A1[s][i]] + ord2*LLc*std::conj(DR[A2[s][i]])*DR[A1[s][i]]);
444
452
RL = (RLc + RRc*std::conj(DL[A2[s][i]]) + LLc*DR[A1[s][i]] + ord2*LRc*std::conj(DL[A2[s][i]])*DR[A1[s][i]]);
453
PfAbs = std::abs(RLc);
445
455
LR = (LRc + RRc*DL[A1[s][i]] + LLc*std::conj(DR[A2[s][i]]) + ord2*RLc*std::conj(DR[A2[s][i]])*DL[A1[s][i]]);
456
Pf2Abs = std::abs(LRc);
458
ItotAbs = std::abs(Itot);
460
if (doWgt && j==0 && PfAbs>0.0 && Pf2Abs > 0.0 && ItotAbs > 0.0){
461
WgtCorr[s][i] = std::max(PfAbs/ItotAbs,Pf2Abs/ItotAbs);
446
464
LL = (LLc + LRc*std::conj(DL[A2[s][i]]) + RLc*DL[A1[s][i]] + ord2*RRc*std::conj(DL[A2[s][i]])*DL[A1[s][i]]);
449
466
if(DEBUG && NITER<2 && printedGood<10 && j==Nchan/2){
450
467
printf("Model Noleak %i: RR = (%.2e, %.2e); RL = (%.2e, %.2e); LR = (%.2e, %.2e); LL = (%.2e, %.2e)\n",i,RRc.real(),RRc.imag(),RLc.real(),RLc.imag(),LRc.real(),LRc.imag(),LLc.real(),LLc.imag());
451
468
printf("Model Leak %i: RR = (%.2e, %.2e); RL = (%.2e, %.2e); LR = (%.2e, %.2e); LL = (%.2e, %.2e)\n",i,RR.real(),RR.imag(),RL.real(),RL.imag(),LR.real(),LR.imag(),LL.real(),LL.imag());
617
634
if(k!=l){Hessian[VisPar[l]*NPar + VisPar[k]] = Hessian[VisPar[k]*NPar + VisPar[l]];};
620
} else { // Residuals for each correlation product:
639
if (doResid){ // Residuals for each correlation product:
621
640
DATA[s][iaux2 ] = resid[0];
622
641
DATA[s][iaux2+1] = resid[1];
623
642
DATA[s][iaux2+2] = resid[2];
624
643
DATA[s][iaux2+3] = resid[3];
627
646
}; // Comes from if(Wgt...)