Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pmcx.mcxlab fails to typecast traj.id output from float32 to uint32 #199

Closed
fangq opened this issue Nov 28, 2023 · 0 comments
Closed

pmcx.mcxlab fails to typecast traj.id output from float32 to uint32 #199

fangq opened this issue Nov 28, 2023 · 0 comments

Comments

@fangq
Copy link
Owner

fangq commented Nov 28, 2023

please see the bug report by Gijs Buist in this mailing list post:

https://groups.google.com/g/mcx-users/c/O79Yk4G8_xM

the example to reproduce the issue

###### code ########

#%% []
import numpy as np
import pmcx
import matplotlib.pyplot as plt
from struct import unpack

#%%[]

print(pmcx.__version__)

cfg={}
cfg['nphoton']=1e1
cfg['vol']=np.ones([60, 60, 60], dtype='uint8')
cfg['vol'][20:40, 30:40, 20:30]=2
cfg['tstart']=0
cfg['tend']=5e-9
cfg['tstep']=5e-9
cfg['srcpos']=[30,30,0]
cfg['srcdir']=[0,0,1]
cfg['prop']=[[0, 0, 1, 1], [0.005, 1, 0.01, 1.37], [0.1, 10, 0.9, 1]]
cfg['detpos']=[[30,20,0,1]]        # to detect photons, one must first define detectors
cfg['debuglevel'] = 'M'

res = pmcx.mcxlab(cfg)

print(res.keys())
print(res['traj'].keys())
print(np.all(res['traj']['id'] == 0))

### output is c struct that needs to be converted to integers in the photon id case (other cases are floats which numpy automatically assumes I guess)
structAr = np.asarray(res['traj']['data'][0], order = 'C')
lenstr = str(len(structAr))
traj_id =  np.array( unpack( lenstr + 'I', structAr))
print(np.all(traj_id == 0))

plt.figure()
plt.plot(res['traj']['id'])
plt.show()


res2 = pmcx.run(cfg)

print(res.keys())
print(res2['traj'].shape)


### output is c struct that needs to be converted to integers in the photon id case (other cases are floats which numpy automatically assumes I guess)
structAr = np.asarray(res2['traj'][0], order = 'C')
lenstr = str(len(structAr))
traj_id =  np.array( unpack( lenstr + 'I', structAr))
print(np.all(traj_id == 0))

plt.figure()
plt.plot(traj_id)
plt.show()
@fangq fangq closed this as completed in fae5b72 Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant