Skip to content

Commit

Permalink
Merge pull request #431 from vtnate/master
Browse files Browse the repository at this point in the history
fix: pd.read_csv not formatted correctly
  • Loading branch information
tarekelgindy authored Dec 4, 2023
2 parents ecb21ee + fa57a4f commit 9a5cb71
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
os:
- ubuntu-latest
- windows-latest
python-version: [ '3.7', '3.8', '3.9' ]
python-version: ['3.8', '3.12']

runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion ditto/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "0.2.3"
__version__ = "0.2.4"
102 changes: 50 additions & 52 deletions ditto/writers/opendss/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def float_to_str(self, f):
def write(self, model, separate_feeders = False, separate_substations = False, write_taps=False, verbose=False):
"""General writing function responsible for calling the sub-functions.
Note: re.sub('[^0-9a-zA-Z]+', '_', object_name) is used to fix node/bus names for OpenDSS,
Note: re.sub('[^0-9a-zA-Z]+', '_', object_name) is used to fix node/bus names for OpenDSS,
which uses dots for phase designation and spaces for paramater delimiters.
:param model: DiTTo model
Expand Down Expand Up @@ -1047,8 +1047,8 @@ def write_storages(self, model):

# Phases
if hasattr(i, "phase_storages") and i.phase_storages is not None:
if i.nominal_voltage < 300: # Line-Neutral voltage for 120 V
txt += " phases=1"
if i.nominal_voltage < 300: # Line-Neutral voltage for 120 V
txt += " phases=1"
else:
txt += " phases={N_phases}".format(N_phases=len(i.phase_storages))

Expand All @@ -1069,7 +1069,7 @@ def write_storages(self, model):
hasattr(i, "connecting_element")
and i.connecting_element is not None
):
if i.nominal_voltage is None:
if i.nominal_voltage is None:
i.nominal_voltage = model[i.connecting_element].nominal_voltage
txt += " bus1={elt}".format(elt=re.sub('[^0-9a-zA-Z]+', '_', i.connecting_element))
if (
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def write_storages(self, model):

# Yearly/Daily/Duty/Charge trigger/Discharge trigger
#
# TODO
# TODO

txt += "\n"
feeder_text_map[substation_name + "_" + feeder_name] = txt
Expand Down Expand Up @@ -1460,12 +1460,12 @@ def write_PVs(self, model):
voltvar_nodes.add(i.name)

if (
hasattr(i, "control_type")
and i.control_type is not None
and i.control_type == "voltwatt_voltvar"
):
txt += " Model=1"
voltwatt_voltvar_nodes.add(i.name)
hasattr(i, "control_type")
and i.control_type is not None
and i.control_type == "voltwatt_voltvar"
):
txt += " Model=1"
voltwatt_voltvar_nodes.add(i.name)

if (
hasattr(i, "timeseries")
Expand Down Expand Up @@ -1539,13 +1539,13 @@ def write_PVs(self, model):
inv_txt = inv_txt.strip(",")
inv_txt += "]"

if len(voltwatt_voltvar_nodes) > 0:
if not len(voltvar_nodes) > 0:
inv_txt += "New XYCurve.VoltVarCurve_{loc} npts=6 Yarray=(1.0,1.0,0.0,0.0,-1.0,-1.0) Xarray=(0.5,0.92,0.98,1.02,1.08,1.5)\n\n".format( loc=substation_name + "_" + feeder_name) # Default voltvar curve used is 1547 Cat-B
if not len(voltwatt_nodes) > 0:
inv_txt += "New XYCurve.VoltWattCurve_{loc} npts=4 Yarray=(1.0,1.0,0.0,0.0) XArray=(0.5,1.06,1.1,1.5)\n\n".format( loc=substation_name + "_" + feeder_name) # Default volt-watt curve used
for node in voltwatt_voltvar_nodes:

if len(voltwatt_voltvar_nodes) > 0:
if not len(voltvar_nodes) > 0:
inv_txt += "New XYCurve.VoltVarCurve_{loc} npts=6 Yarray=(1.0,1.0,0.0,0.0,-1.0,-1.0) Xarray=(0.5,0.92,0.98,1.02,1.08,1.5)\n\n".format( loc=substation_name + "_" + feeder_name) # Default voltvar curve used is 1547 Cat-B
if not len(voltwatt_nodes) > 0:
inv_txt += "New XYCurve.VoltWattCurve_{loc} npts=4 Yarray=(1.0,1.0,0.0,0.0) XArray=(0.5,1.06,1.1,1.5)\n\n".format( loc=substation_name + "_" + feeder_name) # Default volt-watt curve used
for node in voltwatt_voltvar_nodes:
inv_txt += "New InvControl.InvPVCtrVW_{node} Combimode=VV_VW voltage_curvex_ref=rated vvc_curve1=VoltVarCurve_{loc} VV_RefReactivePower=VARMAX_VARS VoltwattYAxis=PAVAILABLEPU voltwatt_curve=VoltWattCurve_{loc} eventlog=yes DeltaQ_factor = 0.25 DeltaP_factor=0.25 PVSystemlist=[{node}]\n\n".format( loc=substation_name + "_" + feeder_name, node=node)

if txt != "":
Expand Down Expand Up @@ -1660,7 +1660,7 @@ def write_timeseries(self, model):
continue
# WARNING - this step can be slow for big systems with lots of data
npoints = len(
pd.read_csv(os.path.join(self.output_path, i.data_location)),header=None
pd.read_csv(os.path.join(self.output_path, i.data_location),header=None)
)

if self.timeseries_iternumber is None:
Expand Down Expand Up @@ -2058,7 +2058,7 @@ def write_loads(self, model):

txt += "\n\n"
feeder_text_map[substation_name + "_" + feeder_name] = txt

for substation_name in substation_text_map:
for feeder_name in substation_text_map[substation_name]:
txt = feeder_text_map[substation_name + "_" + feeder_name]
Expand Down Expand Up @@ -2327,7 +2327,7 @@ def write_regulators(self, model):
pass
# XLT:
try: # probably an index error b/c cyme reader only has api_transformer.reactances = [float(xhl)]
if isinstance(i.reactances[1], (int, float)):
if isinstance(i.reactances[1], (int, float)):
transfo_creation_string += " XLT={}".format(
i.reactances[1]
)
Expand Down Expand Up @@ -2904,11 +2904,11 @@ def write_lines(self, model):
else:
continue

if hasattr(i,'positions') and i.positions is not None and len(i.positions) > 0:
if hasattr(i,'positions') and i.positions is not None and len(i.positions) > 0:
intermediate_txt += i.name
for position in i.positions:
intermediate_txt +=f';({position.long},{position.lat})'
intermediate_txt+='\n\n'
for position in i.positions:
intermediate_txt +=f';({position.long},{position.lat})'
intermediate_txt+='\n\n'

# Set the units in miles for comparison (IEEE 13 nodes feeder)
# TODO: Let the user specify the export units
Expand Down Expand Up @@ -3066,28 +3066,28 @@ def write_lines(self, model):
self.files_to_redirect.append(
os.path.join(output_redirect, self.output_filenames["lines"])
)
if intermediate_txt != "":
output_folder = None
output_redirect = None
if self.separate_substations:
output_folder = os.path.join(self.output_path, substation_name)
output_redirect = substation_name
if not os.path.exists(output_folder):
os.makedirs(output_folder)
else:
output_folder = os.path.join(self.output_path)
output_redirect = ""
if not os.path.exists(output_folder):
os.makedirs(output_folder)
if self.separate_feeders:
output_folder = os.path.join(output_folder, feeder_name)
output_redirect = os.path.join(output_redirect, feeder_name)
if not os.path.exists(output_folder):
os.makedirs(output_folder)
with open(
os.path.join(output_folder, self.output_filenames["intermediates"]), "w"
) as fp:
fp.write(intermediate_txt)
if intermediate_txt != "":
output_folder = None
output_redirect = None
if self.separate_substations:
output_folder = os.path.join(self.output_path, substation_name)
output_redirect = substation_name
if not os.path.exists(output_folder):
os.makedirs(output_folder)
else:
output_folder = os.path.join(self.output_path)
output_redirect = ""
if not os.path.exists(output_folder):
os.makedirs(output_folder)
if self.separate_feeders:
output_folder = os.path.join(output_folder, feeder_name)
output_redirect = os.path.join(output_redirect, feeder_name)
if not os.path.exists(output_folder):
os.makedirs(output_folder)
with open(
os.path.join(output_folder, self.output_filenames["intermediates"]), "w"
) as fp:
fp.write(intermediate_txt)
# Just write the file - don't redirect it

return 1
Expand Down Expand Up @@ -3992,7 +3992,7 @@ def write_master_file(self, model):
"Buscoords {f}\n".format(f=self.output_filenames["buses"])
) # The buscoords are also written to base folder as well as the subfolders

fp.write("set maxcontroliter=50\n") # for volt-var convergence if needed
fp.write("set maxcontroliter=50\n") # for volt-var convergence if needed
if self.has_timeseries:
fp.write("\nSolve mode={timestep} number={iternumber}\n".format(timestep=self.timeseries_solve_format,iternumber=self.timeseries_iternumber)) #Run for first day of year

Expand Down Expand Up @@ -4088,11 +4088,9 @@ def write_master_file(self, model):
"Buscoords {f}\n".format(f=self.output_filenames["buses"])
) # The buscoords are also written to base folder as well as the subfolders

fp.write("set maxcontroliter=50\n") # for volt-var convergence if needed
fp.write("set maxcontroliter=50\n") # for volt-var convergence if needed
if self.has_timeseries:
fp.write("\nSolve mode={timestep} number={iternumber}\n".format(timestep=self.timeseries_solve_format,iternumber=self.timeseries_iternumber)) #Run for first day of year

else:
fp.write("\nSolve\n")


12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

extras_requires = [
"lxml~=4.9",
"pandas~=1.3.5", # Pyton 3.7 does not support pandas 1.4
"pandas~=2.0",
"scipy~=1.7",
numpy_dependency,
"XlsxWriter~=3.0",
Expand Down Expand Up @@ -111,9 +111,11 @@ def run(self):
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
test_suite="tests",
install_requires=[
Expand All @@ -123,7 +125,7 @@ def run(self):
"six~=1.16",
"traitlets~=5.1",
"json_tricks~=3.16",
"pandas~=1.3.5",
"pandas~=2.0",
numpy_dependency,
],
extras_require={
Expand Down

0 comments on commit 9a5cb71

Please sign in to comment.