by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 03 06:39
    ajdawson closed #1577
  • Jun 02 23:30
    miguel123-gis commented #1577
  • Jun 02 13:31
    greglucas milestoned #1576
  • Jun 02 13:31
    greglucas labeled #1576
  • Jun 02 13:31
    greglucas labeled #1576
  • Jun 02 13:29
    greglucas commented #1577
  • Jun 02 05:28
    miguel123-gis commented #1577
  • Jun 02 05:23
    miguel123-gis opened #1577
  • Jun 02 02:29
    jeffreymei opened #1576
  • May 31 20:56
    QuLogic closed #1573
  • May 31 20:56
    QuLogic commented #1573
  • May 31 04:34
    jp2nyy commented #1573
  • May 31 04:28
    lsawade commented #1573
  • May 29 08:22
    stefraynaud commented #1537
  • May 29 08:12
    stefraynaud synchronize #1537
  • May 29 06:22
    stefraynaud commented #1566
  • May 27 22:46
    friedrichknuth commented #1311
  • May 27 21:49
    lukelbd commented #1556
  • May 27 08:01
    stefraynaud commented #1537
  • May 27 07:56
    stefraynaud commented #1575
Ryan May
@dopplershift
I'm not sure about the lines because I'm not sure how you were doing them before. I would think matplotlib's Annotations would be helpful and work. Margins often come down to aspect ratio issues, but I'd expect less of that given you're showing a full globe in an Orthographic projection. Probably need to see code to really see how to fix. Also would be best to post on Matplotlib's discourse (https://discourse.matplotlib.org/c/3rdparty/18) for a longer discussion--feel free to link back here so we see it.
Daniel da Silva
@ddasilva
Thanks @dopplershift, will do!
Elliott Sales de Andrade
@QuLogic
Tagged Cartopy 0.18
Ryan May
@dopplershift
:tada:
Tanim Islam
@tanimislam
Hi, are the cartopy projections callable? How do I get projection coordinates from lat/lng. With basemap I can get x, y = m(long, lat). Here m is the Basemap projection. I ask here because a google search of "cartopy projection coordinates" does not produce relevant information.
Ryan May
@dopplershift
You're looking for transform_point and transform_points methods on the cartopy projection objects.
Tanim Islam
@tanimislam
@dopplershift sorry, this is what I get when I run this query: https://scitools.org.uk/cartopy/docs/latest/search.html?q=project_points
Screen Shot 2020-05-05 at 11.40.16 AM.png
Elliott Sales de Andrade
@QuLogic
Are you sure you actually need to project points?
It's not needed for plotting, for example
Tanim Islam
@tanimislam
@QuLogic why wouldn’t I? What’s wrong with more control versus less?
For instance, I am putting in an artist (like a Polygon), and would like it in projected coordinates. With Basemap, it’s easy and straightforward. Is it so with Cartopy?
Examples in Cartopy use high level constructs (a contour, density plot, etc.). But what about annotations?
Ryan May
@dopplershift
@tanimislam as I said in my original response, you want to look at transform_points. I'm not sure why you're searching for project_points when nothing has said that exists. So you can do:
import cartopy.crs as ccrs
import numpy as np
proj = ccrs.Mercator()
lon = np.linspace(30, 60)
lat = np.linspace(10, 25)
points = proj.transform_points(ccrs.PlateCarree(), lon, lat)
x = points[:, 0]
y = points[:, 1]
This converts lon/lat points to x,y in the Mercator projection. The general approach allows you to directly convert points in one coordinate system to another, without either of them necessarily being a lon/lat coordinate system. That's a very low level capability that's available.
Ryan May
@dopplershift
Now to @QuLogic 's point: one of the nice things about cartopy is that you don't need to go to that low level, even for shapes. Here's an example:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertConformal())

# Rectangle in projection coordinates
rect_proj = plt.Rectangle([-500000, -500000], width=800000, height=800000,
                          facecolor='none', edgecolor='tab:blue')
ax.add_artist(rect_proj)

# Rectangle in lon/lat coordinates
rect_geo = plt.Rectangle([-105, 40], width=15, height=15,
                         facecolor='none', edgecolor='tab:red',
                         transform=ccrs.PlateCarree())
ax.add_artist(rect_geo)

ax.coastlines()
ax.set_extent((-120, -65, 20, 55))
Elliott Sales de Andrade
@QuLogic
You don't need to do it manually for those cases either; pass a transform to annotate or text and you can use the lon/lat directly
Ryan May
@dopplershift
By default, when you initialize an Axes for plotting with CartoPy, you give it a projection. All coordinates then used in plotting, or creating artists, are assumed to be in that coordinate system by default. So the blue rectangle above is assuming it's given coordinate within the Lambert Conformal projection. If you wish to plot data in another coordinate system, like lon/lat, you pass a transform argument which is used to specify what coordinate system the data are in. We do this with the red rectangle above by passing transform=ccrs.PlateCarree().
Tanim Islam
@tanimislam
so standard plotting commands, such as ax.plot and ax.scatter will by default be transformed into that coordinate? How about ax.add_patch where, for instance, Polygons are defined in lng/lat coordinates?
thanks
@dopplershift never mind, I saw your code description for artists
Tanim Islam
@tanimislam
And this is a very different way, from Basemap, to represent a projection of a given region.
pedromarting
@pedromarting
Hello! I want to put shadows in my topographic map but WITHOUT the SRTM function that comes with cartopy (like this example https://scitools.org.uk/cartopy/docs/v0.12/examples/srtm_shading.html) , is that possible? I have a elevation model in a grid format so i can plot that with countourf but i want to add some shadows to that. Thanks!!!
Elliott Sales de Andrade
@QuLogic
Probably something like the Matplotlib shading example https://matplotlib.org/gallery/images_contours_and_fields/shading_example.html
pedromarting
@pedromarting
@QuLogic I try that but it seems that the problem its the input data, take a look at the code

import numpy as np
from matplotlib import cbook
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource
import xarray as xr
import pandas as pd

datapath = './'
topo = xr.open_dataset(datapath+'srtm3_LP2014.grd') #abro la grilla nc topografica
topoz = topo.z

def main():
fig = compare(topoz, plt.cm.gist_earth, ve=0.05)
fig.suptitle('Hola', y=0.95)
plt.show()

def compare(z, cmap, ve=1):
fig, ax = plt.subplots(ncols=1, nrows=1)
ls = LightSource(azdeg=315, altdeg=45)
rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv')
ax.imshow(rgb)
ax.set(xlabel='Blend Mode: "hsv" (default)')
return fig

if name == 'main':
main()

pedromarting
@pedromarting
I forgot to say thank you to all of you! I am new in cartopy (and python) and its amazing!
Ricky
@Rikiti
Hello Everybody, I am not a developer, I am just a user. I would like to know what resampling methods does Cartopy use to do geometric operations with raster images
Ryan May
@dopplershift
@Rikiti I believe it's using a KDTree to do nearest neighbor-type resampling, but I'm not positive at all about that.
Ricky
@Rikiti
thank you! I will look for this
Mark Wieczorek
@MarkWieczorek
Hi Everyone. I would like to draw a map centered on the north/south pole of a planet, but Cartopy doesn't seem to do what I want. For example, in AlbersEqualArea, there is missing "cap" at the pole, and there is an arbitrary longitudinal sector that is missing:
projections-2.png
The same problem exists for EquidistantConic
projections-4.png
And in LambertConformal, while there is no missing "cap", there is still the missing sector:
projections-5.png
Is there a way to plot a polar projection for all longitudes, and without the missing cap at the pole?
Mark Wieczorek
@MarkWieczorek
For info, what I would like to do is make a "square" stereographic projection like this, but if I had to, I would be ok with a circular boundary...
Screen Shot 2020-05-24 at 16.07.25.png
Elliott Sales de Andrade
@QuLogic
Both NorthPolarStereo and SouthPolarStereo exist
Mark Wieczorek
@MarkWieczorek
Yes, but NorthPolarStereo plots the entire globe, and I don't see an option to set a limit on what latitudes to plot.
projections-311.png
Elliott Sales de Andrade
@QuLogic
call .set_extent or .set_boundary like any other projection
Greg
@greglucas
There is a pretty good example here demonstrating both rectangle and circular boundary shapes: https://scitools.org.uk/cartopy/docs/latest/gallery/always_circular_stereo.html#sphx-glr-gallery-always-circular-stereo-py Or the star boundary could be modified to fit your use case as well: https://scitools.org.uk/cartopy/docs/latest/gallery/star_shaped_boundary.html#sphx-glr-gallery-star-shaped-boundary-py
matrixbot
@matrixbot
mark-wieczorek Thanks, that's exactly what I was looking for!
ProfeSergioM
@ProfeSergioM
Hi! Any idea of how to use errorbar in cartopy?
Ryan May
@dopplershift
@MarkWieczorek Those aren't missing sections, those are what happens when you approximate the Earth with a cone, and unwrap that cone to produce a plane. That's what those map projections are doing.
matrixbot
@matrixbot
mark-wieczorek I see that now with the coastlines. Sorry for the confusion, I just don't every remember seeing this type of projection before. I thought it was some special product used only for the present-day configuration of the Earth's continents...