Skip to content

ValueError: 'vertices' must be a 2D list or array with shape Nx2 #512

Closed

Description

@flaviodoliveira

I'm using Python 3.8.5
Matplotlib version 3.1.2
and basemap-1.2.2+dev

I'm running something like:


    llon = lons.min()
    llat = lats.min()
    ulon = lons.max()
    ulat = lats.max()

    fig, ax = plt.subplots()
    
    m = Basemap(llcrnrlon=llon, llcrnrlat=llat, urcrnrlon=ulon,
                urcrnrlat=ulat, resolution='h')

    m.drawcoastlines(linewidth=0.8)
    m.drawcountries(linewidth=0.8)
    m.drawstates(linewidth=0.8)


and then I got this:

File "plt_RAIN.py", line 62, in
m.drawcoastlines(linewidth=0.8)
File "/usr/local/lib/python3.8/dist-packages/mpl_toolkits/basemap/init.py", line 1859, in drawcoastlines
coastlines = LineCollection(self.coastsegs,antialiaseds=(antialiased,))
File "/usr/lib/python3/dist-packages/matplotlib/collections.py", line 1333, in init
self.set_segments(segments)
File "/usr/lib/python3/dist-packages/matplotlib/collections.py", line 1348, in set_segments
self._paths = [mpath.Path(_seg) for _seg in _segments]
File "/usr/lib/python3/dist-packages/matplotlib/collections.py", line 1348, in
self._paths = [mpath.Path(_seg) for _seg in _segments]
File "/usr/lib/python3/dist-packages/matplotlib/path.py", line 129, in init
raise ValueError(
ValueError: 'vertices' must be a 2D list or array with shape Nx2

I checked everything, but I'm used to run this on basemap 1.0.7 and everything was ok.
And when I run without m.drawcoastlines(), there is no problem.

What can I do to run it?

Activity

  1. guziy commented on Mar 31, 2022

    @guziy
    Contributor

    I have a similar problem. I think this might be because your domain does not intersect any coastlines? I have this reproducer:

    # fails 
    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    b = Basemap(projection="cea", llcrnrlon=267.5, urcrnrlon=283.995, llcrnrlat=41.35, urcrnrlat=51, resolution="l") 
    b.drawcoastlines()
    plt.show()

    Note: The above fails in basemap 1.2.1 (matplotlib 3.5.1) and works in basemap 1.1.0 (matplotlib 2.1.1), regression somewhere...

    But if I extend a bit to have an intersection with the ocean coastlines (in this case to the Hudson Bay) it works

    # works 
    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    b = Basemap(projection="cea", llcrnrlon=267.5, urcrnrlon=283.995, llcrnrlat=41.35, urcrnrlat=51.8, resolution="l") 
    b.drawcoastlines()
    plt.show()

    @jswhit I know we are not supposed to bug you with this project, but maybe you have a workaround for this...

  2. WeatherGod commented on Mar 31, 2022

    @WeatherGod
    Member
  3. molinav commented on Mar 31, 2022

    @molinav
    Member

    @guziy With the latest basemap I am not able to reproduce it. If I type your first snippet in IPython, I get this:

    (py38) vic@onyx:~$ python -m IPython --pylab=Tk
    Python 3.8.12 (default, Jan  3 2022, 10:33:21)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.30.1 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: from mpl_toolkits.basemap import Basemap
       ...: import matplotlib.pyplot as plt
       ...: b = Basemap(projection="cea",
       ...:             llcrnrlon=267.5, urcrnrlon=283.995,
       ...:             llcrnrlat=41.35, urcrnrlat=51, resolution="l")
       ...: b.drawcoastlines()
       ...: plt.show()
    
    In [2]: from mpl_toolkits import basemap
    
    In [3]: basemap.__version__
    Out[3]: '1.3.2'
    

    plot_first_snippet

    For this example I am using the basemap wheel in PyPI, which bundles a relatively old GEOS library (3.5.1). Could it be that your basemap installation uses the GEOS from your system, which is probably newer, and the new GEOS does not get on well with the current implementation?

  4. guziy commented on Apr 1, 2022

    @guziy
    Contributor

    @molinav Could you please try to create the following conda environment:

    conda create -n py39 python=3.9 basemap ipython
    conda activate py39

    Here are the versions

    conda list 'matplotlib|basemap|geos'
    #
    # Name                    Version                   Build  Channel
    basemap                   1.2.2            py39h2103e0b_4    conda-forge
    geos                      3.9.1                h9c3ff4c_2    conda-forge
    matplotlib-base           3.5.1            py39h2fa2bec_0    conda-forge
    matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge
    
    

    Here is the info for the basemap=1.2.2 conda package:

    conda search basemap=1.2.2 --info
    basemap 1.2.2 py39hc66db60_2
    ----------------------------
    file name   : basemap-1.2.2-py39hc66db60_2.conda
    name        : basemap
    version     : 1.2.2
    build       : py39hc66db60_2
    build number: 2
    size        : 14.5 MB
    license     : MIT
    subdir      : linux-64
    url         : https://repo.anaconda.com/pkgs/main/linux-64/basemap-1.2.2-py39hc66db60_2.conda
    md5         : e6b784f1281dbe3070858be9d49f7df6
    timestamp   : 2021-12-22 10:32:34 UTC
    constraints : 
      - proj4 <6
      - proj <6
    dependencies: 
      - geos >=3.8.0,<3.8.1.0a0
      - libgcc-ng >=7.5.0
      - libstdcxx-ng >=7.5.0
      - matplotlib-base >=1.0.0,!=3.0.1
      - numpy >=1.16.6,<2.0a0
      - proj
      - pyproj >=1.9.3
      - pyshp >=1.2.0
      - python >=3.9,<3.10.0a0
      - six
    
  5. added a commit that references this issue on Apr 1, 2022
  6. reopened this on Apr 1, 2022
  7. molinav commented on Apr 1, 2022

    @molinav
    Member

    @guziy The basemap conda package needs an update at some point, but I haven't still had time to learn a bit on how to refactor the basemap conda recipe appropriately after my split of basemap into three parts.

    From other issue (#522 (comment)) it seems that we are blocked at the moment to GEOS < 3.9.

  8. guziy commented on Apr 1, 2022

    @guziy
    Contributor
    • I don't know about conda recipies, but willing to learn, are they in this repo?
    • @flaviodoliveira could you please check if the latest develop branch fixes the issue for you as well?
  9. molinav commented on Apr 1, 2022

    @molinav
    Member

    The conda recipe is available in a separate repo:
    https://github.com/conda-forge/basemap-feedstock

    There were a couple of external attempts to update the recipe but they did not succeed or were closed before finishing:
    conda-forge/basemap-feedstock#92
    conda-forge/basemap-feedstock#93

    Unfortunately, I could not still find time to learn about conda recipes to provide my own update there.

  10. molinav commented on Oct 25, 2022

    @molinav
    Member

    @guziy This issue and your fix were included in basemap 1.3.3. Since April, a bit of development on the conda-forge side has been ongoing, and we now have up-to-date basemap packages in conda-forge as well as in PyPI.

    The latest basemap release (1.3.5) has been deployed to PyPI and conda-forge today, it also includes this bugfix of course, and it solves the problem about linking with newer GEOS versions (#522). So I think we can safely close this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions