[ncl-talk] How to convert the value of a NetCDF file to zero

Setareh Rahimi setareh.rahimi at gmail.com
Sun Feb 25 12:35:12 MST 2024


Hi Dennis,

I tested the script you sent and noticed the values of the input file for
some variables will change after using the script (check the attached). In
addition, around the selected area, there would be rectangles in the same
colors, which I did not expect.
 I wonder why this happened. I attached the original input file and the
modified one.
Please kindly advise me in these regards.

Best wishes,

On Fri, Jan 26, 2024 at 6:36 AM Dennis Shea <shea at ucar.edu> wrote:

> Dave ... As always .... THX
> -------------------------
> Attached is an *untested* version of my original script with Dave's
> suggested modifications. Again, I do not have a local NCL version so I can
> not test it.
>
> Note: because the WRF coordinate dimensions are curvilinear, the
> subscripts may return a larger area than 1D coordinate variables. You may
> have to come up with your own version.
>
> Good Luck
>
> D
>
>
>
> On Thu, Jan 25, 2024 at 3:18 PM Dave Allured - NOAA Affiliate via ncl-talk
> <ncl-talk at mailman.ucar.edu> wrote:
>
>> Setareh, with simple 1-D coordinate variables, you would easily do this
>> with coordinate range subscripting.  Read about that in the NCL ref
>> manual.  Here is an example that writes directly into an existing file,
>> rather than making a new file.
>>
>>       f->MSEBIO_ISOP( {0,10}, {10,30} ) = 0
>>
>> However, the coordinates in your particular file are 3-D, so you have to
>> use extra code.  Here is the simplest way.  This is also the slowest, but
>> if you are only working with a small amount of data, it is better to keep
>> the code simple.  This example also writes directly into the existing
>> file.  Not tested:
>>
>>       lat1 = 0
>>       lat2 = 10
>>       lon1 = 10
>>       lon2 = 30
>>
>>       do t = 0, ntimes-1
>>          do i = 0, nlats-1
>>             do j = 0, nlons-1
>>                if ( (XLAT(t,i,j) .ge. lat1) .and. (XLAT(t,i,j) .le. lat2)
>> \
>>                   .and. (XLONG(t,i,j) .ge. lon1) .and. (XLONG(t,i,j) .le.
>> lon2) ) then
>>                      f->MSEBIO_ISOP(t,i,j) = 0
>>                           ! You can add more variables here
>>                end if
>>             end do
>>          end do
>>       end do
>>
>>
>> On Thu, Jan 25, 2024 at 1:04 PM Setareh Rahimi <setareh.rahimi at gmail.com>
>> wrote:
>>
>>> Dear Dave,
>>>
>>> So many thanks for your help. I just checked it and it worked.
>>>
>>> May I ask you please to advise me on how to only convert the values of
>>> all variables to zero for a specific region and not whole the domain? (for
>>> example lat[0,10], and lon[10,30])?
>>>
>>> Thanks in advance.
>>> Kind regards,
>>>
>>> On Thu, Jan 25, 2024 at 11:18 PM Dave Allured - NOAA Affiliate <
>>> dave.allured at noaa.gov> wrote:
>>>
>>>> The problem is that Dennis's program did not copy the file global
>>>> attributes, which contain part of the georeferencing.  Just add this line
>>>> near the top of the program, after the line "print (vNames)":
>>>>
>>>>       copy_VarAtts (f, fout)
>>>>
>>>>
>>>> On Thu, Jan 25, 2024 at 11:07 AM Ehsan Taghizadeh via ncl-talk <
>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>
>>>>> Dear Setareh,
>>>>> I suggest you read the variables from the fout file again. For
>>>>> example, if there is a variable named "V10" in fout, you just need to read
>>>>> that variable from fout, as follows:
>>>>> V10_zero=fout->V10
>>>>>
>>>>> This V10_zero has the same coordinates as V10 in the original file,
>>>>> but its values are zero.
>>>>> I hope this is correct.
>>>>>
>>>>>
>>>>> On Thursday, January 25, 2024 at 06:17:12 PM GMT+3:30, Setareh Rahimi
>>>>> via ncl-talk <ncl-talk at mailman.ucar.edu> wrote:
>>>>>
>>>>> Dear Dennis,
>>>>> I noticed an issue. When I use the attached script it converts all
>>>>> values to zero, but the data is no georefrenced any more. So how can I fix
>>>>> this please?
>>>>> Thanks in advance.
>>>>> Best regards,
>>>>>
>>>>> S.Rahimi
>>>>>
>>>>>
>>>>> On Sun, Jan 21, 2024 at 18:44 Dennis Shea <shea at ucar.edu> wrote:
>>>>>
>>>>> Attached is a script that does what you requested.
>>>>>
>>>>>
>>>>> On Sat, Jan 20, 2024 at 6:40 AM Setareh Rahimi via ncl-talk <
>>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>>
>>>>>
>>>>> Dear NCL users,
>>>>>
>>>>> I have a NetCDF file (attached) that contains some variables. I
>>>>> would like to change the values of all variables to zero for all grid
>>>>> points. So how can I do this using NCL, please?
>>>>>
>>>>> This file is an input file for the WRF-Chem model, and I do not want
>>>>> to change the format of the file, only want to change the values to zero.
>>>>>
>>>>> Please kindly advise me in this regard.
>>>>>
>>>>> Thanks in advance.
>>>>> Kind regards,
>>>>> --
>>>>> S.Rahimi
>>>>>
>>>>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at mailman.ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>

-- 
S.Rahimi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240225/59a55960/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: convert to zero.png
Type: image/png
Size: 86724 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240225/59a55960/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: default.png
Type: image/png
Size: 194451 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240225/59a55960/attachment-0003.png>


More information about the ncl-talk mailing list