cwepr package

Submodules

cwepr.analysis module

Module containing all analysis steps

An analysis step is everything that operates on a dataset and yields a result largely independent of this dataset. E.g., integration or determination of a field correction value.

exception cwepr.analysis.Error[source]

Bases: Exception

Base class for exceptions in this module.

exception cwepr.analysis.WrongOrderError(message='')[source]

Bases: cwepr.analysis.Error

Exception raised when x values are decreasing.

Values given for the common space determination should always be in increasing order.

message

explanation of the error

Type

str

exception cwepr.analysis.NotEnoughDatasetsError(message='')[source]

Bases: cwepr.analysis.Error

Exception raised when common definition range can’t be determined.

This is usually the case when less than two datasets are given for the common space determination.

message

explanation of the error

Type

str

exception cwepr.analysis.NoCommonspaceError(message='')[source]

Bases: cwepr.analysis.Error

Exception raised when common definition range is zero.

message

explanation of the error

Type

str

exception cwepr.analysis.SpectrumNotIntegratedError(message='')[source]

Bases: cwepr.analysis.Error

Exception raised when definite integration is used accidentally.

Definite integration should only be performed on a derivative spectrum.

message

explanation of the error

Type

str

class cwepr.analysis.FieldCorrectionValueFinding[source]

Bases: aspecd.analysis.SingleAnalysisStep

Determine correction value for a field correction.

References for the constants:

g value for Li:LiF:

g(LiLiF) = 2.002293 +- 0.000002

Reference: Rev. Sci. Instrum. 1989, 60, 2949-2952.

Bohr magneton:

mu_B = 9.27401*10**(-24)

Reference: Rev. Mod. Phys. 2016, 88, 035009.

Planck constant:

h = 6.62607*10**(-34)

Reference: Rev. Mod. Phys. 2016, 88, 035009.

VALUE_G_LILIF = 2.002293
VALUE_MuB = 9.27401e-24
VALUE_H = 6.62607e-34
_perform_task()[source]

Wrapper around field correction value determination method.

get_field_correction_value()[source]

Calculates a field correction value.

Finds the approximate maximum of the peak in a field standard spectrum by using the difference between minimum and maximum in the derivative. This value is subtracted from the the expected field value for the MW frequency provided.

Returns

delta_b0 – Field correction value

Return type

float

class cwepr.analysis.BaselineFitting(order=0, percentage=10)[source]

Bases: aspecd.analysis.SingleAnalysisStep

Analysis step for finding a baseline correction polynomial.

order

Order of the polynomial to create

Type

int

percentage

Percentage of the spectrum to consider as baseline on EACH SIDE of the spectrum. I.e. 10% means 10% left and 10 % right.

Type

int

_perform_task()[source]

Wrapper around polynomial determination.

_find_polynomial_by_fit()[source]

Perform a polynomial fit on the baseline.

Assemble the data points of the spectrum to consider and use a numpy polynomial fit on these points.

static _get_points_to_use(data, points_per_side)[source]

Get a number of points from the spectrum to use for a fit.

Slice the list of all data points to have a list of points from each side of the spectrum to use for polynomial fitting.

Parameters
  • data (list) – List from which points should be used on each side.

  • points_per_side (:class:'int') – How many points from each end of the list should be used.

Returns

points_to_use – List only containing the correct number of points from each side and not the points in between.

Return type

list

class cwepr.analysis.IntegrationDefinite[source]

Bases: aspecd.analysis.SingleAnalysisStep

Make definite integration, i.e. calculate the area under the curve.

_perform_task()[source]

Perform the actual integration.

The x values from the dataset are used.

class cwepr.analysis.IntegrationVerification(y, percentage=15, threshold=0.001)[source]

Bases: aspecd.analysis.SingleAnalysisStep

Verify whether the spectrum was correctly preprocessed.

In the case of a correct preprocessing, the curve after the first integration should be close to zero on the rightmost part of the spectrum, i.e. the area under this curve should also be close to zero.

y

y values to use for the integration

Type

list

percentage

Percentage of the spectrum to consider

Type

int

threshold

Threshold for the integral. If the integral determined is smaller the preprocessing is considered to have been successful.

Type

float

_perform_task()[source]

Perform the actual verification.

Perform the actual integration on a certain percentage of the points from the right part of the spectrum and compare them to the threshold.

The result is a boolean: Is the integral lower than the threshold?

class cwepr.analysis.CommonspaceAndDelimiters(datasets, threshold=0.05)[source]

Bases: aspecd.analysis.SingleAnalysisStep

Determine the common definition ranges.

If the common range is inferior to a certain value, an exception is raised. This can be transformed to a warning on a higher level application. In this respect the analysis determines if a large enough common space exists. This is the case if no exception is raised.

Additionally the analysis finds the edges of common ranges and returns them which can be used to display them in a plot.

datasets

List of datasets to consider in the determination.

Type

list

threshold

Distance used for determining whether or not the common definition range of two spectra is large enough (vide infra).

Type

float

minimum

Leftmost end of all spectra determined in the routine.

Type

float

maximum

Rightmost end of all spectra determined in the routine.

Type

float

minimal_width

Smallest width of all spectra determined in the routine.

Type

float

start_points

List of the left ends of all spectra determined in the routine.

Type

list

