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_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.pydss_utils module¶
PyDSS.utils.simulation_utils module¶
- class PyDSS.utils.simulation_utils.SimulationFilteredTimeRange(start, end)[source]¶
Bases:
objectProvides 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
- 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.TimerStats(name)[source]¶
Bases:
objectTracks timing stats for one code block.
- class PyDSS.utils.timing_utils.TimerStatsCollector[source]¶
Bases:
objectCollects statistics for timed code segments.
- log_stats(clear=False)[source]¶
Log statistics for all tracked stats.
- Parameters
clear (bool) – If True, clear all stats.
- 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.TomlEncoderEncodes Enum values instead of Enum objects.
- 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.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