{"id":41130238,"url":"https://github.com/tspspi/pyavaspec","last_synced_at":"2026-01-22T18:26:03.344Z","repository":{"id":47025076,"uuid":"484463537","full_name":"tspspi/pyavaspec","owner":"tspspi","description":"Simple (inofficial) Python library and CLI tool to talk with the AvaSpec-2048-2 spectrometer","archived":false,"fork":false,"pushed_at":"2024-07-01T10:51:26.000Z","size":2456,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-25T14:48:19.012Z","etag":null,"topics":["instrumentation","physics","spectroscopy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tspspi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-22T14:27:53.000Z","updated_at":"2024-07-01T10:51:30.000Z","dependencies_parsed_at":"2022-09-02T22:50:54.664Z","dependency_job_id":null,"html_url":"https://github.com/tspspi/pyavaspec","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tspspi/pyavaspec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspspi%2Fpyavaspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspspi%2Fpyavaspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspspi%2Fpyavaspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspspi%2Fpyavaspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tspspi","download_url":"https://codeload.github.com/tspspi/pyavaspec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspspi%2Fpyavaspec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28667995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T17:07:18.858Z","status":"ssl_error","status_checked_at":"2026-01-22T17:05:02.040Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["instrumentation","physics","spectroscopy"],"created_at":"2026-01-22T18:26:02.671Z","updated_at":"2026-01-22T18:26:03.334Z","avatar_url":"https://github.com/tspspi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python script to access AvaSpec 2048-2 spectrometer\n\nThis is a (unofficial) library and tool to access basic functions (not all data types\nare supported) of the Avaspec 2048-2 spectrometer from Python on platforms that are\nnot supported by the software supplied by the manufacturer. This has been developed\nfor a project where I wanted to use the spectrometer on FreeBSD (note that no reverse\nengineering of the original software took place so I can not be sure this is\nthe proper way to talk to the spectrometer - the results just make sense). This\nproject is in no way associated with the manufacturer of this device!\n\n__Warning__: This project currently applies a fixed calibration to the\nspectrometers data. This might not be suited to any other spectrometer than the\none used by the original author of this software. There will be a configuration\noption some time in future.\n\n## The library interface\n\nThe spectrometer is exposed by the ```PyAvaSpec_2048_2``` class from\nthe ```pyavaspec.pyavaspec``` module. To use this class use\n\n```\nfrom pyavaspec.pyavaspec import PyAvaSpec_2048_2\n```\n\nTo connect to a device one can simply instantiate the ```PyAvaSpec_2048_2```\nclass. This tries to locate the USB spectrometer by the vendor id ```0x1992```\nand product ID ```0x0666```.\n\n```\nwith PyAvaSpec_2048_2() as spec:\n```\n\nWhen not using the ```with``` construct one should close the spectrometer\nmanually in the end to prevent lingering resources:\n\n```\nspec = PyAvaSpec_2048_2()\n\n# ...\n\nspec.close()\n```\n\n| Function                                                                                                                                                                                    | Description                                                                                                                                                                                                                     |\n| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| ```cmdMeasure(integrationTime = 1000, averageCount = 1)```                                                                                                                                  | Performs a measurement                                                                                                                                                                                                          |\n| ```cmdMeasureSoftAverages(integrationTime = 1000, softAverages = 1, hardAverages = 1)```                                                                                                    | Performs a measurement and applies software averaging                                                                                                                                                                           |\n| ```dumpData(data, filename = None, calibration = [0.546875, 299.67])```                                                                                                                     | Dump the supplied data into a data file or to stdout                                                                                                                                                                            |\n| ```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 via ```searchPeaks```, zoom into a specific area via ```xrange```, supply ones own plot title, store the result in a file or display the plot only for a given time |\n| ```indexToWavelength(pixelIndex, calibration = [ 0.546875, 299.67 ])```                                                                                                                     | Converts an index in the data array to a wavelength                                                                                                                                                                             |\n| ```applyMovingAverage(data, windowSize = 10)```                                                                                                                                             | Applies a moving average filter to the data and returns a new data array.                                                                                                                                                       |\n| ```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.                                                   |\n| ```loadData(filename)```                                                                                                                                                                    | Loads a datafile and returns the data array                                                                                                                                                                                     |\n| ```getVersionInformation()```                                                                                                                                                               | Will later be used to query version information from the spectrometer. Currently not functional                                                                                                                                 |\n\n## The CLI utility\n\nThe CLI utility supports a set of options that one can supply:\n\n### Commands\n\nThe spectrometer is controlled via a sequence of arbitrary commands that set\nthe status and execute actions.\n\n| Command                    | Action                                                                                                                                                              |\n| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| measure                    | Performs a measurement with the previous supplied settings as foreground data                                                                                       |\n| measurebg                  | Performs a measurement with previous supplied settings as background data                                                                                           |\n| inttime N                  | Sets the integration time (in milliseconds, default 1000)                                                                                                           |\n| avgsoft N                  | Sets the number of software averages (default 1)                                                                                                                    |\n| avghard N                  | Sets the number of hardware averages (default 1)                                                                                                                    |\n| peakmaxcount N             | Sets the maximum number of peaks (default 10) to search while performing peak search                                                                                |\n| peakavgwindow N            | Sets the size of the averaging window (default 10) while performing peak search                                                                                     |\n| dump                       | Dump data of foreground signal to stdout                                                                                                                            |\n| dumpbg                     | Dump data of background signal to stdout                                                                                                                            |\n| dumppeak                   | Dump peak data to stdout                                                                                                                                            |\n| dumpf [filename]           | Dumps the foreground data (corrected or uncorrected) into the supplied data file                                                                                    |\n| dumpfbg [filename]         | Dumps the background data into the supplied data file                                                                                                               |\n| dumpfpeak [filename]       | Dumps information about peaks into the supplied data file                                                                                                           |\n| loadf [filename]           | Loads the specified datafile into the foreground data buffer                                                                                                        |\n| loadfbg [filename]         | Loads the specified datafile into the background data buffer                                                                                                        |\n| loadfpeaks [filename]      | Loads peak data from the specified data file                                                                                                                        |\n| plotformat [svg,png]       | Selects the plot format to be ```png``` or ```svg```                                                                                                                |\n| plotf [filename] [title]   | Plots the current available foreground data (corrected or uncorrected, found peaks if available) into the specified (PNG or SVG) file                               |\n| plot [title]               | Plots the current available foreground data and shows it to the user                                                                                                |\n| plotfbg [filename] [title] | Plots the current available background data into the specified (PNG or SVG) file                                                                                    |\n| plotbg [title]             | Plots the current available background data and shows it to the user                                                                                                |\n| moveavg                    | Apply a moving average filter to the foreground data                                                                                                                |\n| bgsub                      | Performs background subtraction on the currently available foreground data if background data is available and background subtraction has not happened up until now |\n| peaks                      | Performs peak search using the previously set parameters and stores information for the current foreground data (discarded on next foreground measurement)          |\n| gateon                     | Enabled the external gate (for ex. SDG1032X)                                                                                                                        |\n| gateoff                    | Disable the external gate (for ex. SDG1032X)                                                                                                                        |\n\n### Settings: External SDG1032X control\n\nThe software allows one to control an external function generator (SDG1032X)\nto enable or disable a light source. The communication is handled via\nthe [sdg1032x](https://github.com/tspspi/pysdg1032x) Python library. It's assumed\nthat most parameters (such as waveform, etc.) have already been set up since it\ndoes not make much sense to scan those parameters while running the spectrometer\nin most cases. This might be extended in later versions.\n\n| Option           | Description                                                                      |\n| ---------------- | -------------------------------------------------------------------------------- |\n| --sdg1032xdev    | Supplies the hostname or IP address of the SDG1032X, enabled the SDG1032X module |\n| --sdg1032xch     | Selects the channel (1 or 2) to gate, default 1                                  |\n| --sdg1032xfrq    | Sets the frequency of the selected channel (in Hz)                               |\n| --sdg1032xperiod | Sets the period of the selected channel (in Hz)                                  |\n\n## Sample invocations\n\n### Simple measurement and display\n\nTo simply run a measurement with default settings and display the result run:\n\n```\navacli measure plot\n```\n\n### Measurement with background supression, store everything\n\nThe following command:\n\n* Uses channel 2 of a SDG1032X function generator on 10.0.0.14 as gate\n* Measures background\n   * Stores the background data in ```background.dat```\n   * Stores a plot of the background in ```background.png```\n* Measures the signal\n   * Stores the uncorrected raw signal in ```dataraw.dat```\n   * Plots the uncorrected raw signal in ```dataraw.png```\n* Performs background subtraction\n   * Stores the intermediate result in ```datasub.dat```\n   * Plots the intermediate result in ```datasub.png```\n* Applies a moving average filter\n   * Stores the intermediate result in ```dataavg.dat```\n   * Plots the intermediate result in ```dataavg.png```\n* Performs peak search\n   * Stores peak data in ```peaks.dat```\n   * Plots the corrected signal including the found peak in ```peaks.png```\n   * Shows the plot to the user\n\n```\navacli --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\"\n```\n\n### Loading previous data and generating SVGs\n\n```\navacli 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\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftspspi%2Fpyavaspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftspspi%2Fpyavaspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftspspi%2Fpyavaspec/lists"}