Re: masking the CCSM T42 output with a shape file

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu May 06 2010 - 11:38:17 MDT

Hi Sanjiv,

It's possible that your lat/lon values may not be forming a nice continuous polygon, and instead, they might be random points that define the area. If this is the case, the gc_inout function won't work. If you look at the documentation for this function, it states that the lat/lon arrays that form the polygon must be contained in a hemisphere *and* they must not cross themselves.

To verify that the area you're trying to mask is defined by a "nice" polygon, go back to the "mask_9.ncl" example, and look at the code that attaches the polyline:

http://www.ncl.ucar.edu/Applications/mask.shtml#ex9

Try this for your code and see if you have a "nice" polygon.

If you don't, then there are other ways that you can mask this area. See example 1 at:

http://www.ncl.ucar.edu/Applications/polyg.shtml

The code of interest is this code:

 res@mpAreaMaskingOn = True ; draw only parts of map
 res@mpFillAreaSpecifiers = (/"Water","Land"/) ; what parts to fill
 res@mpSpecifiedFillColors = (/0,0/) ; fill with background color
 res@mpOutlineBoundarySets = "USStates" ; what outlines to use
 res@mpMaskAreaSpecifiers = (/"Conterminous US"/); don't fill here

Using the above code will probably be faster anyway, so you might want to use this in any case.

--Mary

On May 6, 2010, at 8:53 AM, Sanjiv Kumar wrote:

