Re: Is there any way to automatically "crop" an array?

From: Rob Nicholas <rnicholas_at_nyahnyahspammersnyahnyah>
Date: Mon Jun 28 2010 - 10:07:47 MDT

Hi Bridget,

On Fri, Jun 25, 2010 at 2:09 PM, Bridget Thrasher
<bthrasher@climatecentral.org> wrote:
> Say I've got a 2-D array (lat/lon) that has a blob of data in the middle
> surrounded by missing values. Is there an NCL function that will
> automatically crop or trim that array to the edges of the data, thereby
> getting rid of the surrounding cells of missing data? Just curious since I
> don't see anything in the function list that appears to do this.

Although it won't eliminate every missing value, this simple function
should crop the array to the smallest rectangular region that includes
all of the non-missing data:

undef("crop2D")
function crop2D(x:numeric)
local i
begin
    i = ind_resolve(ind(.not.ismissing(ndtooned(x))),dimsizes(x))
    x_crop = x( min(i(:,0)):max(i(:,0)), min(i(:,1)):max(i(:,1)) )
    return(x_crop)
end

The function should retain the metadata associated with the input
array. Untested equivalents for 1-D, 3-D, and 4-D arrays are
attached.

~Rob

--
Robert Nicholas
Department of Atmospheric Sciences
University of Washington, Box 351640
Seattle, WA 98195-1640


_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Mon Jun 28 10:07:52 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 02 2010 - 07:45:13 MDT