nmraspecds.io module

io module of the nmraspecds package.

class nmraspecds.io.DatasetImporterFactory

Bases: DatasetImporterFactory

Factory to return the appropiate importer for the dataset.

The format is currently determined from the type of data.

Raises:

UnsupportedDataFormatError – Raised if a format is set but does not match any of the supported formats

get_importer(source='', importer='', parameters=None)

Return importer object for dataset specified by its source.

The actual code for deciding which type of importer to return in what case should be implemented in the non-public method _get_importer() in any package based on the ASpecD framework.

If no importer gets returned by the method _get_importer(), the ASpecD-interal importers will be checked for matching the file type. Thus, you can overwrite the behaviour of any filetype supported natively by the ASpecD framework, but retain compatibility to the ASpecD-specific file types.

Note

Currently, only filenames/paths are supported, and if source does not start with the file separator, the absolute path to the current directory is prepended.

Parameters:
  • source (str) –

    string describing the source of the dataset

    May be a filename or path, a URL/URI, a LOI, or similar

  • importer (str) –

    Name of the importer to use for importing the dataset

    Default: ‘’

    Added in version 0.2.

  • parameters (dict) –

    Additional parameters for controlling the import

    Default: None

    Added in version 0.2.

Returns:

importer – importer object of appropriate class

Return type:

aspecd.io.DatasetImporter

Raises:

aspecd.io.MissingSourceError – Raised if no source is provided

class nmraspecds.io.BrukerImporter(source=None)

Bases: DatasetImporter

Import data from Bruker format.

Data acquired with Bruker spectrometers are mostly processed in TopSpin Software. If nothing else is given, processed data (processing no. 1) is imported together with metadata. The import of data and metadata is done using nmrglue and then mapped to the dataset.

parameters

Parameters controlling the import

type: class:str

type of data, raw or processed.

Default: pdata

processing_numberstr

Processing number of the desired dataset.

Default: 1

Type:

dict

Raises:

FileNotFound – Raised if source file was not found.

Examples

It is always nice to give some examples how to use the class. Best to do that with code examples:

datasets:
  - source: dataset
    id: data
    label: My Data
import_into(dataset=None)

Perform the actual import into the given dataset.

If no dataset is provided at method call, but is set as property in the importer object, the aspecd.dataset.Dataset.import_from() method of the dataset will be called.

If no dataset is provided at method call nor as property in the object, the method will raise a respective exception.

The dataset object always calls this method with the respective dataset as argument. Therefore, in this case setting the dataset property within the importer object is not necessary.

The actual import should be implemented within the non-public method _import().

Note

A number of parameters of the dataset are automatically assigned after calling out to the non-public method aspecd.io.DatasetImporter._import(), namely the non-public property _origdata of the dataset is populated with a copy of aspecd.dataset.Dataset.data, and id and label are set to aspecd.io.DatasetImporter.source.

Parameters:

dataset (aspecd.dataset.Dataset) – Dataset to import data and metadata into

Raises:

aspecd.io.MissingDatasetError – Raised if no dataset is provided.

class nmraspecds.io.ScreamImporter(source=None)

Bases: DatasetImporter

Import scream data from a pseudo-2D dataset after processing.

Note

Importer not finished yet.

import_into(dataset=None)

Perform the actual import into the given dataset.

If no dataset is provided at method call, but is set as property in the importer object, the aspecd.dataset.Dataset.import_from() method of the dataset will be called.

If no dataset is provided at method call nor as property in the object, the method will raise a respective exception.

The dataset object always calls this method with the respective dataset as argument. Therefore, in this case setting the dataset property within the importer object is not necessary.

The actual import should be implemented within the non-public method _import().

Note

A number of parameters of the dataset are automatically assigned after calling out to the non-public method aspecd.io.DatasetImporter._import(), namely the non-public property _origdata of the dataset is populated with a copy of aspecd.dataset.Dataset.data, and id and label are set to aspecd.io.DatasetImporter.source.

Parameters:

dataset (aspecd.dataset.Dataset) – Dataset to import data and metadata into

Raises:

aspecd.io.MissingDatasetError – Raised if no dataset is provided.

class nmraspecds.io.FittingImporter(source=None)

Bases: DatasetImporter

Import data from DMFit with experimental and simulated data.

Data needs to be exported to ascii-format using the “ Export spec, model with all lines” command.

The file is composed with three comment lines:
  • title of the dataset

  • frequency

  • description of the columns.

31P-spectrum MAS 12 kHz
##freq 283.417
##col_ Hz       Spectrum        Model   Line#1  Line#2

The data then follows in the columns. As only the frequency is available as metadata, most NMR specific processing steps cannot be performed. The data can then be plotted with the special plotter nmraspecds.plotting.FittingPlotter2D which povides a color scheme that explains the single peaks.

attr

Short description

Type:

None

Examples

The import of the dataset is performed as usual. Together with a plot in the simplest case, the recipe looks as follows:

datasets:
  - source: fitting-data
    id: fit-data
    label: My Fitted Data
tasks:
  - kind: Singleplot
    type: FittingPlotter2D
    properties:
      filename: output.pdf
import_into(dataset=None)

Perform the actual import into the given dataset.

If no dataset is provided at method call, but is set as property in the importer object, the aspecd.dataset.Dataset.import_from() method of the dataset will be called.

If no dataset is provided at method call nor as property in the object, the method will raise a respective exception.

The dataset object always calls this method with the respective dataset as argument. Therefore, in this case setting the dataset property within the importer object is not necessary.

The actual import should be implemented within the non-public method _import().

Note

A number of parameters of the dataset are automatically assigned after calling out to the non-public method aspecd.io.DatasetImporter._import(), namely the non-public property _origdata of the dataset is populated with a copy of aspecd.dataset.Dataset.data, and id and label are set to aspecd.io.DatasetImporter.source.

Parameters:

dataset (aspecd.dataset.Dataset) – Dataset to import data and metadata into

Raises:

aspecd.io.MissingDatasetError – Raised if no dataset is provided.