OSeMOSYS / OSeMOSYS_PuLP

OSeMOSYS_PuLP: A Stochastic Modelling Framework for Long-Term Energy Systems Modeling
Apache License 2.0
14 stars 6 forks source link

Capacity Factor dictionary #3

Closed Luiscarlos-A-Torres-Sanchez closed 4 years ago

Luiscarlos-A-Torres-Sanchez commented 4 years ago

Hello,

When I tested OSeMOSYS-PuLP using UTOPIA_BASE.xlsx, the CapacityFactor dictionary was loaded in Python correctly; that is, as described in the Excel file.

Nonetheless, when I started working on a personal file, the code seemed to only read the values for one of the timeslices and assign them to all the remaining ones. This happened under the condition that I was only defining the capacity factor for one (1) technology. Therefore, I looked into the original code (enumrated by lines):

CapacityFactor

  1. CapacityFactor_default_value = p_default_df[p_default_df['PARAM'] == "CapacityFactor"].VALUE.iat[0]

  2. CapacityFactor_specified = tuple([(str(r), str(t), str(l), str(y)) 
    for r, t, l, y in zip(p_df[p_df['PARAM'] == "CapacityFactor"].REGION, 
                                 p_df[p_df['PARAM'] == "CapacityFactor"].TECHNOLOGY, 
                                 p_df[p_df['PARAM'] == "CapacityFactor"].TIMESLICE, 
                                 p_df[p_df['PARAM'] == "CapacityFactor"].YEAR)])
  3. CapacityFactor = {str(r): {str(t): {str(l): {str(y): p_df[(p_df['PARAM'] == "CapacityFactor") & (p_df['REGION'] == r) & (p_df['TECHNOLOGY'] == t) & (p_df['YEAR'] == y)].VALUE.iat[0] if (str(r),str(t),str(l),str(y)) in CapacityFactor_specified else CapacityFactor_default_value for y in YEAR} for l in TIMESLICE} for t in TECHNOLOGY} for r in REGION}

I saw that in the third line, the CapacityFactor is not using the condition for TIMESLICE. So I changed it to:

  1. CapacityFactor = {str(r): {str(t): {str(l): {str(y): p_df[(p_df['PARAM'] == "CapacityFactor") &
    (p_df['REGION'] == r) &
    (p_df['TECHNOLOGY'] == t) &
    (p_df['YEAR'] == y) &
    (p_df['TIMESLICE'] == l)].VALUE.iat[0] 
    if (str(r),str(t),str(l),str(y)) in CapacityFactor_specified 
    else CapacityFactor_default_value for y in YEAR} 
    for l in TIMESLICE} for t in TECHNOLOGY} for r in REGION}

See that I added: & (p_df['TIMESLICE'] == l)

And it then it read it properly. Although this could also be some sort of incompatibility I have been having with Excel.

Please let me know whether adding that is actually necessary.

Best,

Luiscarlos

Dennis3R commented 4 years ago

Thank you! The bug is fixed now