[ncl-talk] Why the res of DstGridMask can not make the destination grid have missing values as defined?

Mary Haley haley at ucar.edu
Wed Dec 21 08:49:40 MST 2016


Lin,

In order to properly debug this, I would need to have a *clean* script and
your input data files.  I haven NO idea what your data looks like, how it
is ordered, what missing values it has, etc, so I have no way of telling
you to create the mask array.

But, yes, you could be very right that the issue is that you are
subscripting "hlat", and not subscripting "hsic" in the way.

If latitude and longitude are indeed coordinate arrays of hsic, then you
should not read latitude and longitude separately off the file, because
they are attached to hsic.  And, if you subscript hsic, the
latitude/longitude coordinate arrays will automatically be subscripted in
the same way.

So, you really only need this:

  hsic = fi->sic({-90.:-50.},:)

and then DstGridLat and DstGridLon should be set as follows, by using the
latitude and longitude coordinate arrays that are attached to hsic:

  Opt at DstGridLat = hsic&latitude
  Opt at DstGridLon = hsic&longitude

I do not know how the internals of the source and destination masking work,
but if you google "ESMF regrid masking" you will find this short
description:


   - Destination masking: Allow some points (usually representative of land
   masses) of the destination grid to not be included in the interpolation.

   - Source masking: Allow some points of the source grid to not be
   included in the interpolation.

So, yes, the destination mask should be working, but it is imperative that
you apply the correct mask! You simply want an array of 0s and 1s, with 0s
at the locations that you *don't* want regridding to occur.

If you look at example #19 at:

http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex19

You will see that the regridding works with a destination grid that had a
mask array for land and ocean.  This was convenient because the data came
with a separate mask array on the file with 0s and 1s.

Also look at example #28 at:

http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex28

This one creates a mask array simply by checking the variable for missing
values:

    Opt at DstMask2D      = where(ismissing(POP_var),0,1)

Sometimes, if I have doubt that the missing values of my data are correct,
I will use the gsn_coordinates procedure to add points at locations where
my data is missing and not missing.

See the last frame of example 7 at:

http://www.ncl.ucar.edu/Applications/plot_data_on_map.shtml#ex7

The way this works is you first create a contour plot of "hsic", for
example:

  res = True
  res at cnFillOn = True
  res at gsnDraw = False
  res at gsnFrame = False
  plot = gsn_csm_contour_map(wks,hsic,res)

and then you can add points for the latitude/longitude locations, coloring
the missing and non-missing points differently:

;---Draw the lat/lon locations as markers
  mkres = True
  mkres at gsMarkerIndex            = 16
  mkres at gsMarkerSizeF            = 3
  mkres at gsnCoordsNonMissingColor = "Black"
  mkres at gsnCoordsMissingColor    = "red"
  gsn_coordinates(wks,plot,hsic,mkres)


--Mary



On Tue, Dec 20, 2016 at 2:39 AM, 林祥 <xianglin72 at icloud.com> wrote:

>
> Hi,Mary
>
>    I found the problem might be in the inconsistence between “hsic" and
> “hlat”
>
>         fi   = addfile("HadISST_ice.nc","r”)
>
>   hsic = fi->sic                          ; it is global
>>
>   hlon = fi->longitude
>>   hlat = fi->latitude({-90.:-50.})        ;  it is regional
>>
>
>    However, the same scripts with such error can not run in mac, while it
>  run well in my Linux and output figure & nc files although error existed
> in masking.
>
>
>
> Thank
>
>
> Lin
>
>
> 在 2016年12月20日,06:06,Mary Haley <haley at ucar.edu> 写道:
>
> Lin,
>
> I'm confused by the comment on this line:
>
>     Opt at SrcGridMask      = where(.not.ismissing(thetao(0,:,:)),1,0)
>  ; thetao is the source grids, with data zero in land, no missing
>
> When you say "data zero in land, no missing", do you mean that the
> "thetao" variable is equal to 0 whenever it is over land, and that it
> contains no missing values?  If so, then using "ismissing" on a variable
> that doesn't contain missing values is never going to return True.
>
> Instead, you want something like this:
>
>     Opt at SrcGridMask      = where(thetao.ne.0,1,0)
>
> This creates a mask array that is equal to 1 at locations where thetao is
> NOT equal to 0, and equal to 0 at locations where thetao is equal to 0.
>
> Just as an example, this line should produce the exact same mask array:
>
>     Opt at SrcGridMask      = where(thetao.eq.0,0,1)
>
> --Mary
>
>
>
>
> On Mon, Dec 19, 2016 at 11:53 AM, 林祥 <xianglin72 at icloud.com> wrote:
>
>> Hi, all
>>
>>        I have many CMIP5 sea ice concentration data and want to regrid
>> them into the same grid coordinate as HadISST.
>>
>>  Since the land area own missing_value (_FillValue) in HadiSST, I also
>> want the regridded data show missing values in land .
>>
>> I use the following  scripts:
>>
>>    fi   = addfile("HadISST_ice.nc","r")
>>   hsic = fi->sic
>>   hlon = fi->longitude
>>   hlat = fi->latitude({-90.:-50.})
>>    …….
>>
>>     Opt at SrcGridMask      = where(.not.ismissing(thetao(0,:,:)),1,0)
>>  ; thetao is the source grids, with data zero in land, no missing
>>     Opt at DstGridMask      = where(.not.ismissing(hsic(0,:,:)),1,0)
>>   ; hsic is the HadISST  SIC data, with missing values in land
>>
>>     Opt at DstGridLat       = hlat
>>   Opt at DstGridLon       = hlon
>> ……..
>>
>>      thetao_regrid = ESMF_regrid(thetao,Opt)
>>
>> However, I found the regridded data “thetao_regrid" show zero values, not
>> missing values in land.
>>
>>
>>        How to make the regridded data have missing values for the same
>> grids as HadISST?
>>
>>
>> Thank
>>
>>
>> Lin
>>
>>
>>
>>
>> _______________________________________________
>> 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/20161221/d06c2d17/attachment.html 


More information about the ncl-talk mailing list