comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Adding or averaging multiple grid arrays returns all NaNs
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Adding or averaging multiple grid arrays returns all NaNs [message #92722] Wed, 17 February 2016 04:34 Go to next message
Luke Conibear is currently offline  Luke Conibear
Messages: 6
Registered: February 2016
Junior Member
Hi,

I have a 2D grid array (lon, lat) for each day of my data:

GRID FLOAT = Array[3999, 1999]

This array is dispersed with values and plots to a map nicely.

When I add multiple grids together or average them (as below), every value in the 2D array turns to NaN, so the plot is blank.

TOTAL_GRID FLOAT = Array[3999, 1999]
total_grid = total_grid + grid
MEAN_GRID FLOAT = Array[3999, 1999]
mean_grid = total_grid / n_days

Does anyone know a solution, as looping for every lat and lon cell would be very computationally expensive for my large data set?

Thanks,
Luke
Re: Adding or averaging multiple grid arrays returns all NaNs [message #92731 is a reply to message #92722] Thu, 18 February 2016 09:47 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
On Wednesday, 17 February 2016 04:34:53 UTC-8, Luke Conibear wrote:
> Hi,
>
> I have a 2D grid array (lon, lat) for each day of my data:
>
> GRID FLOAT = Array[3999, 1999]
>
> This array is dispersed with values and plots to a map nicely.
>
> When I add multiple grids together or average them (as below), every value in the 2D array turns to NaN, so the plot is blank.
>
> TOTAL_GRID FLOAT = Array[3999, 1999]
> total_grid = total_grid + grid
> MEAN_GRID FLOAT = Array[3999, 1999]
> mean_grid = total_grid / n_days
>
> Does anyone know a solution, as looping for every lat and lon cell would be very computationally expensive for my large data set?
>
> Thanks,
> Luke

Hi Luke,

Good question! Am I right that 'NaN' in your data would be treated the same as zero? (It looks like it, since you divide the total by n_days) If so, preparing a "real_grid" from "grid" would work. You could do this before adding grid to total_grid:

grid[Where(Finite(grid, /NAN))] = 0

If you needed to track which grid elements always had NaN, there are ways to handle that too. Let us know if this is sufficient.

--

Cheers,
-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada
www.d-jackson.com
Re: Adding or averaging multiple grid arrays returns all NaNs [message #92732 is a reply to message #92722] Thu, 18 February 2016 14:48 Go to previous messageGo to next message
Luke Conibear is currently offline  Luke Conibear
Messages: 6
Registered: February 2016
Junior Member
Hi Dick,

I've done this and it works to produce a plot, though the magnitude of values is wrong.

I think it's because I'm dividing the total grid by the overall number of days, even though some of the cells only had data for a couple of days within that time frame. I need to somehow only divide cells by the number of days that that cell had a value for.

Any thoughts?
Re: Adding or averaging multiple grid arrays returns all NaNs [message #92737 is a reply to message #92732] Fri, 19 February 2016 05:05 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Make n_days an array of the same size as total_grid. Then each time you add values to some cells in total_grid, also add unity to the corresponding cells in n_days. Then do the final division by n_days only for the elements where n_days is non-zero.
Re: Adding or averaging multiple grid arrays returns all NaNs [message #92738 is a reply to message #92722] Fri, 19 February 2016 09:16 Go to previous message
Luke Conibear is currently offline  Luke Conibear
Messages: 6
Registered: February 2016
Junior Member
Hey Mats

That worked well thanks. I just need to remove a few erroneous very high values that are scattered across the plot. I'll research into a screening process to filter out these "bad" data
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Passing an array of color values into polyfill
Next Topic: Summation Image arrays

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:23:37 PDT 2025

Total time taken to generate the page: 0.20154 seconds