This page is the place to collect user-contributed PyGwy/PyConsole scripts. To add a script, please use the "Post"-Button at the bottom of the page and include a link to your contribution in the list below.
This script was written as a learning tool so sorry for the sloppiness. It exports to a plain text *.tex that can then be compiled with LaTeX typesetting (pdf latex was tested). Attached is the sample output using the the example gwy provided in the gwyddion website.
First you need the template
This will be a *.tex file.
\documentclass[10pt,a4paper,notitlepage]{report}\usepackage[latin1]{inputenc}\usepackage{amsmath}\usepackage{amsfonts}\usepackage{amssymb}\usepackage{graphicx}\usepackage{hyperref}\author{Gwyddion User-Name}\title{GwyddionReport}\begin{document}\maketitle\listoffigures\chapter{Example Output}\section{Introduction}
This pretends to be the main bit of your report.
You will have your normal disclaimers on how this is
a batch report to be quickly presented. Options could
include make this a Beammer to have a quick slideshow
to show your results.
\begin{figure}[hbtp]
\includegraphics[width = \textwidth]{exported-png-0.png}\caption{A gwyddion Figure}\end{figure}\chapter{Your Data}\section{Figures}\include{report}\end{document}
Next you need the script
This can be a *.py file that you import to your gwyddion console. Tested on a Linux machine running Trisquel (ubuntu Free derivative)
######This is GPL licence (the latest version you can find normally): #it is a cheap copy of a script found in the gwyddion.net documentation# pretends to be a quick way to do a batch report using LaTeX but could be done # with minor editing for an HTML report. ##### OBJECTIVE: you have your gwy file with all the images just like you like them.#instead of saving them one by one and then attempt to put them in your report # one by one we just do it all in one batch file. importgwyutils# base namebasePath="Documentos/gwyddion/"baseFile="exported-png-%d.png"basename=basePath+baseFile#basename = "Documentos/gwyddion/exported-png-%d.png"i=0# get list of available containerscons=gwy.gwy_app_data_browser_get_containers()# create tex filetexf=open(basePath+'report.tex','w')# save strings for adding to the reportbeginFigure=r"\begin{figure}[hbtp]"includegraphics=r"\includegraphics[width = \textwidth]{"caption=r"\caption{"# iterate thru containers and datafieldsforcincons:# get directory of datafields where key is key in containerdfields=gwyutils.get_data_fields_dir(c)forkeyindfields.keys():# get processed datafield objectdatafield=dfields[key]# retrieve datafield number in container from key (for example '/0/data')datafield_id=key.split('/')[1]# set palette of datafieldc.set_string_by_name("/%s/base/palette"%datafield_id,"Gwyddion.net")# invert datafield values (processing section) #datafield.invert(0, 0, 1)# request redraw before exportdatafield.data_changed()# export datafield to png, for the first time show export dialogifi==0:gwyutils.save_dfield_to_png(c,key,basename%i,gwy.RUN_INTERACTIVE)else:gwyutils.save_dfield_to_png(c,key,basename%i,gwy.RUN_NONINTERACTIVE)#write to report#texf.append(basename % i)printbasename%i#textf.write("beginFigure")texf.write(beginFigure)texf.write('\n')texf.write(includegraphics)texf.write(baseFile%i)texf.write("}")texf.write('\n')texf.write(caption)texf.write(baseFile%i)texf.write("}")texf.write('\n')texf.write(r'\label{fig:')texf.write(baseFile%i)texf.write("}")texf.write('\n')texf.write("\\end{figure}")texf.write('\n')i+=1# request redraw datawindows with datafieldsdatafield.data_changed()texf.close()#TODO:# would append be better than write?# strings as variables a little too much?# find out how to get the meta data as a caption.# find out how to add graphs and spectroscopies to the file. # more elegant way to add scripts?# Run pdflatex from this console to have a working pdf file at the end. # query for path or use the path that your file is in. # choose tex, HTML or XML output. # make it a module?# DONE: make the name of the file separate from the path to be able to use it as a caption.# DONE: use the figure enviorment on files
Remember to edit your path (or add a msg box of some sort to browse for your path)
Remember that this script will output in png format hence it will work with pdflatex. Also note the pngs and tex files will be in the same filder as your gwy file.
Please let me know if you would like me to add or change something. Please improve it!
This script shows how to remove (delete) a number of channels from the data browser, beginning from the last channel. The number of channels can be selected by the variable: nbr_of_last_channels_to_delete
importgwy,gwyutilsnbr_of_last_channels_to_delete=3save_file=Falsec=gwyutils.get_current_container()dfd=gwyutils.get_data_fields_dir(c)# change behaviour of data browser to leave file# open when no visible object is leftgwy.gwy_app_data_browser_set_keep_invisible(c,True)# sort data field keys with respect to channel number# please check out the documentation for Python's lambda functions# and sorted() for more infodfd_k=sorted(dfd.keys(),key=lambdax:int(x.split('/')[1]))foriinrange(nbr_of_last_channels_to_delete):# make last data field invisible to avoid data browser crashc.set_boolean_by_name(dfd_k[-1]+'/visible',False)# remove last data field and associated data from containerc.remove_by_prefix(dfd_k[-1][0:3])# remove last item from key listdfd_k.pop()ifsave_fileisTrue:# save the current container (file)gwy.gwy_app_file_save()
Last edit: Christoph Zeh 2012-12-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Batch Reporting your Images from gwy file
This script was written as a learning tool so sorry for the sloppiness. It exports to a plain text *.tex that can then be compiled with LaTeX typesetting (pdf latex was tested). Attached is the sample output using the the example gwy provided in the gwyddion website.
First you need the template
This will be a *.tex file.
Next you need the script
This can be a *.py file that you import to your gwyddion console. Tested on a Linux machine running Trisquel (ubuntu Free derivative)
Remember to edit your path (or add a msg box of some sort to browse for your path)
Remember that this script will output in png format hence it will work with pdflatex. Also note the pngs and tex files will be in the same filder as your gwy file.
Please let me know if you would like me to add or change something. Please improve it!
Last edit: David Nečas 2012-08-27
Removing channels from data browser
This script shows how to remove (delete) a number of channels from the data browser, beginning from the last channel. The number of channels can be selected by the variable:
nbr_of_last_channels_to_delete
Last edit: Christoph Zeh 2012-12-28
https://gitlab.com/amunizp/AFM-scripts
Batch reporting LaTeX
Batch reporting Markdown (sadly converted later to other formats such as odt, html and pdf/LateX) 3DD print data