Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError in python basemap?

So I was just using python's basemap for the first time recently and I had a script that worked on a large dataset of about 30,000 points just yesterday. When I came back today, it stopped working and started giving me value errors when I added a new dataset. I don't know what could be causing it but I'm getting a value error?

    ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-16fa79cd74a5> in <module>()
     12     longitude = np.array(df[(df['FLOAT'] == x)]['LONGITUDE'])
     13     latitude = np.array(df[df['FLOAT'] == x]['LATITUDE'])
---> 14     m.plot(longitude,latitude, latlon=True)
     15 parallels = np.arange(-90.,90.,10.)
     16 

C:\Anaconda\lib\site-packages\mpl_toolkits\basemap\__init__.pyc in with_transform(self, x, y, *args, **kwargs)
    534             if self.projection in _cylproj or self.projection in _pseudocyl:
    535                 if x.ndim == 1:
--> 536                     x = self.shiftdata(x)
    537                 elif x.ndim == 0:
    538                     if x > 180:

C:\Anaconda\lib\site-packages\mpl_toolkits\basemap\__init__.pyc in shiftdata(self, lonsin, datain, lon_0)
   4775             thresh = 360.-londiff_sort[-2]
   4776             itemindex = len(lonsin)-np.where(londiff>=thresh)[0]
-> 4777             if itemindex:
   4778                 # check to see if cyclic (wraparound) point included
   4779                 # if so, remove it.

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Anyone have a clue? Maybe there's a data value in the array that doesn't work out right?

like image 564
Raishin Avatar asked Jul 22 '26 04:07

Raishin


1 Answers

This is caused by basemap bug #214.

At the time of writing (2016-03-17), this bug is still open, so you will need to find a workaround:

  • Sort the data prior to plotting. Of course, that may not be desirable if you need to draw the actual line segments.
  • Split the data up in subsections, such as you have done.
like image 197
gerrit Avatar answered Jul 24 '26 17:07

gerrit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!