[ncl-talk] getting a field in an a 2D array

Lyndz olagueralyndonmark429 at gmail.com
Wed Apr 11 23:32:13 MDT 2018


Hi Mary,

This is in relation to my previous post with the subject: "convert polyline
shapefile to netcdf via ncl_convert2nc" where I only wanted to count unique
TC's within a 5x5degree drid box.
It was suggested to sort the input based on the "SN" column first before
counting and updating a column whenever a different "SN" value is read for
every lat-lon points.

I combined some lines from your script and the binning script from the NCL
example page (https://www.ncl.ucar.edu/Applications/binning.shtml). I
attached in this email the script that I am using.

I added the following lines but resulted to some errors:

  sn_unique = get_unique_values(sn)
  snpts       = dimsizes(sn_unique)

  do a=0,snpts-1
         ii := ind(sn.eq.sn_unique(a))
  end do

  npts = dimsizes(ii)
  nlat=lat(ii)
  nlon=lon(ii)
  nvmax=vmax(ii)

  do n=0,npts-1
           if (nlat(n).ge.latS .and. nlat(n).le.latN .and.  \
                 nlon(n).ge.lonW .and. nlon(n).le.lonE .and.  \
                .not.ismissing(nvmax(n)) ) then

                 jl = toint((nlat(n)-latS)/dlat)
                 il = toint((nlon(n)-lonW)/dlon)
                 count(jl,il)  = count(jl,il)  + 1
                 valavg(jl,il) = valavg(jl,il) + nvmax(n)
              end if
  end do


[Errors]
warning:ContourPlotInitialize: no valid values in scalar field; ContourPlot
not possible:[errno=1101]
warning:ContourPlotSetValues: cnLevelSpacingF value exceeds or equals data
range: defaulting
warning:ContourPlotInitialize: no valid values in scalar field; ContourPlot
not possible:[errno=1101]
warning:ContourPlotSetValues: cnLevelSpacingF value exceeds or equals data
range: defaulting
warning:ContourPlotInitialize: no valid values in scalar field; ContourPlot
not possible:[errno=1101]
warning:ContourPlotSetValues: cnLevelSpacingF value exceeds or equals data
range: defaulting

Many thanks for the help.
Sincerely,

Lyndz





On Thu, Apr 12, 2018 at 12:05 PM, Mary Haley <haley at ucar.edu> wrote:

> Dear Lyndz,
>
> I wrote an email answering your question about how to access rows and
> columns of data, but then I realized that I'm not sure this is what you
> really wanted.
>
> It might be easier for you to read each column of data from the file
> individually, and then sort the array(s) that you need.
>
> Since it's not clear what you want to do with the sorted values, I created
> an example that creates a sort vector for the "sn" column, and then it
> prints both "sn" and "year" using this sort vector.
>
> Since I was curious, I also plotted your data with different colored dots
> for each of the unique categories, and different dots for each set of years.
>
> If you are still not sure how to get the sorting you need, please reply
> back to ncl-talk with more information about what you are trying to do.
>
> Thanks
>
> --Mary
>
>
>
> On Tue, Apr 10, 2018 at 8:49 PM, Lyndz <olagueralyndonmark429 at gmail.com>
> wrote:
>
>>
>> Dear NCL experts,
>>
>> I am trying to get a field in a 2D array after sorting. Is there a way to
>> extract the "fourth column" (*(0,4) 198920 in the sample below)*, for
>> example in the 2D array. I tried using the *str_get_field *function, but
>> it does not work for this case.
>>
>> Any suggestion on how to do this correctly?
>>
>>
>> These are the commands that I am using:
>>
>> filename="test.txt"
>> test=readAsciiTable(filename,9,"float",1)
>> i=dim_pqsort_n(test(:,0),1,0)
>> Aout=test(i,:)
>> print(Aout)
>>
>> Variable: Aout
>> Type: float
>> Total Size: 39528 bytes
>>             9882 values
>> Number of Dimensions: 2
>> Dimensions and sizes: [1098] x [9]
>> Coordinates:
>> Number Of Attributes: 1
>>   _FillValue : 9.96921e+36
>> (0,0) 0
>> (0,1) 26.1
>> (0,2) 130
>> (0,3) 40
>> *(0,4) 198920*
>> (0,5) 20
>> (0,6) 1989
>> (0,7) 8
>> (0,8) 26
>> (1,0) 0
>> (1,1) 28.7
>> (1,2) 122.9
>>
>>
>> I'll appreciate any help.
>>
>>
>> Sincerely,
>>
>> Lyndz
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180412/4b3376bb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: count_tc.ncl
Type: application/octet-stream
Size: 6238 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180412/4b3376bb/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binning.png
Type: image/png
Size: 144953 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180412/4b3376bb/attachment.png>


More information about the ncl-talk mailing list