本文整理汇总了Python中mpl_toolkits.basemap.Basemap.shiftdata方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.shiftdata方法的具体用法?Python Basemap.shiftdata怎么用?Python Basemap.shiftdata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.shiftdata方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_less_than_n_by_3_points_should_work
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def test_less_than_n_by_3_points_should_work(self):
bm = Basemap(llcrnrlon=0, llcrnrlat=-80, urcrnrlon=360, urcrnrlat=80, projection='mill')
lons_expected = self._get_2d_lons([10, 15, 20])
# nothing should change
lonsout = bm.shiftdata(lons_expected)
assert_almost_equal(lons_expected, lonsout)
# shift n x 3 and n x 2 grids and compare results over overlapping region
lonsin = self._get_2d_lons([10, 361, 362])
lonsout_expected = bm.shiftdata(lonsin[:])[:, :2]
lonsout = bm.shiftdata(lonsin[:, :2])
assert_almost_equal(lonsout_expected, lonsout)
示例2: test_2_points_should_work
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def test_2_points_should_work(self):
"""
Shiftdata should work with 2 points
"""
bm = Basemap(llcrnrlon=0, llcrnrlat=-80, urcrnrlon=360, urcrnrlat=80, projection='mill')
lons_expected = [10, 15, 20]
lonsout = bm.shiftdata(lons_expected[:])
assert_almost_equal(lons_expected, lonsout)
lonsout_expected = bm.shiftdata([10, 361, 362])
lonsout = bm.shiftdata([10, 361])
assert_almost_equal(lonsout_expected[:len(lonsout)], lonsout)
示例3: test_1_point_should_work
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def test_1_point_should_work(self):
bm = Basemap(llcrnrlon=0, llcrnrlat=-80, urcrnrlon=360, urcrnrlat=80, projection='mill')
# should not fail
lonsout = bm.shiftdata([361])
assert_almost_equal(lonsout, [1.0,])
lonsout = bm.shiftdata([10])
assert_almost_equal(lonsout, [10.0,])
lonsin = np.array([361.0])
lonsin.shape = (1, 1)
lonsout = bm.shiftdata(lonsin[:])
assert_almost_equal(lonsout.squeeze(), [1.0,])
示例4: test_shiftdata_on_monotonous_lons
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def test_shiftdata_on_monotonous_lons(self):
"""
Test that shiftdata with fix_wrap_around keyword added works as before,
when it is True
"""
bm = Basemap(lon_0=0)
lons_in = [120, 140, 160, 180, 200, 220]
lons_out_expect = [-160, -140, 120, 140, 160, 180]
lons_out = bm.shiftdata(lons_in, fix_wrap_around=True)
assert_almost_equal(lons_out, lons_out_expect)
示例5: test_non_monotonous_longitudes
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def test_non_monotonous_longitudes(self):
"""
when called for scatter, the longitudes passed to shiftdata are
not necessarily monotonous...
"""
lons = [179, 180, 180, 0, 290, 10, 320, -150, 350, -250, 250]
bm = Basemap(lon_0=0)
# before, having several break points would cause the exception,
# inside the shiftdata method called from scatter method.
self.assertRaises(ValueError, bm.shiftdata, lons, fix_wrap_around=True)
lons_new = bm.shiftdata(lons, fix_wrap_around=False)
# Check if the modified longitudes are inside of the projection region
for lon in lons_new:
assert lon >= bm.projparams["lon_0"] - 180
assert lon <= bm.projparams["lon_0"] + 180
示例6: Basemap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
map = Basemap(projection='sinu',
lat_0=0, lon_0=0)
lons = np.arange(30, 390, 30)
lats = np.arange(0, 100, 10)
data = np.indices((lats.shape[0], lons.shape[0]))
data = data[0] + data[1]
print data
print lons
lons, data = map.shiftdata(lons, datain = data, lon_0=0)
print lons
llons, llats = np.meshgrid(lons, lats)
x, y = map(llons, llats)
map.contourf(x, y, data)
map.drawcoastlines()
plt.show()
示例7: main
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
def main():
erainterim_075_folder = "/HOME/data/Validation/ERA-Interim_0.75/Offline_driving_data/3h_Forecast"
vname = "PR"
start_year = 1980
end_year = 2010
season_key = "summer"
season_labels = {season_key: "Summer"}
season_to_months = OrderedDict([(season_key, [6, 7, 8])])
# Validate temperature and precip
model_vars = ["TT", "PR"]
obs_vars = ["tmp", "pre"]
obs_paths = [
"/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.tmp.dat.nc",
"/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.pre.dat.nc",
]
model_var_to_obs_var = dict(zip(model_vars, obs_vars))
model_var_to_obs_path = dict(zip(model_vars, obs_paths))
obs_path = model_var_to_obs_path[vname]
cru = CRUDataManager(var_name=model_var_to_obs_var[vname], path=obs_path)
# Calculate seasonal means for CRU
seasonal_clim_fields_cru = cru.get_seasonal_means(
season_name_to_months=season_to_months, start_year=start_year, end_year=end_year
)
# Calculate seasonal mean for erai
flist = get_files_for_season(
erainterim_075_folder, start_year=start_year, end_year=end_year, months=season_to_months[season_key]
)
rpf = MultiRPN(flist)
date_to_field_erai075 = rpf.get_all_time_records_for_name_and_level(varname=vname, level=-1)
# Convert to mm/day
era075 = np.mean([field for field in date_to_field_erai075.values()], axis=0) * 24 * 3600 * 1000
lons_era, lats_era = rpf.get_longitudes_and_latitudes_of_the_last_read_rec()
seasonal_clim_fields_cru_interp = OrderedDict()
# Calculate biases
for season, cru_field in seasonal_clim_fields_cru.items():
seasonal_clim_fields_cru_interp[season] = cru.interpolate_data_to(
cru_field, lons2d=lons_era, lats2d=lats_era, nneighbours=1
)
# Do the plotting ------------------------------------------------------------------------------
plot_utils.apply_plot_params()
fig = plt.figure()
b = Basemap()
gs = gridspec.GridSpec(nrows=3, ncols=1)
ax = fig.add_subplot(gs[0, 0])
xx, yy = b(cru.lons2d, cru.lats2d)
cs = b.contourf(xx, yy, seasonal_clim_fields_cru[season_key], 20)
b.drawcoastlines(ax=ax)
ax.set_title("CRU")
plt.colorbar(cs, ax=ax)
ax = fig.add_subplot(gs[1, 0])
lons_era[lons_era > 180] -= 360
lons_era, era075 = b.shiftdata(lons_era, datain=era075, lon_0=0)
xx, yy = b(lons_era, lats_era)
# mask oceans in the era plot as well
era075 = maskoceans(lons_era, lats_era, era075)
cs = b.contourf(xx, yy, era075, levels=cs.levels, norm=cs.norm, cmap=cs.cmap, ax=ax)
b.drawcoastlines(ax=ax)
ax.set_title("ERA-Interim 0.75")
plt.colorbar(cs, ax=ax)
# differences
ax = fig.add_subplot(gs[2, 0])
diff = era075 - seasonal_clim_fields_cru_interp[season_key]
delta = np.percentile(np.abs(diff)[~diff.mask], 90)
clevs = np.linspace(-delta, delta, 20)
cs = b.contourf(xx, yy, diff, levels=clevs, cmap="RdBu_r", extend="both")
b.drawcoastlines(ax=ax)
ax.set_title("ERA-Interim 0.75 - CRU")
plt.colorbar(cs, ax=ax)
plt.show()
fig.savefig(os.path.join(img_folder, "erai0.75_vs_cru_precip.png"), bbox_inches="tight")
示例8: Basemap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import shiftdata [as 别名]
# convert the sliced data to a pandas dataframe
df = hur_lev.to_dataframe()
# this is a simple way to rotate the coordinates of longitudes from 0-360 to -180-180
new_lons = ((ds.lon.data + 180) % 360) - 180
lons_greenwich = ((lons_pacific + 180) % 360) - 180
# see also:
# basemap shiftdata
from mpl_toolkits.basemap import Basemap, addcyclic, shiftgrid
m = Basemap( epsg=4326 )
new_arr = np.rollaxis( hur_lev.values.T, -1 )
test = m.shiftdata( xds.lon.data, hur_lev.values[1,...][:].T, lon_0=0.0 )
llons, llats = np.meshgrid( test[0], ds.lat.data )
x, y = m(llons, llats)
# m.contourf(x, y, test[1])
# m.drawcoastlines()
m.imshow( test[1] )
plt.savefig('test.png')
scp [email protected]:/home/malindgren/Documents/hur/test.png ~/Documents
# from frank
gdalwarp -multi -overwrite -of NetCDF -t_srs WGS84 hur_Amon_GFDL-CM3_historical_r1i1p1_186001-186412.nc test.nc -wo SOURCE_EXTRA=1000 -wo NUM_THREADS=ALL_CPUS --config CENTER_LONG 0
# test file