Stoner.Data

class Stoner.Data(*args, **kwargs)[source]

Base class object that represents a matrix of data, associated metadata and column headers.

column_headers

list of strings of the column names of the data.

Type:

list

data

The attribute that stores the nuermical data for each Data. This is a DataArray instance - which is itself a subclass of numpy.ma.MaskedArray.

Type:

2D numpy masked array

title

The title of the measurement.

Type:

string

filename

The current filename of the data if loaded from or already saved to disc. This is the default filename used by the Stoner.Core.Data.load() and Stoner.Core.Data.save().

Type:

string

header

A readonly property that returns a pretty formatted string giving the header of tabular representation.

Type:

string

mask

Returns the current mask applied to the numerical data equivalent to self.data.mask.

Type:

array of booleans

mime_type

The possible mime-types of data files represented by each matching filename pattern in Datafile.pattern.

Type:

list of str

patterns

A list of filename extension glob patterns that matrches the expected filename patterns for a Data (*.txt and *.dat”)

Type:

list

priority

Used to indicathe order in which subclasses of Data are tried when loading data. A higher number means a lower priority (!)

Type:

int

setas

Defines certain columns to contain X, Y, Z or errors in X,Y,Z data.

Type:

_stas

shape

Returns the shape of the data (rows,columns) - equivalent to self.data.shape.

Type:

tuple of integers

records

Returns the data in the form of a list of yuples where each tuple maps to the columns names.

Type:

numpy record array

clone

Creates a deep copy of the :py:class`Data` object.

Type:

Data

dict_records

View the data as an array or dictionaries where each dictionary represents one row with keys derived from column headers.

Type:

array of dictionaries

dims

When data columns are set as x,y,z etc. returns the number of dimensions implied in the data set

Type:

int

dtype

Returns the datatype stored in the Data.data attribute.

Type:

numpoy dtype

T

Transposed version of the data.

Type:

DataArray

subclasses

Returns a list of all the subclasses of Data currently in memory, sorted by their py:attr:Stoner.Core.Data.priority. Each entry in the list consists of the string name of the subclass and the class object.

Type:

list

xcol

If a column has been designated as containing x values, this will return the index of that column

Type:

int

xerr

Similarly to Data.xcol but for the x-error value column.

Type:

int

ycol

Similarly to Data.xcol but for the y value columns.

Type:

list of int

yerr

Similarly to Data.xcol but for the y error value columns.

Type:

list of int

zcol

Similarly to Data.xcol but for the z value columns.

Type:

list of int

zerr

Similarly to Data.xcol but for the z error value columns.

Type:

list of int

ucol

Similarly to Data.xcol but for the u (x-axis direction cosine) columns.

Type:

list of int

vcol

Similarly to Data.xcol but for the v (y-axis direction cosine) columns.

Type:

list of int

wcol

Similarly to Data.xcol but for the w (z-axis direction cosine) columns.

Type:

list of int

Methods

SG_Filter([col, xcol, points, poly, order, ...])

Implement a Savitsky-Golay filtering of data for smoothing and differentiating data.

__init__(*args, **kwargs)

Initialise the Data from arrays, dictionaries and filenames.

add(col_a, col_b[, replace, header, index])

Add one column, number or array (col_b) to another column (col_a).

add_column(column_data[, header, index, ...])

Append a column of data or inserts a column to a datafile instance.

annotate_fit(model[, x, y, z, text_only, mode])

Annotate a plot with some information about a fit.

append(value)

S.append(value) -- append value to the end of the sequence

apply(func[, col, replace, header])

Apply the given function to each row in the data set and adds to the data set.

asarray()

Provide a consistent way to get at the underlying array data.

bin([xcol, ycol, bins, mode, clone, yerr])

Bin x-y data into new values of x with an error bar.

clear()

clip(clipper[, column])

Clips the data based on the column and the clipper value.

closest(value[, xcol])

Return the row in a data file which has an x-column value closest to the given value.

colormap_xyz([xcol, ycol, zcol])

Make a xyz plot that forces the use of plt.colormap.

column(col)

Extract one or more columns of data from the datafile.

columns([not_masked, reset])

Iterate over the columns of data int he datafile.

contour_xyz([xcol, ycol, zcol, shape, xlim, ...])

Make a xyz plot that forces the use of plt.contour.

count([value, axis, col])

Count the number of un-masked elements in the DataFile.

