Table#

class ubermagtable.Table(data, units, x=None, attributes=None)#

Tabular data class.

This class builds some functionality around pandas.DataFrame to make it convenient for the analysis and visualisation of time-dependent scalar data. It takes pandas.DataFrame and a units dictionary as input arguments. However, its recommended usage is via ubermagtable.Table.fromfile class method which takes an OOMMF .odt or a mumax3 .txt file and converts it to pandas.DataFrame.

pandas.DataFrame object can be exposed using data argument. Dictionary mapping units to columns is stored in units attribute.

Parameters:
  • data (pandas.DataFrame) – DataFrame with scalar data.

  • units (dict) – Dictionary mapping units to columns.

  • x (str, optional) – Independent variable column name. Defaults to None.

Examples

  1. Defining ubermagtable.Table by reading an OOMMF .odt file.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample', 'oommf-new-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='iteration')

Methods

__dir__

Default dir() implementation.

__eq__

Return self==value.

__lshift__

Merges two tables into a single one.

__repr__

Representation string.

apply

Apply function.

fromfile

Reads an OOMMF .odt or mumax3 .txt scalar data file and returns a ubermagtable.Table object.

irfft

Inverse Real Fast Fourier Transform.

mpl

Table data plot.

rfft

Real Fast Fourier Transform.

selector

Selection list for interactive plotting.

slider

Slider for interactive plotting.

Properties

data

Descriptor allowing setting attributes only with values of a certain type.

dx

Spacing of independent variable.

units

Descriptor allowing setting attributes only with values of a certain type.

x

Independent variable.

xmax

Maximum value of independent variable.

y

Dependent variable(s).


__lshift__(other)#

Merges two tables into a single one.

Tables are merged in such a way that the second operand’s data is concatenated to the first operand’s data. Because independent variable is unique and always successive, the xmax of the first operand is added to the independent variable of the second. If there is no independent variable column in second operand’s table, no merging is allowed and ValueError is raised. If there are non-matching columns, the missing values will be NaN.

Merging is not supported for Fourier transformed tables.

Parameters:

other (ubermagtable.Table) – Second operand.

Returns:

Merged table.

Return type:

ubermagtable.Table

Raises:

ValueError – If second operand’s table does not have independent variable column.

Examples

  1. Merging two tables.

>>> import os
>>> import ubermagtable as ut
...
>>> dirname = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample')
>>> odtfile1 = os.path.join(dirname, 'oommf-old-file1.odt')
>>> odtfile2 = os.path.join(dirname, 'oommf-old-file2.odt')
...
>>> table1 = ut.Table.fromfile(odtfile1, x='t')
>>> table2 = ut.Table.fromfile(odtfile2, x='t')
>>> merged_table = table1 << table2
...
>>> table1.xmax / 1e-12  # in picoseconds
24.999...
>>> table2.xmax / 1e-12  # in picoseconds
15.0
>>> merged_table.xmax / 1e-12  # in picoseconds
39.99...
__repr__()#

Representation string.

Returns:

Representation string.

Return type:

str

Example

  1. Getting representation string.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file3.odt')
>>> table = ut.Table.fromfile(odtfile, x='iteration')
>>> repr(table)
'...
apply(func, columns=None, args=(), **kwargs)#

Apply function.

apply takes a function and its arguments along with a list of columns that the function should be applied to. It uses the fuction on all of the values in the chosen columns and returns an ubermagtable.Table object. This function is based off of pandas.DataFrame.apply.

If columns is not specified, by default the function will be applied to all dependent variable columns i.e. Table.y.

Parameters:
  • func (function) – Function to apply to selected columns.

  • columns (list, optional) – A list of variables to be plotted. Defaults to None.

  • args (turple) – Positional arguments to pass to func in addition to the data.

  • **kwargs – Additional keyword arguments to pass as keywords arguments to func.

Returns:

Result of applying func to selected columns in the table.

Return type:

ubermagtable.Table

Examples

  1. Applying absolute function to data.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> new_table = table.apply(np.abs)
...
classmethod fromfile(filename, /, x=None, rename=True)#

Reads an OOMMF .odt or mumax3 .txt scalar data file and returns a ubermagtable.Table object.

Parameters:
  • filename (str) – OOMMF .odt or mumax3 .txt file.

  • x (str, optional) – Independent variable name. Defaults to None.

  • rename (bool, optional) – If rename=True, the column names are renamed with their shorter versions. Defaults to True.

Returns:

Table object.

Return type:

ubermagtable.Table

Examples

  1. Defining ubermagtable.Table by reading an OOMMF .odt file.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-hysteresis1.odt')
>>> table = ut.Table.fromfile(odtfile, x='B_hysteresis')
  1. Defining ubermagtable.Table by reading a mumax3 .txt file.

>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample', 'mumax3-file1.txt')
>>> table = ut.Table.fromfile(odtfile, x='t')
irfft(x=None, y=None)#

Inverse Real Fast Fourier Transform.

The inverse real fast Fourier transform of columns y with frequency dependent on x.

Parameters:
  • x (str, optional) – The independent variable to be inverse Fourier transformed. If not specified table.x is used. Defaults to None.

  • y (list, optional) – A list of dependent variables to be inverse Fourier transformed. If not specified all columns in table.y are Fourier transformed. Defaults to None.

