Re: problems with EOF_AAO

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Jul 23 2014 - 22:24:18 MDT

The error is telling you that you are trying to assign an array to another
array, but they are not the same size.

Here's an example code that produces the same type of error:

x = random_uniform(-10,10,(/10,5/)) ; x is 10 x 5

y = random_uniform(-10,10,(/5,10,20/)) ; y ix 5 x 10 x 20

do i=0,4
    y(i,:,:) = x
end do

The above script will give you an error:

fatal:Dimension size mismatch on subscript #2, left-hand and right-hand
side dimensions do not match
fatal:["Execute.c":8578]:Execute: Error occurred at or near line 5 in file
dim.ncl

because you are trying to put a 10 x 5 array into a 10 x 20 array.

Note that it mentioned "subscript #2". This is a bit obscure, but this
refers to the rightmost dimension of y (dimension numbering starts at 0 and
goes left to right, so the #2 subscript is the 3rd one from the left).

Your error message is complaining about subscript #1, so this is the second
subscript in "eof_regres":
  do ne=0,neof-1
     eof_regres(ne,:,:) = (/ regCoef(eof_ts(ne,:),
xAnom(X2DEG|:,Y2DEG|:,TIME|:)) /)
  end do

You may want to assign the "regCoef" results to a temporary variable and do
a printVarSummary on that variable to make sure the assignment is what you
expect.

--Mary


On Fri, Jul 18, 2014 at 4:05 PM, Vanúcia Schumacher <
vanucia-schumacher@hotmail.com> wrote:

> Hi users,
>
> I'm trying to plot the EOF_AAO the example of the NCL page and returns
> this error, if someone can help.
>
> fatal:Dimension size mismatch on subscript #1, left-hand and right-hand
> side dimensions do not match
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 90 in
> file eof_aao.ncl
>
> Variable: x
> Type: double
> Total Size: 47436480 bytes
> 5929560 values
> Number of Dimensions: 3
> Dimensions and sizes: [TIME | 360] x [Y2DEG | 91] x [X2DEG | 181]
> Coordinates:
> TIME: [15.5..10934.5]
> Y2DEG: [ -90.. 90]
> X2DEG: [ 0.. 360]
> Number Of Attributes: 5
> PLEV14_14 : 70000
> missing_value : -9.999999999999999e+33
> _FillValue : -9.999999999999999e+33
> long_name : ZG[GX=X2DEG,GY=Y2DEG]
> history : From zg.IPSL
>
> Variable: xClm
> Type: double
> Total Size: 1581216 bytes
> 197652 values
> Number of Dimensions: 3
> Dimensions and sizes: [month | 12] x [Y2DEG | 91] x [X2DEG | 181]
> Coordinates:
> month: [0..11]
> Y2DEG: [ -90.. 90]
> X2DEG: [ 0.. 360]
> Number Of Attributes: 7
> _FillValue : -9.999999999999999e+33
> PLEV14_14 : 70000
> long_name : ZG[GX=X2DEG,GY=Y2DEG]
> history : From zg.IPSL
> missing_value : -9.999999999999999e+33
> time_op_ncl : Climatology: 30 years
> info : function clmMonLLT: contributed.ncl
>
> Variable: xAnom
> Type: double
> Total Size: 47436480 bytes
> 5929560 values
> Number of Dimensions: 3
> Dimensions and sizes: [TIME | 360] x [Y2DEG | 91] x [X2DEG | 181]
> Coordinates:
> TIME: [15.5..10934.5]
> Y2DEG: [ -90.. 90]
> X2DEG: [ 0.. 360]
> Number Of Attributes: 6
> PLEV14_14 : 70000
> missing_value : -9.999999999999999e+33
> _FillValue : -9.999999999999999e+33
> long_name : ZG[GX=X2DEG,GY=Y2DEG]
> history : From zg.IPSL
> anomaly_op_ncl : Anomalies from Annual Cycle: calcMonAnomTLL:
> contributed.ncl
> (0)
> (0) ZG[GX=X2DEG,GY=Y2DEG]: min=-230.4509485966109 max=295.51097=
58631793
>
> Variable: clat
> Type: double
> Total Size: 728 bytes
> 91 values
> Number of Dimensions: 1
> Dimensions and sizes: [Y2DEG | 91]
> Coordinates:
> Number Of Attributes: 4
> standard_name : latitude
> axis : Y
> point_spacing : even
> units : degrees_north
>
> Variable: eof
> Type: double
> Total Size: 131768 bytes
> 16471 values
> Number of Dimensions: 3
> Dimensions and sizes: [evn | 1] x [Y2DEG | 91] x [X2DEG | 181]
> Coordinates:
> evn: [1..1]
> Y2DEG: [ -90.. 90]
> X2DEG: [ 0.. 360]
> Number Of Attributes: 7
> eval_transpose : 47025.64585057087
> eval : 2022102.771574547
> pcvar : 21.81134
> matrix : covariance
> method : transpose
> _FillValue : -9.999999999999999e+33
> long_name : EOF: Wgt: ZG[GX=X2DEG,GY=Y2DEG]
>
> Variable: eof_ts
> Type: double
> Total Size: 2880 bytes
> 360 values
> Number of Dimensions: 2
> Dimensions and sizes: [evn | 1] x [TIME | 360]
> Coordinates:
> evn: [1..1]
> TIME: [15.5..10934.5]
> Number Of Attributes: 4
> ts_mean : -5.431704468921655e-13
> matrix : covariance
> _FillValue : -9.999999999999999e+33
> long_name : EOF: Amplitude: Wgt: ZG[GX=X2DEG,GY=Y2DEG]
>
>
> ;=========================
==========================
=============
> ; Match the AAO pattern at:
> ;
> http://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/aao/aa=
o.loading.shtml
> ;
> ; Use method:
> ;
> http://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/aao/aa=
o.shtml
> ;=========================
==========================
=============
> ; Data source was Reanalysis-2 geopotential height.
> ;
> http://www.esrl.noaa.gov/psd/data/gridded/;data.ncep.reanalysis2.pressure=
.html
>
> ;=========================
==========================
=============
>
> 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"
>
> ; ========================
==========================
==============
> ; User defined parameters that specify region of globe and
> ; ========================
==========================
==============
> latS = -90.
> latN = -20.
> plev = 700
>
> yrStrt = 1981
> yrLast = 2010
>
> var = "ZG_NEW"
> title = str_upper(var)+": "+plev+"hPa "
>
> ymStrt = yrStrt*100 + 1
> ymLast = yrLast*100 + 12
>
> neof = 1 ; Leading EOF only
> optEOF = True
> optETS = False
>
> ; ========================
==========================
==============
> ; Open the file:
> ; ========================
==========================
==============
> f = addfile ("zg.IPSL.2g.nc", "r")
> x=f->ZG_NEW(:,0,:,:)
> printVarSummary(x)
> ; ========================
==========================
==============
> ; compute climatology and Anomalies
> ; ========================
==========================
==============
> xClm = clmMonTLL(x) ; (12,lat,lon)
> printVarSummary(xClm)
>
> xAnom = calcMonAnomTLL ( x, xClm) ; (time, lat,lon)
> printVarSummary(xAnom)
> printMinMax(xAnom, True)
>
> ; ========================
==========================
=================
> ; create weights: sqrt(cos(lat)) [or sqrt(gw) ]
> ; ========================
==========================
=================
> rad = 4.*atan(1.)/180.
> clat = xAnom&Y2DEG
> clat = sqrt( cos(rad*clat) ) ; gw for gaussian grid
> printVarSummary(clat)
>
> ; ========================
==========================
=================
> ; weight all observations
> ; ========================
==========================
=================
> xw = xAnom*conform(xAnom, clat, 1)
> copy_VarMeta(x, xw)
> xw@long_name = "Wgt: "+x@long_name
>
> ; ========================
==========================
=================
> ; Reorder (lat,lon,time) the *weighted* input data
> ; Compute EOFs & Standardize time series
> ; ========================
==========================
=================
> wx = xw(Y2DEG|:,X2DEG|:,TIME|:) ; convenience,
> cleaner code
> delete(xw)
>
> eof = eofunc_Wrap(wx, neof, optEOF)
> eof = -1*eof ; *special* match sign=
 of
> CPC
>
> eof_ts = eofunc_ts_Wrap (wx, eof, optETS)
>
> printVarSummary( eof ) ; examine EOF variables
> printVarSummary( eof_ts )
>
> eof_ts = dim_standardize_n( eof_ts, 0, 1) ; normalize
>
> ; ========================
==========================
=================
> ; Regress
> ; ========================
==========================
=================
>
> eof_regres = eof ; create an array w me=
ta
> data
> do ne=0,neof-1
> eof_regres(ne,:,:) = (/ regCoef(eof_ts(ne,:),
> xAnom(X2DEG|:,Y2DEG|:,TIME|:)) /) ->>>>>>>>> error this line
> end do
>
> ; ========================
==========================
=================
> ; Extract the YYYYMM from the time coordinate
> ; associated with eof_ts [same as x&time]
> ; ========================
==========================
=================
>
> yyyymm = cd_calendar(eof_ts&TIME,-1)
> yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here
>
> ;=========================
==========================
===========
> ; PLOTS
> ;=========================
==========================
===========
> wks = gsn_open_wks("ps","eof")
> gsn_define_colormap(wks,"BlueWhiteOrangeRed")
> plot = new(neof,graphic) ; create graphic array
> ; only needed if paneling
> ; EOF patterns
>
> res = True
> res@gsnAddCyclic = False
> res@gsnDraw = False ; don't draw yet
> res@gsnFrame = False ; don't advance frame yet
> res@gsnPolar = "SH"
> res@gsnSpreadColors = True ; spread out color table
>
> res@mpFillOn = False ; turn off map fill
> res@mpMaxLatF = latN
> res@mpCenterLonF = 180
>
> res@cnFillOn = True ; turn on color fill
> res@cnLinesOn = False ; True is default
> res@cnLineLabelsOn = False ; True is default
> res@lbLabelBarOn = False ; turn off individual lb's
>
> ; set symmetric plot min/max
> symMinMaxPlt(eof_regres, 16, False, res) ; contributed.ncl
> res@cnLevelSpacingF = 5.0 ; *special* match CPC
>
> ; panel plot only resources
>
> resP = True ; modify the panel plot
> resP@gsnMaximize = True ; large format
> resP@gsnPanelLabelBar = True ; add common colorbar
> resP@gsnPaperOrientation = "portrait" ; force portraitorbar
> resP@lbLabelAutoStride = True ; auto stride on labels
>
> resP@txString = title+": "+yrStrt+"-"+yrLast
>
> ;*******************************************
> ; first plot
> ;*******************************************
> do n=0,neof-1
> res@gsnLeftString = "EOF "+(n+1)
> res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"
> plot(n)=gsn_csm_contour_map_polar(wks,eof_regres(n,:,:),res)
> end do
> gsn_panel(wks,plot,(/neof,1/),resP) ; now draw as one plot
>
> ;*******************************************
> ; second plot
> ;*******************************************
> ; EOF time series [bar form]
>
> rts = True
> rts@gsnDraw = False ; don't draw yet
> rts@gsnFrame = False ; don't advance frame yet
> rts@gsnScale = True ; force text scaling
>
> ; these four rtsources allow the user to stretch the plot size, and
> ; decide exactly where on the page to draw it.
>
> rts@vpHeightF = 0.40 ; Changes the aspect ratio
> rts@vpWidthF = 0.85
> rts@vpXF = 0.10 ; change start locations
> rts@vpYF = 0.75 ; the plot
>
>
> rts@tiYAxisString = "Standardized" ; y-axis label
>
> rts@gsnYRefLine = 0. ; reference line
> rts@gsnXYBarChart = True ; create bar chart
> rts@gsnAboveYRefLineColor = "red" ; above ref line fill red
> rts@gsnBelowYRefLineColor = "blue" ; below ref line fill blu=
e
>
> ; panel plot only resources
> rtsP = True ; modify the panel plot
> rtsP@gsnMaximize = True ; large format
> rtsP@txString = title+": "+yrStrt+"-"+yrLast
>
> ; create individual plots
> do n=0,neof-1
> rts@gsnLeftString = "EOF "+(n+1)
> rts@gsnRightString = sprintf("%5.1f", eof_regres@pcvar(n)) +"%"
> plot(n) = gsn_csm_xy (wks,yrfrac,eof_ts(n,:),rts)
> end do
> gsn_panel(wks,plot,(/neof,1/),rtsP) ; now draw as one plot
>
>
>
> ---
> Vanúcia Schumacher
> Mestranda em Meteorologia - UFV
> Meteorologista -UFPel
> Departamento de Meteorologia Agrícola - DEA
> Cel: (31) 9978 2522
> DEA: (31) 3899 1890
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Thu Jul 24 04:24:17 2014

This archive was generated by hypermail 2.1.8 : Fri Aug 01 2014 - 15:10:55 MDT