-
Notifications
You must be signed in to change notification settings - Fork 0
Implement inflow to capacity factor utility and inverse operation #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b00c26b
Implement inflows to capacity factor
MarcoAnarmo 23356e0
Implement capacity factor to inflows
MarcoAnarmo 0d47208
Rename functions to enhance coherence
MarcoAnarmo 38648b9
Assume all columns are in inflows
MarcoAnarmo 1b894b9
Raise an error if duplicated generators are found
MarcoAnarmo 7a7b33f
Not reset indexes for inflows dataframe
MarcoAnarmo 1393e97
Raise an error if Max Production is null for any generator
MarcoAnarmo 5253b56
Add values of Inflows at the end of VRESProfiles
MarcoAnarmo ac03957
Add bool to remove Inflows from the original VRESProfiles
MarcoAnarmo 5db0603
Delete reverse operator in mask definition and usage
MarcoAnarmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import pandas as pd | ||
|
|
||
|
|
||
| def inflowsToCapacityFactors(inflows_df: pd.DataFrame, vres_df: pd.DataFrame, vresProfiles_df: pd.DataFrame) -> pd.DataFrame: | ||
| """ | ||
| Convert inflows to capacity factors and concat them to vresProfiles_df. | ||
|
|
||
| - inflows_df: inflow data with inflows per generator (g) and representative period (rp). | ||
| - vres_df: contains generator technical data, including 'MaxProd'. | ||
| - vresProfiles_df: existing VRES profiles (indexed by rp, k, g). | ||
| """ | ||
| df = inflows_df.copy() | ||
|
|
||
| # Prepare vres_df with ['g','MaxProd'] | ||
| vres_tmp = vres_df.reset_index()[['g', 'MaxProd']] | ||
|
|
||
| if vres_tmp['g'].duplicated().any(): | ||
| raise ValueError("Duplicated generator found in Power_VRES.") | ||
|
|
||
| maxProd = vres_tmp.set_index('g')['MaxProd'].astype(float) | ||
|
|
||
| # Join MaxProd into inflows | ||
| df = df.join(maxProd, on='g', how='left') | ||
|
|
||
| if df['MaxProd'].isna().any() or (df['MaxProd'] == 0).any(): | ||
| raise ValueError("MaxProd is missing or zero for some generators in inflows.") | ||
|
|
||
| # Divide inflow value by MaxProd | ||
| df['value'] = df['value'] / df['MaxProd'] | ||
|
|
||
| # Drop helper column | ||
| df = df.drop(columns=['MaxProd']) | ||
|
|
||
| return pd.concat([vresProfiles_df, df], axis=0) | ||
|
|
||
|
|
||
| def capacityFactorsToInflows(vresProfiles_df: pd.DataFrame, vres_df: pd.DataFrame, inflows_df: pd.DataFrame, remove_Inflows_from_VRESProfiles_inplace: bool = False) -> pd.DataFrame: | ||
| """ | ||
| Convert capacity factors in vresProfiles_df back to inflows. | ||
|
|
||
| - vresProfiles_df: DataFrame with capacity factors (indexed by rp, k, g). | ||
| - vres_df: DataFrame containing generator technical data, including 'MaxProd'. | ||
| - inflows_df: template inflows DataFrame (used to filter only those generators that are inflow-based). | ||
| - remove_Inflows_from_VRESProfiles_inplace: if True, remove inflow generators from the original vresProfiles_df. | ||
| """ | ||
| df = vresProfiles_df.reset_index() | ||
|
|
||
| # Get list of inflow generators | ||
| inflow_generators = inflows_df.reset_index()['g'].unique() | ||
|
|
||
| # Prepare vres_df with ['g','MaxProd'] | ||
| vres_tmp = vres_df.reset_index()[['g', 'MaxProd']] | ||
|
|
||
| if vres_tmp['g'].duplicated().any(): | ||
| raise ValueError("Duplicated generator found in Power_VRES.") | ||
|
|
||
| maxProd = vres_tmp.set_index('g')['MaxProd'].astype(float) | ||
|
|
||
| # Keep only inflow generators | ||
| df = df[df['g'].isin(inflow_generators)] | ||
|
|
||
| # Join MaxProd | ||
| df = df.join(maxProd, on='g', how='left') | ||
|
|
||
| if df['MaxProd'].isna().any() or (df['MaxProd'] == 0).any(): | ||
| raise ValueError("MaxProd is missing or zero for some generators in inflows.") | ||
|
|
||
| # Multiply capacity factor by MaxProd | ||
| df['value'] = df['value'] * df['MaxProd'] | ||
|
|
||
| # Drop helper column | ||
| df = df.drop(columns=['MaxProd']) | ||
|
|
||
| # Remove inflow generators from vresProfiles_df after calculation if requested | ||
| if remove_Inflows_from_VRESProfiles_inplace: | ||
| mask = vresProfiles_df.index.get_level_values('g').isin(inflow_generators) | ||
| vresProfiles_df.drop(vresProfiles_df.index[mask], inplace=True) | ||
|
|
||
| return df.set_index(['rp', 'k', 'g']).sort_index(level="k") | ||
MarcoAnarmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.