-
Notifications
You must be signed in to change notification settings - Fork 11
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
make_SAM_files
and SolarResource.get_SAM_df
updates
#124
Changes from all commits
6029410
66e8f62
c78dc75
b360a61
ea2607e
13ebb1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,21 @@ class SolarResource(BaseResource): | |
-------- | ||
resource.BaseResource : Parent class | ||
""" | ||
def get_SAM_df(self, site): | ||
def get_SAM_df(self, site, extra_cols=None): | ||
""" | ||
Get SAM solar resource DataFrame for given site | ||
|
||
Parameters | ||
---------- | ||
site : int | ||
Site to extract SAM DataFrame for | ||
Site to extract SAM DataFrame for. | ||
extra_cols : dict, optional | ||
A dictionary where they keys are extra columns | ||
to extract from the SAM solar resource DataFrame | ||
and the values are the names the new columns should | ||
have (e.g. extra_cols={'surface_albedo': 'Surface | ||
Albedo'} will extract the 'surface_albedo' from the | ||
resource file and call it 'Surface Albedo' in the output). | ||
|
||
Returns | ||
------- | ||
|
@@ -44,13 +51,16 @@ def get_SAM_df(self, site): | |
'Month': self.time_index.month, | ||
'Day': self.time_index.day, | ||
'Hour': self.time_index.hour}) | ||
if len(self) > 8784: | ||
|
||
if len(self) > 8784 or (self.time_index.minute != 0).any(): | ||
res_df['Minute'] = self.time_index.minute | ||
|
||
time_zone = self.meta.loc[site, 'timezone'] | ||
time_interval = len(self.time_index) // 8760 | ||
|
||
for var in ['dni', 'dhi', 'wind_speed', 'air_temperature']: | ||
main_cols = ['dni', 'dhi', 'wind_speed', 'air_temperature'] | ||
extra_cols = extra_cols or {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting! I've never seen this. So it will go to the {} if extra_cols is bool(False)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! I love using this pattern when I use an optional input with a default value of |
||
for var in main_cols + list(extra_cols): | ||
ds_slice = (slice(None), site) | ||
var_array = self._get_ds(var, ds_slice) | ||
var_array = SAMResource.roll_timeseries(var_array, time_zone, | ||
|
@@ -60,6 +70,7 @@ def get_SAM_df(self, site): | |
|
||
col_map = {'dni': 'DNI', 'dhi': 'DHI', 'wind_speed': 'Wind Speed', | ||
'air_temperature': 'Temperature'} | ||
col_map.update(extra_cols) | ||
res_df = res_df.rename(columns=col_map) | ||
res_df.name = "SAM_-{}".format(site) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, i like this. Always a good idea to add kwargs that can be endlessly expanded (instead of something like sufrace_albedo=True just to add the single new col).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agreed!