comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Adding or averaging multiple grid arrays returns all NaNs
items: Re: Adding or averaging multiple grid arrays returns all NaNs

Adding or averaging multiple grid arrays returns all NaNs
type: item
description: 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
creator: Luke Conibear
date: 2016-02-17T12:34:50-00:00

Re: Adding or averaging multiple grid arrays returns all NaNs
type: item
description: 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
creator: Dick Jackson
date: 2016-02-18T17:47:12-00:00

Re: Adding or averaging multiple grid arrays returns all NaNs
type: item
description: 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?
creator: Luke Conibear
date: 2016-02-18T22:48:56-00:00

Re: Adding or averaging multiple grid arrays returns all NaNs
type: item
description: 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.
creator: Mats Löfdahl
date: 2016-02-19T13:05:35-00:00

Re: Adding or averaging multiple grid arrays returns all NaNs
type: item
description: 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
creator: Luke Conibear
date: 2016-02-19T17:16:46-00:00