更改底图投影会导致数据消失 [英] Changing Basemap projection causes data to disappear

查看:85
本文介绍了更改底图投影会导致数据消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恰如标题所述. 我正在绘制海冰浓度数据和以下代码:

Exactly as the title says. I'm plotting sea ice concentration data and this code:

map = Basemap(projection='cyl', lat_0 = lat_0, lon_0 = lon_0,
          llcrnrlon = llcrnrlon, llcrnrlat = llcrnrlat,
          urcrnrlat = urcrnrlat, urcrnrlon = urcrnrlon,
          area_thresh = 1000., resolution='l')

工作正常. http://i.imgur.com/8i36gn0.png

但是当我尝试更改投影时:

But when I try to change the projection:

map = Basemap(projection='npstere',boundinglat=10,lon_0=270,resolution='l')

我刚得到一张空白地图. http://i.imgur.com/5TazZdC.png

I just get a blank map. http://i.imgur.com/5TazZdC.png

我是否忘记了底图?我虽然更改投影非常简单.

Am I forgetting something about basemap? I though changing the projection was pretty simple.

这是完整的代码

import numpy as np
import math as m
import urllib2
import time
import datetime
import matplotlib.pyplot as plt
import matplotlib.patheffects as path_effects
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.basemap import Basemap
from pydap.client import open_url
from pydap.proxy import ArrayProxy
import scipy
from scipy.ndimage.filters import minimum_filter, maximum_filter

data_url_ice = 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/noaa.oisst.v2.highres/icec.day.mean.2015.v2.nc'

dataset3 = open_url(data_url_ice)

#############################################################################################
# Get Data
#############################################################################################

# Daily Mean Ice Concentration

Lat_ice = dataset3['lat']
Lon_ice = dataset3['lon']
Time_ice = dataset3['time']
Ice_Conc = dataset3['icec']
Ice_Conc = Ice_Conc[-1,:,:]
Ice_Conc = Ice_Conc.array[:]

Ice_Conc[Ice_Conc < 0] = 0
Ice_Conc = Ice_Conc * 100.

Ice_Conc = Ice_Conc.squeeze()

#############################################################################################
# Colormap
#############################################################################################

vmax_ice = 100.0
cmap_ice = LinearSegmentedColormap.from_list('mycmap', [(0     / vmax_ice, 'white'),    #-40
                                                         (50.   / vmax_ice, 'yellow'), #-20
                                                         (100.   / vmax_ice, 'blue')]    # 20
                                              )

#############################################################################################
# Map Projection Info
#############################################################################################

lat_0 = 0
lon_0 = 0

llcrnrlat = -90. # (1,1)
llcrnrlon = 0. # (1,1)

urcrnrlat = 90. # (720,361)
urcrnrlon = 359. # (720,361)

# Daily Mean Ice Concentration

fig = plt.figure(figsize=(14,14))
ax = fig.add_subplot(1,1,1)
#map = Basemap(projection='ortho', lat_0 = 50, lon_0 = -105,
#              area_thresh = 1000., resolution='i')

map = Basemap(projection='npstere',boundinglat=10,lon_0=270,resolution='l')

#map = Basemap(projection='cyl', lat_0 = lat_0, lon_0 = lon_0,
#              llcrnrlon = llcrnrlon, llcrnrlat = llcrnrlat,
#              urcrnrlat = urcrnrlat, urcrnrlon = urcrnrlon,
#              area_thresh = 1000., resolution='l')

map.drawcoastlines()
map.drawcountries()
map.drawmapboundary()
map.fillcontinents(color='white')

levels = np.linspace(0,100,100)
ticks = [0,10,20,30,40,50,60,70,80,90,100]
iceconc = plt.contourf(Lon_ice,Lat_ice,Ice_Conc,levels,cmap=cmap_ice)

# Set Colorbar Text Color
color_bar = map.colorbar(iceconc)
color_bar.set_ticks(ticks)
cbytick_obj = plt.getp(color_bar.ax.axes, 'yticklabels')
plt.setp(cbytick_obj, color='w')

ax.text(0,1.02,'Sea Ice Concentration (%)\n\n',
        verticalalignment='bottom', horizontalalignment='left',
        transform=ax.transAxes, color='w', fontsize=9).set_clip_on(False)
ax.text(0,1.02,'Satellite Measured Daily Mean\n',
        verticalalignment='bottom', horizontalalignment='left',
        transform=ax.transAxes, color='w', fontsize=9).set_clip_on(False)        

plt.savefig('/home/ice_current.png', facecolor='#3e3e3e', bbox_inches='tight')
plt.close("all")

推荐答案

我认为您忘记了最简单的一行,但是您并未显示大多数代码,因此很难猜测. 即

I think you're forgetting the simplest line, however you haven't shown most of your code so it's hard to guess. i.e.

map = Basemap(projection='cyl', lat_0 = lat_0, lon_0 = lon_0,
          llcrnrlon = llcrnrlon, llcrnrlat = llcrnrlat,
          urcrnrlat = urcrnrlat, urcrnrlon = urcrnrlon,
          area_thresh = 1000., resolution='l')

#valid aproximate coordinates for some map projections
lat = [19.2325]
lon = [-155.3395]

#but the actual map coordinates are
x,y = map(lat, lon)
map.plot(x, y, 'ro', markersize=6)

我相信您的数据仍然存在,但是尚未转换为正确的地图坐标.请注意,在示例中他们如何使用m,在您的示例中,您的Basemap实例被命名为map,因此请使用它.我认为他们做到这一点很酷.

I believe your data is still there, but hasn't been converted to proper map coordinates. Notice how in the example they use m, your instance of Basemap is named map in your example so use that. I think it's pretty cool how they did that.

这篇关于更改底图投影会导致数据消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