10000 sam iotools #1371 by shirubana · Pull Request #1556 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

sam iotools #1371 #1556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updates williamhobbs
-metadata now uses and expects 'tz' (non caps).
-If tz data is not numberic, it throws an error.
-function renamed to write_sam()
-source value set to 'pvlib export' if not defined.
  • Loading branch information
shirubana committed Oct 13, 2022
commit 5d7249109dff1fe082d63638c9ca7ba2d6fd6b56
2 changes: 1 addition & 1 deletion pvlib/iotools/psm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def parse_psm3(fbuf, map_variables=None):
if 'Minute' in data.columns:
dtidx = pd.to_datetime(
data[['Year', 'Month', 'Day', 'Hour', 'Minute']])
else:
else:
dtidx = pd.to_datetime(
data[['Year', 'Month', 'Day', 'Hour']])
# in USA all timezones are integers
Expand Down
28 changes: 19 additions & 9 deletions pvlib/iotools/sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import pandas as pd


def saveSAM_WeatherFile(data, metadata, savefile='SAM_WeatherFile.csv',
def write_sam(data, metadata, savefile='SAM_WeatherFile.csv',
standardSAM=True, includeminute=False):
"""
Saves dataframe with weather data from pvlib format on SAM-friendly format.

Parameters
-----------
data : pandas.DataFrame
timeseries data in PVLib format. Should be TZ converted (not UTC).
timeseries data in PVLib format. Should be tz converted (not UTC).
Ideally it is one sequential year data; if not suggested to use
standardSAM = False.
metdata : dictionary
Dictionary with 'latitude', 'longitude', 'elevation', 'source',
and 'TZ' for timezone.
and 'tz' for timezone.
savefile : str
Name of file to save output as.
standardSAM : boolean
Expand Down Expand Up @@ -58,7 +58,7 @@ def _fillYearSAMStyle(df, freq='60T'):
'''
# add zeros for the rest of the year
# add a timepoint at the end of the year
# apply correct TZ info (if applicable)
# apply correct tz info (if applicable)
tzinfo = df.index.tzinfo
starttime = pd.to_datetime('%s-%s-%s %s:%s' % (df.index.year[0], 1, 1,
0, 0)
Expand Down Expand Up @@ -86,8 +86,13 @@ def _fillYearSAMStyle(df, freq='60T'):
latitude = metadata['latitude']
longitude = metadata['longitude']
elevation = metadata['elevation']
timezone_offset = metadata['TZ']
source = metadata['source']
timezone_offset = metadata['tz']

if 'source' in metadata:
source = metadata['source']
else:
source = 'pvlib export'
metadata['source'] = source

# make a header
header = '\n'.join(['Source,Latitude,Longitude,Time Zone,Elevation',
Expand Down Expand Up @@ -125,7 +130,7 @@ def _fillYearSAMStyle(df, freq='60T'):

if 'pressure' in data:
savedata['pressure'] = data.pressure.values

if 'wdir' in data:
savedata['wdir'] = data.wdir.values

Expand Down Expand Up @@ -172,11 +177,16 @@ def tz_convert(df, tz_convert_val, metadata=None):
Adds (or updates) the existing Timezone in the metadata dictionary

"""

if isinstance(tz_convert_val, int) is False:
print("Please pass a numeric timezone, i.e. -6 for MDT or 0 for UTC.")
return

import pytz
if (type(tz_convert_val) == int) | (type(tz_convert_val) == float):
df = df.tz_convert(pytz.FixedOffset(tz_convert_val*60))

if metadata is not None:
metadata['TZ'] = tz_convert_val
if 'tz' in metadata:
metadata['tz'] = tz_convert_val
return df, metadata
return df
0