本文整理匯總了Python中cartopy.crs.Orthographic方法的典型用法代碼示例。如果您正苦於以下問題:Python crs.Orthographic方法的具體用法?Python crs.Orthographic怎麽用?Python crs.Orthographic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cartopy.crs
的用法示例。
在下文中一共展示了crs.Orthographic方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_extend
# 需要導入模塊: from cartopy import crs [as 別名]
# 或者: from cartopy.crs import Orthographic [as 別名]
def plot_extend(resource, file_extension='png'):
"""
plots the extend (domain) of the values stored in a netCDF file:
:parm resource: path to netCDF file
:param file_extension: file format of the graphic. if file_extension=None a matplotlib figure will be returned
:return graphic: graphic in specified format
"""
lats, lons = get_coordinates(resource, unrotate=True)
# box_top = 45
# x, y = [-20, -20, 45, 45, -44], [-45, box_top, box_top, -45, -45]
xy = np.array([[np.min(lons), np.min(lats)],
[np.max(lons), np.min(lats)],
[np.max(lons), np.max(lats)],
[np.min(lons), np.max(lats)]])
fig = plt.figure(figsize=(20, 10), dpi=600, facecolor='w', edgecolor='k')
projection = ccrs.Robinson()
# ccrs.Orthographic(central_longitude=np.mean(xy[:, 0]),
# central_latitude=np.mean(xy[:, 1]),
# globe=None) # Robinson()
ax = plt.axes(projection=projection)
ax.stock_img()
ax.coastlines()
ax.add_patch(mpatches.Polygon(xy, closed=True, transform=ccrs.PlateCarree(), color='coral', alpha=0.6))
# ccrs.Geodetic()
ax.gridlines()
plt.show()
if file_extension is None:
map_graphic = fig
else:
map_graphic = fig2plot(fig=fig, file_extension=file_extension)
plt.close()
return map_graphic
示例2: test_warpcraters
# 需要導入模塊: from cartopy import crs [as 別名]
# 或者: from cartopy.crs import Orthographic [as 別名]
def test_warpcraters(self, box):
"""Test image warping and padding.
Output of this function was tested by visual inspection.
"""
box = np.array(box, dtype='int32')
# Crop image.
img = np.asanyarray(self.img.crop(box))
# Determine long/lat and output projection.
llbd = self.get_llbd(box)
oproj = ccrs.Orthographic(central_longitude=np.mean(llbd[:2]),
central_latitude=np.mean(llbd[2:]),
globe=self.iglobe)
# Determine coordinates of image limits in input and output projection
# coordinates.
iextent, oextent, ores = self.get_extents(llbd, self.geoproj,
self.iproj, oproj)
# Obtain image from igen.WarpImagePad.
imgout_WarpImagePad, WIPsize, WIPoffset = igen.WarpImagePad(
img, self.iproj, iextent, oproj, oextent, origin="upper",
rgcoeff=1.2, fillbg="black")
ctr_xlim = ((self.craters["Long"] >= llbd[0]) &
(self.craters["Long"] <= llbd[1]))
ctr_ylim = ((self.craters["Lat"] >= llbd[2]) &
(self.craters["Lat"] <= llbd[3]))
ctr_wrp = self.craters.loc[ctr_xlim & ctr_ylim, :].copy()
# Get output projection coords.
# [:,:2] becaus we don't need elevation data
# If statement is in case ctr_wrp has nothing in it
if ctr_wrp.shape[0]:
ilong = ctr_wrp["Long"].as_matrix()
ilat = ctr_wrp["Lat"].as_matrix()
res = oproj.transform_points(x=ilong, y=ilat,
src_crs=self.geoproj)[:, :2]
# Get output
ctr_wrp["x"], ctr_wrp["y"] = trf.coord2pix(res[:, 0], res[:, 1],
oextent, WIPsize,
origin="upper")
else:
ctr_wrp["x"] = []
ctr_wrp["y"] = []
ctr_wrpctrloc = igen.WarpCraterLoc(self.craters, self.geoproj, oproj,
oextent, WIPsize, llbd=llbd,
origin="upper")
assert np.all(ctr_wrp == ctr_wrpctrloc)
示例3: test_platecarreetoorthographic
# 需要導入模塊: from cartopy import crs [as 別名]
# 或者: from cartopy.crs import Orthographic [as 別名]
def test_platecarreetoorthographic(self, box):
"""Test full Plate Carree to orthographic transform.
Assumes input_data_gen's image and crater position warping
functions are correct. Output of this function was tested by visual
inspection.
"""
box = np.array(box, dtype='int32')
# Crop image.
img = np.asanyarray(self.img.crop(box))
# Determine long/lat and output projection.
llbd = self.get_llbd(box)
oproj = ccrs.Orthographic(central_longitude=np.mean(llbd[:2]),
central_latitude=np.mean(llbd[2:]),
globe=self.iglobe)
# Determine coordinates of image limits in input and output projection
# coordinates.
iextent, oextent, ores = self.get_extents(llbd, self.geoproj,
self.iproj, oproj)
# Obtain image from igen.WarpImagePad.
imgo, imgwshp, offset = igen.WarpImagePad(
img, self.iproj, iextent, oproj, oextent, origin="upper",
rgcoeff=1.2, fillbg="black")
ctr_xy = igen.WarpCraterLoc(self.craters, self.geoproj, oproj,
oextent, imgwshp, llbd=llbd,
origin="upper")
ctr_xy.loc[:, "x"] += offset[0]
ctr_xy.loc[:, "y"] += offset[1]
distortion_coefficient = ((ores[7, 1] - ores[1, 1]) /
(oextent[3] - oextent[2]))
pixperkm = trf.km2pix(imgo.size[1], llbd[3] - llbd[2],
dc=distortion_coefficient, a=1737.4)
ctr_xy["Diameter (pix)"] = ctr_xy["Diameter (km)"] * pixperkm
# Determine x, y position of central lat/long.
centrallonglat = pd.DataFrame({"Long": [np.mean(llbd[:2])],
"Lat": [np.mean(llbd[2:])]})
centrallonglat_xy = igen.WarpCraterLoc(centrallonglat, self.geoproj,
oproj, oextent, imgwshp,
llbd=llbd, origin="upper")
centrallonglat_xy.loc[:, "x"] += offset[0]
centrallonglat_xy.loc[:, "y"] += offset[1]
img_pc, ctr_pc, dc_pc, cll_pc = igen.PlateCarree_to_Orthographic(
self.img.crop(box), llbd, self.craters, iglobe=self.iglobe,
ctr_sub=False, arad=1737.4, origin="upper", rgcoeff=1.2,
slivercut=0.)
assert np.all(np.asanyarray(img_pc) == np.asanyarray(imgo))
assert np.all(ctr_pc == ctr_xy)
assert dc_pc == distortion_coefficient
assert np.all(cll_pc == centrallonglat_xy)