Filewatcher File Search File Search
Content Search
» » » » » gwyddion_2.20-1_i386.deb » Content »
pkg://gwyddion_2.20-1_i386.deb:1115378/usr/share/doc/gwyddion/  info  control  downloads

gwyddion - Scanning Probe Microscopy visualization and analysis tool…  more info»


Pygwy - Python binding for Gwyddion

Python >= 2.4 
Pygtk >= 2.10, PyGObject >= 2.12, PyCairo >= 1.2:

By configure script:
  ./configure --enable-pygwy

MSVC - set following variables in make.msc:
  PYTHON_TOP = Python installation directory (like C:\Python24)
  PYTHON_LIBRARY = Python linking library (like python24.lib)

Script location
The Python modules are stored in a Gwyddion user directory (~/.gwyddion/pygwy
or %USER_DIRECTORY%/gwyddion/pygwy). The 'pygwy' directory is automatically 
created when it does not exist.

Documentation and API can be generated by using command 'make pygwy-doc' from
current dictionary. Epydoc ( is required for
creating documentation.

Currently there are two types of Python modules:

Process module
Process module is used to manipulate with datafields. Only one function
must be defined:
- run()
  return value: not important
The process module can use predefined variable which contains
the current data container.

File module
File module is used to import and export data. Complete module implements
following functions:
- detect_by_name(filename)
  filename: string containing full path to file
  return value: return score <0,100> where value 0 reflects unknown type, 
                value 100 reflects known type

- detect_by_content(filename, head, tail, filesize)
  filename: string containing full path to file)
  head: string containing few bytes from beginning of the file
  tail: string containing few bytes from end of the file
  filesize: lenght of file in bytes
  return value: return score <0,100> where value 0 reflects unknown type, 
                value 100 reflects known type

- load(filename)
  filename: string containing full path to file
  return value: container of imported data

- save(data, filename)
  data: container of data used for export
  filename: full path to output file
  return value: True when export is successful, False otherwise 

Module variables
Every module must have defined variables which are used to determine 
the module type, location in menu and description.

Required variables for file type module (example):
plugin_type = "FILE"
plugin_desc = "High definition stable format store (.hdsf)" 

Required variables for process type module (example):
plugin_menu = "/Poodle" # the plugin will be located in Data Process/Poodle
plugin_type = "PROCESS"

Module debuging
Currently there is not much options to perform module debugging. 
Only Python exceptions are written to standard output.

Example process module
import gwy

plugin_menu = "/Correct Data/Invert"
plugin_type = "PROCESS"

def run():
   # create undo point
   key = gwy.gwy_app_data_browser_get_current(gwy.APP_DATA_FIELD_KEY)
   gwy.gwy_app_undo_qcheckpointv(, key)

   # get current datafield
   d = gwy.gwy_app_data_browser_get_current(gwy.APP_DATA_FIELD)

   # call invert function
   d.invert(0, 0, 1)

   # report data change to Gwyddion

Example file module
import gwy, sys

plugin_type = "FILE"
plugin_desc = "High definition stable format store (.hdsf)"

def detect_by_name(filename):
   if (filename.endswith(".hdsf")):
      return 100
      return 0

def detect_by_content(filename, head, tail, filesize):
   if (head.startswith("HDSF:")):
      return 100
      return 0

def load(filename):
   c = gwy.Container()
   d = gwy.DataField(100, 100, 100, 100, 1)
   for i in range(100):
      for j in range(100):
         d.set_val(i, j, i) # draws linear gradient
   c.set_object_by_name("/0/data", d)
   return c

def save(data, filename):
   f = open(filename, "w")
   datafield_num = 1   
   for key in data.keys():
      if isinstance(data.get_object(key), gwy.DataField):
         d = data.get_object(key)
         f.write("Datafield "+ str(datafield_num) + '\n')
         datafield_num += 1         
         for row in range(d.get_yres()):
            for col in range(d.get_xres()):
               f.write(str(d.get_val(col, row))+'\n')
   return True

Example for batch processing
import gwy, os

plugin_type = "process"
plugin_menu = /Resample current directory

def run():
   # get list of current directory
   for filename in os.listdir("."):
      if filename.endswith(".gwy"):
         # load file of given name and save it to container
         container = gwy.gwy_app_file_load(filename)
         # iterate thru loaded file's container
         for key in container.keys_by_name():
            # check if object of key is datafield
            if key.endswith("data"):
               # get datafield
               d = container.get_object_by_name(key)
               # scale datafield by 2 using linear interpolation
               d.resample(d.get_xres()*2, d.get_yres()*2, gwy.INTERPOLATION_LINEAR)
               # send message to Gwyddion to notice the content of datafield has changed
         new_filename = filename.rsplit('.', 1)[0] + "-scaled.gwy"
         # write current file to filename
         gwy.gwy_app_file_write(container, new_filename)

Results 1 - 1 of 1
Help - FTP Sites List - Software Dir.
Search over 15 billion files
© 1997-2017