Skip to main content

This module imports a Princeton Instruments LightField (SPE 3.0) file into a python environment.

Project description

# spe2py

spe2py is a module that imports a Princeton Instruments LightField (SPE 3.x) file into a python environment.

### Basic Usage
##### Modules
The `spe2py` module is designed for quick data loading, viewing, and exploration. It is most effective for quick access
to .spe files via a graphical file dialog, and incorporates tooling functionality to view images and plots with as
little typing as possible.

The `spe_loader` module is responsible for the pure .spe file loading functionality, and can (and should) be imported
separately when only lightweight, programmatic loading is necessary.

##### Loading and accessing data
Use the `load()` function to load one or more SPE files at a time into a set of tools:
```python
>>> import spe2py as spe
>>> spe_tools = spe.load()
```
A file selection window will open to allow browsing for source files. The result is an individual SpeTool object, or, in the case where multiple files are loaded at once, a list of SpeTool objects.

Alternatively programmatic loading should be done with with the `spe_loader` module:
```python
>>> import spe_loader as sl
>>> spe_files = sl.load_from_files(['path/to/file1', 'path/to/file2'])
```
The result is an individual SpeFile object, or, in the case where multiple files are loaded at once, a list of SpeFile objects.

Raw data from a file is stored in NumPy arrays and can be accessed directly by
```python
>>> frame_data = spe_tool.file.data[frame][regionOfInterest]
>>> frame_data = spe_tools[n].file.data[frame][regionOfInterest] # where multiple files are loaded
```
or when using the pure loader module:
```python
>>> frame_data = spe_file.data[frame][regionOfInterest]
>>> frame_data = spe_files[n].data[frame][regionOfInterest] # where multiple files are loaded
```

##### Automatic imaging and plotting (spe2py tools only)
To quickly view an individual frame, region-of-interest, or spectrum, use the `image()` or `specplot()` methods. For example,
```python
>>> spe_tool.image() # images the first frame and region of interest
>>> spe_tool.image(f, r) # images frame 'f' and region of interest 'r'
>>> spe_tool.specplot() # plots the loaded spectrum
```

##### Accessing metadata
Upon loading, the metadata contained in the file's XML footer is automatically parsed and stored as an `untangle` object in the `footer` variable. Elements and attributes can be accessed by calling the different elements and subelements of footer, ending with the attribute as a string:
```python
>>> sensor_height = loaded_file.footer.SpeFormat.Calibrations.SensorInformation['height']
```
One can print the full element tree by calling the `xmltree()` method.

### Dependencies
- NumPy - data storage and file reading
- [untangle](https://github.com/stchris/untangle) - XML parsing
- tkinter - file selection dialog (spe2py tools only)
- matplotlib - imaging and plotting (spe2py tools only)

### Version
2.0.0 - Separation of Tooling and Loading functionality


License
----

MIT



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spe2py-2.0.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spe2py-2.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file spe2py-2.0.0.tar.gz.

File metadata

  • Download URL: spe2py-2.0.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for spe2py-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4df0f06f21bec5062a33b04e41d71000705a2b1de8bd77ad3809d5b3f01e291a
MD5 7a4bcdd98e5612b13f7a92f86c3b9b00
BLAKE2b-256 0a6ea03e54abae4d9892aa5c291fd2329cc95cf001c50c19cb639723978fcce3

See more details on using hashes here.

File details

Details for the file spe2py-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spe2py-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ba810d21b05fea583c3851b78a53e9e70abb36ae02a7d3d5d3991f17dbb0f33
MD5 399ca827b166ff40312a3efba4cebfa3
BLAKE2b-256 0bbcfb061b11352191604d3b5ce0012afc749399aebab84f33f07f4b83fda45c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page