end_points

List of the right ends of all spectra determined in the routine.

Type

list

Raises
  • NotEnoughDatasetsError – Exception raised when less than two datasets are provided.

  • WrongOrderError – Exception raised when any given x axis does not start with the smallest and end with the highest value (determined by comparison of the first and last value).

  • NoCommonspaceError – Exception raised when the size of the common definition range is considered too low (vide supra).

_perform_task()[source]

Main function performing the necessary subtasks.

To find the common definition ranges first all relevant data points are collected. Subsequently the common ranges are determined and finally the delimiter points between different ranges are determined. These points are returned as result to possibly display them in a plot using multiple spectra.

Raises

NotEnoughDatasetsError – Exception raised when less than two datasets are provided.

_acquire_data()[source]

All relevant data (see class attributes) are collected.

Raises

WrongOrderError – Exception raised when any given x axis does not start with the smallest and end with the highest value (determined by comparison of the first and last value).

check_commonspace_for_two(index1, index2)[source]

Compare the definition ranges of two datasets.

Determine whether or not the common definition range of two spectra is considered large enough. This is determined by measuring the distance between the start and end points of the spectra x axis. Two factors considered are the difference in length between the axes as well as the user provided threshold value.

The maximum distance allowed on either end is

length_difference + threshold*smaller width

Parameters
  • index1 (int) – Index of one dataset used in the comparison. The index is given for the instance’s list of datasets.

  • index2 (int) – Index of the second dataset used in the comparison.

Raises

NoCommonspaceError – Exception raised when the size of the common definition range is considered too low (vide supra).

_check_commonspace_for_all()[source]

Check all possible common definition ranges.

Todo

Avoid calculating every combination twice.

_find_all_delimiter_points()[source]

Find points where a spectrum starts or ends.

Points very close to the actual edges of the whole definition range are not considered. Different points that are rather close to each other are combined.

This method is used to provide points to display edges of common ranges inside a plot.

_eliminate_close_delimiters(points)[source]

Combine points close to each other.

Combining means, eliminating both and adding a new point between the two.

Close means less than:

0.03*smallest width of all spectra

This threshold is currently rather arbitrary.

class cwepr.analysis.PeakToPeakLinewidth[source]

Bases: aspecd.analysis.SingleAnalysisStep

Linewidth measurement (peak to peak in derivative)

_perform_task()[source]

Perform the actual analysis step on the dataset.

The implementation of the actual analysis step goes in here in all classes inheriting from SingleAnalysisStep. This method is automatically called by self.analyse() after some background checks.

get_peak_to_peak_linewidth()[source]

Calculates the peak-to-peak linewidth.

This is done by determining the distance between the maximum and the minimum in the derivative spectrum which should yield acceptable results in a symmetrical signal.

Returns

linewidth – line width as determined

Return type

float

class cwepr.analysis.LinewidthFWHM[source]

Bases: aspecd.analysis.SingleAnalysisStep

Linewidth measurement at half maximum

_perform_task()[source]

Perform the actual analysis step on the dataset.

The implementation of the actual analysis step goes in here in all classes inheriting from SingleAnalysisStep. This method is automatically called by self.analyse() after some background checks.

get_fwhm_linewidth()[source]

Calculates the line width (full width at half maximum, FWHM).

This is done by subtracting maximum/2, building the absolute value and then determining the minima. The distance between these points corresponds to the FWHM linewidth.

Returns

linewidth – line width as determined

Return type

float

class cwepr.analysis.SignalToNoise(percentage=10)[source]

Bases: aspecd.analysis.SingleAnalysisStep

Measure a spectrum’s signal to noise ratio.

