Re: Having problems masking out the ocean

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 26 2012 - 15:44:35 MDT

Hi all,
This was resolved offline; the attached latitude/longitude arrays did
not have units attributes associated with them (ex. precip&lat@units =
"degrees_north"), which threw the NCL plotting routine off. The issue
had nothing to do with landsea_mask.
Adam

On 10/26/2012 02:31 PM, Madeleine Patterson wrote:
> Hi,
>
> I am still getting the same problem of the mask placing the continents
> in the wrong place (longitude-shifted). Please see attached plot.
>
> Thanks
>
> M
>
> On Fri, Oct 26, 2012 at 3:59 PM, Adam Phillips <asphilli@ucar.edu
> <mailto:asphilli@ucar.edu>> wrote:
>
> Hi Madeleine,
> The key with using landsea_mask is that the latitudes/longitudes
> that you input into landsea_mask must match the direction/span or
> the latitudes/longitudes of the array to be masked. Typically,
> you do not have to do anything to the latitudes/longitudes input
> into landsea_mask. I do not believe you should have to do anything
> with the longitudes assuming they are within the range of -180 to
> 359.99. Try this:
>
>
> in1 = addfile("/model1_precip.nc <http://model1_precip.nc>","r")
> precip = in1->precip ; (:,:) syntax not needed
>
> a = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/landsea.nc
> <http://landsea.nc>","r")
> lsdata = a->LSMASK
> lsm = landsea_mask(lsdata,precip&lat,precip&lon)
> precip = mask(precip,lsm.eq.0,False)
>
> If that doesn't work please let ncl-talk know..
> Adam
>
>
>
> On 10/26/2012 01:47 PM, Madeleine Patterson wrote:
>> Hi,
>>
>> I am trying to create an ocean mask for global precipitation (so
>> that the map just shows precipitation over land areas, but the
>> longitudes of my precip plot and my mask don't match up -
>>
>> Without wanting to create my own mask, via example 5 in
>> http://www.ncl.ucar.edu/Document/Functions/Shea_util/landsea_mask.shtml,
>> is there an easy way to do this... I tried
>>
>> lon = (/lon - 180./) ; subtract 180 from all values
>> lon&lon = lon ; update coordinates
>>
>> ...but this didn't work - my mask was just drawn on the wrong
>> part of the map, (i.e. the map of precipitation didn't shift, but
>> the outline of the continents did shift - and was drawn in the
>> wrong place, so that the same rainfall patterns are shown in
>> different continents.
>>
>> I tried lonflip but this just aligned the continent outline
>> (mask) with the dislocated rainfall map.
>>
>> Am I going to have to specify everything manually, as in example
>> 5 above? My script is below.
>>
>> Thanks
>>
>> Madeleine
>>
>> *************
>> begin
>>
>> ; loading libraries
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> setfileoption("nc","SuppressClose",False)
>>
>>
>> ; open 1st spi map;
>>
>> in1 = addfile("/model1_precip.nc <http://model1_precip.nc>","r")
>>
>>
>> lat =in1->lat
>> lon=in1->lon
>>
>> lon = (/lon - 180./) ; subtract 180 from all values
>> lon&lon = lon ; update coordinates
>>
>> precip = in1->precip(:,:)
>>
>> ;precip1 = in1->precip(:,:)
>> ;precip = lonFlip(precip1)
>>
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ; CREATING A LAND/OCEAN MASK (TO MASK OUT THE OCEAN.....
>>
>> ; 0=ocean, 1=land, 2=lake, 3=small island, 4=ice shelf.
>> ; Values at desired points (e.g. ocean) will be set to _FillValue
>> in the array data after creating a new land/sea mask from
>> one-dimensional lat/lon variables:
>>
>>
>> a = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/landsea.nc
>> <http://landsea.nc>","r")
>> lsdata = a->LSMASK
>> lsm = landsea_mask(lsdata,precip&lat,precip&lon)
>> precip = mask(precip,lsm.eq.0,False)
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> wks1 =gsn_open_wks("newpdf","precip_mod1")
>>
>> gsn_define_colormap(wks1,"BrownBlue12")
>> gsnMaximize = True
>> res1 = True
>> res1@cnLinesOn = False
>> res1@cnFillOn = True ; turn color on
>> ;res1@gsnSpreadColors = True
>>
>> res1@cnFillColors = (/2,3,4,5,6,7/)
>>
>> res1@cnLevelSelectionMode = "ManualLevels" ; set manual contour
>>
>> res1@cnMinLevelValF = 0.0 ; set min contour level
>> res1@cnMaxLevelValF = 0.10 ; set max contour level
>> res1@cnLevelSpacingF = 0.02
>>
>> res1@tiMainString = "Model1 precip"
>> res1@tiDeltaF = 3.0
>> res1@lbAutoManage = True
>>
>>
>> ;;;;
>>
>> plot = gsn_csm_contour_map_ce(wks1,precip,res1)
>>
>> end
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> ______________________________________________________________
> Adam Phillipsasphilli@ucar.edu <mailto:asphilli@ucar.edu>
> NCAR/Climate and Global Dynamics Division(303) 497-1726 <tel:%28303%29%20497-1726>
> P.O. Box 3000
> Boulder, CO 80307-3000http://www.cgd.ucar.edu/cas/asphilli
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Oct 26 15:44:44 2012

This archive was generated by hypermail 2.1.8 : Wed Oct 31 2012 - 09:14:12 MDT