> Hello Mary,
>
> I am trying to mask a global 0.5 degree resolution data for the conterminous USA region only.
>
> I am using the code similar to the code used for the Mississippi River Basin.
>
> For the southern part (masking out the Mexico region) code works very well, but for the northern region, it does not work. I am attaching the output map (with and without masking), as well as my code.
>
> If you can see it and figure out, where i am making mistake, that would be really great.
>
> thanks
>
> sanjiv
>
>
> On Mon, Mar 29, 2010 at 8:59 AM, Sanjiv Kumar <sanjivconscious@gmail.com> wrote:
> Thank you Mary.
>
> This new example is really helpful.
>
> You may also want to upload the "mrb.shp" file with the official applications example. I used my mrb.shp file and it worked for me.
>
> To answer your earlier question: You were right, i wanted to mask out all the points that were falling outside the Mississippi river basin. In other words i wanted to use only the data points falling inside the Mississippi river basin.
>
> Thanks a lot once again.
>
> sanjiv
>
>
>
>
>
> On Sat, Mar 27, 2010 at 9:02 AM, Mary Haley <haley@ucar.edu> wrote:
> Grr. Argh. I misspelled "Mississippi" in this script. :-)
>
> I made an official applications example out of this one (and hopefully spelled Mississippi correctly). See example 9 at:
>
> http://www.ncl.ucar.edu/Applications/mask.shtml#ex9
>
> This script allows you to indicate whether you want to mask the area inside or outside the given geographical outline.
>
> --Mary
>
> On Mar 26, 2010, at 3:44 PM, Mary Haley wrote:
>
>>
>> I need to point something out here. The lat/lon arrays I'm generating get large
>> in a hurry, because there are 88565 points in the MRB outline. This may cause
>> memory problems if your data array is large to start with. I'm only using one that is
>> 16 x 32.
>>
>> You may have to modify the script to loop across each lat/lon point in your data
>> grid and call gc_inout for each one, rather than calling gc_inout with big data arrays.
>>
>> This will slow your script down considerably, but it won't require as much memory.
>>
>> You would remove the lines:
>>
>> > mrb_lat3d = conform_dims((/nlat,nlon,nmrb/),mrb_lat,2)
>> > mrb_lon3d = conform_dims((/nlat,nlon,nmrb/),mrb_lon,2)
>> > lat2d = conform_dims((/nlat,nlon/),lat1d,0)
>> > lon2d = conform_dims((/nlat,nlon/),lon1d,1)
>>
>>
>> and do this instead:
>>
>> ;---Create masked data array.
>> data_mask = data
>>
>> do ilt=0,nlat-1
>> xlat = lat1d(ilt)
>> do iln=0,nlon-1
>> xlon = lon1d(iln)
>> if(.not.gc_inout(xlat,xlon,mrb_lat,mrb_lon)) then
>> data_mask(ilt,iln) = data_mask@_FillValue
>> end if
>> end do
>> end do
>>
>> This can be slow!
>>
>> --Mary
>>
>>
>>
>> On Mar 26, 2010, at 3:27 PM, Mary Haley wrote:
>>
>>> Sanjiv,
>>>
>>> I'm not sure what you mean by "mask the CCSM3 T43 outputs". Do you mean you only want to
>>> do *calculations* over areas of your grid that are not part of the Missippippi River Basin, or do
>>> you want to *graphically* mask out the area that is the Missippippi River Basin?
>>>
>>> There's no way in NCL to provide a lat/lon boundary and say "do the calculations only on the part of
>>> the grid that falls within this boundary". In a situation like this, you would generally need a separate
>>> "mask" array that conrtains 0s and 1s indicating where your data is inside or outside a particular area.
>>>
>>> One thing people have done is to set the areas in the grid that they are not interested in to
>>> data@_FillValue (missing value). This will only work if the functions you plan to use know
>>> how to handle missing data.
>>>
>>> To get your data grid filled with missing values in the area you're not interested in, see the
>>> "gc_inout" function:
>>>
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/gc_inout.shtml
>>>
>>> Note that this can be slow if you have a lot of points in your basin, which you do. And,
>>> this will provide an approximate area only.
>>>
>>> I've attached a sample NCL script that creates a dummy (small) array. I then use gc_inout
>>> to mask out the dummy array that is *not* the MRB (maybe you want the opposite of this).
>>>
>>> I draw the full data contours on the first frame, the masked data contours on the second,
>>> and the lat/lon grid over the masked area in the third.
>>>
>>> [Note: I'm used the new "png" option that will be available in V5.2.0 to gsn_open_wks to create these png images.]
>>> <mrb.000001.png>
>>> <mrb.000002.png>
>>> <mrb.000003.png>
>>> <mrb2.ncl>
>>> --Mary
>>>
>>>
>>> On Mar 26, 2010, at 1:35 PM, Sanjiv Kumar wrote:
>>>
>>>> Mary,
>>>>
>>>> Thank you for the reply.
>>>>
>>>> I did go through that example. This example does not seem sufficient for my problem.
>>>>
>>>> I will try to make my question more clear:
>>>>
>>>> I want to mask the CCSM3 T42 outputs with the Mississippi River Basin shape (MRB) file. I am attaching the MRB shape file here.
>>>>
>>>> So the question is: processing the climate model output for the given shape.
>>>>
>>>> Sanjiv
>>>>
>>>>
>>>>
>>>> On Thu, Mar 25, 2010 at 10:13 AM, Mary Haley <haley@ucar.edu> wrote:
>>>> Sanjiv,
>>>>
>>>> If you have V5.1.1, we have support for reading shapefiles via "addfile".
>>>>
>>>> See:
>>>>
>>>> http://www.ncl.ucar.edu/Applications/shapefiles.shtml
>>>>
>>>> for some examples.
>>>>
>>>> Let me know if this is not enough information.
>>>>
>>>> --Mary
>>>>
>>>>
>>>> On Mar 25, 2010, at 7:16 AM, Sanjiv Kumar wrote:
>>>>
>>>> Hello,
>>>>
>>>> I want to process the output from CCSM T42 runs for the Mississippi River Basin (MRB). I have a shape file for the MRB.
>>>>
>>>> I was wondering whether this can be done with ncl or not.
>>>>
>>>> Thanks
>>>>
>>>> Sanjiv
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>> <mrb.zip>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> <landcover_with_mask.pdf><landcover_wintout_masking.pdf><NV_1800-2000_display_USA.ncl>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu May 6 11:38:38 2010

This archive was generated by hypermail 2.1.8 : Fri May 07 2010 - 10:36:00 MDT