This is done by comparing the absolute maximum of the spectrum to the maximum of the edge part of the spectrum (i.e. a part which is considered to not contain any signal.

percentage

percentage of the spectrum to be considered edge part on any side (i.e. 10% means 10% on each end).

Type

int

_perform_task()[source]

Determine signal to noise ratio.

Call method to get the amplitude of the noise, compare it to the absolute amplitude and set a result.

Todo

numpy.abs or similar should do the trick for absolute values…

_get_noise_amplitude(data_absolute)[source]

Find the maximum of the noise.

This method assembles the data points of the spectrum to consider as noise and returns the maximum.

static _get_points_to_use(data, points_per_side)[source]

Get a number of points from the spectrum to use for a fit.

Slices the list of all data points to have a list of points from each side of the spectrum to consider as noise.

WARNING: The spectral data needs to be provided and/or the percentage to use set in a way that no actual peak lies in this range.

Parameters
  • data (list) – List from which points should be used on each side.

  • points_per_side (:class:'int') – How many points from each end of the list should be used.

Returns

points_to_use – List only containing the correct number of points from each side and not the points in between.

Return type

list

cwepr.dataset module

Dataset (Container for experimental data and respective metadata)

class cwepr.dataset.Dataset[source]

Bases: aspecd.dataset.ExperimentalDataset

Set of data uniting all relevant information.

The unity of numerical and metadata is indispensable for the reproducibility of data and is possible by saving all information available for one set of measurement data in a single instance of this class.

MAPPINGS = [['GENERAL', 'combine_items', [['Date start', 'Time start'], 'Start', ' ']], ['GENERAL', 'combine_items', [['Date end', 'Time end'], 'End', ' ']], ['', 'rename_key', ['GENERAL', 'measurement']], ['', 'rename_key', ['TEMPERATURE', 'temperature_control']]]
import_from_file(filename)[source]

Import data and metadata for a given filename.

The appropriate importer automatically checks whether data and metadata files exist, matching a single format

Parameters

filename (str) – Path including the filename but not the extension.

modify_field_values()[source]

Wrapper method to get all magnetic field data in desired form.

Fills in all variables concerning the magnetic field as appropriate and transforms them from gauss to millitesla.

map_metadata_and_check_for_overrides(metadata)[source]

Perform some operations to yield the final set of metadata.

Modifies names of metadata information as necessary, combines data from the infofile and the spectrometer parameter file and checks for possible overrides.

Parameters

metadata (list) – Loaded metadata to use. First entry: from infofile; Second entry: from spectrometer parameter file.

_check_for_override(data1, data2, name='')[source]

Check if metadata from info file is overridden by parameter file.

Compare the keys in the info file dict with those in each part of the DSC/PAR file to find overrides. Any matching keys are considered to be overridden and a respective note is added to cwepr.metadata.DatasetMetadata.metadata_modifications. The method cascades through nested dicts returning a ‘path’ of the potential overrides. E.g., when the key ‘a’ in the sub dict ‘b’ is found in both dicts the path will be ‘/b/a’.

Parameters
  • data1 (dict) – Original data.

  • data2 (dict) – Data that is added to the original dict.

  • name (str) – Used in the cascade to keep track of the path. This should not be set to anything other than the default value.

static _import_metadata(importer=None)[source]

Import metadata using a selected importer.

The appropriate importer automatically checks whether data and metadata files exist, matching a single format

Parameters

importer (cwepr.importers.ImporterEPRGeneral) – Importer instance to use for the import.

:raises MissingImporterError :: Raised, when no importer is provided

fill_axes()[source]

Add an x axis to the data.

The y (intensity) values (coming from the actual data file) are used as already present. The x (field) values are created from the field data in the metadata.

Both sets are combined and transformed into a numpy array.

class cwepr.dataset.DatasetFactory[source]

Bases: aspecd.dataset.DatasetFactory

Implementation of the dataset factory for recipe driven evaluation

static _create_dataset(source='')[source]

Return cwepr dataset.

Parameters

source (str) –

string describing the source of the dataset

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

Returns

dataset – Dataset object for cwepr package

Return type

cwepr.dataset.Dataset

cwepr.io module

Importers (Preparing raw data for processing)

exception cwepr.io.Error[source]

Bases: Exception

Base class for exceptions in this module.

exception cwepr.io.UnsupportedDataFormatError(message='')[source]

Bases: cwepr.io.Error

Exception raised when given data format is not supported.

message

explanation of the error

Type

str

exception cwepr.io.NoMatchingFilePairError(message='')[source]

Bases: cwepr.io.Error

Exception raised when no pair of data and parameter file is found.

Data and parameter files’ extensions must match a single format.

message

explanation of the error

Type

str

exception cwepr.io.MissingInfoFileError(message='')[source]

Bases: cwepr.io.Error

Exception raised when no user created info file is found.

message

explanation of the error

Type

str

exception cwepr.io.ImportMetadataOnlyError(message='')[source]

Bases: cwepr.io.Error

Exception raised when no importer has been initialized.

This happens when import of metadata is attempted without importing experimental data first.

message

explanation of the error

Type

str

exception cwepr.io.ExperimentTypeError(message='')[source]

Bases: cwepr.io.Error

Exception raised in case of problems with designated experiment type.

This inlcudes to cases: 1) when the data provided does not correspond to a continuous wave experiment or 2) the experiment type cannot be determined.

message

explanation of the error

Type

str

class cwepr.io.ImporterEPRGeneral(data_format=None, source=None)[source]

Bases: aspecd.io.DatasetImporter

Importer super class

Determine the correct specialized importer for a format.

data_format

The format of the data to import. Is set manually or determined automatically.

importers_for_formats

Map of the specialized importers for different formats.

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

  • NoMatchingFilePairError – Raised if no pair of files matching any one supported format can be found. Currently Bruker BES3T, EMX and ESP/ECS formats are supported.

supported_formats = {'BES3T': ['.DTA', '.DSC'], 'Other': ['.spc', '.par']}
import_metadata()[source]

Import metadata from parameter file and user made info file.

Raises
  • MissingInfoFileError – Raised if no user made info file is provided.

  • ImportMetadataOnlyError – Raised when no format specific importer is initialized. This should happen and only happen, when the method is called without first importing the experimental data, because :meth:’_import’ creates an instance of a format specific importer.

static _import_infofile(filename)[source]

Use aspecd method to import user made info file.

Returns

infofile_data – Parsed data from the info file.

Return type

dict

class cwepr.io.ImporterBES3T(source=None)[source]

Bases: cwepr.io.ImporterEPRGeneral

Specialized Importer for the BES3T format.

_import()[source]

Import data file in BES3T format.

The data is checked for plausibility; if values are too large or too small the byte order is changed.

Returns

raw_data – Raw numerical data in processable form.

Return type

numpy.array

import_metadata()[source]

Import parameter file in BES3T format and user created info file.

Returns