curve_fit(func[, xcol, ycol, sigma])

General curve fitting function passed through from scipy.

decompose([xcol, ycol, sym, asym, replace, ...])

Given (x,y) data, decomposes the y part into symmetric and antisymmetric contributions in x.

deduplicate(col[, action, clone])

Remove rows with duplicated values in the given column.

del_column([col, duplicates])

Delete a column from the current DataFile object.

del_nan([col, clone])

Remove rows that have nan in them.

del_rows([col, val, invert])

Search in the numerica data for the lines that match and deletes the corresponding rows.

differential_evolution(model[, xcol, ycol, ...])

Fit model to the data using a differential evolution algorithm.

diffsum(col_a, col_b[, replace, header, index])

Calculate \(\frac{a-b}{a+b}\) for the two columns a and b.

dir([pattern])

Return a list of keys in the metadata, filtering with a regular expression if necessary.

divide(col_a, col_b[, replace, header, index])

Divide one column (col_a) by another column, number or array (col_b).

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

extrapolate(new_x[, xcol, ycol, yerr, ...])

Extrapolate data based on local fit to x,y data.

figure([figure, projection])

Set the figure used by Stoner.plot.PlotMixin.

filter([func, cols, reset])

Set the mask on rows of data by evaluating a function for each row.

find_col(col[, force_list])

Indexes the column headers in order to locate a column of data.shape.

find_duplicates([xcol, delta])

Find rows with duplicated values of the search column(s).

find_peaks(**kwargs)

Interface to scipy.signal.find_peaks() for locating peaks in data.

format(key[, mode, units, prefix, latex, ...])

Return the contents of key pretty formatted using format_error().

get(k[,d])

get_filename(mode)

Force the user to choose a new filename using a system dialog box.

griddata([xcol, ycol, zcol, ucol, shape, ...])

Convert xyz data onto a regular grid.

image_plot([xcol, ycol, zcol, shape, xlim, ylim])

Grid up the three columns of data and plot.

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert(index, obj)

Implement the insert method.

insert_rows(row, new_data)

Insert new_data into the data array at position row.

inset([parent, loc, width, height])

Add a new set of axes as an inset to the current plot.

integrate([xcol, ycol, result, header, ...])

Integrate a column of data, optionally returning the cumulative integral.

interpolate(newX[, kind, xcol, replace])

Interpolate a dataset to get a new set of values for a given set of x data.

items()

Make sure we implement an items that doesn't just iterate over self.

keys()

Return the keys of the metadata dictionary.

legend(*args, **kwargs)

Pass Through to stop attribute access over-riding a handy method.

lmfit(model[, xcol, ycol, p0, sigma])

Wrap the lmfit module fitting.

load(*args, **kwargs)

Create a new Data from a file on disc guessing a better subclass if necessary.

make_bins(xcol, bins[, mode, bin_start, ...])

Generate bin boundaries and centres along an axis.

max([column, bounds])

Find maximum value and index in col_a column of data.

mean([column, sigma, bounds])

Find mean value of col_a data column.

min([column, bounds])

Find minimum value and index in col_a column of data.

multiply(col_a, col_b[, replace, header, index])

Multiply one column (col_a) by another column, number or array (col_b).

normalise([target, base, replace, header, ...])

Normalise data columns by dividing through by a base column value.

odr(model[, xcol, ycol])

Wrap the scipy.odr orthogonal distance regression fitting.

outlier_detection([column, window, shape, ...])

Detect outliers in a column of data.

peaks(**kwargs)

Locates peaks and/or troughs in a column of data by using SG-differentiation.

plot(*args, **kwargs)

Try to make an appropriate plot based on the defined column assignments.

plot_matrix([xvals, yvals, rectang, cmap, ...])

Plot a surface plot by assuming that the current dataset represents a regular matrix of points.

plot_voxels([xcol, ycol, zcol, ucol, cmap])

Make a volumetric plot of data arranged as x,y,z,u.

plot_xy([xcol, ycol, fmt, xerr, yerr])

Makesa simple X-Y plot of the specified data.

plot_xyuv([xcol, ycol, ucol, vcol, wcol])

Make an overlaid image and quiver plot.

plot_xyuvw([xcol, ycol, ucol, vcol, wcol])

Make an overlaid image and quiver plot.

plot_xyz([xcol, ycol, zcol, shape, xlim, ...])

Plot a surface plot based on rows of X,Y,Z data using matplotlib.pcolor().

