Data Files

Data File

class mhi.enerplot.DataFile

An Enerplot Data File

id

The id of the data file (read-only)

name

The name of the data file (read-only)

label

The label of the data file (read-only)

filename

The filename of the data file (read-only)

save_as(filename, file_type=1, folder=None)

Save the datafile to a new path location.

Parameters:
  • filename (str) – location to store the new datafile.
  • file_type (int) – type of file to save (see below)
  • folder (str) – 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, plotted=False, folder=None)

Save a CSV datafile to a new path location.

Parameters:
  • filename (str) – location to store the new datafile.
  • plotted (bool) – If true, only plotted channels, otherwise all channels
  • folder (str) – folder to store saved file in
save_as_comtrade(filename, *channels, folder=None, plotted=False, year=1999, binary=True, station=None, header=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 (str) – location to store the new datafile.
  • *channels (str) – list of channel names to store
  • folder (str) – folder to store saved file in
  • plotted (bool) – if true, all plotted channels are added to output
  • year (int) – year-based file format version (eg, 1991 or 1999)
  • binary (bool) – if true, data is saved in binary format
  • station (str) – Station text to write to file
  • header (str) – 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()

Remove this data file from the workspace

domain

The domain channel of the data file.

Returns:the domain values
Return type:list[float]
num_samples

The number of samples in the data file.

Returns:the number of samples
Return type:int
channels(refresh=False)

Return an indexable dictionary of channels in the DataFile

Parameters:refresh (bool) – forces a reload of the channel cache, if True
Returns:channels in the data file
Return type:IndexableDict[str,Channel]
channel_names(refresh=False)

Return a list of channel names in the data file

Returns:the list of channel names in the data file.
Return type:List[str]
channel(key)

Return the channel by name or index

Parameters:key – A name (str) or an index (int) indicating the required channel
Returns:the indicated channel from the data file
Return type:Channel
trace(n=0)

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 (int) – number of samples in trace (optional)
Returns:buffer to store trace in
Return type:memoryview
analog(func_or_iterable)

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
Return type:memoryview
set_channel(data, name, group='Data')

Add a channel of data to this data file

Parameters:
  • data – a series of data values representing a channel
  • name (str) – name to be given to the channel
  • group (str) – group to create the channel in
Returns:

the create channel

Return type:

Channel

main

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

Mutable Data File

class mhi.enerplot.MutableDataFile

Mutable Data Files

A datafile whose domain can be set from Python

num_samples

The number of samples in the data file.

Returns:the number of samples
Return type:int
trace(n=0)

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 (int) – number of samples in trace (optional)
Returns:buffer to store trace in
Return type:memoryview
analog(func_or_iterable)

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
Return type:memoryview
domain

The domain channel of the data file.

Returns:the domain values
Return type:list[float]
set_domain(*, rate=0, samples=0, duration=0)

Set the domain of the data file

Parameters:
  • rate (float) – Difference between successive domain values
  • samples (int) – Total number of samples
  • duration (float) – The final or ending domain value (inclusive)
Returns:

the domain channel

Return type:

List[float]

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:

mutable_data_file.set_domain(rate=0.001, samples=2001)
mutable_data_file.set_domain(samples=2001, duration=2.000)
mutable_data_file.set_domain(rate=0.001, duration=2.000)
add_channel(data, name, group='Data')

Add a channel of data to this data file

Parameters:
  • data – a series of data values representing a channel
  • name (str) – name to be given to the channel
  • group (str) – group to create the channel in
Returns:

the create channel

Return type:

Channel

channel(key)

Return the channel by name or index

Parameters:key – A name (str) or an index (int) indicating the required channel
Returns:the indicated channel from the data file
Return type:Channel
channel_names(refresh=False)

Return a list of channel names in the data file

Returns:the list of channel names in the data file.
Return type:List[str]
channels(refresh=False)

Return an indexable dictionary of channels in the DataFile

Parameters:refresh (bool) – forces a reload of the channel cache, if True
Returns:channels in the data file
Return type:IndexableDict[str,Channel]
filename

The filename of the data file (read-only)

id

The id of the data file (read-only)

label

The label of the data file (read-only)

main

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

name

The name of the data file (read-only)

remove()

Remove this data file from the workspace

save_as(filename, file_type=1, folder=None)

Save the datafile to a new path location.

Parameters:
  • filename (str) – location to store the new datafile.
  • file_type (int) – type of file to save (see below)
  • folder (str) – 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_comtrade(filename, *channels, folder=None, plotted=False, year=1999, binary=True, station=None, header=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 (str) – location to store the new datafile.
  • *channels (str) – list of channel names to store
  • folder (str) – folder to store saved file in
  • plotted (bool) – if true, all plotted channels are added to output
  • year (int) – year-based file format version (eg, 1991 or 1999)
  • binary (bool) – if true, data is saved in binary format
  • station (str) – Station text to write to file
  • header (str) – 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)
save_as_csv(filename, plotted=False, folder=None)

Save a CSV datafile to a new path location.

Parameters:
  • filename (str) – location to store the new datafile.
  • plotted (bool) – If true, only plotted channels, otherwise all channels
  • folder (str) – folder to store saved file in
set_channel(data, name, group='Data')

Add a channel of data to this data file

Parameters:
  • data – a series of data values representing a channel
  • name (str) – name to be given to the channel
  • group (str) – group to create the channel in
Returns:

the create channel

Return type:

Channel

Channel

class mhi.enerplot.Channel

An Enerplot Channel from a Data File

datafile

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

name

Channel name (read only)

copy()

Copy the channel to the clipboard

domain

The domain for this channel

points()

The number of samples in this channel

data

The samples of this channel (read-only)

extents()

The domain and range of this channel’s sample values

Returns:(minimum x, maximum x), (minimum y, maximum y)
Return type:Tuple[Tuple]
decreasing()

Test if a trace contains strictly decreasing values.

Returns:True if every value is smaller than the previous one.
Return type:bool
increasing()

Test if a trace contains strictly increasing values.

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

Returns:True if every value is larger than the previous one.
Return type:bool
main

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