Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pvlib/iotools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
from pvlib.iotools.sodapro import get_cams # noqa: F401
from pvlib.iotools.sodapro import read_cams # noqa: F401
from pvlib.iotools.sodapro import parse_cams # noqa: F401
from pvlib.iotools.pvsyst import read_panond, parse_panond
from pvlib.iotools.panond import read_panond, parse_panond
60 changes: 35 additions & 25 deletions pvlib/iotools/pvsyst.py → pvlib/iotools/panond.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
import io

def num_type(value):
# Determine if a value is float, int or leave as string


# Determine if a value is float, int or leave as string
if '.' in value:
try: # Detect float
value_out = float(value)
return value_out

except ValueError: # Otherwise leave as string
value_out = value
return value_out

else:

try: # Detect int
value_out = int(value)
return value_out

except ValueError: # Otherwise leave as string
value_out = value
return value_out


def element_type(element):
# Determine if an element is a list then pass to num_type()
Expand All @@ -35,7 +36,7 @@ def element_type(element):
element_out = []
for val in values: # Determine datatype of each value
element_out.append(num_type(val))

return element_out

else:
Expand All @@ -50,13 +51,13 @@ def parse_panond(fbuf):
----------
fbuf : File-like object
Buffer of a .pan or .ond file

Returns
-------
comp : Nested Dictionary
Contents of the .pan or .ond file following the indentation of the file.
The value of datatypes are assumed during reading. The value units are
the default used by PVsyst.
Contents of the .pan or .ond file following the indentation of the
file. The value of datatypes are assumed during reading. The value
units are the default used by PVsyst.

Raises
------
Expand All @@ -72,19 +73,27 @@ def parse_panond(fbuf):
"""
comp = {} # Component
dict_levels = [comp]

fbuf.seek(0)
lines = fbuf.getvalue().splitlines()
for i in range(0, len(lines) - 1): # Reading blank lines. Stopping one short to avoid index error. Last line never contains important data.
if lines[i] == '': # Skipping blank lines
continue

indent_lvl_1 = (len(lines[i]) - len(lines[i].lstrip(' '))) // 2
indent_lvl_2 = (len(lines[i + 1]) - len(lines[i + 1].lstrip(' '))) // 2
line_data = lines[i].split('=')
for i in range(0, len(lines) - 1):
if lines[i] == '': # Skipping blank lines
continue
# Reading blank lines. Stopping one short to avoid index error.
# Last line never contains important data.
indent_lvl_1 = (len(lines[i]) - len(lines[i].lstrip(' '))) // 2
indent_lvl_2 = (len(lines[i + 1]) - len(lines[i + 1].lstrip(' '))) // 2
line_data = lines[i].split('=')
key = line_data[0].strip()
value = element_type(line_data[1].strip()) if len(line_data) > 1 else None
if indent_lvl_2 > indent_lvl_1: # add a level to the dict. The key here will be ignored. Not vital to file function.
# value = element_type(line_data[1].strip()) if len(line_data) > 1 else None
if len(line_data) > 1:
value = element_type(line_data[1].strip())
else:
value = element_type = None
# add a level to the dict. The key here will be ignored.
# Not vital to file function.
if indent_lvl_2 > indent_lvl_1:
current_level = dict_levels[indent_lvl_1]
new_level = {}
current_level[key] = new_level
Expand All @@ -101,19 +110,20 @@ def parse_panond(fbuf):

def read_panond(file):
"""
Retrieve Module or Inverter data from a .pan or .ond text file, respectively.
Retrieve Module or Inverter data from a .pan or .ond text file,
respectively.

Parameters
----------
file : string or path object
Name or path of a .pan/.ond file

Returns
-------
content : Nested Dictionary
Contents of the .pan or .ond file following the indentation of the file.
The value of datatypes are assumed during reading. The value units are
the default used by PVsyst.
Contents of the .pan or .ond file following the indentation of the
file. The value of datatypes are assumed during reading. The value
units are the default used by PVsyst.

Raises
------
Expand All @@ -131,7 +141,7 @@ def read_panond(file):
with open(file, "r", encoding='utf-8-sig') as file:
f_content = file.read()
fbuf = io.StringIO(f_content)

content = parse_panond(fbuf)

return content
File renamed without changes.