plot_xyzuvw([xcol, ycol, zcol, ucol, vcol, wcol])

Plot a vector field plot based on rows of X,Y,Z (U,V,W) data using ,ayavi.

polyfit([xcol, ycol, polynomial_order, ...])

Pass through to numpy.polyfit.

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

quiver_plot([xcol, ycol, ucol, vcol])

Make a 2D Quiver plot from the data.

remove(value)

S.remove(value) -- remove first occurrence of value.

remove_duplicates([xcol, delta, strategy, ...])

Find and remove rows with duplicated values of the search column(s).

rename(old_col, new_col)

Rename columns without changing the underlying data.

reorder_columns(cols[, headers_too, setas_too])

Construct a new data array from the original data by assembling the columns in the order given.

reverse()

S.reverse() -- reverse IN PLACE

rolling_window([window, wrap, exclude_centre])

Iterate with a rolling window section of the data.

rows([not_masked, reset])

Iterate over rows of data.

save([filename, as_loaded, filetype])

Save a string representation of the current self object into the file 'filename'.

scale(other[, xcol, ycol, xmode, ymode, ...])

Scale the x and y data in this DataFile to match the x and y data in another DataFile.

search([xcol, value, columns, accuracy])

Search the numerica data part of the file for lines that match and returns the corresponding rows.

search_index([xcol, value, accuracy, invert])

Return an array of booleans for indexing matching rows for use with search method.

section([x, y, z, r, accuracy])

Assuming data has x,y or x,y,z coordinates, return data from a section of the parameter space.

select(*args, **kwargs)

Produce a copy of the DataFile with only data rows that match a criteria.

setdefault(k[,d])

smooth([window, xcol, ycol, size, replace, ...])

Smooth data by convoluting with a window.

sort(*order[, reverse])

Sort the data by column name.

span([column, bounds])

Return a tuple of the maximum and minimum values within the given column and bounds.

spline([xcol, ycol, sigma, replace, result, ...])

Construct a spline through x and y data and replace, add new data or return spline function.

split(*args[, final])

Recursively splits the current DataFile into a Stoner.Folders.DataFolder.

std([column, sigma, bounds])

Find standard deviation value of col_a data column.

stitch(other[, xcol, ycol, overlap, ...])

Apply a scaling to this data set to make it stich to another dataset.

subplot(*args, **kwargs)

Pass throuygh for matplotlib.pyplot.subplot().

subplot2grid(*args, **kwargs)

Provide a pass through to matplotlib.pyplot.subplot2grid().

subtract(col_a, col_b[, replace, header, index])

Subtract one column, number or array (col_b) from another column (col_a).

swap_column(*swp[, headers_too])

Swap pairs of columns in the data.

threshold(threshold[, col, rising, falling, ...])

Find partial indices where the data in column passes the threshold, rising or falling.

to_hdf([filename])

Write the current object into an hdf5 file or group within a file.

to_pandas()

Create a pandas DataFrame from a Stoner.Data object.

unique(col[, return_index, return_inverse])

Return the unique values from the specified column - pass through for numpy.unique.

update([E, ]**F)

If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values()

Return the values of the metadata dictionary.

x2()

Generate a new set of axes with a second x-scale.

y2()

Generate a new set of axes with a second y-scale.

Attributes

T

Get the current data transposed.

ax

Return the current axis number.

axes

Return the current axes object.

basename

Return the basename of the current filename.

clone

Get a deep copy of the current DataFile.

cmap

Get the current cmap.

column_headers

Pass through to the setas attribute.

data

Property Accessors for the main numerical data.

dict_records

Return the data as a dictionary of single columns with column headers for the keys.

dims

Alias for self.data.axes.

dtype

Return the np dtype attribute of the data.

fig

Get the current figure.

fignum

Return the current figure number.

filename

Return DataFile filename, or make one up.

filepath

Return DataFile filename, or make one up, returning as a pathlib.Path.

header

Make a pretty header string that looks like the tabular representation.

labels

Return the labels for the plot columns.

mask

Return the mask of the data array.

metadata

Read the metadata dictionary.

mime_type

multiple

no_fmt

positional_fmt

priority

records

Return the data as a np structured data array.

setas

Get the list of column assignments.

shape

Pass through the numpy shape attribute of the data.

showfig

Return either the current figure or self or None.

subplots

Return the subplot instances.

template

Return the current plot template.