added generation
This commit is contained in:
29
play.py
29
play.py
@@ -8,18 +8,31 @@ from simple_eta import generate
|
|||||||
|
|
||||||
sigma_um = 12
|
sigma_um = 12
|
||||||
resolution = 200
|
resolution = 200
|
||||||
grid_size = 3
|
grid_size = 2
|
||||||
pixel_size = 25
|
pixel_size = 25
|
||||||
|
|
||||||
|
|
||||||
pos = (37.5,37.5) #x,y
|
# pos = (37.5,47.5) #x,y
|
||||||
t = gaussian_2d(mx=pos[0], my = pos[1], sigma = sigma_um, res = resolution, grid_size = grid_size, pixel_size = pixel_size)
|
# t = gaussian_2d(mx=pos[0], my = pos[1], sigma = sigma_um, res = resolution, grid_size = grid_size, pixel_size = pixel_size)
|
||||||
|
|
||||||
fig, ax = plot_gaussian(t, pixel_size=pixel_size, grid_size = grid_size)
|
# fig, ax = plot_gaussian(t, pixel_size=pixel_size, grid_size = grid_size)
|
||||||
plt.show()
|
# plt.show()
|
||||||
|
|
||||||
res = generate.sum_pixels(t, grid_size)
|
# res = generate.sum_pixels(t, grid_size)
|
||||||
|
|
||||||
|
|
||||||
fig,ax = plt.subplots()
|
# fig,ax = plt.subplots()
|
||||||
im = ax.imshow(res, origin = 'lower')
|
# im = ax.imshow(res, origin = 'lower')
|
||||||
|
|
||||||
|
mx,my, pixels = generate.generate_uniform_hits(sigma = sigma_um, pixel_size = pixel_size, grid_size = grid_size, resolution=resolution, N=300)
|
||||||
|
# pixels2 = generate.sum2x2(t)
|
||||||
|
|
||||||
|
fig, ax = plt.subplots(figsize = (8,8))
|
||||||
|
ax.scatter(mx,my)
|
||||||
|
|
||||||
|
ax.set_xlim(0,grid_size*pixel_size)
|
||||||
|
ax.set_ylim(0,grid_size*pixel_size)
|
||||||
|
ticks = [tick for tick in range(0,pixel_size*grid_size+1, pixel_size)]
|
||||||
|
ax.set_xticks(ticks)
|
||||||
|
ax.set_yticks(ticks)
|
||||||
|
ax.grid()
|
||||||
@@ -30,11 +30,41 @@ def sum_pixels(t, grid):
|
|||||||
# pixels[1,1] = t[resolution//2:, resolution//2:].sum()
|
# pixels[1,1] = t[resolution//2:, resolution//2:].sum()
|
||||||
return pixels
|
return pixels
|
||||||
|
|
||||||
def sum_pixels2(t, grid):
|
def generate_uniform_hits(sigma, pixel_size, grid_size, resolution, N=100, device = 'cpu'):
|
||||||
resolution = t.shape[0]
|
"""
|
||||||
pixels = np.zeros((grid,grid))
|
Generate N gaussians with sigma. Uniformly distributed over
|
||||||
pixels[0,0] = t[0:resolution//2, 0:resolution//2].sum()
|
the 2x2 pixel grid.
|
||||||
pixels[0,1] = t[0:resolution//2, resolution//2:].sum()
|
"""
|
||||||
pixels[1,0] = t[resolution//2:, 0:resolution//2].sum()
|
|
||||||
pixels[1,1] = t[resolution//2:, resolution//2:].sum()
|
x = torch.linspace(0, pixel_size*grid_size, resolution, device = device)
|
||||||
return pixels
|
x,y = torch.meshgrid(x,x, indexing="ij")
|
||||||
|
xs = x.unsqueeze(0).repeat(N,1,1)
|
||||||
|
ys = y.unsqueeze(0).repeat(N,1,1)
|
||||||
|
|
||||||
|
|
||||||
|
#TODO! The genreal cases are actually odd and even
|
||||||
|
if grid_size % 2 == 0:
|
||||||
|
low = (grid_size-1)//2*pixel_size+pixel_size/2
|
||||||
|
high =pixel_size+low
|
||||||
|
else:
|
||||||
|
low = pixel_size*(grid_size//2)
|
||||||
|
high = low+pixel_size
|
||||||
|
|
||||||
|
print(low, high)
|
||||||
|
|
||||||
|
mx = torch.rand(N,1,1, device = device) * (high-low)+low
|
||||||
|
my = torch.rand(N,1,1, device = device) * (high-low) +low
|
||||||
|
|
||||||
|
ts = 1 / (2*math.pi*sigma**2) * \
|
||||||
|
torch.exp(-((xs - my)**2 / (2*sigma**2) + (ys - mx)**2 / (2*sigma**2)))
|
||||||
|
|
||||||
|
|
||||||
|
#Sum signal in pixels for all N depositions
|
||||||
|
step = resolution//grid_size
|
||||||
|
pixels = torch.zeros((N,grid_size,grid_size))
|
||||||
|
for i in range(grid_size):
|
||||||
|
for j in range(grid_size):
|
||||||
|
pixels[:,i,j] = ts[:,i*step:(i+1)*step, j*step:(j+1)*step].sum(axis = 1).sum(axis = 1)
|
||||||
|
|
||||||
|
return mx, my, pixels
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user