3

I have a data series (weather radar) that I am trying to plot with basemap in python. Plotting the raw data is easy; I use meshgrid with the lat/lon points, feed these 2-d data arrays into the first two parameters of contourf and put the data matrix (same dimension as the lat/lon) into the third parameter.

My problem; I then want to do some manipulation with the data. I flatten the lat/lon/data arrays, take null values out of all three arrays, and end up feeding the data back into three vectors- lat, lon, and data. While the rows line up (eg, each index of lat/lon line up with that index in the data vector), they are in random order.

I want to feed this back into contourf, but I'm not sure how to unpack the data back into the initial arrays. Is there any way to plot pure lat/lon/data pairs with contourf? If I have the initial 2-d lat/lon meshgrid arrays, what would be the easiest way (using Numpy) to populate a new 2-d array with my data based on the three vectors my algorithm spits out?

eg:

lat = [44.1, 44.3, 44.2]
lon = [-67.2, -67.4, -67.3]
data = [3, 7, 2]

Original lat/lon meshgrid:

lat = [
        [44.1, 44.1, 44.1],
        [44.2,44.2,44.2],
        [44.3,44.3,44.3]
]
lon = [
        [-67.2,-67.3,-67.4],
        [-67.2,-67.3,-67.4],
        [-67.2,-67.3,-67.4]
]

Data that I need to feed into contourf:

data = [
        [3,nan,nan],
        [nan,2,nan],
        [nan,nan,7]
]

Any ideas? This has to be easier than I'm thinking.

WXMan
  • 310
  • 1
  • 12
  • If still needed, can you post some code that plots the contour fine first then the problem after changing? You just looking for `lat, lon = np.meshgrid(lat, lon)` and `data = np.diag(data)`? – Ken Syme Dec 06 '17 at 15:32
  • This gets difficult with really huge datasets. – Felix D. Jun 14 '18 at 17:19

0 Answers0