# Pygmt.nearneighbor strange behaviour

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-nearneighbor-strange-behaviour/5696>\
**Category:** PyGMT Q&A\
**Created:** [January 23, 2025, 7:52pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-nearneighbor-strange-behaviour/5696 "2025-01-23T19:52:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpath2o](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/dpath2o/32/1732_2.png) [@dpath2o](https://forum.generic-mapping-tools.org/u/dpath2o)\
**Post date:** [January 23, 2025, 7:52pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-nearneighbor-strange-behaviour/5696/1 "2025-01-23T19:52:16Z")

</div>

Can someone please help me undertand (and potentially solve) a problem with nearneighbor?

Here is my code snippet:

```auto
hi_grd = pygmt.nearneighbor(x=np.ravel(lon_mask.values),
                            y=np.ravel(lat_mask.values),
                            z=np.ravel(hi_mask.values),
                            region=ext_plt,
                            spacing="15m",
                            search_radius="20m")

```

Before I put [[hi\_mask]] through [[nearneighbor]] method [[hi\_mask]] has min/max values of:  
0.21114222705364227  
2.829690456390381

However after [[nearneighbor]] [[grdinfo]] reports:

> : Title:  
> : Command:  
> : Remark:  
> : Gridline node registration used [Geographic grid]  
> : Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
> : x\_min: -19.0000000  
> : x\_max: 18.0000000  
> : x\_inc: 0.2500000  
> : name: x  
> : n\_columns: 149  
> : y\_min: -76.0000000  
> : y\_max: -66.0000000  
> : y\_inc: 0.2500000  
> : name: y  
> : n\_rows: 41  
> : zmin: 0.976684  
> : zmax: 0.976684  
> : name: z  
> : scale\_factor: 1 add\_offset: 0  
> : format: classic  
> : Default CPT:

where:

```auto
hi_bar = reg_cice.hi.mean(dim='time',skipna=True).compute()
hi_mask = hi_bar.where((fic > 0) & (fic < 1), np.nan)

```

and [[fic]] is a gridded field that ranges from 0 to 1.

The 0.97 value that [[grdinfo]] is reporting is odd because it appears to be picking up the values of [[fic]], which for some reason xarray is unaware or is able to deal reporting of masked values better/worse than [[grdinfo]] or possibly [[nearneighbor]].

Any help is kindly appreciated.
