Skip to content
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

Cast array to float before computation #179

Open
ppinchuk opened this issue Aug 5, 2024 · 0 comments
Open

Cast array to float before computation #179

ppinchuk opened this issue Aug 5, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ppinchuk
Copy link
Collaborator

ppinchuk commented Aug 5, 2024

We should cast to numpy float to avoid the following error:

In [8]: spa_test.azimuth()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
AttributeError: 'numpy.float64' object has no attribute 'radians'

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

TypeError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 spa_test.azimuth()

File ~/miniconda3/envs/py312/lib/python3.12/site-packages/rex/utilities/solar_position.py:405, in SolarPosition.azimuth(self)
    395 @property
    396 def azimuth(self):
    397     """
    398     Solar azimuth angle
    399
   (...)
    403         Solar azimuth angle in degrees
    404     """
--> 405     azimuth = self._azimuth(self.time_index, self.latitude, self.longitude)
    407     return self._format_output(azimuth)

File ~/miniconda3/envs/py312/lib/python3.12/site-packages/rex/utilities/solar_position.py:316, in SolarPosition._azimuth(time_index, lat, lon)
    314 n, zulu = SolarPosition._parse_time(time_index)
    315 ra, dec = SolarPosition._calc_sun_pos(n)
--> 316 ha = SolarPosition._calc_hour_angle(n, zulu, ra, lon)
    317 azimuth = SolarPosition._calc_azimuth(dec, ha, lat)
    318 return azimuth

File ~/miniconda3/envs/py312/lib/python3.12/site-packages/rex/utilities/solar_position.py:175, in SolarPosition._calc_hour_angle(n, zulu, ra, lon)
    173 gmst = (6.697375 + 0.06570982441908 * n + 1.00273790935 * zulu) * 15
    174 # Local mean sidereal time in radians
--> 175 lmst = np.radians(np.remainder(gmst + lon, 360))
    176 # Hour angle in radians
    177 ha = lmst - ra

TypeError: loop of ufunc does not support argument 0 of type numpy.float64 which has no callable radians method

Error produced with pandas = 2.2.2, numpy = 1.26.4.

spa_test = spa.SolarPosition(sam_df['datetime'].values, sites.iloc[0, 1:3].values)

Fixed with spa_test = spa.SolarPosition(sam_df['datetime'].values, sites.iloc[0, 1:3].values.astype('float64'))

ALSO!
Azimuth calculation implementation is bugged. Missing these lines from the SAM code:
https://github.com/NREL/ssc/blob/20cc2e75b0f5b77aacc9ae3200a327dfe54abf92/shared/lib_irradproc.cpp#L181-L184

This can be fixed on the user side by:

test_ar = np.array((((ha <= 0.0) & (ha >= -np.pi), (ha >= np.pi))))

azm_adj = np.where(np.any(test_ar, axis=0), np.pi - azm, np.pi + azm)

But this should be fixed in the code instead (and add tests for this calculation!)

@ppinchuk ppinchuk added the bug Something isn't working label Aug 5, 2024
@ppinchuk ppinchuk self-assigned this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant