I just added a test of intersects_bbox to SVN that seems to be working correctly for short paths containing masked values. It would appear that masked values *should* be dealt with correctly (that is, in exactly the same way as they are drawn) by the intersection code. However, there is probably a side case here that I'm missing. As Eric suggests, see if you can break it down into a simple example that fails and hopefully the problem and/or solution will be more obvious from that.
Cheers, Mike Eric Firing wrote: > Evan Mason wrote: > >> Hi, wonder if anyone can help me with path and bbox. I have a set of >> ocean drifter tracks and I want to know if they pass through a >> particular boxed area. This is straightforward to do but I wanted to >> try to do it with matplotlib.transforms and matplotlib.path, which look >> well-suited to this kind of task using 'intersects_bbox'. >> >> The essence of my code is below. I have a single drifter track (lon, >> lat) and have defined a boxed area. At no time does the drifter >> approach or enter the box - however, the final line, >> >> print track.intersects_bbox(bbox) >> >> returns True, which it shouldn't. In total I have 340 tracks. My code >> says 74 pass though the box, but by counting there should be only about >> 9. Any help appreciated, thanks, Evan >> >> >> import numpy as N >> import numpy.ma <http://numpy.ma> as MA >> import matplotlib.transforms as BB >> import matplotlib.path as PP >> >> In [200]: lon >> Out[200]: >> masked_array(data = [-15.52 -15.521 -15.541 ..., -- -- --], >> mask = [False False False ..., True True True], >> fill_value=1e+20) >> >> In [201]: lat >> Out[201]: >> masked_array(data = [29.2 29.2 29.196 ..., -- -- --], >> mask = [False False False ..., True True True], >> fill_value=1e+20) >> >> In [202]: len(lon), len(lat) >> Out[202]: (3750, 3750) >> >> track = MA.transpose([lon, lat]) >> track = PP.Path(track) >> bbox = BB.Bbox.from_extents(-15.95, 29.6, -15.9, 29.65) >> >> In [206]: print track.intersects_bbox(bbox) >> 1 >> > > Evan, > > Can you strip the problem down more? That is, find one track that is > misdiagnosed, and then try to find the shortest segment of it that still > gets misdiagnosed. You could try subsampling and/or chopping chunks off > the ends. If you can get it down to a track with only a few points, so > that you can email a very short but complete script with illustrative > data, that would make it much easier for someone to figure out what is > going on. > > I suspect it is related to the masked values. If you strip the masked > points out of your lon and lat arrays, do you get the same result? > Try making an example with only 3 points, say with the middle one > masked, and then unmasked. > > Eric > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users