Skip to content

Commit

Permalink
Added pixel size to preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
bcolsen committed Jun 20, 2017
1 parent 8d758e7 commit 28a71a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
51 changes: 34 additions & 17 deletions diffraction_ring_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def __init__(self, filename = None):

#log_pattern = log(1+a*self.pattern)#/log(1+a*self.pattern).max()*255

self.img = self.axes.imshow(self.pattern, cmap='gray', aspect='equal')
self.img = self.axes.imshow(self.pattern, cmap='gray', aspect='equal', interpolation='bicubic')
#axi.set_xlim(0, size[1])
#axi.set_ylim(0, size[0])
#canvas = axi.figure.canvas
Expand Down Expand Up @@ -977,36 +977,58 @@ def __init__(self, parent, id, title):

self.parent = parent

wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, 350))
wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, 450))

wx.StaticText(self, -1, 'Pattern Properties', (20,20))
wx.StaticText(self, -1, 'Accelerating Voltage (kV): ', (20, 80))
#wx.StaticText(self, -1, 'Wavelength (m): ', (20, 130))
wx.StaticText(self, -1, 'Camera Length (cm): ', (20, 180))
wx.StaticText(self, -1, 'Resolution (PPI): ', (20, 230))
wx.StaticText(self, -1, 'Pixel Size (1/Å): ', (20, 325))

wavelen_btn = wx.Button(self, 3, 'Wavelength (m):', (20, 125))
self.wavelen_text = wx.StaticText(self, -1, '', (200, 130))
self.accv_sc = wx.SpinCtrl(self, -1, '', (200, 75), (60, -1))
self.wavelen_text = wx.StaticText(self, -1, '', (230, 130))

self.accv_sc = wx.SpinCtrl(self, -1, '', (230, 75), (80, -1))
self.accv_sc.SetRange(1, 500)
self.accv_sc.SetValue(self.parent.accv)

self.camlen_sc = wx.SpinCtrl(self, -1, '', (200, 175), (60, -1))
self.camlen_sc = wx.SpinCtrl(self, -1, '', (230, 175), (80, -1))
self.camlen_sc.SetRange(1, 5000)
self.camlen_sc.SetValue(self.parent.camlen)

self.imgcal_tc = wx.TextCtrl(self, -1, '', (200, 225), (60, -1))
self.imgcal_tc = wx.TextCtrl(self, -1, '', (230, 225), (80, -1))
imagecal_text = '%.2f' % (self.parent.imgcal)
self.imgcal_tc.SetValue(imagecal_text)

self.pixel_size_tc = wx.TextCtrl(self, -1, '', (230, 325), (80, -1))
print(self.parent.pixel_size)
pixel_size_text = '%.3g' % (self.parent.pixel_size*10**-10)
self.pixel_size_tc.SetValue(pixel_size_text)

cal_btn = wx.Button(self, 4, 'Calculate Pixel Size', (100, 275))

set_btn = wx.Button(self, 1, 'Set', (70, 275))
set_btn = wx.Button(self, 1, 'Set Pixel Size', (70, 390))
set_btn.SetFocus()
clear_btn = wx.Button(self, 2, 'Close', (185, 275))
clear_btn = wx.Button(self, 2, 'Close', (185, 390))

self.Bind(wx.EVT_BUTTON, self.OnSet, id=1)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=2)
self.Bind(wx.EVT_BUTTON, self.OnWavelen, id=3)
self.Bind(wx.EVT_BUTTON, self.OnCalPxSize, id=4)
self.Bind(wx.EVT_CLOSE, self.OnClose)

def OnCalPxSize(self, event):
self.parent.camlen = self.camlen_sc.GetValue()
self.parent.accv = self.accv_sc.GetValue()
accvm = self.parent.accv * 1000
self.parent.wavelen = con.h/(sqrt(2 * con.m_e * con.e * accvm)) * 1/(sqrt(1 + (con.e * accvm)/(2 * con.m_e * con.c**2)))
self.parent.imgcal = float(self.imgcal_tc.GetValue())

