matplotlib / matplotlib/basemap

Wind vector rotation troubles (rotate_vector)

Đang mở
#269 13 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
817
Fork
395
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I am currently working with a gridded data set that has its wind vectors already in an earth-relative frame. When looking to rotate the wind vectors appropriately for plotting on a Basemap projection I've run into a strange problem where the vectors, quite simply, look rather odd. I ran a few tests with simple test points to make sure the `rotate_vector` routine appeared to be working correctly, and it seemed fine. But when I run a whole model output grid through the `rotate_vector` routine, it seems to produce wind fields which don't look quite right (see below).

![windrotation](https://cloud.githubusercontent.com/assets/8594627/13229985/835d93e0-d971-11e5-9d16-f06c7b4e0042.png)

Here are some stats associated with the point that has the red star on the plot with the title 'Rotated vectors'

```
Lat and Lon: 39.11, -70.0144

Original U and V: 1.30, 7.14
Rotated U and V: -1.33 , 7.13
```

Now note how the rotated wind at this point is aligned along the -70 meridian, which would suggest that in earth relative terms we might expect the wind components to be more along the lines of u=0 and v=7. However, judging from above that's certainly not the case.

Now, if I rotate that same vector, _by itself_, I get the following rotated wind:

`Rotated U and V: -0.03 7.26`

And see the second plot for a visual:

![windrotation_1pt](https://cloud.githubusercontent.com/assets/8594627/13230022/c1508f9a-d971-11e5-83c4-3b92c3878a57.png)

It would seem desirable to have the same behavior for the single point that we have for the gridded set of winds.

The only thing special about the gridded data, that I have noticed, is that the latitudes can vary in a non-standard way with increasing x dimension, west to east (e.g. 35.5N, 34.2N, 33.1N, 36.2N, etc.). It wasn't clear if this was okay within `rotate_vector`. In some simple tests it didn't seem to be a problem.

It would be nice to be able to use this routine for not only a set of gridded data, but observations as well. It's worth noting that observations wouldn't necessarily be ordered in a nice, regular way given the nature that observations tend to be irregularly spaced (e.g. surface stations co-located with airports).

Unfortunately I don't have any suggestions for a solution, but am hopeful others may have an idea.

Below is the snippet of code used to generate the first plot above.

Thanks!
Jacob

```
import nemsio
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

# Get the input file
f='restart_file'
nio=nemsio.nemsfile(f)

skip=25
u10=u[::skip,::skip,0]
v10=v[::skip,::skip,0]
lats=nio.lats[::skip,::skip]
lons=nio.lons[::skip,::skip]

# Create the figure
fig=plt.figure(figsize=(18, 6))

# Domain covers NE CONUS
llcrnrlon=-84.0
llcrnrlat=35.0
urcrnrlon=-60.0
urcrnrlat=49.0
res='l'

m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat,urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat,\
rsphere=(6378137.00,6356752.3142),\
resolution=res,projection='lcc',\
lat_1=25.0,lon_0=-95.0)

#The vector rotation to the Basemap projection just specified
u10_rot, v10_rot, x, y = m.rotate_vector(u10, v10, lons, lats, returnxy=True)

parallels = np.arange(-80.,90,5.)
meridians = np.arange(0.,360.,5.)

# - First sublot is without rotation
ax = fig.add_subplot(121)
ax.set_title('Without rotation')

m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='#cc9955', lake_color='aqua', zorder = 0)
m.drawcoastlines(color = '0.15')

m.drawparallels(parallels)
m.drawmeridians(meridians)

m.barbs(x, y, u10, v10, pivot='middle', barbcolor='black',zorder=10)

# - Second subplot is with rotation

ax = fig.add_subplot(122)
ax.set_title('Rotated vectors')

m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='#cc9955', lake_color='aqua', zorder = 0)
m.drawcoastlines(color = '0.15')
m.drawparallels(parallels)
m.drawmeridians(meridians)
m.barbs(x, y, u10_rot, v10_rot,
pivot='middle', barbcolor='black',zorder=10)

m.scatter(-70.0144,39.11,s=175,color='red',marker='*',latlon=True)
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ Basemap được cung cấp và so sánh các kết quả của m.rotate_vector cho điểm đơn và các mảng lưới được cắt. Điều tra cách routine xử lý lưới vĩ độ hai chiều không theo chuẩn và các tọa độ quan sát không đều; được xem là hoàn tất khi hành vi xoay nhất quán hoặc các ràng buộc tọa độ được hỗ trợ đã được xác lập rõ ràng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
matplotlib, python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.