0

I have data that has wind speed/direction for 16 different height levels. This data is recorded in 1 minute intervals. I am attempting to create a 2-d chart that has the height levels on the y-axis and time on the x-axis.

00:00, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet
00:01, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 
00:02, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet  
...
23:58, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 
23:59, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 

From this data, I have isolated the wind speed and direction into 2 (1440,16) arrays, one for u-component and one for v-component. I also, have time_list which is just a list with 1440 elements and my level_heights which is a 1-d array of 16 elements.

Put them together to plot:

...
ax.barbs([time_list,level_heights],u,v)
...

I get the following error:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I am not sure what is going on or how to resolve.

Jonathon
  • 251
  • 1
  • 7
  • 20

1 Answers1

1

If you really want to display all 1440 times, you will have 1440 x 16 data points, so all the variables you pass to ax.barbs() should have these dimensions.

Edit: I got it to work with your sample data using this shortcut mentioned in the ax.barbs() documentation:

X, Y: [...] If not given, they will be generated as a uniform integer meshgrid based on the dimensions of U and V.

import numpy as np
import matplotlib.pyplot as plt

level_heights = [720, 700]
u = np.array([[ 36.10376018, -3.65789061], [ 35.96327862, -45.10811509]]) 
v = np.array([[ 36.58522244, -51.57043568], [ 36.44286749, -24.64179281]])

fig, ax = plt.subplots()
ax.barbs(u, v)

ax.set_xticks([0, 1])
ax.set_xticklabels(['start', '1 minute'])

ax.set_yticks([0, 1])
ax.set_yticklabels(level_heights);

wind plot

You may want to reverse the order of level_heights to make the plot more natural.

Arne
  • 9,990
  • 2
  • 18
  • 28
  • But I am only plotting wind on 16 levels and my data only is 1 minute winds for each level. Nothing in between. How would I expand that to a list of length 1440? – Jonathon May 08 '20 at 13:02
  • @Jonathon Impossible to say for sure without seeing the data, but presumably you could do it in the same way you got the `time_list`? – Arne May 08 '20 at 13:12
  • I have updated my question to include a sample of what my actual data source looks like. – Jonathon May 08 '20 at 13:24
  • @Jonathon Thanks, that helped me to understand the problem. I have edited my answer. – Arne May 08 '20 at 13:53
  • Could you copy+paste small data samples of the variables actually used in the function call into your question? E.g. `time_list[:2]`, `level_heights[:2]`, `u[:2, :2]` and `v[:2, :2]`. – Arne May 08 '20 at 14:02
  • In order: ```[datetime.datetime(1900, 1, 1, 0, 0), datetime.datetime(1900, 1, 1, 0, 1)] [720, 700] [[ 36.10376018 -3.65789061] [ 35.96327862 -45.10811509]] [[ 36.58522244 -51.57043568] [ 36.44286749 -24.64179281]]``` – Jonathon May 08 '20 at 14:05
  • Ignore the datetime format. It is actually in my data as $H:$M:$S. I simplified it for the question above. – Jonathon May 08 '20 at 14:07
  • I just realised we don't need to bother with passing the dates and heights to the plotting function. See my updated answer. – Arne May 08 '20 at 14:37