PyDSS.utils package

Submodules

PyDSS.utils.dataframe_utils module

PyDSS.utils.dataframe_utils.read_dataframe(filename, index_col=None, columns=None, parse_dates=False, remove_unnamed=True, strip_column_units=False, **kwargs)[source]

Convert filename to a dataframe. Supports .csv, .json, .feather, .h5. Handles compressed files.

Parameters
  • filename (str) –

  • index_col (str | int | None) – Index column name or index

  • columns (list or None) – Use these columns if the file is CSV and does not define them.

  • parse_dates (bool) –

  • remove_unnamed (bool) – Remove any column that starts with “Unnamed”.

  • strip_column_units (bool) – Remove units from column names.

  • kwargs (kwargs) – Passed to underlying library for dataframe conversion. Consider setting parse_dates=True if the index is a timestamp.

Returns

Return type

pd.DataFrame

Raises

FileNotFoundError – Raised if the file does not exist.

PyDSS.utils.dataframe_utils.write_dataframe(df, file_path, compress=False, keep_original=False, **kwargs)[source]

Write the dataframe to a file with in a format matching the extension.

Note that the feather and h5 formats do not support row indices. Index columns will be lost for those formats. If the dataframe has an index then it should be converted to a column before calling this function.

This function only supports storing a single dataframe inside an HDF5 file. It always uses the key ‘data’.

Parameters
  • df (pd.DataFrame) –

  • file_path (str) –

  • compress (bool) –

  • keep_original (bool) –

  • kwargs (pass keyword arguments to underlying library) –

Raises
  • InvalidParameter if the file extension is not supported.

  • InvalidParameter if the DataFrame index is set.

PyDSS.utils.dss_utils module

PyDSS.utils.dss_utils.get_load_shape_resolution_secs()[source]
PyDSS.utils.dss_utils.get_node_names_by_type(kv_base_threshold=1.0)[source]

Return a mapping of node type to node names.

Parameters

kv_base_threshold (float) – Voltage to use as threshold for identifying primary vs secondary

Returns

keys are “primaries” or “secondaries” values are a list of node names

Return type

dict

PyDSS.utils.dss_utils.read_pv_systems_from_dss_file(filename)[source]

Return PVSystem names specified in OpenDSS deployment file.

Parameters

filename (str) –

Returns

Return type

list

PyDSS.utils.pydss_utils module

PyDSS.utils.pydss_utils.form_Yprim(values)[source]
PyDSS.utils.pydss_utils.form_Yprim_2(values)[source]
PyDSS.utils.pydss_utils.get_Yprime_Matrix(dssObjects)[source]

PyDSS.utils.simulation_utils module

class PyDSS.utils.simulation_utils.CircularBufferHelper(window_size)[source]

Bases: object

append(val)[source]
average()[source]
class PyDSS.utils.simulation_utils.SimulationFilteredTimeRange(start, end)[source]

Bases: object

Provides filtering in a time range.

