Re: Reorganizing two arrays into one

From: Skylar Haines <skylar.haines_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 16 2013 - 09:34:54 MDT

Thanks Adam!

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

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"

begin

 ;;;;;read in ITASE 02-1 NA ice core
data***************************************************

data1=readAsciiTable("/Users/sky/Desktop/NCL_class/NCL_Final/ITASE-02-1_DJF_JJA_seasonal.txt",2,"float",0)
  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"

;;;;;read in Seasonal ERA
MSLP************************************************************************
infile="/Users/sky/Desktop/NCL_class/NCL_Final/ERA_interim_monthlymean_MSL_Wind_1979_2001.grib"
f=addfile(infile,"r")
 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)
 time=f->initial_time0_hours ;read in time
 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> 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.
> Adam
>
>
>
> 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
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 16 09:35:45 2013

This archive was generated by hypermail 2.1.8 : Tue Apr 23 2013 - 12:54:13 MDT