[ncl-talk] Extracting temperature from specific grids where LU_INDEX = 2
Imran Hosen
hosen.imran09 at gmail.com
Tue Mar 14 23:02:53 MDT 2017
Dear Guido,
Good day!
It seems to me that *"mask"* function is better for me as I am extracting
data for 24 hours. I don't want to use "*where"* function as it needs a
loop. Finally, I wrote the script as follows:
T2 = f_1->T2(0:24,:,:)
LU_INDEX = f_1->LU_INDEX(0,:,:) ; (LU_INDEX = landuse index)
T2_masked = mask(T2,(LU_INDEX.ne.2), False)
print(T2_masked)
Then I am trying to get area average temperature for 24 hours and
calculated area average as follows:
T2_area_avg = dim_avg_n_Wrap(T2_masked,(/1,2/))
print(T2_area_avg)
After printing T2_area_avg, I'm getting a set of real values for 24 hours.
But I'm not sure whether T2_area_avg accurately left all missing vales.
Also, I'm not getting a way to check which values (only real or both real
and missing values) are considered for T2_area_avg calculation. You said
that NCL deals with missing values without problem. *Could you please tell
me how NCL is dealing with missing values for calculating T2_area_avg. *
*Is "dim_avg_n_Wrap" function only considering the real values without
missing values??? *
Ardently looking forward to your further advise.
Kind regards,
Imran
On Wed, Mar 15, 2017 at 1:08 AM, Imran Hosen <hosen.imran09 at gmail.com>
wrote:
> Hi Guido and Barry,
>
> Thanks again for your further advices.
>
> Actually, in the study domain, it has 117 rows*117 columns (total 13689
> grids). The grids have different land use index (LU_INDEX). I ran
> simulations using the WRF model for simulating different climate variables.
> Now, my goal is, I want to plot (XY plot) the hourly temperature difference
> between the grid cells whose LU_INDEX=2 and LU_INDEX=1. Therefore, I want
> to extract temperature seperately for the grid cells whose LU_INDEX=2. I'll
> do same thing for the grid cells whose LU_INDEX=1. Then I will make XY
> plot, although I never experinced NCL for making XY plot. Hope, now you
> will understand my goal.
>
> If I use mask function as the script I wrote, then T2_masked = T2 (only
> for the grid cells where LU_INDEX is not equal to 2), right??? So, I made a
> mistake in my script, and I should follow your previous suggestion, right??
>
> When I use mask or where function, it is showing both real and FillValue.
> Really, I want to extract only real values for the grid cells where
> LU_INDEX=2 and want to escape the FillValues.
>
> Okay, I'll try to implement your advice and let you know the update.
>
> Wish your uninterrupted sound health.
>
> Kind regards,
> Imran
>
> On Tue, Mar 14, 2017 at 8:24 PM, 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/Docu
>> ment/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>
>>
>>
>>
>>
>
>
> --
> *Md. Imran Hosen*
> PhD Student
> Victoria University
> College of Engineering and Science
> Footscray Park Campus
> Victoria, Australia
> Mob. +61470371562 <+61%20470%20371%20562>
>
>
>
--
*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/20170315/2ef0812d/attachment.html
More information about the ncl-talk
mailing list