self.parent.PixelSize()
print(self.parent.pixel_size)
pixel_size_text = '%.3g' % (self.parent.pixel_size*10**-10)
self.pixel_size_tc.SetValue(pixel_size_text)

def OnWavelen(self, event):
self.parent.accv = self.accv_sc.GetValue() * 1000
Expand All @@ -1016,18 +1038,13 @@ def OnWavelen(self, event):
self.wavelen_text.SetLabel(wavelen_label)

def OnSet(self, event):

pixel_size = float(self.pixel_size_tc.GetValue())
pixel_size *= 10**10
self.parent.pixel_size = pixel_size
print(self.parent.pixel_size)
circles = self.parent.toolbar.circles
lines = self.parent.toolbar.lines

self.parent.camlen = self.camlen_sc.GetValue()
self.parent.accv = self.accv_sc.GetValue()
accvm = self.parent.accv * 1000
self.parent.wavelen = con.h/(sqrt(2 * con.m_e * con.e * accvm)) * 1/(sqrt(1 + (con.e * accvm)/(2 * con.m_e * con.c**2)))
self.parent.imgcal = float(self.imgcal_tc.GetValue())

self.parent.PixelSize()

del self.parent.axes.texts[-len(circles)-len(lines):]

for circle in circles:
Expand Down
Binary file removed examples/Au_Sim.tif
Binary file not shown.
4 changes: 2 additions & 2 deletions profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class radial(wx.Frame):

def __init__(self, parent, pattern_open, circles, pixel_size, size):
wx.Frame.__init__(self,parent,-1,
"Intensity Profile - "+parent.filename ,size=(550,350))
"Intensity Profile - "+parent.filename ,size=(700,500))

iconFile = os.path.join(parent.iconspath, "diff_profiler_ico.ico")
icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
Expand Down Expand Up @@ -561,7 +561,7 @@ def plot(self, lw=1, col='b'):
else: cmap='gray'
#print(cmap, self.polar_neg)
log_polar = rot90(log(1+self.gamma*self.polar_grid))
self.axes.imshow(log_polar, cmap=cmap, origin='lower',
self.axes.imshow(log_polar, cmap=cmap, origin='lower', interpolation='bicubic',
extent=(0, self.drdf.max(), 0, self.rdf.max()+self.rdf.max()*.2))
if self.prosim:
self.axes.plot(self.prosim_inv_d,self.prosim_int, linewidth=1, c='r', zorder = 40)
Expand Down
6 changes: 3 additions & 3 deletions ring_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def set_cursor(self, cursor):
class ring_pattern(wx.Frame):

def __init__(self, parent):
wx.Frame.__init__(self,parent,-1,"Ring Figure - "+parent.filename ,size=(550,350))
wx.Frame.__init__(self,parent,-1,"Ring Figure - "+parent.filename ,size=(550,400))

self.parent = parent

Expand Down Expand Up @@ -210,7 +210,7 @@ def ring_plot(self):
if self.background_sub == 1:
self.do_background_sub()

self.axes.imshow(self.pattern_open_crop, cmap = 'gray',
self.axes.imshow(self.pattern_open_crop, cmap = 'gray', interpolation='bicubic',
extent=(-self.parent.drdf.max(), self.parent.drdf.max(), -self.parent.drdf.max(), self.parent.drdf.max()))

if self.prosim == 1:
Expand Down Expand Up @@ -323,7 +323,7 @@ def do_plot_sim(self):
def do_prosim(self):
if self.ring_patt == []:
self.ring_patt = make_profile_rings(self.parent.prosim_int, self.parent.prosim_inv_d, self.origin, self.parent.boxs)
self.axes.imshow(self.ring_patt[:,:self.ring_patt.shape[1]//2], cmap='gray', origin='lower',
self.axes.imshow(self.ring_patt[:,:self.ring_patt.shape[1]//2], cmap='gray', origin='lower', interpolation='bicubic',
extent=(-self.parent.prosim_inv_d.max(), 0, -self.parent.prosim_inv_d.max(), self.parent.prosim_inv_d.max()))
print(self.parent.prosim_inv_d.max())

0 comments on commit 28a71a5

Please sign in to comment.