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

ValueError: operands could not be broadcast together with shapes (5,) (10,) #81

Open
WieFel opened this issue Sep 19, 2024 · 1 comment

Comments

@WieFel
Copy link

WieFel commented Sep 19, 2024

Describe the bug
Hi, I am trying to use the pm_fao56 function to calculate the PET, but I am always getting the following error:

...
Cell In[41], [line 13](vscode-notebook-cell:?execution_count=41&line=13)
     [10] lat = 48.32829 * np.pi / 180  # Latitude of the meteorological station, converting from degrees to radians
     [11] elevation = 180  # meters above sea-level
---> [13] pet_df = pyet.pm_fao56(tmean, wind, rs=rs, elevation=elevation, lat=lat, rh=rh)
     [14] return pet_df

File .venv/lib/python3.11/site-packages/pyet/combination.py:626, in pm_fao56(tmean, wind, rs, rn, g, tmax, tmin, rhmax, rhmin, rh, pressure, elevation, lat, n, nn, rso, a, b, ea, albedo, kab, as1, bs1, clip_zero)
    [622] pressure, gamma, dlt, lambd, ea, es = _lambda_gamma_dlt_ea_es(
    [623]     elevation, pressure, tmean, tmax, tmin, rhmax, rhmin, rh, ea
    [624] )
    [625] gamma1 = gamma * (1 + 0.34 * wind)
--> [626] rn = calc_rad_net(
    [627]     tmean,
    [628]     rn,
    [629]     rs,
    [630]     lat,
    [631]     n,
    [632]     nn,
    [633]     tmax,
...
File .venv/lib/python3.11/site-packages/pandas/core/roperator.py:15, in rsub(left, right)
     [14] def rsub(left, right):
---> [15]     return right - left

ValueError: operands could not be broadcast together with shapes (5,) (10,)

Additionally, I am always seeing the following warning. I am not passing any timestamp into the pm_fao56 function. So I wonder where this warning can come from.

pyrealm/rad_utils.py:210: RuntimeWarning: '<' not supported between instances of 'Timestamp' and 'int', sort order is undefined for incomparable objects.

To Reproduce
Steps to reproduce the behavior:

  1. Use the following code:
import pyet

meteo = pd.DataFrame({'tmean': [27.1 , 27.16, 27.22, 27.28, 27.34], 'rh': [42. , 41.6, 41.2, 40.8, 40.4], 'wind': [1.876, 1.876, 1.876, 1.876, 1.876], 'rs': [ 8.52768 , 10.062144, 11.596608, 13.131072, 14.665536]})
print(meteo)
tmean, rh, wind, rs = [meteo[col] for col in meteo.columns]

lat = 48.32829 * np.pi / 180  # Latitude of the meteorological station, converting from degrees to radians
elevation = 180  # meters above sea-level

pet_df = pyet.pm_fao56(tmean, wind, rs=rs, elevation=elevation, lat=lat, rh=rh)

where the meteo dataframe looks like this:

   tmean    rh   wind         rs
0  27.10  42.0  1.876   8.527680
1  27.16  41.6  1.876  10.062144
2  27.22  41.2  1.876  11.596608
3  27.28  40.8  1.876  13.131072
4  27.34  40.4  1.876  14.665536
  1. See the error output

Expected behavior
The calculation should be executed without an error.

Additional context
Using Python 3.11.6 and pyet version 1.3.1

@WieFel
Copy link
Author

WieFel commented Sep 23, 2024

I tried to find the issue in the source code, and came to the point that in the function calc_rad_long

solar_rat = clip(rs / rso, 0.3, 1)

the dataframe in rso is containing a datetime index, and that is apparently causing the shape of rs / rso to be 2x the expected shape. Both, the shapes of rs and rso are (5,).

rs looks like this:

0    0.0
1    0.0
2    0.0
3    0.0
4    0.0

rso looks like this:

1970-01-01 00:00:00.000000000    6.58243
1970-01-01 00:00:00.000000001    6.58243
1970-01-01 00:00:00.000000002    6.58243
1970-01-01 00:00:00.000000003    6.58243
1970-01-01 00:00:00.000000004    6.58243

However, the resulting shape of rs / rso is (10,).

Changing rs / rso to rs.values / rso.values solves the problem. But I am asking myself if that is the desired solution!?

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

1 participant