Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Adding or averaging multiple grid arrays returns all NaNs
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
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
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?
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.
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