def modifyGridLinesForCyl(lon, lat, west, east):
lon[lon > east] -= 360.0
lon[lon < west] += 360.0
ii = np.where(np.abs(lon[1:]-lon[:-1]) > 180.0)[0][::-1]
lon, lat = list(lon), list(lat)
for i in ii:
if lon[i] < lon[i+1]:
latB = (lat[i+1]*(lon[i]-west) + lat[i]*(east-lon[i+1]))\
/ ((lon[i]-west) + (east-lon[i+1]))
lon = lon[:i+1] + [west, np.nan, east] + lon[i+1:]
else:
latB = (lat[i]*(lon[i+1]-west) + lat[i+1]*(east-lon[i]))\
/ ((lon[i+1]-west) + (east-lon[i]))
lon = lon[:i+1] + [east, np.nan, west] + lon[i+1:]
lat = lat[:i+1] + [latB, np.nan, latB] + lat[i+1:]
for i in [i for i in np.where(np.abs(lat) == 90.0)[0][::-1]
if i not in [0, len(lat)]]:
lon = lon[:i] + [lon[i-1], np.nan, lon[i+1]] + lon[i+1:]
lat = lat[:i] + [lat[i], np.nan, lat[i]] + lat[i+1:]
return lon, lat
def sample_tripolar_cyl():
plon, plat = 60.0, 63.333700283430055
lonsize = 3.0
lats_south = np.linspace(-90.0, plat, 91)
lons_north = np.linspace(-90.0, 90.0, 46)
lons, lats = getGridLines_tripolar(
plon, plat, lonsize, lats_south, lons_north, 100)
west, east, south, north = -180.0, 180.0, -90.0, 90.0
lons_cyl, lats_cyl = [], []
for lon, lat in zip(lons, lats):
lon_cyl, lat_cyl = modifyGridLinesForCyl(lon, lat, west, east)
lons_cyl.append(lon_cyl)
lats_cyl.append(lat_cyl)
m = Basemap(projection='cyl',
llcrnrlon=west, llcrnrlat=south,
urcrnrlon=east, urcrnrlat=north,
resolution='i')
m.drawmapboundary(linewidth=0.4, color='k')
m.fillcontinents(color='silver', lake_color='silver')
for lon_cyl, lat_cyl in zip(lons_cyl, lats_cyl):
m.plot(lon_cyl, lat_cyl, linewidth=0.4, color=linecolor)
plt.show()
linecolor = '#636363'
sample_tripolar_cyl()