processed_param_data – Parsed data from the source parameter file.

Return type

dict

class cwepr.io.ParserDSC[source]

Bases: object

Parser for a *.DSC parameter file belonging to the BES3T format.

parse_dsc(file_content)[source]

Main method for parsing a *.DSC.

The is split into its three parts and each of the three parts into a dictionary

Parameters

file_content (str) – Content of a complete *.DSC file.

Returns

three_parts_processed – The three parts of the file, each represented by a dictionary containing pairs of keys (parameter names) and values (parameter values) The dictionaries of part one and three are additionally subdivided based on headlines.

Return type

list

static add_units(parsed_dsc_data)[source]

Adds the units to the data values concerning the field.

Parameters

parsed_dsc_data (list) – Original data.

Returns

parsed_dsc_data – Data with units added.

Return type

list

static _get_three_parts(file_content)[source]

Split a *.DSC file into three parts.

The three parts are: Descriptor Information, Standard Parameter Layer and Device Specific Layer.

The file is split at the second and third headline which start with convenient markers.

Parameters

file_content (str) – Content of a complete *.DSC file.

Returns

three_parts – The three parts of the file.

Return type

list

static _subdivide_part1(part1)[source]

Pre process the first part of a *.DSC file.

First part corresponds to “Descriptor Information. The crude string is split into subdivisions; the delimiter employed allows to detect the different headlines made up of three lines starting with asterisks, the center line containing additional text.

Each subdivision is then transformed into a dict entry with the headline, stripped of the first two characters (*t) as key and the remaining information as value. Lines containing an asterisk only are removed.

Parameters

part1 (str) – Raw first part of a file.

Returns

part1_clean – All subdivisions from the file with headlines as keys and list of lines as values; lines devoid of information removed.

Return type

dict

static _create_dict_p1p3(p1p3_split, delimiter, delimiter_width=0)[source]

Create a dict from the first or third part () of a *.DSC file.

First part corresponds to “Descriptor Information, third part corresponds to “Device Specific Layer” For every subdivision. lines are split at tabs. The method accounts for lines containing only a parameter name with no corresponding value.

Note

The format of part 3 of a *.DSC file does not work with tabs, but rather with with a variable number of spaces.

Parameters
  • p1p3_split (dict) – Preprocessed first or third part of a file, split into subdivisions with the headline as key. Subdivisions split into lines with lines devoid of information removed.

  • delimiter (str) – Delimiter separating parameter name and value in one line.

  • delimiter_width (int) – Used to split at a variable number of spaces (could be used for other delimiters, too, though). The method will count all characters before the first delimiter character and determine the number of delimiter characters from the difference to the value of delimiter width. If set to zero a single character delimiter will be applied.

Returns

p1p3_dict – Data from the input as pairs of key (subdivision name) and value (subdivision info). Each subdivision info is also a dict with keys (parameter names) and values (parameter values).

Return type

dict

static _subdivide_part2(part2)[source]

Pre process the second part of a *.DSC file.

Second part corresponds to the “Standard parameter layer” The crude string is split into lines; lines devoid of information (e.g. containing only an asterisk) are removed.

Note

every line containing asterisks is removed as these appear only in headlines and as delimiters.

Note

For reasons that will probably never be known, in this part, parameter names are separated from the values by four spaces instead of a tab.

Parameters

part2 (str) – Raw second part of a file.

Returns

entries_clean – All lines from the file part except those devoid of information.

Return type

list

static _create_dict_part2(part2_split)[source]

Create a dict from the second part of a *.DSC file.

Second part corresponds to the “Standard parameter layer” Lines are split at tabs. The method accounts for lines containing only a parameter name with no corresponding value.

Parameters

part2_split (list) – Preprocessed second part of a file, split into lines, with lines devoid of information already removed.

:raises ExperimentTypeError:: raised when the type of the experiment file cannot be determined from the parameter file or if it is not CW.

Returns

part2_dict – Data from the input as pairs of key (parameter name) and value (parameter value).

Return type

dict

static _subdivide_part3(part3)[source]

Pre process the third part of a *.DSC file.

Third part corresponds to the “Device Specific Layer” The crude string is split into subdivisions, which start with a headline containing the fragment “.DVC” Each subdivision is then transformed into a dict entry with the headline, stripped of the first eight characters (“.DVC”) as key and the remaining information as value. Lines containing asterisks are removed.

Parameters

part3 (str) – Raw third part of a file.

Returns

subparts_clean – All subdivisions from the file with headlines as keys and list of lines as values; lines devoid of information removed.

Return type

dict

_map_dsc(dsc_data)[source]

Prepare data from dsc file and include it in the metadata.

Parameters

dsc_data (list) – List containing all three parts of a dsc file as dicts.

Returns

mapped_data – data with the necessary modifications applied to allow for addition to the metadata.

Return type

list

static _map_descriptor(mapper)[source]

Prepare part one of the dsc file data for adding to the metadata.

Parameters

mapper (aspecd.metadata.MetadataMapper) – metadata mapper containing the respective first part of the dsc file as metadata.

static _map_device(mapper)[source]

Prepare part three of the dsc file data for adding to the metadata.

Parameters

mapper (aspecd.metadata.MetadataMapper) – metadata mapper containing the respective third part of the dsc file as metadata.

