Repository navigation
Closed
Description
Describe the bug
Hi, I'm trying to run a ModelChain model using a weather file obtained through get_pvgis_tmy() function. However I am getting an error with the weather data
To Reproduce
Steps to reproduce the behavior:
weather, months, inputs, metadata = pvlib.iotools.get_pvgis_tmy(latitude, longitude, outputformat='epw', coerce_year=2023)
system_loss = 0.1
times = weather.index
solar_position = pvlib.solarposition.get_solarposition(times, latitude, longitude)
system = pvlib.pvsystem.PVSystem(
surface_tilt=30,
surface_azimuth=150,
module_parameters=sandia_modules["Canadian_Solar_CS6X_300M__2013_"],
inverter_parameters=cec_inverters["ABB__MICRO_0_25_I_OUTD_US_208__208V_"],
temperature_model_parameters=pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS["sapm"]["open_rack_glass_glass"],
)
mc = pvlib.modelchain.ModelChain(system, location=location)
mc.prepare_inputs(weather)
Error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'radians'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In[6], line 23
21 mc = pvlib.modelchain.ModelChain(system, location=location)
22 print(mc)
---> 23 mc.prepare_inputs(weather)
24 # # mc.run_model(weather)
25
26 # ac_power = mc.ac * (1 - system_loss)
27 # dc_power = mc.dc['p_mp'] # Maximum power point (Pmp)
28
29 # print(dc_power)
File ~/.local/share/virtualenvs/Lowfield-Green-CSxyL99o/lib/python3.10/site-packages/pvlib/modelchain.py:1424, in ModelChain.prepare_inputs(self, weather)
1421 self._assign_weather(weather)
1423 self._prep_inputs_solar_pos(weather)
-> 1424 self._prep_inputs_airmass()
1425 self._prep_inputs_albedo(weather)
1426 self._prep_inputs_fixed()
File ~/.local/share/virtualenvs/Lowfield-Green-CSxyL99o/lib/python3.10/site-packages/pvlib/modelchain.py:1255, in ModelChain._prep_inputs_airmass(self)
1251 def _prep_inputs_airmass(self):
1252 """
1253 Assign airmass
1254 """
-> 1255 self.results.airmass = self.location.get_airmass(
1256 solar_position=self.results.solar_position,
1257 model=self.airmass_model)
1258 return self
File ~/.local/share/virtualenvs/Lowfield-Green-CSxyL99o/lib/python3.10/site-packages/pvlib/location.py:319, in Location.get_airmass(self, times, solar_position, model)
316 else:
317 raise ValueError(f'{model} is not a valid airmass model')
--> 319 airmass_relative = atmosphere.get_relative_airmass(zenith, model)
321 pressure = atmosphere.alt2pres(self.altitude)
322 airmass_absolute = atmosphere.get_absolute_airmass(airmass_relative,
323 pressure)
File ~/.local/share/virtualenvs/Lowfield-Green-CSxyL99o/lib/python3.10/site-packages/pvlib/atmosphere.py:219, in get_relative_airmass(zenith, model)
217 # set zenith values greater than 90 to nans
218 z = np.where(zenith > 90, np.nan, zenith)
--> 219 zenith_rad = np.radians(z)
221 model = model.lower()
223 if 'kastenyoung1989' == model:
TypeError: loop of ufunc does not support argument 0 of type float which has no callable radians method
Would anyone know if there's something wrong with the code or if it's a bug? Thank you!!
Activity
[-]Error with using weather file (zenith conversion in airmass?)[/-][+]Error with using PVGIS weather data (zenith conversion in airmass?)[/+]cwhanse commentedon Feb 25, 2025
The error tells you that
zenithis a single value, withfloattype. Somehow you aren't getting a time series of weather data. What doestimeslook like?cwhanse commentedon Feb 25, 2025
@expeon07 happy to help you diagnose this problem here. For questions like "is there something wrong" we prefer a post to the pvlib-python google group, or stackoverflow. If we find a bug, then a GH issue is welcome.
expeon07 commentedon Feb 25, 2025
times is a DateTimeIndex in UTC
Thanks for the info about where to post questions! Can also transfer this question on stackoverflow if it takes long
cwhanse commentedon Feb 25, 2025
Let's do that. Please link your SO post here.
expeon07 commentedon Feb 25, 2025
Sure, question is still on staging-ground. But it has the same title. Will update later when it gets published.
Thank you!!
expeon07 commentedon Feb 28, 2025
Hi @cwhanse, here is the SO post: https://stackoverflow.com/questions/79470682/error-with-using-pvgis-weather-data-zenith-conversion-in-airmass
Thank you!
kandersolar commentedon Mar 3, 2025
There's a workaround posted at the SO question.
The problem, which is probably something to fix on our side, is that
get_pvgis_tmy(..., outputformat='epw')is returning columns with dtypeobjectinstead offloat64. See:vs
AdamRJensen commentedon Mar 3, 2025
Personally, I see no reason we should support different download options (
outputformat) for theget_pvgis_tmyorget_pvgis_hourlyfunctions. It's the same data but with a lot more maintenance and some quite complicated code behind the scenes.I suggest that we make the two PVGIS get functions simply use the
outputformat=jsonbehind the scenes.I would also be in favor of removing the option of the PVGIS read functions being able to read EPW files as this can be done using the dedicated
pvlib.iotools.read_epwfunction.kandersolar commentedon Mar 3, 2025
Which format option to use should be at least partially informed by the data that PVGIS returns for each of them. Some formats don't include all columns. But I don't know about
jsonspecifically.AdamRJensen commentedon Mar 22, 2025
This seems to be an undesirable effect of the
pvlib.iotools._coerce_and_roll_tmyfunction which is applied whencoerce_yearis specified. As an example, whenoutputformat='epw'andcoerce_yearis not specified then the DataFrame has the correct dtypes:The reason that
outputformat='epw'is the only format type that is affected, is that it has a non-float column called 'data_source_unct'.