Opus File Converter (opusFC) Documentation

Introduction

The opusFC module converts binary OPUS files into NumPy arrays. It is primarily intended to be used with Quasar as part of the orange-spectroscopy add-on for the Orange3 Data Mining suite.

Usage

To determine the contents of a file:

f = /path/to/opusfile.0
dbs = opusFC.listContents(f)
print(dbs)

Load the first datablock in dbs:

data = opusFC.getOpusData(f, dbs[0])

Access loaded data and parameters:

data.x                    # X coordinates
data.parameters['SNM']    # Sample name
data.description          # Description of data object
opusFC.paramDict['SNM']     # String description of SNM

Access and save visible images:

images = opusFC.getVisImages(f)

for img in images:
    data = img['image']
    title = img['Title']
    imgext = img['imgext']
    f = "{0}_{1}.{2}".format(f, title, imgext)
    with open(f, 'wb') as fd:
        fd.write(data)

Contributing

opusFC is distributed as a compiled python/cython module only. Feedback, bug reports, and other contributions are welcomed at the python-opusfc-dist github repo or by contacting the authors directly.

Authors

opusFC is written by Stuart Read and Mike Richards for the Mid-IR beamline at the Canadian Light Source Inc.

Reference

class opusFC.BaseDataReturn(dimension, dataType, deriv, parameters, x, minY, maxY)

Base class for data object returned by .getOpusData().

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

class opusFC.ImageDataReturn(mapX, mapY, spectra, **kwds)

Hyperspectral data object returned by .getOpusData() for 3D image datablocks.

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

mapX

1D numpy array of X map coordinates

Type:

ndarray

mapY

1D numpy array of Y map coordinates

Type:

ndarray

spectra

3D numpy array of spectral maps dataObject.spectra[row][column][x]

Type:

ndarray

class opusFC.ImageTRCDataReturn(mapX, mapY, labels, traces, **kwds)

Map(s) of a single spectral feature/integral/calculation returned by .getOpusData() for 3D image TRC datablocks.

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

mapX

1D numpy array of X map coordinates

Type:

ndarray

mapY

1D numpy array of Y map coordinates

Type:

ndarray

labels

List of trace block names

Type:

list of str

traces

3D numpy array of trace maps with same index as labels: dataObject.traces[:,:,index]

Type:

list of ndarray

class opusFC.MultiRegionDataReturn(regions, **kwds)

Hyperspectral multiregion point map(s) returned by .getOpusData() for multiregion 3D point mapping datablocks.

Maps are _not_ guaranteed to be perfect XY grids and so spectral coordinates cannot be specfied by origin point and dx/dy values as in :class:ImageDataReturn.

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

regions

List of regions. Each region is a :class:Region containing

Type:

list of Region

regions[0].title

description of region

Type:

str

regions[0].mapX

1D numpy array of X map coordinates

Type:

ndarray

regions[0].mapY

1D numpy array of Y map coordinates

Type:

ndarray

regions[0].start_time

timestamps of spectrum acquisition array

Type:

ndarray

regions[0].spectra

2D numpy array of of spectra in the region: returnedObject.regions[region index].spectra[row]

Type:

ndarray

class opusFC.MultiRegionTRCDataReturn(labels, regions, **kwds)

Hyperspectral multiregion point map(s) returned by .getOpusData() for multiregion 3D point mapping datablocks.

Maps are _not_ guaranteed to be perfect XY grids and so spectral coordinates cannot be specfied by origin point and dx/dy values as in :class:ImageDataReturn.

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

labels

List of trace block names

Type:

list of str

regions

List of regions. Each region is a :class:Region containing

Type:

list of Region

regions[0].title

description of region

Type:

str

regions[0].mapX

1D numpy array of X map coordinates

Type:

ndarray

regions[0].mapY

1D numpy array of Y map coordinates

Type:

ndarray

regions[0].spectra

2D numpy array of traces in the region: returnedObject.regions[region index].spectra[row] As with :class:ImageTRCDataReturn, the index of the resulting array corresponds to the .labels index

Type:

ndarray

opusFC.OpusDict()

Returns a dictionary for translating parameter keys to lower_case_strings.

class opusFC.Region(title, mapX, mapY, start_time, spectra)

Returned as part of a :class:MultiRegionDataReturn.

title

description of region

Type:

str

mapX

1D numpy array of X map coordinates

Type:

ndarray

mapY

1D numpy array of Y map coordinates

Type:

ndarray

start_time

timestamps of spectrum acquisition array

Type:

ndarray

spectra

2D numpy array of of spectra in the region: spectra[row]

Type:

ndarray

class opusFC.SingleDataReturn(y, **kwds)

Single spectrum data object returned by .getOpusData() for 2D datablocks.

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

y

1D numpy array of y values

Type:

ndarray

class opusFC.TimeResolvedDataReturn(z, spectra, **kwds)

Time-resolved spectra data object returned by .getOpusData() for 3D-TRS datablocks.

Z Axis units are available from dataObject.parameters[‘ZTX’]

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of spectrum x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

z

1D numpy array of z (time) axis coordinates

Type:

ndarray

spectra

2D numpy array of spectral time series dataObject.spectra[z][x]

Type:

ndarray

class opusFC.TimeResolvedTRCDataReturn(labels, traces, **kwds)

Time-resolved trace data object returned by .getOpusData() for 3D-TRS TRC datablocks.

x axis units are available from dataObject.parameters[‘DXU’]

description

Description of the data object attributes

Type:

str

dimension

Datablock dimensions (2D or 3D)

Type:

str

dataType

The datablock type (AB, TR, SSC, etc)

Type:

str

derivative

Datablock derivative (NONE, 1DER, 2DER, NDER)

Type:

str

parameters

Dictionary of relevant data/sample/instrument parameters

Type:

dict

x

1D numpy array of trace x coordinates

Type:

ndarray

minY

Minimum y value

Type:

float

maxY

Maximum y value

Type:

float

labels

List of trace names

Type:

list of str

traces

2D numpy array of traces with same index as labels: dataObject.traces[index]

Type:

list of ndarray

opusFC.decode_string(s, encodings=('ascii', 'utf8', 'latin1'))

Attempt to decode a string

opusFC.getOpusData(path, datablock)

This function returns a DataReturn object containing the data and data parameters for the specified datablock in the given file.

Parameters:
  • path (path) – Path to file

  • datablock (tuple of str) – tuple(datablocktype, dimensions, derivative) as returned by .listContents()

Returns:

Object containing the requested data and associated parameters. Data structure is as specified in data.description and can be one of the three types described in DataReturn

Return type:

DataReturn

opusFC.getVisImages(path)

This function returns a list containing a dictionary for each visible image in the given file.

Parameters:

path (path) – Path to file

Returns:

List containing a dictionary for each visible image in the file.

Each dictionary contains:

{‘image’: bytes(), # Image data

’imgext’: ‘bmp’, # Image type (‘bmp’ or ‘jpeg’) ‘Pos. X’: 33733.0} # Useful image attributes

opusFC.help()

Print a help message containing the available functions.

opusFC.imghdr_what(h)

Simplified version of imghdr.what()

opusFC.isOpusFile(path)

Tests if the given file is an OPUS data file.

Parameters:

path (path) – Path to file

Returns:

True if an OPUS file

Return type:

bool

opusFC.listContents(path)

This function returns a list of datablocks for a given file. Each datablock is identified by blocktype, dimensions and derivative.

Parameters:

path (path) – Path to file

Returns:

List containing a (datablocktype, dimensions, derivative) tuple for each datablock in the file

Return type:

list of tuple(str, str, str)

Indices and tables