[ncl-talk] Extracting temperature from specific grids where LU_INDEX = 2

Barry Lynn barry.h.lynn at gmail.com
Tue Mar 14 03:31:18 MDT 2017


Hi:

I used the mask command to remove data I did not want to map. I am not sure
what the values become in the masked area.

Another way to do this is for a single time loop

lu_index = LU_INDEX(time,:,:)
my_t2 = lu_index
my_t2 = -9999
; assuming t2 has dimensions of space, not time.

dims2d = dimsizes(lu_index)

do j = 1, dims2d(0)
do i = 1, dims2d(1)

if (lu_index(j,i).eq.1) then
my_t2(j,i) = t2(j,i)
end if
end do
end do


On Tue, Mar 14, 2017 at 11:24 AM, Guido Cioni <guidocioni at gmail.com> wrote:

> Can you tell me what is the final goal? Otherwise it is really difficult
> to give you advices :)
>
> Are you *sure* that your script is working correctly? As far as I
> understand the mask function acts only on the values where the mask array
> condition is true, so in your case T2_masked should be untouched, i.e.
> T2_masked=T2. Have you tried printing or plotting the difference
> T2-T2_masked?You should instead mask all the points that *DO NOT* have
> LU_INDEX=2, as I previously suggested. Furthermore, you should set the
> FillValue BEFORE calling mask, otherwise the True, False conditions will
> not apply correctly. If you are more confident with the where syntax use
> something like this
>
> where( LU_INDEX=2, T2(time_i,:,:), T2 at _FilllValue)
>
> However you would need to do that for every time instant with a loop...
>
> Now to the other question. *Are you really sure* that you want to SUBSET
> your data given a certain condition? If you just need to extract statistics
> from those data having the original array masked is the best way to go as
> NCL will deal with Missing Values without problems. If you instead try to
> subset your data you will end up with a weird shaped array, as the
> LU_INDEX=2 condition, I believe, is not spatially coherent like say a box
> or a circle. One way to go would be to convert the temperature array to a
> 1-D one with ndtooned (https://www.ncl.ucar.edu/
> Document/Functions/Built-in/ndtooned.shtml), apply the ind function and
> then convert back to a multidimensional array (Example 3 at this page is
> useful http://www.ncl.ucar.edu/Document/Functions/Built-in/minind.shtml).
> But really, it is cumbersome and useless depending on what is your final
> goal.
>
> I think there are a lot of examples on the online guide.
>
> Good Luck
>
> Guido Cioni
> http://guidocioni.altervista.org
>
> On 14 Mar 2017, at 10:06, Imran Hosen <hosen.imran09 at gmail.com> wrote:
>
> Dear Guido and Barry,
>
> Thank you so much for your heartfelt and prompt response. Yes, your
> suggestions are working fine for my script.
>
> Guido, your assumption is absolutely right. According your suggestion I
> wrote the script as follows:
>
> T2 = f_1->T2(:,:,:)
> LU_INDEX = f_1->LU_INDEX(0,:,:)       ; (LU_INDEX = landuse index)
> T2_masked = mask(T2,(LU_INDEX.eq.2), True)
> T2_masked at _FillValue = -9999
> print(T2_masked)
>
> The script works fine and it is extracting both real values and FillValues
> (missing values). *But, I want to extract only real values*. I have seen
> that "*ind*" function can be used for extracting real values for *one-dimensional
> array*. Could you please suggest me what function I can use to extract
> the real values for *two-dimensional array*.
>
> Your further suggestion will be highly appreciated.
>
> Kind regards,
> Imran
>
>
> On Tue, Mar 14, 2017 at 6:55 PM, Guido Cioni <guidocioni at gmail.com> wrote:
>
>> Hi Imran,
>> unfortunately I’m not really an expert of WRF, so I’m going to give you a
>> general hint which may work. You should be more precise next time as
>> generally people do not know what is LU_INDEX and what is its structure ;)
>>
>> I assume that you want to extract temperature, which is 3-D (time, lat,
>> lon) using a mask array LU_INDEX which is 2-D (lat, lon). Again, if this
>> assumption is wrong please be more specific. You have many choices, but I
>> believe that for the sake of clarity you may want to go for an array which
>> has the same dimensions but missing values where LU_INDEX is not 2. So you
>> may want to do something like this:
>>
>> T2_masked=mask(T2, LU_INDEX.ne.2, False).
>>
>> You need to have a Missing Value attribute set for the T2 variable of
>> course. As a result you will get an array with the same dimensions, so that
>> it’s easier to compare with the original one, but with Missing Values where
>> your condition is False, so that for every computation these points will
>> not be considered. You can achieve something similar with the where
>> function. Please have a look here (http://www.ncl.ucar.edu/Docum
>> ent/Functions/Built-in/mask.shtml).
>>
>> Cheers
>>
>>
>> Il giorno 14 mar 2017, alle ore 04:38, Imran Hosen <
>> hosen.imran09 at gmail.com> ha scritto:
>>
>> Dear NCL users,
>>
>> Good day!
>>
>> I'm a new user of NCL. I want to extract temperature (T2) from wrfout
>> file for the specific grid points where the LU_INDEX = 2.
>>
>> For example,
>> f = addfile("./wrfout.nc)
>> T2 = f->T2(:,:,:)
>>
>> It will extract temperature for whole domain for all time steps. In my
>> case, I only want to extract temperature for all time steps but for the
>> specific grids which grids represent LU_INDEX = 2.
>>
>> Could you please suggest how to do it. I would grateful to you if anyone
>> please share a script.
>>
>> Thanks in advance.
>>
>> Kind regards,
>> Imran
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>>
>
>
> --
> *Md. Imran Hosen*
> PhD Student
> Victoria University
> College of Engineering and Science
> Footscray Park Campus
> Victoria, Australia
> Mob. +61470371562 <+61%20470%20371%20562>
>
>
>
>


-- 
Barry H. Lynn, Ph.D
Senior 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
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170314/4062082a/attachment.html 


More information about the ncl-talk mailing list