Package: renishawWiRE
renishawWiRERenishaw Raman spectroscopy parser in pythonA python wrapper for read-only accessing the wdf Raman spectroscopy file format created
by the WiRE software of Ranishaw Inc.  Renishaw Inc owns copyright of
the wdf file format.Ideas for reverse-engineering the WDF format is inspired by:Renishaw File Readerby Alex Henderson (DOI:10.5281/zenodo.495477))Renishaw IO module inGwyddionInstallationRequirements:python>=3.6Numpy>=1.12.0Matplotlib>=2.1.0(optional, if you want to plot the spectra in the examples)Pillow>=3.4.0(optional, if you want to extract the white light
image)Warningthere are some API changes toPillowafter
version 7.2.0 (thanks @markotoplak). Please updaterenishawWiREto version >= 0.1.8 if you are experiencing problems with Tiff image
extraction.You can choose any of the following installation methods:1. Versions hosted on PyPI: viapip# Optionally on a virtualenv# Add --user if you don't want to install as sys adminpipinstall--upgraderenishawWiREIf you need full plotting / image extraction support, consider
specifying the extras topip.# Optionally on a virtualenvpipinstall--upgrade"renishawWiRE[plot]"2.HEADversion: viagit+pipTo install the package without examples, run the following commands
(installing extramatplotlibandPillowif not present):gitclonehttps://github.com/alchem0x2A/py-wdf-reader.gitcdpy-wdf-reader
pipinstall-e".[plot]"3. Viaconda-forgeThe version hosted onconda-forgewill install all dependent packages includingnumpymatplotlibandPillow.
Note the slight difference of package name compared with PyPI.condainstall-cconda-forgerenishaw_wireTest installationSimply try if importing works:python-c"import renishawWiRE"and test the executable binary:wdf-export-hAdditionally, if you want to test the examples, download them from thebinary
releaseand overwrite the dummy files withinexamples/spectra_files/:wgethttps://github.com/alchem0x2A/py-wdf-reader/releases/download/binary/spectra_files.zipunzip-ospectra_files.zip-dexamples/rmspectra_files.zip# To avoid unexpected pushing to repo due to large file sizegitupdate-index--skip-worktreeexamples/spectra_files.wdfBasic UsageCheck the sample codes inexamples/folder for more details about
what the package can do.1. Simple script for exporting wdf spectra (version > 0.1.11)The package also installs a simple wrapper scriptwdf-exportfor
exporting spectra in the wdf file to plain-text formats. If the
measurement contains mapping information, the optical image is also
exported (as.svgfile)UsageSimply use the base name of input file for the exported text file:wdf-exportpath/to/wdf_fileor specifying the input and output fileswdf-exportpath/to/wdf_file-opath/to/output.csv2. Python APIGet file informationrenishawWiRE.WDFReaderis the main entry point to get information of a WDF file.# The following example shows how to get the info from a WDF file# Check `examples/ex1_getinfo.py`fromrenishawWiREimportWDFReader#`filename` can be string, file obj or `pathlib.Path`filename="path/to/your/file.wdf"reader=WDFReader(filename)reader.print_info()Get single point spectrum / spectraWhen the spectrum is single-point (WDFReader.measurement_type == 1),WDFReader.xdatais the spectral points, andWDFReader.spectrais
the accumulated spectrum.# Example to read and plot single point spectrum# Assume same file as in previous section# Check `examples/ex2_sp_spectra.py`importmatplotlib.pyplotaspltwavenumber=reader.xdataspectra=reader.spectraplt.plot(wavenumber,spectra)Anexampleis shown below:Get depth series spectraA depth series measures contains single point spectra with varied
Z-depth. For this typeWDFReader.measurement_type == 2. The code to
get the spectra are the same as the one in the single point spectra
measurement, instead that theWDFReade.spectrabecomes a matrix with
size of(count, point_per_spectrum). TheWDFReader.zposreturns
the values of z-scan points.For details of Z-depth data processing, check thisexampleGet line scan from StreamLine™ / StreamHR Line™ measurementsFor mapped measurements (line or grid scan),WDFReader.measurement_type == 3.  The code to get the spectra are
the same as the one in the single point spectra measurement, instead
that theWDFReade.spectrabecomes a matrix with size of(count, point_per_spectrum):# Example to read line scane spectrum# Check `examples/ex3_linscan.py`filename="path/to/line-scan.wdf"reader=WDFReader(filename)wn=reader.xdataspectra=reader.spectraprint(wn.shape,spectra.shape)Anexampleof the line scane is shown below:It is also possible to correlate the xy-coordinates with the
spectra. For a mapping measurement,WDFReader.xposandWDFReader.yposwill contain the point-wise x and y coordinates.# Check examples/ex4_linxy.py for detailsx=reader.xposy=reader.ypos# Cartesian distanced=(x**2+y**2)**(1/2)Get grid mapping from StreamLine™ / StreamHR Line™ measurementsFinally let's extract the grid-spaced Raman data. For mapping data
withspectra_wpixels in the x-direction andspectra_hin the
y-direction, the matrix of spectra is shaped into(spectra_h, spectra_w, points_per_spectrum).Make sure your xy-coordinates starts from the top left corner.# For gridded data, x and y are on rectangle grids# check examples/ex5_mapping.py for detailsx=reader.xposy=reader.yposspectra=reader.spectra# Use other packages to handle spectra# write yourself the function or use a 3rd-party libraymapped_data=some_treating_function(spectra,**params)# plot mapped data using plt.imshowplt.pcolor(mapped_data,extends=[0,x.max()-x.min(),y.max()-y.min(),0])Anexampleof mapping data is shown below:You can also work on the white-light image which automatically saved
during a mapped scan. The jpeg-form image can be obtained byWDFReader.imgas an io object, and some further informations about
the dimensions etc. For this to work you needPillowinstalled as third-party
library:Get coordinates of white-light image# There are two-sets of coordinates.# `xpos` and `ypos` are the Stage XY-coordinate of the mapped area# while `img_origins` and `img_dimensions` are size (μm) of white-light image# See examples/ex6_mapping_img.py for detailsimportmatplotlib.imageasmpimgimg_x0,img_y0=reader.img_originsimg_w,img_h=reader.img_dimensionsplt.imshow(reader.img,extent=(img_x0,img_x0+img_w,img_y0+img_h,img_y0))Anexampleof mapped area on white light image is shown below:Overlaying white-light image with mapped spectra# `img_cropbox` is the pixel positions for cropping# Requires PIL to operate# See examples/ex7_overlay_mapping.py for detailsimg=PIL.Image.open(reader.img)img1=img.crop(box=reader.img_cropbox)extent=...# Same extent for both imagesplt.imshow(img1,alpha=0.5,extent=extent)# White light imageplt.imshow(spectra,alpha=0.5,extent=extent)# Mapped spectraThe followingexampleshows the
overlayed image of both fields. Some degree of misalignment can be
observed.TODOsThere are still several functionalities not implemented:Extract image infoVerify image coordinate superpositionImprove series measurement retrievalTesting on various version of Renishaw instrumentsBinary utilitiesBug reportsThe codes are only tested on the Raman spectra files that generated
from my personal measurements. If you encounter any peculiar behavior
of the package please kindly open an issue with your report /
suggestions. Thx!