# Re: Reorganizing two arrays into one

Date: Tue Apr 16 2013 - 09:59:52 MDT

Hi Skylar,
In this case the error message is telling you what the issue is. The
rightmost dimensions of the two input arrays must be equal in size. You
can check this by running:
printVarSummary(ZZ2)
printVarSummary(ZZ1)

ts = data1(0:43,1) ; ts will be a 1D array of size 44.
...
n_ts=dimsizes(ts) ; n_ts = 44
...

Z1=new((/46,nlat,nlon/),"float") ; Z1 will have 46 timesteps
do i=0,43 ; but you are only filling 44 timesteps with
values
Z1(i,:,:) = (/ws_MSLP(i,:,:)/)
end do

Z2=new((/n_ts,nlat,nlon/),"float") ; Z2 will have 44 timesteps
do i=0,43
Z2(i,:,:)=(/ts(i)/) ;populate Z2 for all years with timeseries
end do

Thus, Z1 will have 46 timesteps, and Z2 will have 44. If you wish to
correlate them you could do this:
Z=escorc(Z1(lat|:,lon|:,time|:43),Z2(lat|:,lon|:,time|:)) ; dimension
reordering done within the function call,
; only use first 44 timesteps of Z1

Now all that being said I do not think you need to even set up your Z1
or Z2 arrays if all you want to do is correlate your 1D array of ice
concentrations against the 3D ws_MSLP array. Assuming that you wish to
correlate the first 44 timesteps of ws_MSLP with the 44 timesteps of ts,
all you have to do is this:

finarr = ws_MSLP(0,:,:) ; set up finarr for metadata only
finarr = (/ escorc(ts,ws_MSLP(lat|:,lon|:,time|:)) /)

The (/ /) mean to only pass the data to the lefthand side of the =
sign, and not to pass any metadata (or erase any). The above two lines
also assume that ws_MSLP has 44 timesteps.

The resulting array (finarr) will contain a lat x lon array containing
the correlation pattern.

One final note: ZZ1(:,:,:) = ZZ1 in NCL syntax. You do not need to put
the (:,:,:).

Hope that helps. If not, please respond to ncl-talk..

