from ctypes import CDLL, POINTER, c_int, c_double,c_float,c_long,c_char_p from numpy.ctypeslib import ndpointer import numpy.ctypeslib as clb import numpy as np from astropy.io import fits from scipy.stats import randint from glob import glob from datetime import datetime import os lib_path = os.path.dirname(os.path.realpath(__file__)) #lib_path += "/add_CTI.so" lib_path += "/libmoduleCTI.so" lib = CDLL(lib_path) CTI_simul = lib.__getattr__('CTI_simul') CTI_simul.argtypes = [POINTER(POINTER(c_int)),c_int,c_int,c_int,c_int,POINTER(c_float),POINTER(c_float),\ c_float,c_float,c_float,c_int,POINTER(c_int),c_int,POINTER(POINTER(c_int))] ''' get_trap_h = lib.__getattr__('save_trap_map') get_trap_h.argtypes = [POINTER(c_int), c_int, c_int, c_int, c_int, POINTER(c_float), c_float, c_float, c_char_p] def get_trap_map(seeds,nx,ny,nmax,rho_trap,beta,c,out_dir): hsp_result = np.zeros(ny*nx*nmax) nsp = len(rho_trap) seeds1 = seeds.astype(np.int32) seeds_p = np.ctypeslib.as_ctypes(seeds1) rho_trap1 = rho_trap.astype(np.float32) rho_trap_p = np.ctypeslib.as_ctypes(rho_trap1) filename = (out_dir+"/trap.bin").encode('utf-8') get_trap_h(seeds_p,c_int(int(nsp)),c_int(int(nx)),c_int(int(ny)),\ c_int(int(nmax)),rho_trap_p,c_float(beta),\ c_float(c),filename) def bin2fits(bin_file,fits_dir,nsp,nx,ny,nmax): data = np.fromfile(bin_file,dtype=np.float32) data = data.reshape(nx,nsp,ny,nmax).transpose(1,3,2,0) for i in range(nsp): print("transfering trap type "+str(i+1)) datai = data[i] ntrap = datai[0,:,:] for j in range(nmax-1): h = datai[j+1,:,:] h[np.where(ntrap