[ncl-talk] Can't add arrays to do average.
Walter Kolczynski
walter.kolczynski at noaa.gov
Wed Sep 30 20:25:38 MDT 2015
First, you say you know there are nicer ways, why aren't you using one
of them? This is a one-line operation in ncl using dim_avg_n_Wrap, which
also eliminates the loop, which is inherently slow in interpreted
languages like NCL.
Second, using a fill value of zero is definitely the problem and just a
bad idea generally. Because you assign the zero as the missing value and
then initialize the array with zeros, when you try to add a value to
that, the result is still a missing value ( ? + a = ? ). If you want to
do it this way, you need to either use a different missing value or
initialize the sum to the first sst value instead. Plus, if you want an
average, you need to divide by the number of times at the end.
Also note that if your data actually *has* missing data, your method
will produce missing data at those locations, whereas using the built-in
function will ignore the missing data and calculate the average based on
times that exist.
Third, you are overwriting the fill value is for the input data. It is
likely you don't even need to set the fill value, but if you do you
should make sure you are setting it to the proper value for your
dataset, which is unlikely to be zero, as zero is a terrible choice for
anomaly data where 0 is a valid (even common) value.
- Walter
On 2015-09-30 19:34, Sebastian Otarola-Bustos wrote:
> Hi everybody, I'm working with NOA high resolution daily sea surface
> temperature anomalies. I have 3D variable sst(days,lat,lon) and want
> to compute average for the week, so I created sst_avg(lat,lon) float
> 2D array full with zeros, to save the sum of all days in this
> variable( very simple). But the problem is that this sum is not
> working so sst_avg is full of zeros after the operation.
>
> The main features of the code arre below:
>
> *sst = a->anom*
> *dims = dimsizes(sst)*
> *times = dims(0)*
> *row = dims(1)*
> *col = dims(2)
>
> *
> *sst at _FillValue = 0.*
> *sst_avg = new((/row,col/),"float",0.)*
> *sst_avg at _FillValue = 0.*
> *copy_VarCoords(sst(0,:,:),sst_avg)*
> * printVarSummary(sst)
> do it =0,times-1*
> *sst_avg = sst_avg + sst(it,:,:)*
> * print(sst_avg)*
> * end do*
> *printVarSummary(sst_avg)
> *
> sst.PNG, and sst_avg.PNG show the information of sst and sst_avg after
> the iteration.
>
> I thought that has something to do with @FillValue, but I changed this
> and the only thing I got was very huge and nonsense numbers instead of
> sst_avg full with zeros.
>
> P.S: I know there are nicer ways of computing average, but my doubt is
> mainly about the sum that is not working. Thank you very much in
> advance and any help would be really appreciated.
>
> All the best,
> Sebastián.
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150930/04d5db95/attachment.html
More information about the ncl-talk
mailing list