class cwepr.io.ImporterEMXandESP(source=None)[source]

Bases: cwepr.io.ImporterEPRGeneral

Specialized Importer for the BES3T format.

_import()[source]

Import data file in BES3T format.

The data is checked for plausibility; if values are too large or too small the byte order is changed.

Returns

raw_data – Raw numerical data in processable form.

Return type

numpy.array

import_metadata()[source]

Import parameter file in BES3T format and user created info file.

Returns

processed_param_data – Parsed data from the source parameter file.

Return type

dict

class cwepr.io.ParserPAR[source]

Bases: object

Parser for *.par file belonging to the EMX and ESP/ECS formats.

parse_and_map(file_content)[source]

Wrapper method for parsing and mapping.

Returns

content_mapped – Prepared metadata

Return type

dict

static _map_par(dict_)[source]
static _parse1(file_content)[source]

Main method for parsing a *.par into a dictionary.

The method _parse2 (vide infra) does the exact same thing in a different manner.

Parameters

file_content (str) – Content of a complete *.par file.

Returns

content_parsed

Return type

dict

static _parse2(file_content)[source]

Alternative for parsing a *.par file using regular expressions.

The method _parse1 (vide supra) does the exact same thing in a different manner.

Uses raw string to avoid confusion concerning escape sequences.

Parameters

file_content (str) – Content of a complete *.par file.

Returns

content_parsed

Return type

dict

class cwepr.io.ImporterFactoryEPR[source]

Bases: aspecd.io.DatasetImporterFactory

Factory that returns correct importer class for a given file.

supported_formats = {'BES3T': ['.DTA', '.DSC'], 'Other': ['.spc', '.par']}
_get_importer(source)[source]

Main method returning the importer instance.

Call the correct importer for the data format set. If no format is set, it is automatically determined from the given filename.

Raises

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

_find_format(source)[source]

Find out the format of the given file.

Determine the format of the given filename by checking if a data and metadata file matching any supported format are present.

Determination is performed by checking if files with the correct name and extension are present.

Raises

NoMatchingFilePairError – Raised if no pair of files matching any one supported format can be found. Currently only Bruker BES3T format is supported.

class cwepr.io.ExporterASCII[source]

Bases: aspecd.io.DatasetExporter

Export a dataset in ASCII format.

Exports the complete dataset to an ASCII file. At the same time, the respective metadata is exported into a YAML file using the functionality provided by aspecd.

_export()[source]

Export the dataset’s numeric data and metadata.

_get_and_prepare_metadata()[source]

Prepare the dataset’s metadata to be imported.

Transforms the metadata to a dict and subsequently eliminates all instances of numpy.array by transforming them into lists (vide infra).

Returns

metadata_prepared – transformed metadata

Return type

dict

_remove_arrays(dictionary)[source]

Removes instances of numpy.array from a given dict

Numpy arrays may interfere with the YAML functionality used for the export.

Note

This is a cascading method that also works on nested dicts.

Parameters

dictionary (dict) – Dictionary to relieve of arrays.

Returns

dictionary – Dictionary relieved of arrays.

Return type

dict

cwepr.metadata module

Metadata

Supplementary data for a dataset, i.e. everything that is not part of the literal experimental results, such as identifier, date of the experiment…

exception cwepr.metadata.Error[source]

Bases: Exception

Base class for exceptions in this module.

exception cwepr.metadata.NotEnoughValuesError(message='')[source]

Bases: cwepr.metadata.Error

Exception raised when magnetic field data cannot be calculated.

This happens when not enough different values are provided to calculate all other values.

message

explanation of the error

Type

str

exception cwepr.metadata.UnequalUnitsError(message='')[source]

Bases: cwepr.metadata.Error

Exception raised when addends have unequal units.

This is relevant when two physical quantities that shall be added or subtracted do not have the same unit.

message

explanation of the error

Type

str

class cwepr.metadata.DatasetMetadata[source]

Bases: aspecd.metadata.ExperimentalDatasetMetadata

Set of all metadata for a dataset object.

experiment

Metadata object containing information such as the type of the experiment performed.

Type

cwepr.metadata.Experiment

spectrometer

Metadata object containing information on the spectrometer used.

Type

cwepr.metadata.Spectrometer

magnetic_field

Metadata object containing information on the magnetic field applied in the experiment.

Type

cwepr.metadata.BFieldData

bridge

Metadata object containing information on the microwave bridge used.

Type

cwepr.metadata.Brige

signal_channel

Metadata object containing information on the signal channel applied.

Type

cwepr.metadata.SignalChannel

probehead

Metadata object containing information on the probehead used in the experiment.

Type

cwepr.metadata.Probehead

metadata_modifications

List of all modifications performed on the metadata, e.g, overrides.

Type

list

class cwepr.metadata.Sample[source]

Bases: aspecd.metadata.Sample

Metadata information on the sample measured.

class cwepr.metadata.BFieldData(dict_=None)[source]

Bases: aspecd.metadata.Metadata

Metadata class including all variables concerning the magnetic field.

can_calculate()[source]

Check if enough data is present to determine field values.

Checks if enough different pieces of information are provided to calculate all information concerning the field sector and sweeping steps.

Note

Currently, the possibility of calculating the sector width from the width and the number of steps is not accounted for.