On 04/16/2013 09:36 AM, Skylar Haines wrote:
> And this is the only error to the script: "fatal:escorc: The last
> dimension of x must be equal to the last dimension of y" reflecting
> the mentioned error above.
>
>
> On Tue, Apr 16, 2013 at 11:34 AM, Skylar Haines
> <skylar.haines@maine.edu <mailto:skylar.haines@maine.edu>> wrote:
>
>
> That worked great. Now I have a new problem involving the ordering
> of my dimensions so that I can run a correlation.
> The script works fine until the command for the correlation,
> "Z=escorc(ZZ1(:,:,:),ZZ2(:,:,:))" What I am trying to do is run a
> correlation between ERA_Interim Seasonal MSLP (time,lat,lon) with
> ice core data(time,concentration). At this point I created a loop
> to get the datasets to have the same amount of data (44 points),
> so they are comparable, but I am not sure if I have organized
> their respective dimensions correctly to run a correlation.
>
> I hope this makes sense, and appreciate all help!
>
> -Skylar
>
>
> begin
> ;;;;;read in ITASE 02-1 NA ice core
> data***************************************************
> printVarSummary(data1)
> ;print(data1)
> yr = data1(0:43,0)
> ts = data1(0:43,1)
> yr@_FillValue= -9999.99
> ts@_FillValue= -9999.99
> ;print(ts)
> n_ts=dimsizes(ts)
> n_yr=dimsizes(yr)
> ;data1!0 = "time"
> ;data1!1 = "concentration"
>
> MSLP************************************************************************
> infile="/Users/sky/Desktop/NCL_class/NCL_Final/ERA_interim_monthlymean_MSL_Wind_1979_2001.grib"
> MSLP=f->MSL_GDS0_SFC_123(:,:,:) ;read in MSL data
> MSLP=MSLP*0.01 ;convert MSL pressure to mb
> ;WS=f->10SI_GDS0_SFC_123 (:,:,:) ;read in wind speed data
> lat=f->g0_lat_1
> lon=f->g0_lon_2
>
> nMSLP=dimsizes(MSLP)
> ;print("nMSLP="+nMSLP)
> nlat=dimsizes(lat)
> nlon=dimsizes(lon)
> ;print("nlat="+nlat)
> ntime=dimsizes(time)
> ;print("ntime="+ntime)
> ;printVarSummary(time)
>
> ;T_season =month_to_seasonN(time,(/"DJF","JJA"/))
> ;printVarSummary(T_season)
> ;nT_season=dimsizes(T_season)
> ;print("nT_season="+nT_season)
> MSLP_season=month_to_seasonN(MSLP,(/"DJF","JJA"/))
> printVarSummary(MSLP_season)
> nMSLP_season=dimsizes(MSLP_season)
> print("nMSLP_season="+nMSLP_season)
>
> ws_MSLP= new((/46,nlat,nlon/),"float")
>
> ws_MSLP(0::2,:,:) = (/ MSLP_season(0,:,:,:) /) ; assign season 0
> to the 0th, 2nd, 4th, etc time slots.
> ws_MSLP(1::2,:,:) = (/ MSLP_season(1,:,:,:) /) ; assign season 1
> to the 1st, 3rd, 5th, etc time slots.
>
>
> printVarSummary(ws_MSLP)
>
>
> Z1=new((/46,nlat,nlon/),"float") ;populate with ERA MSLP data
> do i=0,43
> Z1(i,:,:) = (/ws_MSLP(i,:,:)/)
> end do
>
> Z2=new((/n_ts,nlat,nlon/),"float")
> do i=0,43
> Z2(i,:,:)=(/ts(i)/) ;populate Z2 for all years with timeseries
> end do
>
>
>
> Z1!0="time"
> Z1!1="lat"
> Z1!2="lon"
> Z2!0="time"
> Z2!1="lat"
> Z2!2="lon"
>
>
> ;Reorder dimensions - must save in new grids
> ;-------------------------------------------
> ZZ1=Z1(lat|:,lon|:,time|:) ;REANALYSIS GRIDS
> ZZ2=Z2(lat|:,lon|:,time|:) ;TIMESERIES GRIDS
>
>
> ;Run 0-lag correlation function
> ;------------------------------
> Z=escorc(ZZ1(:,:,:),ZZ2(:,:,:))
>
> print(Z)
>
> ;Z is the 2D correlation map that you will plot
>
> end
>
>
> On Mon, Apr 15, 2013 at 9:01 PM, Adam Phillips <asphilli@ucar.edu
> <mailto:asphilli@ucar.edu>> wrote:
>
> Hi Skylar,
> I think you can just use index subscripting to do what you
> want. Try this:
> MSL_SEASON_new= new((/46,241,480/),"float")
> (You don't need to have a 4D array with the first dimension as
> size one.)
>
> (assign dimension names and coordinate variables as you were)
>
> then:
> MSL_SEASON_new(0::2,:,:) = (/ MSL_SEASON(0,:,:,:) /) ; assign
> season 0 to the 0th, 2nd, 4th, etc time slots.
> MSL_SEASON_new(1::2,:,:) = (/ MSL_SEASON(1,:,:,:) /) ; assign
> season 1 to the 1st, 3rd, 5th, etc time slots.
>
> This is of course untested, so check the new array to make
> sure that the above coding is doing what you want/expect it to.
>
> If the above doesn't help please let ncl-talk know.
>
>
>
> On 4/15/13 6:50 PM, Skylar Haines wrote:
>> All,
>>
>> I have converted ERA Interim monthly data into seasonal data,
>> DJF and JJA, and get my variable:
>>
>> Variable: MSL_season
>> Type: float
>> Total Size: 21285120 bytes
>> 5321280 values
>> Number of Dimensions: 4
>> Dimensions and sizes:[season | 2] x [initial_time0_hours |
>> 23] x [g0_lat_1 | 241] x [g0_lon_2 | 480]
>> Coordinates:
>> season: [DJF..JJA]
>> initial_time0_hours: [1569072..1761936]
>> g0_lat_1: [90..-90]
>> g0_lon_2: [ 0..359.25]
>> Number Of Attributes: 10
>> center :European Center for Medium-Range Weather Forecasts
>> (RSMC)
>> long_name :Seasonal Means: Mean sea level pressure
>> units :Pa
>> _FillValue :1e+20
>> level_indicator :1
>> gds_grid_type :0
>> parameter_table_version :128
>> parameter_number :151
>> forecast_time :0
>> forecast_time_units :hours
>> (0)nMSL_season=2
>> (1)nMSL_season=23
>> (2)nMSL_season=241
>> (3)nMSL_season=480
>>
>>
>> I would like to be able to have this data in a single array
>> such that the seasons, DJF and JJA, are in relative order
>> (i.e. DJF 1979, JJA 1979, DJF 1979-1980, JJA 1980, etc.):
>>
>> MSL_SEASON= new((/1,46,241,480/),"float")
>> MSL_SEASON!0="season"
>> MSL_SEASON!1="time"
>> MSL_SEASON!2="lat"
>> MSL_SEASON!3="lon"
>>
>>
>> MSL_SEASON&season = season
>> MSL_SEASON&time = time
>> MSL_SEASON&lat = lat
>> MSL_SEASON&lon = lon
>>
>>
>> Seems to me like a simple task, but I have been struggling
>> with it for a while now. I'm not sure whether a loop may be
>> involved. I am not sure of the correct syntax regarding
>> coordinate subscripting, either.
>>
>> Any help would greatly be appreciated.
>>
>> -Skylar
>>
>>
>> _______________________________________________
>> 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
>
>
>

```--
______________________________________________________________