classmethod from_settings(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return SimulationFilteredTimeRange from the simulation settings.

Parameters

settings (dict) – settings from project simulation.toml

Returns

Return type

SimulationFilteredTimeRange

is_within_range(timestamp)[source]

Return True if the timestamp is within the filtered range.

Parameters

timestamp (datetime) –

Returns

Return type

bool

PyDSS.utils.simulation_utils.create_datetime_index_from_settings(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return time indices created from the simulation settings.

Parameters

settings (SimulationSettingsModel) –

Returns

Return type

pd.DatetimeIndex

PyDSS.utils.simulation_utils.create_loadshape_pmult_dataframe(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return a loadshape dataframe representing all available data. This assumes that a loadshape has been selected in OpenDSS.

Parameters

settings (SimulationSettingsModel) –

Returns

Return type

pd.DatetimeIndex

PyDSS.utils.simulation_utils.create_loadshape_pmult_dataframe_for_simulation(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return a loadshape pmult dataframe that only contains time points used by the simulation. This assumes that a loadshape has been selected in OpenDSS.

Parameters

settings (SimulationSettingsModel) –

Returns

Return type

pd.DataFrame

PyDSS.utils.simulation_utils.create_time_range_from_settings(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return the start time, step time, and end time from the settings.

Parameters

settings (SimulationSettingsModel) –

Returns

(start, end, step)

Return type

tuple

PyDSS.utils.simulation_utils.get_simulation_resolution(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return the simulation of the resolution

Parameters

settings (SimulationSettingsModel) –

Returns

Return type

datetime

PyDSS.utils.simulation_utils.get_start_time(settings: PyDSS.simulation_input_models.SimulationSettingsModel)[source]

Return the start time of the simulation.

Parameters

settings (SimulationSettingsModel) –

Returns

Return type

datetime

PyDSS.utils.timing_utils module

Utility functions for timing measurements.

class PyDSS.utils.timing_utils.Timer(timer_stats, name)[source]

Bases: object

Times a code block.

class PyDSS.utils.timing_utils.TimerStats(name)[source]

Bases: object

Tracks timing stats for one code block.

get_stats()[source]

Get the current stats summary.

Returns

Return type

dict

log_stats()[source]

Log a summary of the stats.

update(duration)[source]

Update the stats with a new timing.

class PyDSS.utils.timing_utils.TimerStatsCollector[source]

Bases: object

Collects statistics for timed code segments.

clear()[source]

Clear all stats.

get_stat(name)[source]

Return a TimerStats.

Parameters

name (str) –

Returns

Return type

TimerStats

log_stats(clear=False)[source]

Log statistics for all tracked stats.

Parameters

clear (bool) – If True, clear all stats.

register_stat(name)[source]

Register tracking of a new stat.

Parameters

name (str) –

Returns

Return type

TimerStats

PyDSS.utils.timing_utils.get_time_duration_string(seconds)[source]

Returns a string with the time converted to reasonable units.

PyDSS.utils.timing_utils.timed_debug(func)[source]

Decorator to measure and logger.debug a function’s execution time.

PyDSS.utils.timing_utils.timed_info(func)[source]

Decorator to measure and logger.info a function’s execution time.

PyDSS.utils.timing_utils.track_timing(timer_stats)[source]

Decorator to track statistics on a function’s execution time.

Parameters

timer_stats (TimerStatsCollector) –

PyDSS.utils.utils module

Utility functions for the jade package.

class PyDSS.utils.utils.TomlEnumEncoder(_dict=<class 'dict'>, preserve=False)[source]

Bases: toml.encoder.TomlEncoder

Encodes Enum values instead of Enum objects.

dump_value(v)[source]
PyDSS.utils.utils.check_redirect(file_name)[source]

Runs redirect command for dss file And checks for exception

Parameters

file_name (str) – dss file to be redirected

Raises

Exception – Raised if the command fails

PyDSS.utils.utils.decompress_file(filename)[source]

Decompress a file.

Parameters

filename (str) –

Returns

Returns the new filename.

Return type

str

PyDSS.utils.utils.deserialize_timedelta(text)[source]
PyDSS.utils.utils.dump_data(data, filename, **kwargs)[source]

Dump data to the filename. Supports JSON, TOML, YAML, or custom via kwargs.

Parameters
  • data (dict) – data to dump

  • filename (str) – file to create or overwrite

PyDSS.utils.utils.get_cli_string()[source]

Return the command-line arguments issued.

Returns

Return type

str

PyDSS.utils.utils.interpret_datetime(timestamp)[source]

Return a datetime object from a timestamp string.

Parameters

timestamp (str) –

Returns

Return type

datetime.datetime

PyDSS.utils.utils.iter_elements(element_class, element_func)[source]

Yield the return of element_func for each element of type element_class.

Parameters
  • element_class (class) – Subclass of opendssdirect.CktElement

  • element_func (function) – Function to run on each element

Yields

Return of element_func

Examples

>>> import opendssdirect as dss
>>> def get_reg_control_info():
    return {
        "name": dss.RegControls.Name(),
        "enabled": dss.CktElement.Enabled(),
        "transformer": dss.RegControls.Transformer(),
    }
>>> for reg_control in iter_elements(opendssdirect.RegControls, get_reg_control_info):
    print(reg_control["name"])
PyDSS.utils.utils.load_data(filename, **kwargs)[source]

Load data from the file. Supports JSON, TOML, YAML, or custom via kwargs.

Parameters

filename (str) –

Returns

Return type

dict

PyDSS.utils.utils.make_human_readable_size(size, decimals=2)[source]

Convert bytes to human readable representation.

Parameters
  • size (float) – Size in bytes.

  • decimals (int, optional) – the decimal places, by default 2

Returns

Human reable size string with unit.

Return type

str

PyDSS.utils.utils.make_json_serializable(obj)[source]
PyDSS.utils.utils.make_timestamps(data)[source]
PyDSS.utils.utils.serialize_timedelta(timedelta_object)[source]

Module contents