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

Guido Cioni guidocioni at gmail.com
Tue Mar 14 03:24:53 MDT 2017


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 <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 <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 <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 <mailto: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/Document/Functions/Built-in/mask.shtml <http://www.ncl.ucar.edu/Document/Functions/Built-in/mask.shtml>).
> 
> Cheers
> 
> 
>> Il giorno 14 mar 2017, alle ore 04:38, Imran Hosen <hosen.imran09 at gmail.com <mailto: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 <http://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 <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <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
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170314/ca3d7a76/attachment.html 


More information about the ncl-talk mailing list