|
From: Jeff W. <jef...@no...> - 2013-06-25 00:09:42
|
> Goodman, Alexander (398J-Affiliate) > <mailto:ale...@jp...> > June 24, 2013 4:30 PM > Just something I thought I should add to this, but would the following > code seem like a reasonable workaround? Basically, since > map_coordinates() cannot handle mask arrays, I thought that perhaps > passing in the actual mask itself to interp() with order=3 may produce > close to reasonable results, eg: > > dataout = interp(datain, xin, yin, xout, yout, masked=True, order=3) > maskin = datain.mask.astype(int) > maskout = interp(datain.mask, xin, yin, xout, yout, order=3) > dataout.mask = dataout.mask | maskout > > Thanks, > Alex > > > ------------------------------------------------------------------------ Alex: The basemap.interp docstring includes a note describing a trick I often use with masked arrays: Note If datain is a masked array and order=1 (bilinear interpolation) is used, elements of dataout will be masked if any of the four surrounding points in datain are masked. To avoid this, do the interpolation in two passes, first with order=1 (producing dataout1), then with order=0 (producing dataout2). Then replace all the masked values in dataout1 with the corresponding elements in dataout2 (using numpy.where). This effectively uses nearest neighbor interpolation if any of the four surrounding points in datain are masked, and bilinear interpolation otherwise. I suppose the same trick might work with order=3, but I have never tried it. -Jeff |
|
From: Jeff W. <jef...@no...> - 2013-06-26 12:20:05
|
> Goodman, Alexander (398J-Affiliate) > <mailto:ale...@jp...> > June 24, 2013 6:27 PM > Hi Jeff, > > Thanks for the quick reply. However I am a little lost with your > suggested solution. The issue here is that if datain is a masked > array, dataout will not be a masked array when order=3 is used unless > masked=True is set, but this just results in none of the elements > (besides those outside the domain of xin and yin) being masked. So are > you saying to try setting the mask to what it would be after running > interp() with order=0? I would appreciate a more concrete example. > > Thanks, > Alex Alex: After pondering this a bit more, I don't think you can use order=3 with masked arrays. Any reason why you can't using a combo of bilinear and nearest neighbor as I described in my previous email? -Jeff > > > > Goodman, Alexander (398J-Affiliate) > <mailto:ale...@jp...> > June 24, 2013 4:30 PM > Just something I thought I should add to this, but would the following > code seem like a reasonable workaround? Basically, since > map_coordinates() cannot handle mask arrays, I thought that perhaps > passing in the actual mask itself to interp() with order=3 may produce > close to reasonable results, eg: > > dataout = interp(datain, xin, yin, xout, yout, masked=True, order=3) > maskin = datain.mask.astype(int) > maskout = interp(datain.mask, xin, yin, xout, yout, order=3) > dataout.mask = dataout.mask | maskout > > Thanks, > Alex > > > ------------------------------------------------------------------------ |
|
From: Benjamin R. <ben...@ou...> - 2013-06-26 13:34:17
Attachments:
compose-unknown-contact.jpg
|
I have done something slightly different that works more generally. I am trying to recall it from memory, so some details may be wrong. Essentially, do the interpolation you want on a filled version of the masked array (filling with a value that makes sense for your data). Then, do the same interpolation on the mask, and cast the mask back as booleans. Finally, build the output masked array by combining the two together with one of the constructors. Cheers! Ben Root On Jun 26, 2013 7:22 AM, "Jeff Whitaker" <jef...@no...> wrote: > Goodman, Alexander (398J-Affiliate) <ale...@jp...> > June 24, 2013 6:27 PM > Hi Jeff, > > Thanks for the quick reply. However I am a little lost with your suggested > solution. The issue here is that if datain is a masked array, dataout will > not be a masked array when order=3 is used unless masked=True is set, but > this just results in none of the elements (besides those outside the domain > of xin and yin) being masked. So are you saying to try setting the mask to > what it would be after running interp() with order=0? I would appreciate a > more concrete example. > > Thanks, > Alex > > > Alex: After pondering this a bit more, I don't think you can use order=3 > with masked arrays. Any reason why you can't using a combo of bilinear and > nearest neighbor as I described in my previous email? > > -Jeff > > > > > Goodman, Alexander (398J-Affiliate) <ale...@jp...> > June 24, 2013 4:30 PM > Just something I thought I should add to this, but would the following > code seem like a reasonable workaround? Basically, since map_coordinates() > cannot handle mask arrays, I thought that perhaps passing in the actual > mask itself to interp() with order=3 may produce close to reasonable > results, eg: > > dataout = interp(datain, xin, yin, xout, yout, masked=True, order=3) > maskin = datain.mask.astype(int) > maskout = interp(datain.mask, xin, yin, xout, yout, order=3) > dataout.mask = dataout.mask | maskout > > Thanks, > Alex > > > ------------------------------ > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |