-
Notifications
You must be signed in to change notification settings - Fork 135
Description
**Hello,
When I execute my code with fdtd.set_backend("numpy"), it functions properly. However, switching to fdtd.set_backend("torch") leads to an error:**
Exception has occurred: TypeError
'torch.dtype' object is not callable
File "C:\Users\yo0003\moein\FDTD.py", line 73, in
grid[row:row+1,col:col+1,0] = fdtd.AbsorbingObject(permittivity=45.38,conductivity=0.77, name=str(row) + "," + str(col))
~~~~^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'torch.dtype' object is not callable
this is my code:
import torch
import fdtd
import numpy as np
from line_profiler import LineProfiler
import nibabel as nib
import matplotlib.pyplot as plt
device = torch.device("cpu")
Load the MNC file
mnc_img = nib.load('C:\Users\yo0003\moein\MATLAB_DRIVE\Matlab\subject04.mnc')
Get the data as a numpy array
data = mnc_img.get_fdata()
pic=20*data[250,:,:]
pic = np.pad(pic, ((10, 10), (10, 10)), mode='constant', constant_values=0)
for i in range(len(pic[:,1])):
for j in range(len(pic[1,:])):
if pic[i,j]==160:
pic[i,j]=20
if pic[i,j]==80 or pic[i,j]==180 or pic[i,j]==100:
pic[i,j]=120
if pic[i,j]==140 or pic[i,j]==200 :
pic[i,j]=220
pic=pic[::4,::4]
plt.imshow(pic)
plt.show()
pic = np.pad(pic, ((40, 40), (40, 40)), 'constant', constant_values=((0, 0), (0, 0)))
Set FDTD backend to CPU
fdtd.set_backend("torch")
Create a 2D grid with a single layer in the z-direction
Lx=len(pic[:,1])
Ly=len(pic[1,:])
freq=1e9
landa=3e8/freq
grid = fdtd.Grid(shape=(Lx, Ly, 1), grid_spacing=0.1*landa)
Brain=np.zeros((Lx, Ly,2))
# Add a light source
grid[20, 20, 0] = fdtd.PointSource(period=landa/3e8, name="source")
#*********************************************************
avg
#*********************************************************
loc=np.where(pic==120)
try:
# Your problematic code here, e.g.:
grid[40:50,50:60,0] = fdtd.Object(permittivity=45)
except Exception as e:
print("Error:", str(e))
# Importing the traceback module to print the full stack trace
import traceback
print("Full traceback:\n", traceback.format_exc())
for row, col in zip(*loc):
grid[row:row+1,col:col+1,0] = fdtd.AbsorbingObject(permittivity=45.38,conductivity=0.77, name=str(row) + "," + str(col))