Utilityrate5.ElectricityRates.ur_ec_tou_mat a touple, does not support item assi

  • frohro
  • Topic Author
More
24 Feb 2020 01:30 #7997 by frohro
Hi Paul,
It is time to go home here, but I thought I'd send you a query, since you are six or more hours ahead of me, and if I wait until tomorrow, it will delay an answer another day.  :-)
I'm trying to change the utility rate, and finding it immutable.  Maybe I need to use the assign method.  Here is what I'm doing:
Code:
Code:

ur.ElectricityRates.ur_ec_tou_mat[0][4] = rate_sheet.cell_value(i, 1)
I get the following error:
Code:
   ur.ElectricityRates.ur_ec_tou_mat[0][4] = rate_sheet.cell_value(i, 1) TypeError: 'tuple' object does not support item assignment
Any ideas?
And thanks!
Rob

Please Log in or Create an account to join the conversation.

  • pgilman
More
24 Feb 2020 15:01 #7998 by pgilman
Hi Rob,

To assign values as they appear in this screenshot of the energy charge input table in the SAM user interface,



the 'ur_ec_tou_mat' array would be defined as (with line breaks and spacing to make it more legible):
Code:
ur_ec_tou_mat = [ [ 1, 1, 1+38, 0, 0.12, 0 ], [ 2, 1, 1+38, 0, 0.05, 0 ], [ 3, 1, 1+38, 0, 0.25, 0 ], [ 4, 1, 1+38, 0, 0.26, 0 ] ]

To assign the buy rate for Period 1, Tier 1 to $0.10/kWh, you would set:
Code:
ur_ec_tou_mat[0][4] = 0.1

So, that part of your assignment looks correct.

From the PySAM 2.0 documentation for the Utilityrate5 module, it looks like 'ur_ec_tou_mat' is a sequence: nrel-pysam.readthedocs.io/en/2.0.2/modules/Utilityrate5.html#module-PySAM.Utilityrate5 .

The error message suggests that `ur.ElectricityRates.ur_ec_tou_mat` is a tuple. Tuples, unlike lists, are immutable in Python, so they can't be changed.

Is that enough information to solve the problem?

Thanks,
Paul.

Please Log in or Create an account to join the conversation.

  • frohro
  • Topic Author
More
24 Feb 2020 19:17 #8003 by frohro
Thanks Paul,
You and I agree on everything here.  You have nicely summarized things.  Python does indeed think the type is tuple, and certainly tuples are not mutable. 
Code:
type(ur.ElectricityRates.ur_ec_tou_mat) Out[114]: tuple
This is unfortunate, because I need to modify the electric rates to make my rates change over time.  I think I have all the code do do that put together now, but I was assuming that the rates were mutable.  I'm not really a python programmer (yet), and I'm still stuck.  There must be a way around this.  Any other ideas? 
Thanks,
Rob

Please Log in or Create an account to join the conversation.

  • frohro
  • Topic Author
More
24 Feb 2020 20:45 #8004 by frohro
Hi Paul,
I found my answer.   You convert the tuple to a list, and then make a new tuple with the values of the list. It seems to work.
Code:
temp_list = [list(x) for x in ur.ElectricityRates.ur_ec_tou_mat] temp_list[0][4] = rate_sheet.cell_value(i, 1) temp_list[1][4] = rate_sheet.cell_value(i, 2) ur.ElectricityRates.ur_ec_tou_mat = tuple(temp_list)
Thanks,
Rob

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum