@@ -1285,6 +1285,67 @@ Image_applyCTF(PyObject *obj, PyObject *args, PyObject *kwargs)
12851285 return nullptr ;
12861286}
12871287
1288+ /* Apply CTF to this image */
1289+ PyObject *
1290+ xmipp_getPSF (PyObject *obj, PyObject *args, PyObject *kwargs)
1291+ {
1292+ import_array ();
1293+ PyObject *inputCTF = nullptr ;
1294+ double Ts=0.5 ;
1295+ size_t rowId=0 ;
1296+
1297+ try
1298+ {
1299+ PyArg_ParseTuple (args, " O|dk" , &inputCTF,&Ts,&rowId);
1300+ if (inputCTF != nullptr )
1301+ {
1302+ PyObject *pyStr;
1303+ if (PyUnicode_Check (inputCTF) || MetaData_Check (inputCTF))
1304+ {
1305+ CTFDescription ctf;
1306+ ctf.enable_CTF =true ;
1307+ ctf.enable_CTFnoise =false ;
1308+ if (MetaData_Check (inputCTF))
1309+ ctf.readFromMetadataRow (MetaData_Value (inputCTF), rowId );
1310+ else
1311+ {
1312+ pyStr = PyObject_Str (inputCTF);
1313+ FileName fnCTF = (char *)PyUnicode_AsUTF8 (pyStr);
1314+ ctf.read (fnCTF);
1315+ }
1316+ ctf.Tm =Ts;
1317+ ctf.produceSideInfo ();
1318+
1319+ MultidimArray<double > psfProfile (512 );
1320+ MultidimArray<std::complex <double > > ctfProfile (256 );
1321+ double resolutionStep=1 /(2 *Ts*256 );
1322+ for (int k=0 ; k<256 ; k++)
1323+ {
1324+ ctf.precomputeValues (k*resolutionStep,0.0 );
1325+ dAi (ctfProfile, k)=ctf.getValueAt ();
1326+ }
1327+
1328+ FourierTransformer fft;
1329+ fft.inverseFourierTransform (ctfProfile, psfProfile);
1330+ CenterFFT (psfProfile, true );
1331+
1332+ npy_intp dims[1 ];
1333+ dims[0 ] = MULTIDIM_SIZE (psfProfile);
1334+ auto * arr = (PyArrayObject*) PyArray_SimpleNew (1 , dims, NPY_DOUBLE);
1335+ void * data = PyArray_DATA (arr);
1336+ void *mymem = psfProfile.getArrayPointer ();
1337+ memcpy (data, mymem, MULTIDIM_SIZE (psfProfile)*sizeof (double ));
1338+ return (PyObject*)arr;
1339+ }
1340+ }
1341+ }
1342+ catch (XmippError &xe)
1343+ {
1344+ PyErr_SetString (PyXmippError, xe.what ());
1345+ }
1346+ return nullptr ;
1347+ }
1348+
12881349/* projectVolumeDouble */
12891350PyObject *
12901351Image_projectVolumeDouble (PyObject *obj, PyObject *args, PyObject *kwargs)
@@ -1434,6 +1495,8 @@ xmipp_methods[] =
14341495 " I2aligned=image_align(I1,I2), align I2 to resemble I1." },
14351496 { " applyCTF" , (PyCFunction) Image_applyCTF, METH_VARARGS,
14361497 " Apply CTF to this image. Ts is the sampling rate of the image." },
1498+ { " getPSF" , (PyCFunction) xmipp_getPSF, METH_VARARGS,
1499+ " Get PSF from a CTF. default Ts=0.5A" },
14371500 { " projectVolumeDouble" , (PyCFunction) Image_projectVolumeDouble, METH_VARARGS,
14381501 " project a volume using Euler angles" },
14391502 { nullptr } /* Sentinel */
0 commit comments