Adding or averaging multiple grid arrays returns all NaNs [message #92722] |
Wed, 17 February 2016 04:34  |
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   |
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
|
|
|
|
|
|