PriithonTutorials

Learning is best done by browsing and excercising (working / complete) examples

From the PriithonHandbook

Demo 1: synthetic "star/bead images"

Simulation of 2d images of resolution limited point sources with two types of noise sources:

   1 >>> a = F.gaussianArr((256,256), sigma=3, peakVal=100, orig=0, wrap=1) # shape of a perfect bead
   2 >>> b = F.poissonArr((256,256), mean=.001)        # random bead positions
   3 >>> c = 100 + F.convolve(a,b)
   4 >>> d = c + F.noiseArr((256,256), stddev=1)
   5 >>> e = F.poissonize(d)
   6 >>> Y.view(c) # noise free
   7 >>> Y.view(e) # with "readout" noise and quantum shot noise

Demo 2: image file analysis

Image analysis of data saved in any file format

   1   Drag image-file into PyShell window (jpg,bmp,tiff, ... or fits or MRC/Priism format)
   2   Select: 'view'
   3 >>> a = Y.vd(-1) # get data from latest viewer
   4 >>> U.mmms(a) # show min,max,mean,stddev of whole (nd)data-set
   5 
   6  # set viewer into mode so that each left-mouse-click shows a line profile
   7  #   (averaged over deltaY=15 pixel) in graph-plot window
   8 >>> Y.vLeftClickHorizProfile(-1, 15, '-+')
   9  # click into the image viewer window !

some first steps in image processing

interactive session

   1 
   2 >>> a = F.noiseArr(shape=(256, 256), stddev=1.0, mean=0.0, type=N.float32)
   3 # window: 0) a
   4 >>> Y.view(a)
   5 >>> b = F.gaussianArr(shape=(256, 256), sigma=3, integralScale=None, peakVal=1, orig=0, wrap=True, type=N.float32)
   6 # window: 1) b
   7 >>> Y.view(b)
   8 >>> c = F.convolve(a, b, conj=0, killDC=0)
   9 # window: 3) c
  10 >>> Y.view(c)
  11 >>> def doit(a):
  12 ...     b = F.gaussianArr(shape=a.shape, sigma=3, integralScale=None, peakVal=1, orig=0, wrap=True, type=N.float32)
  13 ...     c = F.convolve(a, b, conj=0, killDC=0)
  14 ...     Y.view(b)
  15 ...
  16 
  17 >>>
  18 >>>
  19 >>> w = F.ringArr(shape=(256, 256), radius1=20, radius2=40, orig=None, wrap=0, type=N.float32)
  20 # window: 4) w
  21 >>> Y.view(w)
  22 # window: 5) b
  23 >>> doit(w)
  24 >>> def doit2(a, sigma=3):
  25 ...     '''
  26 ...     this low-pass filters with gaussian 
  27 ...     gaussian sigma can be specified (or defaults to 3)
  28 ...     '''
  29 ...     b = F.gaussianArr(shape=a.shape, sigma=3, integralScale=None, peakVal=1, orig=0, wrap=True, type=N.float32)
  30 ...     c = F.convolve(a, b, conj=0, killDC=0)
  31 ...     Y.view(c)
  32 ...
  33 >>>
  34 # window: 7) c
  35 >>> doit2(w+a, sigma=3)

from a "script-file"

put this into a file listInfo.py ! You can either execute this from a unix terminal with

priithon listInfo.py

or -- if you

  1. set the 'x' (executable) permission (( chmod +x listInfo.py )) you can even call it by

  2. make sure to include the first line (#!/usr/bin/env priithon) and hope that it really finds your priithon installation in the shell $PATH

listInfo.py
#or you might need:
./listInfo.py
   1 #!/usr/bin/env priithon
   2 
   3 from Priithon.all import * # this preload all Priithon-modules the same way as the interactive shell
   4 
   5 import glob
   6 dd = glob.glob('/home/haase/Brandeis/2004_Nov/*.mrc')
   7 # here you could "drag and drop" a multiple files and assign var name 'dd'
   8 dd.sort()
   9 
  10 for f in dd:
  11     print '================================'
  12     print f
  13     print '================================'
  14     a = Mrc.bindFile(f)
  15     print a.Mrc.info()
  16     print "recalculate Min/Max/Mean/Stddev over all sections:"
  17     print U.mmms(a)
  18     print "min/max/mean of first extended header float from all sections:"
  19     print U.mmm(a.Mrc.extFloats[:,0])

The simplest standalone GUI program

Here is a boiled down GUI program. For a more complete one see next section. However, this still contains -- at the end of the file -- the obligatory  if __name__ == '__main__'  check, that allows to also import the file as a module. In the case __name__ is NOT '__main__' ! The rest is "short-circuited" by using the oh-so-powerful Y.buttonbox

Put this into a file gui.py ! You can either execute this from a unix terminal with

priithon gui.py

or -- if you

  1. make sure to include the first line (#!/usr/bin/env priithon) and hope that it really finds your priithon installation in the shell $PATH

  2. set the 'x' (executable) permission (( chmod +x gui.py ))

you can even call it by

gui.py
#or you might need:
./gui.py
   1 #!/usr/bin/env priithon
   2 
   3 ## this a template for the 
   4 ## most simple / standalone GUI program
   5 
   6 import sys
   7 sys.app = None # dummy to force Priithon.Y getting loaded
   8 import wx
   9 from Priithon.all import Y # *
  10 
  11 def main():
  12     Y.buttonBox([
  13         ('hello', 'wx.MessageBox("Welcome to Priithon GUI !")'),
  14         ('ask',   'a=wx.GetTextFromUser("enter var a:")'),
  15         '\n',
  16         ('shell', 'Y.shell()')
  17         ])
  18 
  19 if __name__ == '__main__':
  20     if wx.GetApp():
  21         main()
  22     else:
  23         import sys
  24         sys.app = wx.PySimpleApp()
  25         main()
  26         sys.app.MainLoop()

Another simple standalone GUI program

A wxPython GUI program requires some -- essentially always constant -- extra lines of code. a. at the end of the file the  if __name__ == '__main__'  check, that allows to also import the file as a module. In the case __name__ is NOT '__main__' ! a. the application class that starts everyhing (if PyShell is not already running -- see a. ) a. the frame class that shows the "main window"

TODO.

last edited 2007-03-15 04:58:55 by guanine