[ncl-talk] Getting the grid point values of certain values in a masked array

Dennis Shea shea at ucar.edu
Fri Sep 14 08:46:54 MDT 2018


*http://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/ind.shtml>
*http://www.ncl.ucar.edu/Document/Functions/Built-in/ind_resolve.shtml*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/ind_resolve.shtml>

===

[SNIP]
  avo_plane   = wrf_user_intrp3d(avo,z,"h",height,0.,False)

  printVarSummary(avo_plane)         ; [south_north | ?] x [west_east | ?]
  printMinMax(avo_plane,0)
  print("---")

  avo_plane1  = avo_plane*1.e-05
  copy_VarMeta(avo_plane, avo_plane1)

  printVarSummary(avo_plane1)        ; (:,:)
  printMinMax(avo_plane1,0)
  print("---")
                              ; not sure why the following was done
 ;?? avo_masked  = where(avo_plane1.gt.0.006,0.006,avo_plane1 at _FillValue)
 ;??copy_VarMeta(avo_plane1, avo_masked)   ;

 ;??printVarSummary(avo_masked)        ; (:,:)
 ;??printMinMax(avo_masked,0)
 '??print("---")
;-------------------------------------------------------
; determine the indices where crit is exceeded

  lat2d  = a->XLAT(time,:,:)         ; (:,:)
  lon2d = a->XLONG(time,:,:)
  *printVarSummary*(lat2d)

  lat1d  = *ndtooned*(lat2d)
  lon1d = *ndtooned*(lon2d)
  avo1d = *ndtooned*(avo_plane1)
  crit     = 0.006
  ncrit   = *num*(avo1d.ge.crit)
  print("ncrit="+ncrit)
  print("---")

  if (ncrit.gt.0) then
      ind_crit = *ind*(avo1d.ge.crit)
      ji           = *ind_resolve*(ind_crit, dimsizes(avo_plane1))
      print(ji)

     dimji  =* dimsizes*(ji)
      print(dimji)
      npts   = dimji(0)       ; number of elements > crit
      ndim   = dimji(1)       ; rank

     do n=0,npts-1
        jj = ji(n,0)
        ii = ji(n,1)
        print(jj+"  "+ii+"  "+lat2d(jj,ii)+"  "+lon2d(jj,ii)+"
"+avo_plane1(jj,ii))
     end do

  else
      print("No grid points exceeded the critical value: crit="+crit)
      exit
  end if


On Thu, Sep 13, 2018 at 9:16 AM, Ty Buckingham <
ty.buckingham at manchester.ac.uk> wrote:

> Thanks for the help so far, Barry.
>
> Does anyone else have any ideas on how to resolve this?
>
> Thanks
> Ty
> ------------------------------
> *From:* Barry Lynn [barry.h.lynn at gmail.com]
> *Sent:* 13 September 2018 16:03
> *To:* Ty Buckingham
> *Subject:* Re: [ncl-talk] Getting the grid point values of certain values
> in a masked array
>
> Ty:
>
> Please (always) send to NCL-Talk.  I need to go and I won't be able to
> respond right now.
>
>
>
> On Thu, Sep 13, 2018 at 4:38 PM Ty Buckingham <
> ty.buckingham at manchester.ac.uk> wrote:
>
>> This where statement:
>>
>>   avo_masked  = where(avo_zoom.gt.0.006,1,avo_zoom at _FillValue)
>>
>> Is working just fine. I've attached a snippet of what the output from
>> this looks like (it's over 58,000 values so I haven't printed them all).
>> What I'd like to do next is to disregard all of the co-ordinates equal to
>> 9.96921e+36 and just keep the coordinates for the values that equal 1.
>> For example, from the snippet I'd like the co-ordinates (387,37-39) and
>> none of the others. This where statement:
>>
>>    avo_gridpts = where(avo_masked.eq.1,avo_masked,0)
>>
>> Gives me the same result as the first where statement.
>>
>> To try and explain it visually - I'm using vorticity (avo in the script)
>> as a proxy for the location of a cold front in my data. I then want all of
>> the coordinates for where avo is 1 so i can have a list of coordinates that
>> refer to the location of my cold front.
>>
>> Thanks
>> Ty
>>
>>
>> ------------------------------
>> *From:* Barry Lynn [barry.h.lynn at gmail.com]
>> *Sent:* 13 September 2018 14:21
>>
>> *To:* Ty Buckingham
>> *Cc:* ncl-talk
>> *Subject:* Re: [ncl-talk] Getting the grid point values of certain
>> values in a masked array
>>
>> Hi:
>>
>> But you haven't explained why the where statement is not working for.
>>
>> Can you print out the values that go into the where statement and  result
>> from the where statement and send a sample.
>>
>> On Thu, Sep 13, 2018 at 4:18 PM Ty Buckingham <
>> ty.buckingham at manchester.ac.uk> wrote:
>>
>>> I have the coordinates for all of the values - including both the masked
>>> and filled values.
>>>
>>> What I want is to isolate all the coordinates where the value = 1 and
>>> save these coordinates as a 1D array and ignore all the coordinates where
>>> the value =/= 1.
>>>
>>> Ty
>>> ------------------------------
>>> *From:* Barry Lynn [barry.h.lynn at gmail.com]
>>> *Sent:* 13 September 2018 14:15
>>> *To:* Ty Buckingham
>>> *Cc:* ncl-talk
>>> *Subject:* Re: [ncl-talk] Getting the grid point values of certain
>>> values in a masked array
>>>
>>> Hi:
>>>
>>> When you extract the data, you should check and see what the coordinates
>>> are.
>>>
>>> If there are none, they can be added.
>>>
>>> Barry
>>>
>>> On Thu, Sep 13, 2018 at 3:18 PM Ty Buckingham <
>>> ty.buckingham at manchester.ac.uk> wrote:
>>>
>>>> Yes, there's no problem with the data itself, I'm just not sure how to
>>>> extract values that equal 1 into a new array so they keep their lat/lon
>>>> values.
>>>>
>>>> Thanks
>>>> Ty
>>>> ------------------------------
>>>> *From:* Barry Lynn [barry.h.lynn at gmail.com]
>>>> *Sent:* 13 September 2018 12:44
>>>> *To:* Ty Buckingham; ncl-talk
>>>> *Subject:* Re: [ncl-talk] Getting the grid point values of certain
>>>> values in a masked array
>>>>
>>>> Hi:
>>>>
>>>> Have you tried using PrintMinMAX(Variable, False) to see the range of
>>>> your data?
>>>>
>>>> Barry
>>>>
>>>> On Thu, Sep 13, 2018 at 1:53 PM Ty Buckingham <
>>>> ty.buckingham at manchester.ac.uk> wrote:
>>>>
>>>>> I'm not entirely sure of the syntax. If I try something like:
>>>>>
>>>>>   avo_masked  = where(avo_zoom.gt.0.006,1,avo_zoom at _FillValue)
>>>>>
>>>>>   avo_gridpts = where(avo_masked.eq.1,avo_masked,0)
>>>>>
>>>>>
>>>>> I still get all of the false values and their corresponding grid
>>>>> points, when I only want avo_gridpts to contain the values equal to 1 and
>>>>> their corresponding grid point values.
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>> Ty
>>>>> ------------------------------
>>>>> *From:* Barry Lynn [barry.h.lynn at gmail.com]
>>>>> *Sent:* 13 September 2018 10:50
>>>>> *To:* Ty Buckingham
>>>>> *Subject:* Re: [ncl-talk] Getting the grid point values of certain
>>>>> values in a masked array
>>>>>
>>>>> Hi:
>>>>>
>>>>> There should be.  If you want to find only those values, then set the
>>>>> middle part of your where statement equal to that.
>>>>>
>>>>> However, unless  the values are exact you might have a problem finding
>>>>> them.  Then, you might multiply by 1000 and then include the integer
>>>>> function.
>>>>>
>>>>> Barry
>>>>>
>>>>> On Thu, Sep 13, 2018 at 12:46 PM Ty Buckingham <
>>>>> ty.buckingham at manchester.ac.uk> wrote:
>>>>>
>>>>>> Hi Barry,
>>>>>>
>>>>>> It is indeed. Is there anyway to extract the grid points of all the
>>>>>> values equal to 0.006 and ignore the rest?
>>>>>>
>>>>>> Thanks
>>>>>> Ty
>>>>>> ________________________________________
>>>>>> From: Barry Lynn [barry.h.lynn at gmail.com]
>>>>>> Sent: 13 September 2018 06:00
>>>>>> To: Ty Buckingham
>>>>>> Cc: ncl-talk
>>>>>> Subject: Re: [ncl-talk] Getting the grid point values of certain
>>>>>> values in a masked array
>>>>>>
>>>>>> Hi:
>>>>>>
>>>>>> The where statement:
>>>>>>
>>>>>>
>>>>>> avo_masked  = where(avo_zoom.gt.0.006,0.006,avo_zoom at _FillValue)
>>>>>>
>>>>>>
>>>>>> will set every grid with a value of 0.006 or greater equal to 0.006.
>>>>>>
>>>>>>
>>>>>> Is that what you wanted to do?
>>>>>>
>>>>>>
>>>>>> Barry
>>>>>>
>>>>>> On Thu, Sep 13, 2018 at 12:18 AM Ty Buckingham <
>>>>>> ty.buckingham at manchester.ac.uk<mailto:ty.buckingham at manchester.ac.uk>>
>>>>>> wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> I have a masked array and wish to get the grid points (or lat/lons)
>>>>>> of all of the values that are above a certain threshold. I've been messing
>>>>>> around with 'where' and 'if' statements but can't quite get it.
>>>>>>
>>>>>> I've attached my script.
>>>>>>
>>>>>> Any help?
>>>>>>
>>>>>> Thanks in advance!
>>>>>> Ty
>>>>>> _______________________________________________
>>>>>> ncl-talk mailing list
>>>>>> ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Barry H. Lynn, Ph.D
>>>>>> Senior Associate Scientist, Lecturer,
>>>>>> The Institute of the Earth Science,
>>>>>> The Hebrew University of Jerusalem,
>>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>>> Tel: 972 547 231 170
>>>>>> Fax: (972)-25662581
>>>>>>
>>>>>> C.E.O, Weather It Is, LTD
>>>>>> Weather and Climate Focus
>>>>>> http://weather-it-is.com
>>>>>> Jerusalem, Israel
>>>>>> Local: 02 930 9525
>>>>>> Cell: 054 7 231 170
>>>>>> Int-IS: x972 2 930 9525
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> Barry H. Lynn, Ph.D
>>>>> Senior Associate Scientist, Lecturer,
>>>>> The Institute of the Earth Science,
>>>>> The Hebrew University of Jerusalem,
>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>> Tel: 972 547 231 170
>>>>> Fax: (972)-25662581
>>>>>
>>>>> C.E.O, Weather It Is, LTD
>>>>> Weather and Climate Focus
>>>>> http://weather-it-is.com
>>>>> Jerusalem, Israel
>>>>> Local: 02 930 9525
>>>>> Cell: 054 7 231 170
>>>>> Int-IS: x972 2 930 9525
>>>>>
>>>>>
>>>>
>>>> --
>>>> Barry H. Lynn, Ph.D
>>>> Senior Associate Scientist, Lecturer,
>>>> The Institute of the Earth Science,
>>>> The Hebrew University of Jerusalem,
>>>> Givat Ram, Jerusalem 91904, Israel
>>>> Tel: 972 547 231 170
>>>> Fax: (972)-25662581
>>>>
>>>> C.E.O, Weather It Is, LTD
>>>> Weather and Climate Focus
>>>> http://weather-it-is.com
>>>> Jerusalem, Israel
>>>> Local: 02 930 9525
>>>> Cell: 054 7 231 170
>>>> Int-IS: x972 2 930 9525
>>>>
>>>>
>>>
>>> --
>>> Barry H. Lynn, Ph.D
>>> Senior Associate Scientist, Lecturer,
>>> The Institute of the Earth Science,
>>> The Hebrew University of Jerusalem,
>>> Givat Ram, Jerusalem 91904, Israel
>>> Tel: 972 547 231 170
>>> Fax: (972)-25662581
>>>
>>> C.E.O, Weather It Is, LTD
>>> Weather and Climate Focus
>>> http://weather-it-is.com
>>> Jerusalem, Israel
>>> Local: 02 930 9525
>>> Cell: 054 7 231 170
>>> Int-IS: x972 2 930 9525
>>>
>>>
>>
>> --
>> Barry H. Lynn, Ph.D
>> Senior Associate Scientist, Lecturer,
>> The Institute of the Earth Science,
>> The Hebrew University of Jerusalem,
>> Givat Ram, Jerusalem 91904, Israel
>> Tel: 972 547 231 170
>> Fax: (972)-25662581
>>
>> C.E.O, Weather It Is, LTD
>> Weather and Climate Focus
>> http://weather-it-is.com
>> Jerusalem, Israel
>> Local: 02 930 9525
>> Cell: 054 7 231 170
>> Int-IS: x972 2 930 9525
>>
>>
>
> --
> Barry H. Lynn, Ph.D
> Senior Associate Scientist, Lecturer,
> The Institute of the Earth Science,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> C.E.O, Weather It Is, LTD
> Weather and Climate Focus
> http://weather-it-is.com
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
>
>
> _______________________________________________
> 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/20180914/3903cd5e/attachment.html>


More information about the ncl-talk mailing list