Re: Problems creating new array with calculated values

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri Sep 07 2012 - 12:31:07 MDT

Hi Hyacinth,
In this case I think it might be best to use the ind function:

vals = ind(nino3.ge.1.)
print(nino3(vals))
nino3_cases_maps = NOAA(vals,:,:)

You will want to check to make sure that this method is doing what you
think it is doing by verifying that the desired maps are being selected.
But this method is much less complex than using a double do loop.
Hope that helps..
Adam

On 09/07/2012 11:13 AM, Hyacinth Nnamchi wrote:
> Hi;
>
> Thanks immensely Adam, your suggestion solved the problem.
>
> But I still find it hard to pick the 'maps' of the selected cases and
> put into the new variable created. The code runs, and plot created but
> I noticed am taking the data at ONLY one time step.
>
>
> do j = 0,NYEAR-1,1 ;Length of entire
> series = 112
> do i = 0,n_nino3-1,1 ;selected cases, same as length of new
> data = 21
> if(nino3(j).ge.1.)then & nbsp; ;time series
> index = 112
> nino3_cases_maps(i,:,:) = NOAA(j,:,:) ;nino3_cases_maps = 21 X 89
> X 180 ;;;;; NOAA = 112 X 89 X 180
> end if
> end do
> end do
>
> printVarSummary(nino3_cases_maps) ;21 X 89 X 180
> print(nino3_cases_maps(:,1,20)) ; CONSTANT VALUE INDICATING THAT IT
> IS PICKED AT ONLY ONE STEP
>
>
>
> ;*************************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> loa d "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> begin
>
> ; ==============================================================
> ; User defined parameters
> ; ==============================================================
>
> yrStrt = 1900
> yrLast = 2011
> NYEAR = (yrLast-yrStrt)+1
> print(NYEAR)
>
> season = "DJF" ; choose Jun-Jul-Aug seasonal mean
> ;=============================================================
> ; Open the file: Read only the user specified period
> ; ==============================================================
> f = addfile ("/home/nnamchi/work/datasets/sst/sst.mnmean.nc", "r")
> TIME = f->time
> YYYY = cd_calendar(TIME,-1)/100 & nbsp; ; entire file
> iYYYY = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
> noaa = short2flt(f->sst(iYYYY,:,:))
> printVarSummary(noaa)
> delete([/TIME,YYYY,iYYYY/]) ; Release memory
> ; ==============================================================
> ; global seasonal mean; de-trend; flip longitudes
> ; ==============================================================
> NOAA = month_to_season (noaa,season)
> nyrs = dimsizes(NOAA&time)
> printVarSummary(NOAA) ; note the longitude coord
>
> NOAA = dtrend_msg_n(NOAA&time,NOAA,True,False,0) ;de-trend data
>
> NOAA = lonFlip(NOAA)
>
> ;===========================================
> nino3 = wgt_areaave_Wrap (NOAA(time |:, {lon|-150:-90}, {lat |
> -5:5}),1.0, 1.0, 0) ;Nino 3 index
> nino3 = dim_standardize_Wrap(nino3,0) ; normalize
>
> ;=====================================================
>
> n_nino3 = dim_num_n(nino3.ge.1.,0)
> print(n_nino3) ; 21 cases shown
>
> nino3_cases = nino3.ge.1.
> print(nino3_cases) ;True indicated for the timesteps
> corresponding to n_nino3
>
> dimZ = dimsizes(NOAA(0,:,:))
> nino3_cases_maps = new ((/n_nino3,dimZ(0),dimZ(1)/),float)
> printVarSummary(nino3_cases_maps) ;21 X 89 X 180
>
>
> ;====================================================
> ; Pick NOAA SST map for those cases where nino3 ge. 1.
> ;=====================================================
>
> ;
> do j = 0,NYEAR-1,1 ;Length of
> entire series = 112
> do i = 0,n_nino3-1,1 ;selected cases, same as length of new
> data = 21
> if(nino3(j).ge.1.)then ;time series
> index = 112
> nino3_cases_map s(i,:,:) = NOAA(j,:,:) ;nino3_cases_maps = 21 X 89
> X 180 ;;;;; NOAA = 112 X 89 X 180
> end if
> end do
> end do
>
>
> printVarSummary(nino3_cases_maps)
> print(nino3_cases_maps(:,1,20)) ; CONSTANT VALUE INDICATING THAT IT
> IS PICKED AT ONLY ONE STEP
> end
> >
> > Message: 8
> > Date: Thu, 06 Sep 2012 09:40:31 -0600
> > From: Adam Phillips <asphilli@ucar.edu>
> > Subject: Re: Problems creating new array with calculated
> > values
> > To: ncl-talk@ucar.edu
> > Message-ID: <5048C3EF.5010607@ucar.edu>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Hi Hyacinth,
> > Try this:
> >
> > dimZ = dimsizes(NOAA(0,:,:)
> > nino3_cas es_maps = new ((/n_nino3,dimZ(0),dimZ(1)/),float)
> >
> > I think the problem is that in this code:
> > nino3_cases_maps = new ((/n_nino3,dimsizes(NOAA(0,:,:))/),float)
> >
> > NCL sees n_nino3 as a scalar (which is fine), but sees the
> > dimsizes(NOAA(0,:,:) as an _array_ or size 2, which is why it is giving
> > you this error message:
> > fatal:_NclBuildArray: each element of a literal array must have the
> > same dimension sizes, at least one item doesn't
> >
> > If my suggestion does not fix your issue please let ncl-talk know.. Adam
> >
> > On 09/06/2012 09:19 AM, Hyacinth Nnamchi wrote:
> > > Hi Users,
> > >
> > > I'd like to create an array to hold a new data:
> > > nino3_cases_maps = new ((/n_nino3,dimsizes(NOAA(0,:,:))/),float)
> > >
> > > But I got the following error message:
> > >
> > > fatal:_NclBuildArray: each element of a literal array mus t have the
> > > same dimension sizes, at least one item doesn't
> > > fatal:["Execute.c":7556]:Execute: Error occurred at or near line
> 50 in
> > > file trial_comp_1.ncl
> > >
> > > Perhaps the problem is that a dimension of the an array (n_nino3) is
> > > not known before hand, and ncl is supposed to take it from a
> preceding
> > > calculation. Does anyone know what am doing wrong here?
> > >
> > > Thanks in advance.
> > >
> > > Hyacinth
> > >
> > > Copyright (C) 1995-2012 - All Rights Reserved
> > > University Corporation for Atmospheric Research
> > > NCAR Command Language Version 6.1.0-beta
> > > The use of this software is governed by a License Agreement.
> > > See http://www.ncl.ucar.edu/ for more details.
> > >
>
>
>
> _______________________________________________
> 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 Sep 7 12:31:18 2012

This archive was generated by hypermail 2.1.8 : Tue Sep 11 2012 - 15:30:42 MDT