Skip to content
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

Merged
merged 6 commits into from
Mar 21, 2022

Conversation

ppinchuk
Copy link
Collaborator

Added one new input parameter to the make_SAM_files and one new input parameter to the SolarResource.get_SAM_df function to facilitate the addition of user input to files. This was necessary for the processing of the 2020 TMY files for PVWatts (see email chain from Janine Keith starting on January 21, 2022).

The new input parameter to make_SAM_files is extra_meta_data, which is a dictionary mapping a meta column name to a meta column value. This allows users to add extra meta data to their output files.

The new input parameter to SolarResource.get_SAM_df is extra_cols, which pulls extra data from the SAM solar resource DataFrame. The key of the dictionary represents the name of the column to copy from the SAM solar resource DataFrame, and the value represents the name to give the data in the output.

Together, these new options could used likes this:

NSRDBX.make_SAM_files(
    ...
    write_time=True,
    extra_meta_data={"TMY Year": "2020"},
    extra_cols={"surface_albedo": "Surface Albedo"}
)

The output would then look something like this:

Location ID Latitude Longitude Elevation Time Zone Country State County Urban Population Landcover TMY Year Version
150658 40.13 -105.22 1615.5 -7 United States Colorado Boulder None 363 140 2020 3.2.0
Year Month Day Hour Minute DNI DHI Wind Speed Temperature Surface Albedo  
2020 1 1 0 30 0 0 5.1 -14 0.87      
2020 1 1 1 30 0 0 5.3 -13 0.87      
2020 1 1 2 30 0 0 5.3 -13 0.87      
2020 1 1 3 30 0 0 5.2 -13 0.87      
2020 1 1 4 30 0 0 5.1 -13 0.87      
... ... ... ... ... ... ... ... ... ...      

Note the addition of TMY Year in the meta data and the Surface Albedo column in the time series data.

@ppinchuk ppinchuk marked this pull request as ready for review March 20, 2022 19:58
"""
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
Copy link
Member

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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agreed!

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 {}
Copy link
Member

Choose a reason for hiding this comment

The 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)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 None in the function declaration. I feel it is an elegant way to get around the fact that you should never use mutables as default arguments.

@ppinchuk ppinchuk merged commit 289e742 into main Mar 21, 2022
@ppinchuk ppinchuk deleted the pp/make_SAM_file_updates branch March 21, 2022 19:43
github-actions bot pushed a commit that referenced this pull request Mar 21, 2022
`make_SAM_files` and `SolarResource.get_SAM_df` updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants