Re: Region masking for EOF Analysis

From: Andrew Dawson <dawson_at_nyahnyahspammersnyahnyah>
Date: Wed Jan 18 2012 - 10:37:09 MST

This statement:

sst = mask(sst, sst.ne.6, False)

Simply replaces with the missing value any location where SST is not equal
to 6. Essentially anywhere where your SST anomaly is not equal to exactly 6
will become missing (masked out). This is certainly not what you want. In
the example the masking array is a variable that has been read from file
which contains specific regions indicated with specific values. It seems
like in this mask points in the Atlantic region are set to the value 6.

If you want to use a simple region you can use the coordinate subscripting
built into NCL (see the reference manual). If you want something more
complex you may have to create your own mask variable for your grid, or
take some other approach depending on your needs. If the latter then I'm
sure other people on the list can help.

Andrew

2012/1/18 Hyacinth Nnamchi <hyacinth.1@hotmail.com>

> Hi Users,
>
> I'm trying to compute EOF by masking domains outside the Atlantic Ocean
> using the eof_3.ncl script:
> http://wwlynn@thompsonwilson.co.uklynn@thompsonwilson.co.ukw.ncl.ucar.edu/Applications/Scripts/eof_3.ncl<http://www.ncl.ucar.edu/Applications/Scripts/eof_3.ncl>.
> This has not worked (Pse note: Unlike the said example I'm NOT reading
> several files, may be this is where my confusion starts).
>
> 1) It's indicated thus in the user defined paramers:
>
> region = 6 ; Atlantic
>
> My question is: Does ncl have already predefined regions? Can someone refer me to the appropriate documentation/listing?
> (If none, then I think that the major problem for a newbie like me is modifying the code for several files* to work well for only a file).
>
> 2) To mask the Atlantic, I merely say:
>
> sst = mask(sst,sst.ne.region,False) ; to mask the region
>
> When I run the code, both the eof and eof_ts are ALL undefined.
>
> Thanks in advance for any suggestions.
>
>
>
> Hyacinth
>
>
> ; ==============================================================
>
> 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"
>
> begin
> ; ==============================================================
> ; User defined parameters that specify region of globe and
> ; ==============================================================
> latS = -45.
> latN = 70.
> lonL = -105.
> lonR = 20.
> region = 6
>
> yrStrt = 1950
> yrLast = 2008
>
> season = "JJA" ; choose Jun-Jul-Aug seasonal mean
>
> neof = 2 ; number of EOFs
> optEOF = True
> optEOF@jopt = 0 ; This is the default; most commonly used; no need to specify.
> ;;optEOF@jopt = 1 ; **only** if the correlation EOF is desired
>
> optETS = False
>
> ; ==============================================================
> ; Open the file: Read only the user specified period
> ; ==============================================================
> f = addfile ("/home/nnamchi/work/ictp2011/ocean/HadISST_sst.nc", "r")
> ; f = addfile ("/home/nnamchi/work/datasets/sst.mnmean.nc","r")
>
> TIME = f->time
> YYYY = ut_calendar(TIME,-1)/100 ; entire file
> iYYYY = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
>
> sst = f->sst(iYYYY,:,:)
> printVarSummary(sst) ; variable overview
>
> ; ==============================================================
> ; dataset longitudes span 0=>357.5
> ; Because EOFs of the North Atlantic Oscillation are desired
> ; use the "lonFlip" (contributed.ncl) to reorder
> ; longitudes to span -180 to 177.5: facilitate coordinate subscripting
> ; ==============================================================
> ;
> sst = lonFlip( sst )
> ; printVarSummary(sst) ; note the longitude coord
>
> ;=================================================;
> ; Remove the annual cycle
> ;=================================================;
> xClm = clmMonTLL(sst)
> printVarSummary(xClm) ; (12,nlat,nlon)
> sst = calcMonAnomTLL (sst, xClm) ; replace with anonamlies
> sst@long_name = "ANOMALIES: "+sst@long_name
> ; ==============================================================
> ; compute desired global seasonal mean: month_to_season (contributed.ncl)
> ; ==============================================================
> ;=================================================;
> ; Mask out all regions but that sprcified by the user =>'region'
> ;=================================================;
> sst = mask(sst,sst.ne.region,False) ; data for region
>
> ;==================================
> ======================================
> SLP = month_to_season (sst, season)
> nyrs = dimsizes(SLP&time)
> ;==================================================================
> ; create weights: sqrt(cos(lat)) [or sqrt(gw) ]
> ; =================================================================
> rad = 4.*atan(1.)/180.
> clat = f->lat
> clat = sqrt( cos(rad*clat) ) ; gw for gaussian grid
>
> ; =================================================================
> ; weight all observations
> ; =================================================================
> wSLP = SLP ; copy meta data
> wSLP = SLP*conform(SLP, clat, 1)
> wSLP@long_name = "Wgt: "+wSLP@long_name
>
> ; =================================================================
> ; Reorder (lat,lon,time) the *weighted* input data
> ; Access the area of interest via coordinate subscripting
> ; =======
> ==========================================================
> x = wSLP({lat|latS:latN},{lon|lonL:lonR},time|:)
>
> eof = eofunc_Wrap(x, neof, optEOF)
> eof_ts = eofunc_ts_Wrap (x, eof, optETS)
> ; eof = eof
>
> printVarSummary( eof ) ; examine EOF variables
> printVarSummary( eof_ts )
>
> print(eof_ts)
>
> ; system ("rm eof_ts.dat")
> ; asciiwrite("eof_ts.dat", eof_ts)
> ; =================================================================
> ; Normalize time series: Sum spatial weights over the area of used
> ; =================================================================
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
Dr Andrew Dawson
Atmospheric, Oceanic & Planetary Physics
Clarendon Laboratory
Parks Road
Oxford OX1 3PU, UK
Tel: +44 (0)1865 282438
Email: dawson@atm.ox.ac.uk
Web Site: http://www2.physics.ox.ac.uk/contacts/people/dawson

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jan 18 10:37:29 2012

This archive was generated by hypermail 2.1.8 : Mon Jan 23 2012 - 12:45:14 MST