Raises

NotEnoughValuesError – Raised when not enough different pieces of information are provided to determine the other variables.

calculate_values()[source]

Perform the calculation of all field values left out.

Calculate the different values concerning the sector and sweeping steps of the magnetic field.

Note

Currently, the possibility of calculating the sector width from the with and the number of steps is not accounted for.

:raises UnequalUnitsError :: Raised, when two physical quantities shall be added or subtracted that have unequal units.

_calc_field_width(units_error_message)[source]
_calc_field_limits(units_error_message)[source]
_calc_step_data(units_error_message)[source]
gauss_to_millitesla()[source]

Transform magnetic field parameters from gauss to millitesla.

class cwepr.metadata.Experiment[source]

Bases: aspecd.metadata.Metadata

General information on what type of experiment was performed.

class cwepr.metadata.SpectrometerInfo[source]

Bases: aspecd.metadata.Metadata

Metadata information on what type of spectrometer was used.

class cwepr.metadata.BridgeInfo[source]

Bases: aspecd.metadata.Metadata

Metadata information on the microwave bridge employed.

class cwepr.metadata.SignalChannel[source]

Bases: aspecd.metadata.Metadata

Metadata information information on the signal channel employed.

Todo

Currently aspecd crashes when the creation of an instance of aspecd.metadata.PhysicalQuantity is attempted from an empty parameter field (such as time_constant). Find a workaround or make the supervisor of aspecd find one.

class cwepr.metadata.Probehead[source]

Bases: aspecd.metadata.Metadata

Metadata information on the probe head employed.

cwepr.plotting module

Module containing data plotters for different applications.

exception cwepr.plotting.Error[source]

Bases: Exception

Base class for exceptions in this module.

exception cwepr.plotting.NoIntegralDataProvidedError(message='')[source]

Bases: cwepr.plotting.Error

Exception raised when integral data is missing.

This happens when a spectrum with integration should be plotted but no data for the integral is provided.

message

explanation of the error

Type

str

class cwepr.plotting.BaselineControlPlotter(data, coefficients)[source]

Bases: aspecd.plotting.SinglePlotter

Plotter to visualize possible baseline fits.

Visualize the spectrum and a number of possible baseline correction polynomials.

coefficients

List containing any number of other lists each containing a set of polynomial coefficients for a polynomial that might be used for the baseline correction. The order of the coefficients is considered to highest to lowest as returned by numpy.polyfit().

Type

list

data

Array containing the x (field) and y (intensity) values of the spectrum that shall be visualized with the polynomials

Type

numpy.array

_create_plot()[source]

Plot the spectrum and one or more baselines.

Plots the spectrum as well as one curve for each set of polynomial coefficients provided. The polynomial are indicated in the legend by their order. The final diagram is displayed.

class cwepr.plotting.SimpleSpectrumPlotter[source]

Bases: aspecd.plotting.SinglePlotter

Simple but highly customizable plotter for a single spectrum.

_set_defaults()[source]

Create default values for all settings of the plot.

set_color(color)[source]

Sets the color of the main (derivative) curve.

Parameters

color (str or RGBA tuple) – The color to use.

set_title(title)[source]

Sets the title of the plot.

Parameters

title (str) – The title to use.

set_x_axis_name(name)[source]

Sets the label of the x axis.

Parameters

name (str) – The name to use.

set_y_axis_name(name)[source]

Sets the label of the y axis.

Parameters

name (str) – The name to use.

set_curve_name(name)[source]

Sets the label of the main (derivative) curve in the legend.

Parameters

name (str) – The name to use.

set_draw_zeroline(do_draw)[source]

Set whether the zero line should be drawn.

Parameters

do_draw (bool) – Should the zero line be drawn?

set_zeroline_thickness(thickness)[source]

Sets thickness of the zero line.

Parameters

thickness (float) – Thickness of the zero line; default: 0.5

set_zeroline_color(color)[source]

Sets the color of the zero line.

Parameters

color (str or RGBA tuple) – The color to use.

set_fit_axis_to_spectrum(do_fit)[source]

Whether the x axis limits should be fitted to width of the spectrum.

Parameters

do_fit (bool) – Should the width of the plot fit the width of the curve?

set_x_axis_limits(left, right)[source]

Sets the limits of the x axis.

Note

Using None as a limit will leave the respective limit unchanged.

Parameters
  • left (float) – Left limit in units of the x axis.

  • right (:class:'float') – Right limit in units of the x axis.

_create_plot()[source]

Draw and display the plot.

The plot settings are put into the parameter attribute.

_make_labels_and_title()[source]

Create the title as well as the labels for the axes.

_plot_lines(x_coordinates, y_coordinates)[source]

Draw the spectrum curve and the zero line (if necessary).

Parameters
  • x_coordinates (list) – x values for plotting

  • y_coordinates (list) – y values for plotting

_make_axis_limits(x_coordinates)[source]

Set the limits of the x axis.

The limits are first fitted to the width of the spectrum (if necessary),then overridden with user specified values (if applicable).

Parameters

x_coordinates (list) – x values to plot. These are necessary for determining the correct limits.

class cwepr.plotting.SpectrumAndIntegralPlotter(integral_1=None, integral_2=None)[source]

Bases: cwepr.plotting.SimpleSpectrumPlotter

