Package: pyavaspec-tspspi
Python script to access AvaSpec 2048-2 spectrometerThis is a (unofficial) library and tool to access basic functions (not all data types
are supported) of the Avaspec 2048-2 spectrometer from Python on platforms that are
not supported by the software supplied by the manufacturer. This has been developed
for a project where I wanted to use the spectrometer on FreeBSD (note that no reverse
engineering of the original software took place so I can not be sure this is
the proper way to talk to the spectrometer - the results just make sense). This
project is in no way associated with the manufacturer of this device!Warning: This project currently applies a fixed calibration to the
spectrometers data. This might not be suited to any other spectrometer than the
one used by the original author of this software. There will be a configuration
option some time in future.The library interfaceThe spectrometer is exposed by thePyAvaSpec_2048_2class from
thepyavaspec.pyavaspecmodule. To use this class usefrom pyavaspec.pyavaspec import PyAvaSpec_2048_2To connect to a device one can simply instantiate thePyAvaSpec_2048_2class. This tries to locate the USB spectrometer by the vendor id0x1992and product ID0x0666.with PyAvaSpec_2048_2() as spec:When not using thewithconstruct one should close the spectrometer
manually in the end to prevent lingering resources:spec = PyAvaSpec_2048_2()

# ...

spec.close()FunctionDescriptioncmdMeasure(integrationTime = 1000, averageCount = 1)Performs a measurementcmdMeasureSoftAverages(integrationTime = 1000, softAverages = 1, hardAverages = 1)Performs a measurement and applies software averagingdumpData(data, filename = None, calibration = [0.546875, 299.67])Dump the supplied data into a data file or to stdout```plotData(data, peaks = [], peakFwhmLine = False, xrange = None, calibration = [ 0.546875, 299.67 ], filename = None, fileformat = 'png', title = "Spectrometer output", showtimeout = 0)Plots the supplied data. One can add peaks previously found viasearchPeaks, zoom into a specific area viaxrange, supply ones own plot title, store the result in a file or display the plot only for a given timeindexToWavelength(pixelIndex, calibration = [ 0.546875, 299.67 ])Converts an index in the data array to a wavelengthapplyMovingAverage(data, windowSize = 10)Applies a moving average filter to the data and returns a new data array.searchPeaks(data, maxPeaks = 10)Performs peak search in the supplied data. One should already have done background subtraction and applied a moving average filter for this to work. Returns a list of peaks.loadData(filename)Loads a datafile and returns the data arraygetVersionInformation()Will later be used to query version information from the spectrometer. Currently not functionalThe CLI utilityThe CLI utility supports a set of options that one can supply:CommandsThe spectrometer is controlled via a sequence of arbitrary commands that set
the status and execute actions.CommandActionmeasurePerforms a measurement with the previous supplied settings as foreground datameasurebgPerforms a measurement with previous supplied settings as background datainttime NSets the integration time (in milliseconds, default 1000)avgsoft NSets the number of software averages (default 1)avghard NSets the number of hardware averages (default 1)peakmaxcount NSets the maximum number of peaks (default 10) to search while performing peak searchpeakavgwindow NSets the size of the averaging window (default 10) while performing peak searchdumpDump data of foreground signal to stdoutdumpbgDump data of background signal to stdoutdumppeakDump peak data to stdoutdumpf [filename]Dumps the foreground data (corrected or uncorrected) into the supplied data filedumpfbg [filename]Dumps the background data into the supplied data filedumpfpeak [filename]Dumps information about peaks into the supplied data fileloadf [filename]Loads the specified datafile into the foreground data bufferloadfbg [filename]Loads the specified datafile into the background data bufferloadfpeaks [filename]Loads peak data from the specified data fileplotformat [svg,png]Selects the plot format to bepngorsvgplotf [filename] [title]Plots the current available foreground data (corrected or uncorrected, found peaks if available) into the specified (PNG or SVG) fileplot [title]Plots the current available foreground data and shows it to the userplotfbg [filename] [title]Plots the current available background data into the specified (PNG or SVG) fileplotbg [title]Plots the current available background data and shows it to the usermoveavgApply a moving average filter to the foreground databgsubPerforms background subtraction on the currently available foreground data if background data is available and background subtraction has not happened up until nowpeaksPerforms peak search using the previously set parameters and stores information for the current foreground data (discarded on next foreground measurement)gateonEnabled the external gate (for ex. SDG1032X)gateoffDisable the external gate (for ex. SDG1032X)Settings: External SDG1032X controlThe software allows one to control an external function generator (SDG1032X)
to enable or disable a light source. The communication is handled via
thesdg1032xPython library. It's assumed
that most parameters (such as waveform, etc.) have already been set up since it
does not make much sense to scan those parameters while running the spectrometer
in most cases. This might be extended in later versions.OptionDescription--sdg1032xdevSupplies the hostname or IP address of the SDG1032X, enabled the SDG1032X module--sdg1032xchSelects the channel (1 or 2) to gate, default 1--sdg1032xfrqSets the frequency of the selected channel (in Hz)--sdg1032xperiodSets the period of the selected channel (in Hz)Sample invocationsSimple measurement and displayTo simply run a measurement with default settings and display the result run:avacli measure plotMeasurement with background supression, store everythingThe following command:Uses channel 2 of a SDG1032X function generator on 10.0.0.14 as gateMeasures backgroundStores the background data inbackground.datStores a plot of the background inbackground.pngMeasures the signalStores the uncorrected raw signal indataraw.datPlots the uncorrected raw signal indataraw.pngPerforms background subtractionStores the intermediate result indatasub.datPlots the intermediate result indatasub.pngApplies a moving average filterStores the intermediate result indataavg.datPlots the intermediate result indataavg.pngPerforms peak searchStores peak data inpeaks.datPlots the corrected signal including the found peak inpeaks.pngShows the plot to the useravacli --sdg1032xdev 10.0.0.14 --sdg1032xch 2 gateoff measurebg dumpfbg background.dat plotfbg background.png "Background" gateon measure gateoff dumpf dataraw.dat plotf dataraw.png "Raw signal" bgsub dumpf datasub.dat plotf datasub.png "Background subtracted" moveavg dumpf dataavg.dat plotf dataavg.png "Averaged and subtracted signal" peaks plotf peaks.png "Peaks" dumpfpeak peaks.dat plot "Peaks"Loading previous data and generating SVGsavacli loadfbg background.dat loadf dataraw.dat plotformat svg plotf dataraw.svg "Raw signal" plotfbg background.svg "Background" bgsub plotf datasub.svg "Background subtracted" moveavg plotf dataavg.svg "Averaged and subtracted signal" peaks plotf peaks.svg "Peaks"