3

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?

6
  • As far as I can tell, np.where in line 4776 is returning an array where it should be returning a single value. What are the shapes of your longitude and latitude arrays? Commented Aug 5, 2015 at 17:35
  • (2140L,) for both of them when I print the shape value. Commented Aug 5, 2015 at 17:38
  • That is, if you mean the longitude and latitude arrays I'm passing in. I don't know what basemap really does with them after that very well. It works when I switch back to an older csv file so I imagine there has to be something wrong with a data entry or two... I just don't know why it would cause problems with basemap as long as it's a valid pairing. The data range in the new file tends to run on the longitude from -179.829 to 179.796. The latitudes are pretty far from the maximum. Commented Aug 5, 2015 at 17:45
  • 1
    If that's the case, It seems there's not enough information to solve the problem without the problem data and code itself. Are the new and old csv files similar? If so, do a diff and see what values are causing the problems. Commented Aug 5, 2015 at 18:57
  • Well, it's 300,000+ data entries... I can only imagine it has something to do with trying to draw a line that extends over one of the map edges. It seems to work fine as long as the line I'm asking it to draw doesn't do that. Commented Aug 5, 2015 at 20:14

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.