pyfasma-spc


Namepyfasma-spc JSON
Version 0.4.2 PyPI version JSON
download
home_pagehttps://github.com/lepa22/pyfasma-spc
SummaryA Python package for handling SPC files
upload_time2024-10-06 19:23:36
maintainerNone
docs_urlNone
authorRohan Isaac
requires_python<4.0,>=3.12
licenseGNU General Public License v3 (GPLv3)
keywords scientific spc spectra data analysis
VCS
bugtrack_url
requirements numpy
Travis-CI
coveralls test coverage No coveralls.
            # spc

[![Build Status](https://travis-ci.org/rohanisaac/spc.svg?branch=master)](https://travis-ci.org/rohanisaac/spc)

A module for working with .SPC files in Python. SPC is a binary data format to store a variety of spectral data, developed by Galactic Industries Corporation in the '90s. Popularly used Thermo Fisher/Scientific software GRAMS/AI. Also used by others including Ocean Optics, Jobin Yvon Horiba. Can store a variety of spectrum including FT-IR, UV-VIS, X-ray Diffraction, Mass Spectroscopy, NMR, Raman and Fluorescence spectra.

The SPC file format can store either single or multiple y-values, and the x-values can either be given explicitly or even spaced x-values can be generated based on initial and final points as well as number of points. In addition the format can store various log data and parameters, as well as various information such as axis labels and scan type.

## Features

1. Extracts header information into object members
2. For each subfile, extract subfile data into `subFile` class objects `sub[0]` (, `sub[1]`, `sub[2]`, ...)
3. Extract x and y values into numpy `ndarray`
4. Attempts to interpret x,y, and z labels, as well as scan type
5. Member functions to output data in text, or plot using `matplotlib`

## Installation

### Requirements

```
python2.7+
numpy
matplotlib (optional, for plotting)
```

Download zip and extract or clone repository. From the resulting folder run

```bash
$ cd ~/Downloads/spc-master/
$ python setup.py install
```

## Usage

From a Python/IPython session or in a script

```python
>>> import spc
>>> f = spc.File('/Desktop/sample.spc')  # read file
x-y(20)  # format string
>>> f.data_txt()  # output data
>>> f.write_file('output.txt')  # write data to file
>>> f.plot()  # plot data
```

Note the format string outputed refers to where data is stored the object, which corresponds to the various ways data can be stored in the spc file format. Items before the `-` means that data is global, after the `-` means the data is in a subFile, and the (n) refers to the number of subfiles.

### Examples

Format string | Meaning
------------- | --------------------------------------------------------------------
x-y(3)        | one global x-data series, 3 corresponding y-data series
-xy(4)        | four subfiles with individual x and y data series
gx-y(10)      | single global x-data (generated), and 10 corresponding y-data series

### Accessing data

The object generated is populated with all the data and metadata from the file. The data can be manully accessed using the entry in the table corresponding to the format string outputted.

format string | x-values                  | y-values
------------- | ------------------------- | -------------------------
-xy(n)        | f.sub[0].x ... f.sub[n].x | f.sub[0].y ... f.sub[n].y
x-y(n)        | f.x                       | f.sub[0].y ... f.sub[n].y
gx-y(n)       | f.x (generated)           | f.sub[0].y ... f.sub[n].y

Depending on the information stored in the file, there are a number of metadata fields that may be populated. Some commonly used fields are

metadata            | variable
------------------- | -----------
x-label             | f.xlabel
y-label             | f.ylabel
z-label             | f.zlabel
Comment (formatted) | f.cmnt
Comment (raw)       | f.fcmnt
Experiment type     | f.exp_type
Log dictionary      | f.log_dict
Log (remaining)     | f.log_other

To get a full list of data/metadata stored in the object, you can run `object.__dict__` on the file and subFile objects.

### Functions

Functions      | Description
-------------- | -------------------------------------
f.data_txt()   | Outputs data to stdout
f.debug_info() | Human readable metadata for debugging
f.plot()       | Plots data using matplotlib
f.write_file() | Writes data to text file

### File versions supported

File versions are given by the second bit in the file, `fversn` in an SPC object. Currently the library supports the following `fversn` bytes.

fversn | Description      | Support      | Notes
------ | ---------------- | ------------ | ----------------------------------------------------------------
0x4B   | New format (LSB) | Good         | z-values are not accounted for in data_txt() and plot() commands
0x4C   | New format (MSB) | None         | need sample file to test
0x4D   | Old format       | Good         |
0xCF   | SHIMADZU format  | Very limited | no metadata support, only tested on one file, no specifications

## File converter

The file converter can be use to convert files/directories from the terminal.

### CLI: convert.py

```
$ python convert.py --help
usage: convert.py [-h] [-c | -t] filefolder [filefolder ...]

Converts *.spc binary files to text using the spc module

positional arguments:
  filefolder  Input *.spc files or directory

optional arguments:
  -h, --help  show this help message and exit
  -c, --csv   Comma separated output file (.csv) [default]
  -t, --txt   Tab separated output file (.txt)
```

#### Examples

```
Convert file1.spc and file2.spc to file1.txt and file2.txt (tab delimited)
$ python convert.py file1.spc file2.spc -t
Convert the spc files in spc_dir to .csv files
$ python convert.py spc_dir
```

### GUI: convert_gui.py

Uses Tk which is generally included as part of Python standard library.

#### Notes

1. Only works with Python 2.7 right now, need to fix imports for Python 3.x
2. Only works on a single folder at a time.
3. Tkinter sometimes needs to be installed on linux distributions

![Tk based Graphical interface](images/gui.png)

### Notes

- Used format specification from SDK [1]
- Loads entire file into memory
- Data uses variable naming as in SPC.H

### Todo

- ~~Use flag for 16bit and test~~
- Check struct string (`<` vs others, using signed vs. unsigned ints)
- Remove repetitions in sub class
- Remove multiple definitions of flag bits
- Better debug info that works all the time
- Year info for old data
- ~~Fix exponent in 16 bit format~~
- Add labels to ~~plots and~~ text output
- Merge both subFile classes, they are pretty similar

## References

[1] "Thermo Scientific SPC File Format." Thermo Fisher Scientific, Web. 20 July 2014\. <http://ftirsearch.com/features/converters/SPCFileFormat.htm>.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lepa22/pyfasma-spc",
    "name": "pyfasma-spc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": "scientific, SPC, spectra, data analysis",
    "author": "Rohan Isaac",
    "author_email": "rohan_isaac@yahoo.com",
    "download_url": "https://files.pythonhosted.org/packages/54/66/e87df0d6d10bb7a0ffa79b7104aec528c8f9fc15f8bae96819954ba910e1/pyfasma_spc-0.4.2.tar.gz",
    "platform": null,
    "description": "# spc\n\n[![Build Status](https://travis-ci.org/rohanisaac/spc.svg?branch=master)](https://travis-ci.org/rohanisaac/spc)\n\nA module for working with .SPC files in Python. SPC is a binary data format to store a variety of spectral data, developed by Galactic Industries Corporation in the '90s. Popularly used Thermo Fisher/Scientific software GRAMS/AI. Also used by others including Ocean Optics, Jobin Yvon Horiba. Can store a variety of spectrum including FT-IR, UV-VIS, X-ray Diffraction, Mass Spectroscopy, NMR, Raman and Fluorescence spectra.\n\nThe SPC file format can store either single or multiple y-values, and the x-values can either be given explicitly or even spaced x-values can be generated based on initial and final points as well as number of points. In addition the format can store various log data and parameters, as well as various information such as axis labels and scan type.\n\n## Features\n\n1. Extracts header information into object members\n2. For each subfile, extract subfile data into `subFile` class objects `sub[0]` (, `sub[1]`, `sub[2]`, ...)\n3. Extract x and y values into numpy `ndarray`\n4. Attempts to interpret x,y, and z labels, as well as scan type\n5. Member functions to output data in text, or plot using `matplotlib`\n\n## Installation\n\n### Requirements\n\n```\npython2.7+\nnumpy\nmatplotlib (optional, for plotting)\n```\n\nDownload zip and extract or clone repository. From the resulting folder run\n\n```bash\n$ cd ~/Downloads/spc-master/\n$ python setup.py install\n```\n\n## Usage\n\nFrom a Python/IPython session or in a script\n\n```python\n>>> import spc\n>>> f = spc.File('/Desktop/sample.spc')  # read file\nx-y(20)  # format string\n>>> f.data_txt()  # output data\n>>> f.write_file('output.txt')  # write data to file\n>>> f.plot()  # plot data\n```\n\nNote the format string outputed refers to where data is stored the object, which corresponds to the various ways data can be stored in the spc file format. Items before the `-` means that data is global, after the `-` means the data is in a subFile, and the (n) refers to the number of subfiles.\n\n### Examples\n\nFormat string | Meaning\n------------- | --------------------------------------------------------------------\nx-y(3)        | one global x-data series, 3 corresponding y-data series\n-xy(4)        | four subfiles with individual x and y data series\ngx-y(10)      | single global x-data (generated), and 10 corresponding y-data series\n\n### Accessing data\n\nThe object generated is populated with all the data and metadata from the file. The data can be manully accessed using the entry in the table corresponding to the format string outputted.\n\nformat string | x-values                  | y-values\n------------- | ------------------------- | -------------------------\n-xy(n)        | f.sub[0].x ... f.sub[n].x | f.sub[0].y ... f.sub[n].y\nx-y(n)        | f.x                       | f.sub[0].y ... f.sub[n].y\ngx-y(n)       | f.x (generated)           | f.sub[0].y ... f.sub[n].y\n\nDepending on the information stored in the file, there are a number of metadata fields that may be populated. Some commonly used fields are\n\nmetadata            | variable\n------------------- | -----------\nx-label             | f.xlabel\ny-label             | f.ylabel\nz-label             | f.zlabel\nComment (formatted) | f.cmnt\nComment (raw)       | f.fcmnt\nExperiment type     | f.exp_type\nLog dictionary      | f.log_dict\nLog (remaining)     | f.log_other\n\nTo get a full list of data/metadata stored in the object, you can run `object.__dict__` on the file and subFile objects.\n\n### Functions\n\nFunctions      | Description\n-------------- | -------------------------------------\nf.data_txt()   | Outputs data to stdout\nf.debug_info() | Human readable metadata for debugging\nf.plot()       | Plots data using matplotlib\nf.write_file() | Writes data to text file\n\n### File versions supported\n\nFile versions are given by the second bit in the file, `fversn` in an SPC object. Currently the library supports the following `fversn` bytes.\n\nfversn | Description      | Support      | Notes\n------ | ---------------- | ------------ | ----------------------------------------------------------------\n0x4B   | New format (LSB) | Good         | z-values are not accounted for in data_txt() and plot() commands\n0x4C   | New format (MSB) | None         | need sample file to test\n0x4D   | Old format       | Good         |\n0xCF   | SHIMADZU format  | Very limited | no metadata support, only tested on one file, no specifications\n\n## File converter\n\nThe file converter can be use to convert files/directories from the terminal.\n\n### CLI: convert.py\n\n```\n$ python convert.py --help\nusage: convert.py [-h] [-c | -t] filefolder [filefolder ...]\n\nConverts *.spc binary files to text using the spc module\n\npositional arguments:\n  filefolder  Input *.spc files or directory\n\noptional arguments:\n  -h, --help  show this help message and exit\n  -c, --csv   Comma separated output file (.csv) [default]\n  -t, --txt   Tab separated output file (.txt)\n```\n\n#### Examples\n\n```\nConvert file1.spc and file2.spc to file1.txt and file2.txt (tab delimited)\n$ python convert.py file1.spc file2.spc -t\nConvert the spc files in spc_dir to .csv files\n$ python convert.py spc_dir\n```\n\n### GUI: convert_gui.py\n\nUses Tk which is generally included as part of Python standard library.\n\n#### Notes\n\n1. Only works with Python 2.7 right now, need to fix imports for Python 3.x\n2. Only works on a single folder at a time.\n3. Tkinter sometimes needs to be installed on linux distributions\n\n![Tk based Graphical interface](images/gui.png)\n\n### Notes\n\n- Used format specification from SDK [1]\n- Loads entire file into memory\n- Data uses variable naming as in SPC.H\n\n### Todo\n\n- ~~Use flag for 16bit and test~~\n- Check struct string (`<` vs others, using signed vs. unsigned ints)\n- Remove repetitions in sub class\n- Remove multiple definitions of flag bits\n- Better debug info that works all the time\n- Year info for old data\n- ~~Fix exponent in 16 bit format~~\n- Add labels to ~~plots and~~ text output\n- Merge both subFile classes, they are pretty similar\n\n## References\n\n[1] \"Thermo Scientific SPC File Format.\" Thermo Fisher Scientific, Web. 20 July 2014\\. <http://ftirsearch.com/features/converters/SPCFileFormat.htm>.\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3 (GPLv3)",
    "summary": "A Python package for handling SPC files",
    "version": "0.4.2",
    "project_urls": {
        "Homepage": "https://github.com/lepa22/pyfasma-spc",
        "Repository": "https://github.com/lepa22/pyfasma-spc"
    },
    "split_keywords": [
        "scientific",
        " spc",
        " spectra",
        " data analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd483c63cf46ab3d5875383469e59822ce6b49142d23d77cf33fc6ff682f41a0",
                "md5": "539078c719e498d52d311d120d8c0dcc",
                "sha256": "d35a368c09d9401be21705f94faa0251e57c0f92904367fef9dbaee0053380dc"
            },
            "downloads": -1,
            "filename": "pyfasma_spc-0.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "539078c719e498d52d311d120d8c0dcc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 25270,
            "upload_time": "2024-10-06T19:23:34",
            "upload_time_iso_8601": "2024-10-06T19:23:34.541110Z",
            "url": "https://files.pythonhosted.org/packages/bd/48/3c63cf46ab3d5875383469e59822ce6b49142d23d77cf33fc6ff682f41a0/pyfasma_spc-0.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5466e87df0d6d10bb7a0ffa79b7104aec528c8f9fc15f8bae96819954ba910e1",
                "md5": "338d645f9ed00f01bac7df946fcf34d8",
                "sha256": "5a0d801f5124aaf2631180c5ddd55ec890eab9797907b208ff4d2ce7fcc5cce6"
            },
            "downloads": -1,
            "filename": "pyfasma_spc-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "338d645f9ed00f01bac7df946fcf34d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 26150,
            "upload_time": "2024-10-06T19:23:36",
            "upload_time_iso_8601": "2024-10-06T19:23:36.216666Z",
            "url": "https://files.pythonhosted.org/packages/54/66/e87df0d6d10bb7a0ffa79b7104aec528c8f9fc15f8bae96819954ba910e1/pyfasma_spc-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-06 19:23:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lepa22",
    "github_project": "pyfasma-spc",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": []
        }
    ],
    "lcname": "pyfasma-spc"
}
        
Elapsed time: 0.69597s