Stoner.Core.DataFile

class Stoner.Core.DataFile(*args)[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 DataFile. 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.DataFile.load() and Stoner.Core.DataFile.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 extenion glob patterns that matrches the expected filename patterns for a DataFile (*.txt and *.dat”)

Type

list

priority

Used to indicathe order in which subclasses of DataFile 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 columsn names.

Type

numpy record array

clone

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

Type

DataFile

dict_records

View the data as an array or dictionaries where each dictionary represnets one row with keys dervied 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 DataFile.data attribute.

Type

numpoy dtype

T

Transposed version of the data.

Type

DataArray

subclasses

Returns a list of all the subclasses of DataFile currently in memory, sorted by their py:attr:Stoner.Core.DataFile.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 DataFile.xcol but for the x-error value column.

Type

int

ycol

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

Type

list of int

yerr

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

Type

list of int

zcol

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

Type

list of int

zerr

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

Type

list of int

ucol

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

Type

list of int

vcol

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

Type

list of int

wcol

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

Type

list of int

Methods

__init__(*args, **kargs)

Initialise the DataFile from arrays, dictionaries and filenames.

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

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

append(value)

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

asarray()

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

clear()

closest(value[, xcol])

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

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.

count([value, axis, col])

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

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.

dir([pattern])

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

extend(values)

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

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).

get(k[,d])

get_filename(mode)

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

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.

items()

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

keys()

Return the keys of the metadata dictionary.

load(*args, **kargs)

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

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.

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])

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

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

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

section(**kargs)

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

select(*args, **kargs)

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

setdefault(k[,d])

sort(*order, **kargs)

Sort the data by column name.

split(*args[, final])

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

swap_column(*swp, **kargs)

Swap pairs of columns in the data.

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: 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.

Attributes

T

Get the current data transposed.

basename

Return the basename of the current filename.

clone

Get a deep copy of the current DataFile.

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.

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.

mask

Return the mask of the data array.

metadata

Read the metadata dictionary.

mime_type

patterns

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.