Package: renishaw-wdf
This package provides Python support for using Renishaw Wdf data files. These
files are used to hold spectroscopic data from the line ofRaman microscopesmanufactured byRenishaw plc.This package requires Python 3.8 or later.See the accompanying fileLICENSEfor license details.DocumentationThe package is documented using python docstrings which yield assistance in most editors.
Documentation can be generated usingpydoc:$python-mpydoc*Entityname*For instance:$python-mpydocwdf.WdfBasic usageUse the Wdf class to open data files.
For instance, to print the values for the first spectrum in a file to two columns:fromwdfimportWdfwithWdf(filename)asdata:forx,iinzip(data.xlist(),data[0]):print(f"{x}\t{i}")Or using matplotlib to plot the spectral data graphically:importmatplotlib.pyplotaspltfromwdfimportWdfwithWdf(filename)asdata:plt.plot(data.xlist(),data[0])plt.show()The Wdf class is iterable and supports indexing to obtain spectra. The result ofWdf[]orWdf.spectrum()is a non-mutable sequence of floating point values.A Wdf file is divided into sections, many of which store a collection of named properties.
Known section identifiers are provided by constants in the WdfBlockId module and sections are
identified by an ID (defining a type of section) and a unique ID (defining a specific instance).
To obtain the properties for a the first map section stored in a file theget_section_propertiesmethod can be used as shown below.fromwdfimportWdfBlockIdprops=data.get_section_properties(WdfBlockId.MAP,-1)print(props["Title"].value)Spectra often have additional information stored about the collection environment such as
the time collected or the X and Y position of the spectrum if part of an area map, or the
temperature for a member of a temperature series. These values are stored as data origins
and are accessed using theoriginsproperty with the data type as a key to obtain the
sequence of values that can then be indexed by the spectrum index.fromwdfimportWdf,WdfDataTypeindex=1# spectrum indexwithWdf(filename)asdata:# the spectrum timestamp (as a datetime)timestamp=data.origins[WdfDataType.Time][index]# Print all data origin values:fororiginindata.origins:print(origin,data.origins[origin][index],sep="\t")Map informationIf the file contains maps generated from the collected data these can be plotted
using numpy and matplotlib.importnumpyasnpimportmatplotlib.pyplotaspltfromwdfimportWdf,WdfBlockIdmapindex=-1# first available mapwithWdf(filename)asdata:shape=data.map_area.count.x,data.map_area.count.ymapinfo=data.get_section_properties(WdfBlockId.MAP,mapindex)mapdata=np.array(data.get_map_data(mapindex),dtype=float)fig=plt.figure()ax=fig.add_subplot(1,1,1)ax.set_title(mapinfo["Label"].value)ax.imshow(mapdata.reshape(shape))fig.show()Example filesThere are some examples of using the library in thedemos/folder.The installation will also registerwdfbrowseras an executable application. This is
implemented from thewdf.browsermodule and provides a view of all the sections and
properties provided in a Wdf file.Thewdfbrowserutility depends on additional packages: numpy, matplotlib and Pillow.
These can be installed usingpipor any other package management tool.$pipinstallnumpymatplotlibPillowThewdfpackage does not have any package dependencies beyond the python standard library.Installation from source$pythonsetup.pyinstallBugs and issuesBug reports should be e-mailed to the support contact for the package.