Plotter for a derivative spectrum including integrations.

Plot derivative spectrum as well as the first and / or second integral curve. Either integral curve can be omitted but NOT BOTH.

integral_1

y values of the first integration

Type

list

integral_2

y values of the second integration

Type

list

Raises

NoIntegralDataProvidedError – Raised when data for both integration is omitted.

_set_defaults()[source]

Set default settingsl.

Settings are applied as in the super class, plus additional settings for colors and names of the integral curves.

set_integral1_color(color)[source]

Sets the color of the first integral curve.

Parameters

color (str or RGBA tuple) – The color to use.

set_integral1_name(name)[source]

Sets the label of the first integral curve in the legend.

Parameters

name (str) – The name to use.

set_integral2_color(color)[source]

Sets the color of the second integral curve.

Parameters

color (str or RGBA tuple) – The color to use.

set_integral2_name(name)[source]

Sets the label of the second integral curve in the legend.

Parameters

name (str) – The name to use.

_plot_lines(x_coordinates, y_coordinates)[source]

Perform the actual plot for spectrum and integral(s).

Draw the spectrum curve and the zero line (if necessary). Additionally draw one or both integral curves. Either one of the integral curves can be omitted but NOT BOTH.

Parameters
  • x_coordinates (list) – x values for plotting

  • y_coordinates (list) – y values for plotting

Raises

NoIntegralDataProvidedError – Raised when data for both integrations is omitted.

class cwepr.plotting.Multiplotter(datasets, integrals=None)[source]

Bases: aspecd.plotting.MultiPlotter

Plotter used for plotting multiple spectra at the same time.

datasets

List of datasets to plot.

Type

list

integrals

List of the numeric of the integrals to be indicated in the legend. Can be omitted.

Type

list

_set_defaults()[source]

Create default values for all settings of the plot.

set_curve_names(names)[source]

Sets the names for the different curves.

Parameters

names (list) – List of ‘str’ containing the names.

set_curve_colors(colors)[source]

Sets the colors for the different curves.

Parameters

colors (list) – List of ‘str’ and or RGBA containing the colors.

set_title(title)[source]

Sets the title of the plot.

Parameters

title (str) – The title to use.

set_x_axis_name(name)[source]

Sets the label of the x axis.

Parameters

name (str) – The name to use.

set_y_axis_name(name)[source]

Sets the label of the y axis.

Parameters

name (str) – The name to use.

set_draw_zeroline(do_draw)[source]

Set whether the zero line should be drawn.

Parameters

do_draw (bool) – Should the zero line be drawn?

set_zeroline_thickness(thickness)[source]

Sets thickness of the zero line.

Parameters

thickness (float) – Thickness of the zero line; default: 0.5

set_zeroline_color(color)[source]

Sets the color of the zero line.

Parameters

color (str or RGBA tuple) – The color to use.

set_fit_axis_to_spectrum(do_fit)[source]

Whether the x axis limits should be adapted to spectrum width.

Parameters

do_fit (bool) – Should the width of the plot fit the width of the curve?

set_show_integrals(do_show)[source]

Whether the integrals should be shown in the legend if provided.

Parameters

do_show (bool) – Should the integrals be indicated?

_create_plot()[source]

Draw and display the plot.

static get_x_axis_limits(x_axes)[source]

Get reasonable limits for the x axis.

Determined the x axis limits using the lowest starting point and highest end point.

_make_labels()[source]

Create the title as well as the labels for the axes.

_plot_lines(x_coordinates, y_coordinates, curve_index)[source]

Draw the spectrum curve.

Parameters
  • x_coordinates (list) – x values for plotting

  • y_coordinates (list) – y values for plotting

_make_axis_limits(x_coordinates)[source]

Set the limits of the x axis.

Parameters

x_coordinates (list) – x values to plot. These are necessary for determining the correct limits.

class cwepr.plotting.PlotSaver(filename=None)[source]

Bases: aspecd.plotting.Saver

Saver used to save an image of a given plot.

set_format(data_format)[source]

Sets the data format to save to (Default: .png).

Parameters

data_format (str) – File extension

set_res(res)[source]

Sets the resolution for the saved image (Default: 300 dpi).

Parameters

res (int) – Resolution (dpi)

set_defaults()[source]

Sets the default values for data format and resolution.

_save_plot()[source]

Perform the actual saving of the plot.

Uses the resolution (in dpi) specified in parameters/size.

cwepr.processing module

Module containing all processing steps.

A processing step is anything that modifies the dataset without giving an independent result. E.g., Field Correction or Baseline correction.

class cwepr.processing.FieldCorrection(correction_value=0)[source]

Bases: aspecd.processing.ProcessingStep

Processing step for field correction.

Perform a linear field correction of the data with a correction value previously determined.

Parameters

correction_value (float) – The previously determined correction value.

_perform_task()[source]

Shift all field axis data points by the correction value.

class cwepr.processing.FrequencyCorrection(nu_given, nu_target)[source]

Bases: aspecd.processing.ProcessingStep

Convert data of a given frequency to another given frequency.

This is used to make spectra comparable.

References for the constants:

g value for Li:LiF:

g(LiLiF) = 2.002293 +- 0.000002

Reference: Rev. Sci. Instrum. 1989, 60, 2949-2952.

