Re: masking the CCSM T42 output with a shape file

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sat Mar 27 2010 - 07:02:22 MDT

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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Mar 27 07:02:27 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 01 2010 - 11:31:45 MDT