Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-11 Thread Juan A. Saenz
Jeff, thanks for your reply.

One situation where one might require masked nearest neighbor 
interpolation is when, on a given fixed grid, interpolating velocities 
on cell corners (B-grid) to faces (C-grid). Cells will be defined as 
either land or ocean cells, masked or un-masked respectively. The masked 
or un-masked character of cells does not change. Interpolating 
velocities from corners adjacent to masked cells, to cell centers on 
un-masked cells will require the behavior in question. Imagine two 
adjacent cells, one masked and the other not. The velocities on the cell 
corners that lie on the coast (adjacent to a masked and an un-masked 
cell) are masked. A desireable behavior of the interpolator would be to 
produce an un-masked cell centered velocity on the un-masked cell that 
uses values from adjacent un-masked velocity values.

Thanks,
Juan


On 8/03/11 12:23 AM, Jeff Whitaker wrote:
> On 3/7/11 5:50 AM, Jeff Whitaker wrote:
>> On 3/6/11 8:58 PM, Juan A. Saenz wrote:
>>> Hi,
>>>
>>> I use Basemap and netCDF4-python on a regular basis, and find them
>>> very useful tools. Thank you for developing them!
>>>
>>> I noticed that when using basemap.interp for nearest neighbor
>>> (order=0) the interpolation is not masked, and nearest neighbor masked
>>> values will be used in the interpolation. I was wondering if you could
>>> suggest a way to do nearest neighbor interpolation where masked are
>>> supported, i.e. nearest neighbor values that are not masked.
>>>
>>> Thanks for your help,
>>> Juan
>>>
>> Juan:  I agree that this would be desirable behavior.  Unfortunately,
>> it's not obvious to me how to do it.  I'll think about it and get back
>> to you.  (cc'ing matplotlib-users list).
>>
>> -Jeff
>>
>
> Juan: On second thought, I'm not sure this is desirable behavior.  I 
> would guess that most of the time, if a nearest neighbor is masked, 
> the user would expect the interpolation routine to return a masked 
> value.  I would be interested to hear what others think.
>
> -Jeff
>


-- 
Juan A. Saenz
Postdoctoral Fellow

Geophysical Fluid Dynamics
Research School of Earth Sciences
Australian National University

Building 61
Mills Road
Canberra, ACT 0200
AUSTRALIA
Office: +61 2 6125 9968
Admin:  +61 2 6125 5502
Fax:+61 2 6257 2737


--
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-11 Thread Juan A. Saenz
If I think of something, I'll let you know.

In the meantime, I'd like to point out the following:
Nearest neighbor returns a masked interpolation point if the nearest 
neighbor is masked (this is just what you've already told me). If there 
are two equidistant neighbors, it returns the one on the "bottom". I, 
naively, expected it to return the unmasked one, but I suppose that this 
is just natural. It might be worth pointing this out in the documentation.

Thanks again,
Juan

On 8/03/11 10:52 AM, Jeff Whitaker wrote:
> On 3/7/11 2:25 PM, Juan A. Saenz wrote:
>> Jeff, thanks for your reply.
>>
>> One situation where one might require masked nearest neighbor 
>> interpolation is when, on a given fixed grid, interpolating 
>> velocities on cell corners (B-grid) to faces (C-grid). Cells will be 
>> defined as either land or ocean cells, masked or un-masked 
>> respectively. The masked or un-masked character of cells does not 
>> change. Interpolating velocities from corners adjacent to masked 
>> cells, to cell centers on un-masked cells will require the behavior 
>> in question. Imagine two adjacent cells, one masked and the other 
>> not. The velocities on the cell corners that lie on the coast 
>> (adjacent to a masked and an un-masked cell) are masked. A desireable 
>> behavior of the interpolator would be to produce an un-masked cell 
>> centered velocity on the un-masked cell that uses values from 
>> adjacent un-masked velocity values.
>>
>> Thanks,
>> Juan
>>
>
> Juan:  I can see why you want it in this case, but I think in general 
> users would expect a masked value if the nearest neighbor is masked.  
> In addition, I don't see how to implement it easily.  How far are you 
> willing to go to find a nearest neighbor that is not masked?
>
> In short, for your use case you'll have to implement your own custom 
> solution.  Of course, if you can show me a simple modification to the 
> Basemap interp function that does what you want, and can be enabled 
> with a kwarg, I'll reconsider.
>
> -Jeff
>
>>
>> On 8/03/11 12:23 AM, Jeff Whitaker wrote:
>>> On 3/7/11 5:50 AM, Jeff Whitaker wrote:
 On 3/6/11 8:58 PM, Juan A. Saenz wrote:
> Hi,
>
> I use Basemap and netCDF4-python on a regular basis, and find them
> very useful tools. Thank you for developing them!
>
> I noticed that when using basemap.interp for nearest neighbor
> (order=0) the interpolation is not masked, and nearest neighbor 
> masked
> values will be used in the interpolation. I was wondering if you 
> could
> suggest a way to do nearest neighbor interpolation where masked are
> supported, i.e. nearest neighbor values that are not masked.
>
> Thanks for your help,
> Juan
>
 Juan:  I agree that this would be desirable behavior.  Unfortunately,
 it's not obvious to me how to do it.  I'll think about it and get back
 to you.  (cc'ing matplotlib-users list).

 -Jeff

>>>
>>> Juan: On second thought, I'm not sure this is desirable behavior.  I 
>>> would guess that most of the time, if a nearest neighbor is masked, 
>>> the user would expect the interpolation routine to return a masked 
>>> value.  I would be interested to hear what others think.
>>>
>>> -Jeff
>>>
>>
>>
>
>


--
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-07 Thread Jeff Whitaker
On 3/7/11 2:25 PM, Juan A. Saenz wrote:
> Jeff, thanks for your reply.
>
> One situation where one might require masked nearest neighbor 
> interpolation is when, on a given fixed grid, interpolating velocities 
> on cell corners (B-grid) to faces (C-grid). Cells will be defined as 
> either land or ocean cells, masked or un-masked respectively. The 
> masked or un-masked character of cells does not change. Interpolating 
> velocities from corners adjacent to masked cells, to cell centers on 
> un-masked cells will require the behavior in question. Imagine two 
> adjacent cells, one masked and the other not. The velocities on the 
> cell corners that lie on the coast (adjacent to a masked and an 
> un-masked cell) are masked. A desireable behavior of the interpolator 
> would be to produce an un-masked cell centered velocity on the 
> un-masked cell that uses values from adjacent un-masked velocity values.
>
> Thanks,
> Juan
>

Juan:  I can see why you want it in this case, but I think in general 
users would expect a masked value if the nearest neighbor is masked.  In 
addition, I don't see how to implement it easily.  How far are you 
willing to go to find a nearest neighbor that is not masked?

In short, for your use case you'll have to implement your own custom 
solution.  Of course, if you can show me a simple modification to the 
Basemap interp function that does what you want, and can be enabled with 
a kwarg, I'll reconsider.

-Jeff

>
> On 8/03/11 12:23 AM, Jeff Whitaker wrote:
>> On 3/7/11 5:50 AM, Jeff Whitaker wrote:
>>> On 3/6/11 8:58 PM, Juan A. Saenz wrote:
 Hi,

 I use Basemap and netCDF4-python on a regular basis, and find them
 very useful tools. Thank you for developing them!

 I noticed that when using basemap.interp for nearest neighbor
 (order=0) the interpolation is not masked, and nearest neighbor masked
 values will be used in the interpolation. I was wondering if you could
 suggest a way to do nearest neighbor interpolation where masked are
 supported, i.e. nearest neighbor values that are not masked.

 Thanks for your help,
 Juan

>>> Juan:  I agree that this would be desirable behavior.  Unfortunately,
>>> it's not obvious to me how to do it.  I'll think about it and get back
>>> to you.  (cc'ing matplotlib-users list).
>>>
>>> -Jeff
>>>
>>
>> Juan: On second thought, I'm not sure this is desirable behavior.  I 
>> would guess that most of the time, if a nearest neighbor is masked, 
>> the user would expect the interpolation routine to return a masked 
>> value.  I would be interested to hear what others think.
>>
>> -Jeff
>>
>
>


-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : jeffrey.s.whita...@noaa.gov
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-07 Thread Jeff Whitaker

On 3/7/11 7:38 AM, Aman Thakral wrote:
On a similar note, are there any alternatives available to nearest 
neighbor?  For example, kriging?  I remember seeing a geostats library 
in python (hpgl i think), but I found the API rather impractical and 
difficult to use.


Thanks,
Aman


Aman:  The basemap interp function is just a convenience function for 
simple regridding (linear, cubic and nearest neighbor).  
scipy.interpolate 
(http://docs.scipy.org/doc/scipy/reference/interpolate.html) provides 
many more options.


-Jeff


On Mon, Mar 7, 2011 at 8:23 AM, Jeff Whitaker > wrote:


On 3/7/11 5:50 AM, Jeff Whitaker wrote:
> On 3/6/11 8:58 PM, Juan A. Saenz wrote:
>> Hi,
>>
>> I use Basemap and netCDF4-python on a regular basis, and find them
>> very useful tools. Thank you for developing them!
>>
>> I noticed that when using basemap.interp for nearest neighbor
>> (order=0) the interpolation is not masked, and nearest neighbor
masked
>> values will be used in the interpolation. I was wondering if
you could
>> suggest a way to do nearest neighbor interpolation where masked are
>> supported, i.e. nearest neighbor values that are not masked.
>>
>> Thanks for your help,
>> Juan
>>
> Juan:  I agree that this would be desirable behavior.
 Unfortunately,
> it's not obvious to me how to do it.  I'll think about it and
get back
> to you.  (cc'ing matplotlib-users list).
>
> -Jeff
>

Juan: On second thought, I'm not sure this is desirable behavior.  I
would guess that most of the time, if a nearest neighbor is
masked, the
user would expect the interpolation routine to return a masked
value.  I
would be interested to hear what others think.

-Jeff



--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users




--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-07 Thread Aman Thakral
On a similar note, are there any alternatives available to nearest
neighbor?  For example, kriging?  I remember seeing a geostats library in
python (hpgl i think), but I found the API rather impractical and difficult
to use.

Thanks,
Aman

On Mon, Mar 7, 2011 at 8:23 AM, Jeff Whitaker  wrote:

> On 3/7/11 5:50 AM, Jeff Whitaker wrote:
> > On 3/6/11 8:58 PM, Juan A. Saenz wrote:
> >> Hi,
> >>
> >> I use Basemap and netCDF4-python on a regular basis, and find them
> >> very useful tools. Thank you for developing them!
> >>
> >> I noticed that when using basemap.interp for nearest neighbor
> >> (order=0) the interpolation is not masked, and nearest neighbor masked
> >> values will be used in the interpolation. I was wondering if you could
> >> suggest a way to do nearest neighbor interpolation where masked are
> >> supported, i.e. nearest neighbor values that are not masked.
> >>
> >> Thanks for your help,
> >> Juan
> >>
> > Juan:  I agree that this would be desirable behavior.  Unfortunately,
> > it's not obvious to me how to do it.  I'll think about it and get back
> > to you.  (cc'ing matplotlib-users list).
> >
> > -Jeff
> >
>
> Juan: On second thought, I'm not sure this is desirable behavior.  I
> would guess that most of the time, if a nearest neighbor is masked, the
> user would expect the interpolation routine to return a masked value.  I
> would be interested to hear what others think.
>
> -Jeff
>
>
>
> --
> What You Don't Know About Data Connectivity CAN Hurt You
> This paper provides an overview of data connectivity, details
> its effect on application quality, and explores various alternative
> solutions. http://p.sf.net/sfu/progress-d2d
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-07 Thread Jeff Whitaker
On 3/7/11 5:50 AM, Jeff Whitaker wrote:
> On 3/6/11 8:58 PM, Juan A. Saenz wrote:
>> Hi,
>>
>> I use Basemap and netCDF4-python on a regular basis, and find them
>> very useful tools. Thank you for developing them!
>>
>> I noticed that when using basemap.interp for nearest neighbor
>> (order=0) the interpolation is not masked, and nearest neighbor masked
>> values will be used in the interpolation. I was wondering if you could
>> suggest a way to do nearest neighbor interpolation where masked are
>> supported, i.e. nearest neighbor values that are not masked.
>>
>> Thanks for your help,
>> Juan
>>
> Juan:  I agree that this would be desirable behavior.  Unfortunately,
> it's not obvious to me how to do it.  I'll think about it and get back
> to you.  (cc'ing matplotlib-users list).
>
> -Jeff
>

Juan: On second thought, I'm not sure this is desirable behavior.  I 
would guess that most of the time, if a nearest neighbor is masked, the 
user would expect the interpolation routine to return a masked value.  I 
would be interested to hear what others think.

-Jeff


--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp nearest neighbor

2011-03-07 Thread Jeff Whitaker
On 3/6/11 8:58 PM, Juan A. Saenz wrote:
> Hi,
>
> I use Basemap and netCDF4-python on a regular basis, and find them 
> very useful tools. Thank you for developing them!
>
> I noticed that when using basemap.interp for nearest neighbor 
> (order=0) the interpolation is not masked, and nearest neighbor masked 
> values will be used in the interpolation. I was wondering if you could 
> suggest a way to do nearest neighbor interpolation where masked are 
> supported, i.e. nearest neighbor values that are not masked.
>
> Thanks for your help,
> Juan
>
Juan:  I agree that this would be desirable behavior.  Unfortunately, 
it's not obvious to me how to do it.  I'll think about it and get back 
to you.  (cc'ing matplotlib-users list).

-Jeff

--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp

2010-02-25 Thread Friedrich Romstedt
2010/2/26 Andrew Charles :
> Aye, now that I read the docstring with a rested pair of eyes it's
> clear that xout and yout are meshgrids (rank 2 arrays). Thanks,
> problem solved.

For convenience, I recently heard about numpy.meshgrid, which does the
job for you.  See its __doc__, but it's fairly easy: numpy.meshgrid(x,
y).

Friedrich

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp

2010-02-25 Thread Andrew Charles
On Thu, Feb 25, 2010 at 7:26 PM, Friedrich Romstedt
 wrote:
> 2010/2/25 Andrew Charles :
>> I'm trying to interpolate from one grid to another using Basemap's
>> interp function. It seems to want the lat and lon axis of the new grid
>> to have the same shape:
>>
>> 3524  if xout.shape != yout.shape:
>> 3535     raise ValueError, 'xout and yout must have same shape!'
>>
>> The grid I'm interpolating to is 144 by 72
>>
>> I'm calling it as interp(x,lon,lat,plon,plat)
>> where lon and plon are numpy arrays with shape (144,) lat has shape
>> (73,) plat has shape(72,) and x has shape (72, 144)
>>
>> Does interp() really only work if the target grid is square?
>
> I guess it wants a meshgrid

Aye, now that I read the docstring with a rested pair of eyes it's
clear that xout and yout are meshgrids (rank 2 arrays). Thanks,
problem solved.

-
Andrew Charles

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap interp

2010-02-25 Thread Friedrich Romstedt
Andrew, I sent this to you personally, unintentionally, and want it to
be on the list too.  So you have it doubled now, sorry.

2010/2/25 Andrew Charles :
> I'm trying to interpolate from one grid to another using Basemap's
> interp function. It seems to want the lat and lon axis of the new grid
> to have the same shape:
>
> 3524  if xout.shape != yout.shape:
> 3535     raise ValueError, 'xout and yout must have same shape!'
>
> The grid I'm interpolating to is 144 by 72
>
> I'm calling it as interp(x,lon,lat,plon,plat)
> where lon and plon are numpy arrays with shape (144,) lat has shape
> (73,) plat has shape(72,) and x has shape (72, 144)
>
> Does interp() really only work if the target grid is square?

I guess it wants a meshgrid, use e.g.:

lats = len(lat)
lons = len(lon)

lat = lat[:, numpy.newaxis].repeat(lons, axis = 1)
lon = lon[numpy.newaxis, :].repeat(lats, axis = 0)

- or the other way round -

lat = lat[numpy.newaxis, :].repeat(lons, axis = 0)
lon = lat[:, numpy.newaxis].repeat(lats, axis = 1)

depending on what axis lat and lon should respectively be associated with.

A meshgrid is a sequence of coordinate grids.  For each point KEY, the
coordinates are MESHGRID[:, KEY].  Thus you can via meshgrids specifiy
also distorted grids to interpolate to (e.g. a wavy rectangular grid
or something).  (I guess this is actually needed when doing Mercator
to Postels or similar).

Friedrich

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Basemap interp

2010-02-24 Thread Andrew Charles
I'm trying to interpolate from one grid to another using Basemap's
interp function. It seems to want the lat and lon axis of the new grid
to have the same shape:

3524  if xout.shape != yout.shape:
3535 raise ValueError, 'xout and yout must have same shape!'

The grid I'm interpolating to is 144 by 72

I'm calling it as interp(x,lon,lat,plon,plat)
where lon and plon are numpy arrays with shape (144,) lat has shape
(73,) plat has shape(72,) and x has shape (72, 144)

Does interp() really only work if the target grid is square?

-
Andrew Charles

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users