Skip to content

CEC modules not accessible through database and local csv-file #1632

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

Closed
kimcholi opened this issue Jan 10, 2023 · 6 comments
Closed

CEC modules not accessible through database and local csv-file #1632

kimcholi opened this issue Jan 10, 2023 · 6 comments

Comments

@kimcholi
Copy link

I am currently working with PVlib to do a solar energy estimation of an actual setup. This will be done by comparing the modelled power outputs with the measured power outputs of the system. The module implemented in this PV system are stored in the CEC database and are: Trina Solar TSM-400DE09.08, Trina Solar TSM-395DE09.08. Unfortunately they are not available to access via pvlib.pvsystem.retrieve_sam('CECMod‘) but are listed in the csv-file which I downloaded from https://github.com/NREL/SAM/blob/develop/deploy/libraries/CEC%20Modules.csv

First of all, I am wondering if someone knows why they are available on the local csv-file of CEC module library for Fall 2022 release but not accessible when pvlib.pvsystem.retrieve_sam('CECMod‘) is used. Secondly, I have tried to access the information of the PV modules via cec_modules_local.iloc[14224]. But this also gives me an error as soon as I try to plot the power output of the model, see below. I tried to convert the data frame in order to get the correct type of parameters and data but it did not work. I solved the problem in the end by creating a dataframe with all the parameters from the csv-file via copy & paste basically, which is not the nicest solution.

TypeError                                 Traceback (most recent call last)
Cell In [3], line 1
----> 1 mc_core1_1.run_model(df_tmy) #p_mp is in W, hourly values
      2 mc_core1_2.run_model(df_tmy) 
      3 mc_core2.run_model(df_tmy) 

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/modelchain.py:1809, in ModelChain.run_model(self, weather)
   1806 self.spectral_model()
   1807 self.effective_irradiance_model()
-> 1809 self._run_from_effective_irrad(weather)
   1811 return self

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/modelchain.py:1897, in ModelChain._run_from_effective_irrad(self, data)
   1876 """
   1877 Executes the temperature, DC, losses and AC models.
   1878 
   (...)
   1894 ``diode_params`` (if dc_model is a single diode model).
   1895 """
   1896 self._prepare_temperature(data)
-> 1897 self.dc_model()
   1898 self.dc_ohmic_model()
   1899 self.losses_model()

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/modelchain.py:794, in ModelChain.cec(self)
    793 def cec(self):
--> 794     return self._singlediode(self.system.calcparams_cec)

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/modelchain.py:771, in ModelChain._singlediode(self, calcparams_model_function)
    763 def _make_diode_params(photocurrent, saturation_current,
    764                        resistance_series, resistance_shunt,
    765                        nNsVth):
    766     return pd.DataFrame(
    767         {'I_L': photocurrent, 'I_o': saturation_current,
    768          'R_s': resistance_series, 'R_sh': resistance_shunt,
    769          'nNsVth': nNsVth}
    770     )
--> 771 params = calcparams_model_function(self.results.effective_irradiance,
    772                                    self.results.cell_temperature,
    773                                    unwrap=False)
    774 self.results.diode_params = tuple(itertools.starmap(
    775     _make_diode_params, params))
    776 self.results.dc = tuple(itertools.starmap(
    777     self.system.singlediode, params))

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/pvsystem.py:63, in _unwrap_single_value.<locals>.f(*args, **kwargs)
     60 @functools.wraps(func)
     61 def f(*args, **kwargs):
     62     unwrap = kwargs.pop('unwrap', True)
---> 63     x = func(*args, **kwargs)
     64     if unwrap and len(x) == 1:
     65         return x[0]

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/pvsystem.py:561, in PVSystem.calcparams_cec(self, effective_irradiance, temp_cell)
    552 temp_cell = self._validate_per_array(temp_cell)
    554 build_kwargs = functools.partial(
    555     _build_kwargs,
    556     ['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref',
    557      'R_s', 'alpha_sc', 'Adjust', 'EgRef', 'dEgdT',
    558      'irrad_ref', 'temp_ref']
    559 )
--> 561 return tuple(
    562     calcparams_cec(
    563         effective_irradiance, temp_cell,
    564         **build_kwargs(array.module_parameters)
    565     )
    566     for array, effective_irradiance, temp_cell
    567     in zip(self.arrays, effective_irradiance, temp_cell)
    568 )

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/pvsystem.py:562, in <genexpr>(.0)
    552 temp_cell = self._validate_per_array(temp_cell)
    554 build_kwargs = functools.partial(
    555     _build_kwargs,
    556     ['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref',
    557      'R_s', 'alpha_sc', 'Adjust', 'EgRef', 'dEgdT',
    558      'irrad_ref', 'temp_ref']
    559 )
    561 return tuple(
--> 562     calcparams_cec(
    563         effective_irradiance, temp_cell,
    564         **build_kwargs(array.module_parameters)
    565     )
    566     for array, effective_irradiance, temp_cell
    567     in zip(self.arrays, effective_irradiance, temp_cell)
    568 )

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pvlib/pvsystem.py:2149, in calcparams_cec(effective_irradiance, temp_cell, alpha_sc, a_ref, I_L_ref, I_o_ref, R_sh_ref, R_s, Adjust, EgRef, dEgdT, irrad_ref, temp_ref)
   2044 '''
   2045 Calculates five parameter values for the single diode equation at
   2046 effective irradiance and cell temperature using the CEC
   (...)
   2144 
   2145 '''
   2147 # pass adjusted temperature coefficient to desoto
   2148 return calcparams_desoto(effective_irradiance, temp_cell,
-> 2149                          alpha_sc*(1.0 - Adjust/100),
   2150                          a_ref, I_L_ref, I_o_ref,
   2151                          R_sh_ref, R_s,
   2152                          EgRef=EgRef, dEgdT=dEgdT,
   2153                          irrad_ref=irrad_ref, temp_ref=temp_ref)

TypeError: unsupported operand type(s) for /: 'str' and 'int'

Is someone familiar with this problem and can maybe help me out? Thank you very much, I would appreciate it.

@kandersolar
Copy link
Member

First of all, I am wondering if someone knows why they are available on the local csv-file of CEC module library for Fall 2022 release but not accessible when pvlib.pvsystem.retrieve_sam('CECMod‘) is used.

The retrieve_sam function name is maybe a little misleading; it doesn't go and fetch the latest CSV file from the SAM repository, but rather reads in a local copy of that file that is shipped and installed with pvlib itself. pvlib's copy of those SAM files are somewhat out of date and in need of an update (#1345). In the meantime you can use retrieve_sam with either a filepath of a file that you downloaded from the SAM repository, or you can even pass it the github URL of that file and it will download it too.

But this also gives me an error

Based on the error message (TypeError: unsupported operand type(s) for /: 'str' and 'int'), I'm guessing that the Adjust parameter is accidentally being specified as a string instead of a proper number (float or similar).

@kimcholi
Copy link
Author

Thanks for the explanation.

I tried it with the filepath of a the CEC modules file which I downloaded which unfortunately gave me this error. How can I feed the github URL to retrieve_sam()? I tried retrieve_sam('https://github.com/NREL/SAM/blob/a2c7a4acd465d68f80e9d5ff9f5bb40b13f8130b/deploy/libraries/CEC%20Modules.csv') which gives me the error: ValueError: invalid name https://github.com/nrel/sam/blob/a2c7a4acd465d68f80e9d5ff9f5bb40b13f8130b/deploy/libraries/cec%20modules.csv.
I also tried retrieve_sam(https://github.com/NREL/SAM/blob/a2c7a4acd465d68f80e9d5ff9f5bb40b13f8130b/deploy/libraries/CEC%20Modules.csv) which gives me this error: SyntaxError: invalid decimal literal.

Yes I figured this as well, but even when I download the csv file again and run the code it still gives me the error. I also tried to convert all the parameters which did not help. The best solution which is not very nice looking was to add this to the script:

coop_395 = {'Technology':'Mono-c-Si', 
            'Bifacial':0,
            'STC':395.08,
            'PTC':368.4,
            'A_c':1.91,
            'Length':'NaN',
            'Width':'NaN',
            'N_s':60,
            'I_sc_ref':12.21,
            'V_oc_ref':41,
            'I_mp_ref':11.62,
            'V_mp_ref':34,
            'alpha_sc':0.004029,
            'beta_oc':-0.10906,
            'T_NOCT':44.8,
            'a_ref':1.51294,
            'I_L_ref':12.2126,
            'I_o_ref':2.0705e-11,
            'R_s':0.200014,
            'R_sh_ref':925.102,
            'Adjust':6.66353,
            'gamma_r':-0.357,
            'BIPV':'N',
            'Version':'SAM 2021.12.02',
            'Date':'11/16/2022'}
module_coop_395_man = pd.Series(data=coop_395, index =['Technology','Bifacial','STC','PTC','A_c','Length','Width','N_s','I_sc_ref',
                                                   'V_oc_ref','I_mp_ref','V_mp_ref','alpha_sc','beta_oc','T_NOCT','a_ref',
                                                   'I_L_ref','I_o_ref','R_s','R_sh_ref','Adjust','gamma_r','BIPV','Version',
                                                   'Date'])


@cwhanse
Copy link
Member

cwhanse commented Jan 10, 2023

retrieve_sam takes two arguments. This statement retrieves the file:

pvlib.pvsystem.retrieve_sam(name='cecmod', path='https://github.com/NREL/SAM/blob/patch/deploy/libraries/CEC%20Modules.csv')

@kimcholi
Copy link
Author

kimcholi commented Jan 10, 2023

Thank you very much for explaining how to access it via the link @cwhanse . Unfortunately, this also does not work, I really do not know where the problem is.

If I use the function like this cec_modules = pvlib.pvsystem.retrieve_sam(name = 'cecmod', path='https://github.com/NREL/SAM/blob/patch/deploy/libraries/CEC%20Modules.csv'), I get an error (see below) and it tells me that Trina_Solar_TSM_400DE09_08 is not part of the database basically.
When I look at the csv-file on github and download it, the two modules, I am trying to implement, are listed in the csv-file and I can get the parameters with module_coop_400 = cec_modules_local.iloc[14224], which then are the wrong type and I get an error again. However, if I try to access the two modules via my script, I get the error you see below. And if I execute the following cec_modules.to_csv('cec_modules.csv'), also the two modules are not listed anymore in the csv-file, which I find very confusing. Does someone have an explanation for this?

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pandas/core/indexes/base.py:3803, in Index.get_loc(self, key, method, tolerance)
   3802 try:
-> 3803     return self._engine.get_loc(casted_key)
   3804 except KeyError as err:

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pandas/_libs/index.pyx:138, in pandas._libs.index.IndexEngine.get_loc()

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pandas/_libs/index.pyx:165, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:5745, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:5753, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'Trina_Solar_TSM_400DE09_08'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In [4], line 55
     50 inverter_ksat_1 = cec_inverters['SMA_America__SB5_0_1SP_US_40__240V_']
     51 #inverter_ksat_2 = cec_inverters['']
     52 
     53 #Coop
     54 #module_coop_400 = cec_modules_local.iloc[14224] #building
---> 55 module_coop_400 = cec_modules['Trina_Solar_TSM_400DE09_08'] #building
     57 #module_coop_395 = cec_modules_local.iloc[14207] #roof
     58 #module_coop_400 = cec_modules['Trina Solar TSM-395DE09.08'] #building
     60 inverter_coop_1 = cec_inverters['SMA_America__STP50_US_40__480V_']

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pandas/core/frame.py:3804, in DataFrame.__getitem__(self, key)
   3802 if self.columns.nlevels > 1:
   3803     return self._getitem_multilevel(key)
-> 3804 indexer = self.columns.get_loc(key)
   3805 if is_integer(indexer):
   3806     indexer = [indexer]

File /opt/anaconda3/envs/pvlib/lib/python3.10/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key, method, tolerance)
   3803     return self._engine.get_loc(casted_key)
   3804 except KeyError as err:
-> 3805     raise KeyError(key) from err
   3806 except TypeError:
   3807     # If we have a listlike key, _check_indexing_error will raise
   3808     #  InvalidIndexError. Otherwise we fall through and re-raise
   3809     #  the TypeError.
   3810     self._check_indexing_error(key)

KeyError: 'Trina_Solar_TSM_400DE09_08'

@cwhanse
Copy link
Member

cwhanse commented Jan 10, 2023

@kimcholi I was mistaken. Leave the 'name' argument out.

cecmods = pvlib.pvsystem.retrieve_sam(path='https://raw.githubusercontent.com/NREL/SAM/patch/deploy/libraries/CEC%20Modules.csv')

then cecmods['Trina_Solar_TSM_400DE09_08'] exists.

@pvlib/pvlib-core this is not optimal behavior. If name is not None then pvlib direct to its own files, even when path is specified. If path is specified alone, it works but (as a user) I'm expecting pvlib to be confused as to what I asked it to read (modules or inverters).

@kimcholi
Copy link
Author

Great, it worked @cwhanse. Thank you for your very quick work and help!

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

No branches or pull requests

3 participants