Bohr magneton:

mu_B = 9.27401*10**(-24)

Reference: Rev. Mod. Phys. 2016, 88, 035009.

Planck constant:

h = 6.62607*10**(-34)

Reference: Rev. Mod. Phys. 2016, 88, 035009.

nu_given

Given frequency of the data present.

Type

float

nu_target

Frequency that the data should be converted to.

Type

float

VALUE_G_LILIF = 2.002293
VALUE_MuB = 9.27401e-24
VALUE_H = 6.62607e-34
_perform_task()[source]

Perform the actual transformation / correction.

For the conversion the x axis data is first converted to an axis in units of using the given frequency, then converted back using target frequency.

_transform_to_g(value)[source]

Transform a field (B) axis value to a g axis value.

Parameters
  • value (float) –

  • value to transform. (B) –

Returns

  • g_value (float)

  • Transformed value.

_transform_to_b(value)[source]

Transform a g axis value to a field (B) axis value.

Parameters
  • value (float) –

  • value to transform. (g) –

Returns

  • b_value (float)

  • Transformed value.

class cwepr.processing.BaselineCorrection(coefficients)[source]

Bases: aspecd.processing.ProcessingStep

Perform a baseline correction using a polynomial previously determined.

coefficients

List of the polynomial coefficients of the polynomial to subtract.

Type

list

_perform_task()[source]

Perform the actual correction.

Baseline correction is performed by subtraction of a previously determined polynomial.

class cwepr.processing.BaselineCorrectionWithCalculatedDataset(baseline_dataset=None)[source]

Bases: aspecd.processing.ProcessingStep

Perform a baseline correction using a polynomial previously determined.

baseline_dataset

Dataset containing the baseline to subtract.

Type

cwepr.dataset.Dataset

_perform_task()[source]

Perform the actual correction.

Baseline correction is performed by subtraction of a previously determined polynomial.

class cwepr.processing.SubtractSpectrum(second_dataset)[source]

Bases: aspecd.processing.ProcessingStep

Subtract one spectrum from another.

Processing routine to subtract a given spectrum, i.e. in general a background, from the processed spectrum

second_dataset

Dataset containing the spectrum that should be subtracted.

Type

cwepr.dataset.Dataset

_perform_task()[source]

Wrapper around the _subtract() method.

interpolate()[source]

Perform a potentially necessary interpolation.

Interpolates the spectrum that should be subtracted from the other one on the x values of this other spectrum.

_subtract()[source]

Perform the actual subtraction.

The actual subtraction. The second spectrum (the one gets subtracted is first interpolated on the x values of the other one.

class cwepr.processing.AddSpectrum(second_dataset)[source]

Bases: aspecd.processing.ProcessingStep

Add one spectrum to another.

second_dataset

Dataset containing the spectrum that should be added.

Type

cwepr.dataset.Dataset

_perform_task()[source]

Wrapper around the _add() method.

interpolate()[source]

Perform a potentially necessary interpolation.

Interpolates the spectrum that should be added to the other one on the x values of this other spectrum.

_add()[source]

Perform the actual subtraction.

The actual subtraction. The second spectrum (the one gets subtracted) is first interpolated on the x values of the other one.

class cwepr.processing.PhaseCorrection[source]

Bases: aspecd.processing.ProcessingStep

Processing step for phase correction.

The functionality is suitable for automatic phase correction, no parameters need to be provided manually.

_perform_task()[source]

Perform the actual phase correction.

The phase angle is acquired from the dataset’s metadata and transformed to radians if necessary. The phase correction is then applied and the corrected data inserted into the dataset.

class cwepr.processing.NormaliseMaximum[source]

Bases: aspecd.processing.ProcessingStep

Normalise a spectrum concerning the height of the maximum.

Should only be used on an integrated spectrum.

_perform_task()[source]

Perform the actual processing step on the dataset.

The implementation of the actual processing goes in here in all classes inheriting from ProcessingStep. This method is automatically called by self.processing() after some background checks.

class cwepr.processing.NormaliseArea(integral)[source]

Bases: aspecd.processing.ProcessingStep

Normalise a spectrum concerning the area under the curve.

Should only be used on an integrated spectrum.

Parameters

integral (float) – Area under the curve.

_perform_task()[source]

Perform the actual processing step on the dataset.

The implementation of the actual processing goes in here in all classes inheriting from ProcessingStep. This method is automatically called by self.processing() after some background checks.

class cwepr.processing.NormaliseScanNumber[source]

Bases: aspecd.processing.ProcessingStep

Normalise a spectrum concerning the number of scans used.

This is necessary to make spectra where the intensity of different scans is added comparable to ones where it is averaged.

_perform_task()[source]

Perform the actual processing step on the dataset.

The implementation of the actual processing goes in here in all classes inheriting from ProcessingStep. This method is automatically called by self.processing() after some background checks.

class cwepr.processing.IntegrationIndefinite[source]

Bases: aspecd.processing.ProcessingStep

Perform an indefinite integration.

Indefinite integration means integration yielding a integral function.

_perform_task()[source]

Perform the actual integration.

Perform the actual integration using trapezoidal integration functionality from scipy. The keyword argument initial=0 is used to yield a list of length identical to the original one.

Module contents

Package for reproducible evaluation of cwepr data.