Data Files#

Data File#

class mhi.enerplot.DataFile(*, _ctx: Context | None = None, _ident: Dict[str, Any] | None = None)#

An Enerplot Data File

property id: str#

The id of the data file (read-only)

property name: str#

The name of the data file (read-only)

property label: str#

The label of the data file

property filename: str#

The filename of the data file (read-only)

property modified: bool#

Whether or not this is an Enerplot “modified” datafile

save() bool#

Save an Enerplot-modifiable datafile

Requires Enerplot 1.0.1 or later

Returns:

a True if the file state was dirty and required saving, False otherwise.

save_as(filename: str | Path, file_type: int = 1, folder: str | Path | None = None) None#

Save the datafile to a new path location.

Parameters:
  • filename – location to store the new datafile.

  • file_type – type of file to save (see below)

  • folder – folder to store saved file in

“File Save Type” Format Codes#

Format Code

Description

DataFile.FST_CSV

Comma Separated Values

DataFile.FST_COMTRADE_1999_ASCII

COMTRADE 1999 (Binary)

DataFile.FST_COMTRADE_1999_BINARY

COMTRADE 1999 (ASCII)

DataFile.FST_COMTRADE_1991_ASCII

COMTRADE 1999 (Binary)

DataFile.FST_COMTRADE_1991_BINARY

COMTRADE 1999 (ASCII)

DataFile.FST_PSSE

PSSE

save_as_csv(filename: str | Path, plotted: bool = False, folder: str | Path | None = None) None#

Save a CSV datafile to a new path location.

Parameters:
  • filename – location to store the new datafile.

  • plotted – If true, only plotted channels, otherwise all channels

  • folder – folder to store saved file in

save_as_comtrade(filename: str | Path, *channels, folder: str | Path | None = None, plotted: bool = False, year: int = 1999, binary: bool = True, station: str | None = None, header: str | None = None) None#

Save an COMTRADE datafile to a new path location.

If no channel names are given, and plotted is not set to True, all data will be saved.

Parameters:
  • filename – location to store the new datafile.

  • *channels – list of channel names to store

  • folder – folder to store saved file in

  • plotted – if true, all plotted channels are added to output

  • year – year-based file format version (eg, 1991 or 1999)

  • binary – if true, data is saved in binary format

  • station – Station text to write to file

  • header – Header text to write to file

Example

The following code will save channels named A, B, and C, as well as any channel used in a plot, in an ASCII COMTRADE file:

datafile.save_as_comtrade("new_file.cfg", "A", "B", "C",
                          plotted=True, binary=False)
remove() None#

Remove this data file from the workspace

property num_samples: int#

The number of samples in the data file.

Returns:

the number of samples

Return type:

int

property domain: Trace#

The domain channel of the data file.

Returns:

the domain values

set_domain(*, rate: float = 0, samples: int = 0, duration: float = 0) Trace#

Set the domain of the data file

Parameters:
  • rate – Difference between successive domain values

  • samples – Total number of samples

  • duration – The final or ending domain value (inclusive)

Returns:

the domain channel

Example

To create a time channel, with every millisecond, from 0.000 seconds up to and including 2.000 seconds, use one of the following statements:

data_file.set_domain(rate=0.001, samples=2001)
data_file.set_domain(samples=2001, duration=2.000)
data_file.set_domain(rate=0.001, duration=2.000)
channels(refresh: bool = False) IndexableDict[str, Channel]#

Return an indexable dictionary of channels in the DataFile

Parameters:

refresh – forces a reload of the channel cache, if True

Returns:

channels in the data file

channel_names(refresh: bool = False) List[str]#

Return a list of channel names in the data file

Parameters:

refresh – forces a reload of the channel cache, if True

Returns:

the list of channel names in the data file.

channel(key: str | int) Channel#

Return the channel by name or index

Parameters:

key – A name or an index indicating the required channel

Returns:

the indicated channel from the data file

trace(n: int = 0) Trace#

Create a new trace for the data file.

If the number of samples is not specified, it defaults to the length of the data file’s domain.

Parameters:

n – number of samples in trace (optional)

Returns:

buffer to store trace in

analog(func_or_iterable) Trace#

Create a new analog trace for the data file.

The length of the trace corresponds to the number of samples in the data file’s domain channel.

If given an iterable object, successive values from the iterable are copied into the trace.

If given a callable function, the function is repeatedly called with sucessive values from the domain channel, and the resulting values are copied into the trace.

Parameters:

func_or_iterable – source to generate channel values from

Returns:

the generated trace

set_channel(data, name: str, group: str = 'Data') Channel#

Add or replace a channel of data to this data file

Parameters:
  • data – a series of data values representing a channel

  • name – name to be given to the channel

  • group – group to create the channel in

Returns:

the create channel

property main: Enerplot#

A reference to the Application object that returned this Remotable object.

Channel#

class mhi.enerplot.Channel(*, _ctx: Context | None = None, _ident: Dict[str, Any] | None = None)#

An Enerplot Channel from a Data File

property datafile: DataFile#

The data file which this channel is a member of (read-only)

property name: str#

Channel name (read only)

copy() None#

Copy the channel to the clipboard

property domain: Trace#

The domain for this channel

points() int#

The number of samples in this channel

property data: array#

The samples of this channel (read-only)

decreasing() bool#

Test if a trace contains strictly decreasing values.

Returns:

True if every value is smaller than the previous one.

static div(a, b, inf=inf, nan=nan) float#

Handle x/0 and 0/0 without raising DivisionByZeroException

increasing() bool#

Test if a trace contains strictly increasing values.

A strictly increasing trace is suitable to use as the domain of a dataset.

Returns:

True if every value is larger than the previous one.

property main: Enerplot#

A reference to the Application object that returned this Remotable object.

property read_only: bool#

Whether or not the data is immutable

extents() Tuple[Tuple[float, float], Tuple[float, float]]#

The domain and range of this channel’s sample values

Returns:

domain (minimum x, maximum x) and range (minimum y, maximum y)