Returns:

Result of applying a inverse real Fourier transform to selected columns in the table.

Return type:

ubermagtable.Table

Examples

  1. Applying inverse Fourier transforms to the table.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-new-file5.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> ifft_table = table.rfft().irfft()
...
mpl(ax=None, figsize=None, x=None, y=None, xlim=None, multiplier=None, filename=None, **kwargs)#

Table data plot.

This method plots scalar values as a function of x. If x is not passed, self.x is used. mpl adds the plot to matplotlib.axes.Axes passed via ax argument. If ax is not passed, matplotlib.axes.Axes object is created automatically and the size of a figure can be specified using figsize. To choose particular data columns to be plotted y can be passed as a list of column names. The range of x values on the horizontal axis can be defined by passing a length-2 tuple using xlim.

It is often the case that the time length is small (e.g. on a nanosecond scale). Accordingly, multiplier can be passed as \(10^{n}\), where \(n\) is a multiple of 3 (…, -6, -3, 0, 3, 6,…). According to that value, the horizontal axis will be scaled and appropriate units shown. For instance, if multiplier=1e-9 is passed, the horizontal axis will be divided by \(1\,\text{ns}\) and \(\text{ns}\) units will be used as axis labels. If multiplier is not passed, the best one is calculated internally. The plot can be saved as a PDF when filename is passed. This method plots the data using matplotlib.pyplot.plot() function, so any keyword arguments accepted by it can be passed.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to which the field plot is added. Defaults to None - axes are created internally.

  • figsize (tuple, optional) – The size of a created figure if ax is not passed. Defaults to None.

  • x (str, optional) – Independent variable. Defaults to None.

  • y (list, optional) – A list of variables to be plotted. Defaults to None.

  • xlim (tuple) – A length-2 tuple setting the limits of the horizontal axis.

  • multiplier (numbers.Real, optional) – Time axis multiplier.

  • filename (str, optional) – If filename is passed, the plot is saved. Defaults to None.

Examples

  1. Visualising time-dependent data.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> table.mpl()
rfft(x=None, y=None)#

Real Fast Fourier Transform.

The real fast Fourier transform of columns y with frequency dependent on x.

Parameters:
  • x (str, optional) – The independent variable to be Fourier transformed. If not specified table.x is used. Defaults to None.

  • y (list, optional) – A list of dependent variables to be Fourier transformed. If not specified all columns in table.y are Fourier transformed. Defaults to None.

Returns:

Result of applying a real Fourier transform to selected columns in the table.

Return type:

ubermagtable.Table

Examples

  1. Applying Fourier transforms to the table.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-new-file5.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> fft_table = table.rfft()
...
selector(x=None, **kwargs)#

Selection list for interactive plotting.

Based on the independent variables, ipywidgets.SelectMultiple widget is returned for selecting the data columns to be plotted. This method is based on ipywidgets.SelectMultiple, so any keyword argument accepted by it can be passed.

Parameters:

x (str, optional) – Independent variable. Defaults to None.

Returns:

Selection list.

Return type:

ipywidgets.SelectMultiple

Example

  1. Get the widget for selecting data columns.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> table.selector()
SelectMultiple(...)
slider(x=None, multiplier=None, description=None, **kwargs)#

Slider for interactive plotting.

Based on the values in the independent variable column, ipywidgets.SelectionRangeSlider is returned for navigating interactive plots. This method is based on ipywidgets.SelectionRangeSlider, so any keyword argument accepted by it can be passed.

Parameters:
  • x (str, optional) – Independent variable. Defaults to None.

  • multiplier (numbers.Real, optional) – multiplier can be passed as \(10^{n}\), where \(n\) is a multiple of 3 (…, -6, -3, 0, 3, 6,…). According to that value, the values will be scaled and appropriate units shown. For instance, if multiplier=1e-9 is passed, the slider points will be divided by \(1\,\text{ns}\) and \(\text{ns}\) units will be used in the description. If multiplier is not passed, the optimum one is computed internally. Defaults to None.

  • description (str) – Slider description. Defaults to None.

Returns:

Independent variable slider.

Return type:

ipywidgets.SelectionRangeSlider

Example

  1. Get slider for the independent variable.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> table.slider()
SelectionRangeSlider(...)
property dx#

Spacing of independent variable.

property x#

Independent variable.

Returns:

Column name.

Return type:

str

property xmax#

Maximum value of independent variable.

Returns:

Independent variable range.

Return type:

numbers.Real

Examples

  1. Getting independent variable range.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file1.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> table.xmax / 1e-12  # get the results in picoseconds
24.999...
property y#

Dependent variable(s).

This property returns all data column names that are not specified as independent.

Returns:

Independent variables.

Return type:

list

Examples

  1. Getting data columns.

>>> import os
>>> import ubermagtable as ut
...
>>> odtfile = os.path.join(os.path.dirname(__file__),
...                        'tests', 'test_sample',
...                        'oommf-old-file5.odt')
>>> table = ut.Table.fromfile(odtfile, x='t')
>>> table.y
[...]