Core
SpinData object for storing N-dimensional data with coordinates
- class spinlab.core.data.SpinData(values=array([], dtype=float64), dims=[], coords=[], attrs={}, spinlab_attrs={'attenuation': 25, 'center_field': 3435.0, 'data_format': 'XEPR', 'data_type': 'EPR', 'frequency': 9625482000.0, 'power': 0.4743, 'pulse_attenuation': 0, 'scans': 1}, proc_attrs=None, **kwargs)
Bases:
ABCDataSpinData Class for handling spinlab data
The SpinData class is inspired by pyspecdata nddata object which handles n-dimensional data, axes, and other relevant information together.
This class is designed to handle data and axes together so that performing NMR processing can be performed easily.
- values
Numpy Array containing data
- Type:
numpy.ndarray
- coords
List of numpy arrays containing axes of data
- Type:
list
- dims
List of axes labels for data
- Type:
list
- attrs
Dictionary of parameters for data
- Type:
dict
- add_proc_attrs(proc_attr_name, proc_dict)
Stamp processing step to SpinData object
- Parameters:
proc_attr_name (str) -- Name of processing step (e.g. "fourier_transform")
proc_dict (dict) -- Dictionary of processing parameters for this processing step.
- exp_info()
Print experiment attributes currently in attrs dictionary
- phase()
Return phase of SpinData object
- Returns:
- phase of data calculated from sum of imaginary
divided by sum of real components
- Return type:
phase (float,int)
- proc_info(step_name=None)
Print processing steps and parameters currently in proc_attrs list
- select(selection)
Select subset of 2D data object
- Parameters:
selection (int, range, list, tuple) -- list or tuple of slices to keep
- Returns:
subset of SpinData object
- Return type:
SpinData object
Examples
data.select((1, range(5,10), 15)) # keeps slices: 1, 5, 6, 7, 8, 9, and 15
- show_attrs(show_exp_info=False, show_spinlab_info=True, show_proc_info=True)
Print experiment attributes, spinlab attributes and processing steps
- spinlab_info()
Print parameters currently in used in spinlab
- squeeze()
Remove all length 1 dimensions from data
Warning
Axes information is lost
Examples
data.squeeze()
- class spinlab.core.base.ABCData(values=array([], dtype=float64), dims=[], coords=[], attrs={}, sl_attrs={}, error=None, **kwargs)
Bases:
objectN-Dimensional Data Object
- values
Data values in
- Type:
numpy.ndarray
- dims
List of strings giving dimension labels
- Type:
list
- coords
Collection of numpy.ndarrays defining the axes
- Type:
Coords
- attrs
dictionary of parameters
- Type:
dict
- error
If not None, error for values which are propagated during mathematical operations
- Type:
numpy.ndarray
- proc_attrs
List of processing steps
- Type:
list
- align(b)
Align two data objects for numerical operations
- Parameters:
b -- Object to align with self
- Returns:
self and b aligned data objects
- Return type:
tuple
- argmax(dim)
Return value of coord at values maximum for given dim
- Parameters:
dim (str) -- Dimension to perform operation along
- argmax_index(dim)
Return index of coord at values maximum for given dim
- Parameters:
dim (str) -- Dimension to perform operation along
- argmin(dim)
Return value of coord at values minimum for given dim
- Parameters:
dim (str) -- Dimension to perform operation along
- argmin_index(dim)
Return index of coord at values minimum for given dim
- Parameters:
dim (str) -- Dimension to perform operation along
- chunk(dim, new_dims, new_sizes)
Note
This is a placeholder for a function that's not yet implemented
- Parameters:
dim (str) -- Assume that the dimension dim is a direct product of the dimensions given in new_dims, and chunk it out into those new dimensions.
new_dims (list of str) --
The new dimensions to generate. Note that one of the elements of the list can be dim if you like.
It's assumed that the ordering of dim is a direct product given in C-ordering (i.e. the inner dimensions are listed last and the outer dimensions are listed first -- here "inner" means that changes to the index of the inner-most dimension correspond to adjacent positions in memory and/or adjacent indeces in the original dimension that you are chunking)
new_sizes (list of int) -- sizes of the new dimensions`
- Returns:
self -- The new nddata object. Note that uniformly ascending or descending coordinates are manipulated in a rational way, e.g. [1,2,3,4,5,6] when chunked to a size of [2,3] will yield coordinates for the two new dimensions: [1,4] and [0,1,2]. Coordinates that are not uniformly ascending or descending will yield and error and must be manually modified by the user.
- Return type:
nddata_core
- concatenate(b, dim)
Concatenate SpinData objects
- Parameters:
b (SpinData) -- Data object to append to current data object
dim (str) -- dimension to concatenate along
- copy()
Return deepcopy of sldata object
- Returns:
deep copy of data object
- cumulative_sum(dim)
Calculate Cumulative sum of sldata object
- Returns:
cumulative sum of data object
- property dtype
Values type
- Type:
type
- fold()
Fold 2d data to original ND shape
- get_coord(dim)
Return coord corresponding to given dimension name
- Parameters:
dim (str) -- Name of dim to retrieve coordinates from
- Returns:
array of coordinates
- Return type:
numpy.ndarray
- index(dim)
Find index of given dimension name
- Parameters:
dim (str) -- Name of dimension to index
- Returns:
Index value of dim
- Return type:
int
- is_sorted(dim)
Determine if coords corresponding to give dim are sorted in ascending order :param dim: Dimension to check if sorted :type dim: str
- Returns:
True if sorted, False otherwise.
- Return type:
bool
- maximum(dim)
Return max for given dim
- Parameters:
dim (str) -- Dimension to take maximum along
- merge_attrs(b)
Merge the given dictionaries
- Parameters:
b (nddata_core) -- attributes to merge into object
- minimum(dim)
Return min for given dim
- Parameters:
dim (str) -- Dimension to perform operation along
- property ndim
Number of dimensions
- Type:
str
- new_dim(dim, coord)
Add new dimension with length 1
- Parameters:
dim (str) -- Name of new dimension
coord (int, float) -- New coord
- rename(dim, new_name)
Rename dim
- Parameters:
dim (str) -- Name of dimension to rename
new_name (str) -- New name for dim
- reorder(dims)
Reorder dimensions
- Parameters:
dims (list) -- List of strings in new order
- property shape
Shape of values
- Type:
tuple
- property size
Returns values.size. Total number of elements in numpy array.
- smoosh(old_dims, new_name)
Note
Not yet implemented.
smoosh does the opposite of chunk -- see :func`:~nddata_core.chunk`
- sort(dim)
Sort the coords corresponding to the given dim in ascending order
- Parameters:
dim (str) -- dimension to sort
- sort_dims()
Sort the dimensions
- split(dim, new_dim, coord)
Split the dimension dim into
- squeeze(dim)
Remove length 1 axes
- sum(dim)
Perform sum down given dimension
- Parameters:
dim (str) -- Dimension to perform sum down
- unfold(dim)
Unfold ND data to 2d data
- Parameters:
dim (str) -- Dimension to make first (length N), all other dimensions unfolded so that values has shape (N x M)
- spinlab.core.util.concat(data_list, dim, coord=None, casting='same_kind')
Concatenates list of data objects down another dimension
- Parameters:
data_list (list) -- List of SpinData objects to concatenate
dim (str) -- new dimension name
coord -- coords for new dimension
- Returns:
concatenated data object
- Return type:
data (SpinData)
- spinlab.core.util.get_slice(data, dim, slice_index)
Get data slice of SpinData object
- spinlab.core.util.implements_np(np_function)
register a numpy function for special handling in SPECIAL_NP_HANDLED
- spinlab.core.util.update_axis(data, start_stop, dim=0, new_dims=0, spacing='lin', verbose=False)
Update axis
Update dimensions (dims) and axis (coords) of a slData object. The name of the dims will be replaced with the name giving in new_dims. The variable start_stop defines the values of the new coords. This can be either a tuple (start values, stop value) or a vector with values. If the start and stop value is provided, either a linear axis (spacing = "lin", default) or a logarithmically space (spacing = "log") will be created. The new axis will replace the coords in the sldata object.
The function is currently implemented for 1D objects only.
- Parameters:
data (SpinData) -- slData object
start_stop (tuple or vector) -- Coords for new dimension
dim (int) -- Dimension to act on
new_dims (str) -- Name of the new dimension. If None the name will not be changed.
spacing (str) -- "lin" for linear spaced axis or "log" for logarithmically spaced axis
- Returns:
concatenated data object
- Return type:
data (SpinData)
- spinlab.core.ufunc.generate_data(shape)
Generate a SpinData object filled with random normal values.
- Parameters:
shape (tuple) -- Shape of the output array. Each element defines the length of one dimension. Dimensions are labeled
x0,x1, etc.- Returns:
Data object with random values and integer coordinates.
- Return type: