nmraspecds.processing module

processing module of the nmraspecds package.

class nmraspecds.processing.ExternalReferencing

Bases: SingleProcessingStep

Referencing of the dataset to a given offset (in Hz).

Following the analysis step nmraspecds:analysis:ChemicalShiftCalibration, in this processing step, the axis of the dataset is adapted using the provided offset to reference the spectrum.

Often it is necessary to reference to a chemical shift of a different type of nucleus. This is accounted for with adapting the offset to the dataset’s nucleus in the case, both types of nuclei are given. The gyromagnetic ratios (γ/10^7 rad s^–1 T^–1) [1] are used via the spindata package by Benno Meier.

References

[1] https://doi.org/10.1351/pac200173111795

parameters[]

Offset (in Hz) to add to the base frequency to obtain correct axis.

Type:

float or dict

Examples

In the simplest case, the offset (SR in TopsSpin) is known and can just be inserted here:

- kind: processing
  type: ExternalReferencing
  properties:
    parameters:
      offset: 532

More sophisticated, the type of nucleus is also given to automatically account for the gyromagnetic ratios of the nuclei:

- kind: processing
  type: ExternalReferencing
  properties:
    parameters:
      offset: 532
      offset_nucleus: 13C

In reality, the combination of the analysis step with the corresponding processing step is powerful to use and could look as follows:

- kind: singleanalysis
  type: ChemicalShiftCalibration
  properties:
    parameters:
      standard: adamantane
      nucleus: 1H
  result: my_offset

- kind: processing
  type: ExternalReferencing
  properties:
    parameters:
      offset: my_offset
static applicable(dataset)

Check whether processing step is applicable to the given dataset.

Returns True by default and needs to be implemented in classes inheriting from SingleProcessingStep according to their needs.

This is a static method that gets called automatically by each class inheriting from aspecd.processing.SingleProcessingStep. Hence, if you need to override it in your own class, make the method static as well. An example of an implementation testing for two-dimensional data is given below:

@staticmethod
def applicable(dataset):
    return len(dataset.data.axes) == 3
Parameters:

dataset (aspecd.dataset.Dataset) – dataset to check

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.process() method of the aspecd.dataset.Dataset class and ensures the history of each processing step to get written properly.

Returns:

history_record – history record for processing step

Return type:

aspecd.history.ProcessingHistoryRecord

process(dataset=None, from_dataset=False)

Perform the actual processing step on the given dataset.

If no dataset is provided at method call, but is set as property in the SingleProcessingStep object, the aspecd.dataset.Dataset.process() method of the dataset will be called and thus the history written.

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

The aspecd.dataset.Dataset object always call this method with the respective dataset as argument. Therefore, in this case setting the dataset property within the aspecd.processing.SingleProcessingStep object is not necessary.

The actual processing step should be implemented within the non-public method _perform_task(). Besides that, the applicability of the processing step to the given dataset(s) will be checked automatically using the non-public method _check_applicability(), default parameter values will be set calling the non-public method _set_defaults(), and the parameters will be sanitised by calling the non-public method _sanitise_parameters() prior to calling _perform_task().

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to apply processing step to

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset the processing step has been applied to

Return type:

aspecd.dataset.Dataset

Raises:
to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

In this particular case, the key “dataset” from the top level of the resulting dictionary will be removed, but not keys with the same name on lower levels of the resulting dict.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

class nmraspecds.processing.Normalisation

Bases: Normalisation

Normalize data additionally to number of scans.

Extension of the class aspecd:processing:Normalization. For all other kinds see the documentation of the parent class.

Additional kind:

  • scan_number

    Data is divided by the number of scans.

Examples

As there are no further settings, the normalization is performed in an recipe as follows:

- kind: processing
  type: Normalisation
  properties:
    parameters:
      kind: scan_number
static applicable(dataset)

Check whether processing step is applicable to the given dataset.

Returns True by default and needs to be implemented in classes inheriting from SingleProcessingStep according to their needs.

This is a static method that gets called automatically by each class inheriting from aspecd.processing.SingleProcessingStep. Hence, if you need to override it in your own class, make the method static as well. An example of an implementation testing for two-dimensional data is given below:

@staticmethod
def applicable(dataset):
    return len(dataset.data.axes) == 3
Parameters:

dataset (aspecd.dataset.Dataset) – dataset to check

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.process() method of the aspecd.dataset.Dataset class and ensures the history of each processing step to get written properly.

Returns:

history_record – history record for processing step

Return type:

aspecd.history.ProcessingHistoryRecord

process(dataset=None, from_dataset=False)

Perform the actual processing step on the given dataset.

If no dataset is provided at method call, but is set as property in the SingleProcessingStep object, the aspecd.dataset.Dataset.process() method of the dataset will be called and thus the history written.

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

The aspecd.dataset.Dataset object always call this method with the respective dataset as argument. Therefore, in this case setting the dataset property within the aspecd.processing.SingleProcessingStep object is not necessary.

The actual processing step should be implemented within the non-public method _perform_task(). Besides that, the applicability of the processing step to the given dataset(s) will be checked automatically using the non-public method _check_applicability(), default parameter values will be set calling the non-public method _set_defaults(), and the parameters will be sanitised by calling the non-public method _sanitise_parameters() prior to calling _perform_task().

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to apply processing step to

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset the processing step has been applied to

Return type:

aspecd.dataset.Dataset

Raises:
to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

In this particular case, the key “dataset” from the top level of the resulting dictionary will be removed, but not keys with the same name on lower levels of the resulting dict.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict