Re: help with Replacing missing value in an array with zeros

From: Erik Noble <enoble_at_nyahnyahspammersnyahnyah>
Date: Fri, 18 Jul 2008 14:17:46 -0400

Dear Adam,
Thank you for pointing out the 1D requirement for ind.

I used the dim_avg function earlier and wound up with negative values.
I mistook this as a result of trying to average -9999 fill values. I
see from your example that its not. But I still get negative values
when I start out with only positive numbers. I'm trying to make my 3D
array "r" (time, lat, lon) into a 1D array to plot as a bar graph,
line plot, etc,...but I shouldn't be getting the negative numbers.

Below is my reasoning. Am I using dim_avg wrong?
Thank you,
Erik

ncl 0> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
ncl 1> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
ncl 2> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
ncl 3> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
ncl 4> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
ncl 6> a=addfile("200609_CMORPH_3hr-025deg.nc","r")
ncl 7> r=a->CMORPH
ncl 8> printVarSummary(r)

Variable: r
Type: float
Total Size: 60099840 bytes
            15024960 values
Number of Dimensions: 3
Dimensions and sizes: [time | 240] x [lat | 222] x [lon | 282]
Coordinates:
            time: [2006090100..2006093021]
            lat: [-20.125..35.125]
            lon: [-35.125..35.125]
Number Of Attributes: 4
  lonFlip : longitude coordinate variable has been reordered via lonFlip
  long_name : merged microwave precipitation
  units : mm/hr
  _FillValue : -999
ncl 9> max_r = max(r)
ncl 10> min_r = min(r)
ncl 11> print(min_r)

Variable: min_r
Type: float
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -9999
ncl 12> print(max_r)

Variable: max_r
Type: float
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 50
ncl 13> x = dim_avg(r)
ncl 14> y = dim_avg(x)
ncl 15> max_y = max(y)
ncl 16> min_y = min(y)
ncl 17> print(min_y)
Variable: min_y
Type: float
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -6503.074
ncl 18> print(max_y)

Variable: max_y
Type: float
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -0.7426707
ncl 19>

On Fri, Jul 18, 2008 at 1:56 PM, Adam Phillips <asphilli_at_cgd.ucar.edu> wrote:
> Hi Erik,
>
> dim_avg ignores all data that is set to _FillValue, as you can see here:
>
> ncl 0> a = (/1,2,3,4,5,-999/)
> ncl 1> a@_FillValue = -999
> ncl 2> print(dim_avg(a))
> (0) 3
>
> So I don't know that you want to replace all the _FillValue data with 0's.
>
> Second, the ind documentation states that the input array must be
> 1-dimensional, and you are inputting a 3-dimensional array. That is what the
> "fatal:Number of dimensions in parameter (0) of (ind) is (3), (1)
> dimensions were expected" error message means. Continuing with the
> interactive ncl from above:
> ncl 3> a(ind(ismissing(a))) = 0
> ncl 4> print(a)
>
> Variable: a
> Type: integer
> Total Size: 24 bytes
> 6 values
> Number of Dimensions: 1
> Dimensions and sizes: [6]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -999
> (0) 1
> (1) 2
> (2) 3
> (3) 4
> (4) 5
> (5) 0
>
> Adam
>
>
> Erik Noble wrote:
>>
>> Dear NCL,
>> I was testing the ind and ismissing functions out in command line
>> mode on my data to exclude the fill value when I do an average of the
>> data (using dim_avg) . I followed examples #1 and #2 at
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml
>> The ncl ind function page does not explain why i might be getting the
>> error that i am getting. Could I have some help resolving this?
>>
>> Thank you for your time.
>> -Erik
>>
>>
>> ncl 15> printVarSummary(r)
>>
>>
>> Variable: r
>> Type: float
>> Total Size: 60099840 bytes
>> 15024960 values
>> Number of Dimensions: 3
>> Dimensions and sizes: [time | 240] x [lat | 222] x [lon | 282]
>> Coordinates:
>> time: [2006090100..2006093021]
>> lat: [-20.125..35.125]
>> lon: [-35.125..35.125]
>> Number Of Attributes: 4
>> lonFlip : longitude coordinate variable has been reordered via
>> lonFlip
>> long_name : merged microwave precipitation
>> units : mm/hr
>> _FillValue : -9999
>> ncl 16> r@_FillValue = -9999
>> ncl 17> r(ind(ismissing(r))) = 0
>> fatal:Number of dimensions in parameter (0) of (ind) is (3), (1)
>> dimensions were expected
>> fatal:Execute: Error occurred at or near line 12
>>
>> ncl 18> ir =ind(.not.ismissing(r))
>> fatal:Number of dimensions in parameter (0) of (ind) is (3), (1)
>> dimensions were expected
>> fatal:Execute: Error occurred at or near line 14
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> --------------------------------------------------------------
> Adam Phillips asphilli_at_ucar.edu
> National Center for Atmospheric Research tel: (303) 497-1726
> ESSL/CGD/CAS fax: (303) 497-1333
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jul 18 2008 - 12:17:46 MDT

This archive was generated by hypermail 2.2.0 : Mon Jul 21 2008 - 14:41:34 MDT