question about ssc.data_set_table

  • Cho
  • Topic Author
More
01 Feb 2021 04:57 #9249 by Cho
Below  is a test example I wrote. When I tried to read the table using ssc.data_get_table(dat, b'test'), I got an integer. How can I read the table as a table or a dataframe? Thanks!
import pandas as pd
from PySSC import PySSC


if __name__ == "__main__":
   ssc = PySSC()
   dat = ssc.data_create()

   # System characteristics
   ssc.data_set_number(dat, b'system_capacity', 2.33)

   table = ssc.data_create()
   ssc.data_set_number(table, b'lat', 37.95)
   ghi = pd.read_excel(r'.\ghi.xlsx')
   ghi = ghi['ghi_w_m2']
   ssc.data_set_array(table, b'gh', ghi)

   ssc.data_set_table(dat, b'test', table)

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

  • Paul Gilman
More
01 Feb 2021 18:52 #9250 by Paul Gilman
Replied by Paul Gilman on topic question about ssc.data_set_table
Hi Cho,

If you are writing a program in Python to interact with SSC, it might be easier to use the PySAM package as described here: sam.nrel.gov/software-development-kit-sdk.html.

You can find documentation of the functions in sscapi.h here:

github.com/NREL/ssc/blob/develop/ssc/sscapi.h

Best regards,
Paul.

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

  • Cho
  • Topic Author
More
01 Feb 2021 20:41 #9251 by Cho
Replied by Cho on topic question about ssc.data_set_table
Thank you Paul. I'm trying to edit on some old scripts with PySSC and it's not very easy to rewrite them all with PySAM. 
I looked up the SSC Reference Manual and tried the following as well. But I got error running the last line. How can I read the content in a ssc table?
ssc.data_free(table)
table = ssc.data_create()
table = ssc.data_get_table(dat, b'test')
print(ssc.data_get_array(table, b'gh'))

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

  • dguittet
More
04 Feb 2021 01:24 - 04 Feb 2021 01:28 #9261 by dguittet
Replied by dguittet on topic question about ssc.data_set_table
Hello Cho,

I was able to reproduce your error using the PySSC from PySAM's most recent release as well as the PySSC distributed from SAM 2017.9.5. Unfortunately, that means it might take some time to dig into where the bug is coming from.

Depending on your workflow, I would suggest using PySAM's PySSC version which allows you to run a compute module such as PVWatts from a Python dictionary:

from PySAM.PySSC import PySSC, ssc_sim_from_dict

ssc = PySSC()
table = ssc.data_create()
ssc.data_set_number(table, b'lat', 37.95)
ssc.data_set_array(table, b'gh', (2.0, ) * 8760)

sim_dict = {'solar_resource_data': table,'array_type': 0.0, 'azimuth': 180.0, 'batt_simple_enable': 0.0, 'dc_ac_ratio': 1.2, 'en_snowloss': 0.0, 'gcr': 0.4, 'inv_eff': 96.0, 'losses': 14.0757, 'module_type': 0.0, 'system_capacity': 4.0, 'tilt': 20.0, 'adjust:constant': 0.0}
sim_dict.update({'tech_model': 'pvwattsv7', 'financial_model': 'None', 'system_capacity': 2.33})

ssc_sim_from_dict(sim_dict) # an error will be thrown because solar_resource_data is not complete

If you really prefer to keep with the old method and want to query the values from the table, here is a work-around:

from PySAM.PySSC import PySSC
import PySAM.Pvwattsv7 as pv

ssc = PySSC()
table = ssc.data_create()
ssc.data_set_number(table, b'lat', 37.95)
ssc.data_set_array(table, b'gh', (2.0, ) * 8760)

dat = ssc.data_create()
ssc.data_set_table(dat, b'solar_resource_data', table)  # must be set to a valid SSC_TABLE/dictionary-type variable, otherwise the wrapping will fail
model = pv.wrap(dat)
print(model.SolarResource.solar_resource_data)


Best,

Darice
Last edit: 04 Feb 2021 01:28 by dguittet.

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

Moderators: Paul Gilman
Powered by Kunena Forum