[Thread Prev][Thread Next][Index]

Re: [ferret_users] scat2grid_nbin_xy using mode instead of mean



Hi Nandini,
If you are a Fortran (or c) programmer, then it would be a fairly simple job to take one of the existing scat2grid  functions and use it as a model for a new external function that uses the mode.  If this seems like a possibility for you, I would be happy to consult with you getting started with this.

There may be ways to use the scat2grid_nbin function. Do the data take on just a few discrete values?  If so then you could create a few gridded variables, number of obs with value v1, number of obs with value v2, number of obs with value v3, and then use Ferret to combine the results.

If your scattered locations are xpts, ypts, and the data are fpts which take on the values 17 or 18, and xaxpts, yaxpts are coordinates of the axes of the result grid, then it might look something like this:
yes? let mask_v1 = if fpts EQ 17 then 1
yes? let mask_v2 = if fpts EQ 18 then 1

yes? let ngrid_v1 = scat2grid_nbin_xy(xpts,ypts, mask_v1, xaxpts, yaxpts)
yes? let ngrid_v2 = scat2grid_nbin_xy(xpts,ypts, mask_v2, xaxpts, yaxpts)

yes? let bin_mode_1_2 = if ngrid_v1 gt ngrid_v2 then 18 else 17
This is just a sketch of the kinds of ideas that might be possible, but this sort of thing gets unwieldy very fast for more than a very small number of discrete values. You'd also need to do something to handle the value of zero, if there are grid cells with counts of zero. 

-Ansley

On 2/4/2016 12:25 PM, Nandini Ramesh wrote:
Hi, 

I have some scattered data that needs to be interpolated onto an xy grid. The simplest way to do this is to use scat2grid_bin_xy, which calculates the average of all of the values that fall within a particular gridbox. What I need is a very similar function that instead of calculating the mean, calculates the mode from my scattered data; i.e., I need the function to choose the most-repeated value that appears in each gridbox rather than the mean of all values that appear in each gridbox. This is because in this case, I am considering the most-repeated value at a particular location to be the best estimate, and all other values to be incorrect. I looked at the documentation, but wasn't able to figure out how to do this. Does anybody here know of a function that does this, or how to manipulate one of the scat2grid functions to get this result?

Thank you for your help!

Cheers,
Nandini

Nandini Ramesh
PhD Candidate, 
Lamont-Doherty Earth Observatory


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement