Re: Problems extracting run from dim_numrun using dim_sum

From: Cannavina, Dominique <d.cannavina11_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 03 2012 - 10:34:12 MDT

Hi Adam

That is great thank you, I had got locked into trying to extract the unique runs and hadn't realise that I had already extracted them. :-)

Thanks for your help

Kind regards

Dominique

________________________________
From: ncl-talk-bounces@ucar.edu [ncl-talk-bounces@ucar.edu] on behalf of Adam Phillips [asphilli@ucar.edu]
Sent: 02 October 2012 23:15
To: ncl-talk@ucar.edu
Subject: Re: Problems extracting run from dim_numrun using dim_sum

Hi Dominique,
x = dim_numrun_n(cold_mn, 1, 0) ; cold_mn = time x lat x lon

For the above syntax, dum_numrun_n will return the number of unique runs present at each lat lon point. Take a look at example #2 here:
http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_numrun_n.shtml

x(0,:,:) will contain the number of instances at each lat/lon point where the run length = 1.
x(1,:,:) will contain the number of instances at each lat/lon point where the run length = 2.
and so on.

So, if you want to see the number of instances of run length 5 at 40N, 5E, you can do this:
print(x(4,{40},{5}))

The following syntax will put the same input in every instance of spell_tot_unique_mn, because the right hand side of the equation is not changing with every iteration of nr.
do nr=0,nspell-1
spell_tot_unique_mn(nr,:,:) = dim_sum_n(cold_mn1,0)

end do

I'm not sure if I'm right or not, but after reading your email I don't think you need to use dim_sum_n at all, and just use the output from dim_numrun_n as that returns the number of unique runs for each run length at each grid point. If I am incorrect in my line of thinking here, please respond back to ncl-talk further describing what you are trying to accomplish. Adam

On 10/2/12 12:24 PM, Cannavina, Dominique wrote:

Hi NCL Talk

I have extracted a daily minimum temperature (t2_mn) for consecutive years from a data set over a specified area (lat, lon).

dim_numrun_n was used to find the number of cold spells (i.e. number of consecutive cold spells of 1 day, 2 days....20 days etc

tcrit = 0 ; specify cut off temperature 'tcrit'

cold_mn = where(t2_mn.le.tcrit, 1, 0) ;create 0/1 array

cold_mn1 = dim_numrun_n(cold_mn, 1, 0) ; opt = 0 means total (time,lat,lon)

.

.

.

Variable: cold_mn1

Type: integer

Total Size: 67145680 bytes

16786420 values

Number of Dimensions: 3

Dimensions and sizes: [run_length | 12235] x [lat | 28] x [lon | 49]

Coordinates:

run_length: [1..12235]

lat: [73.5..33]

lon: [-27..45]

Number Of Attributes: 2

cold_crit_values : 0

long_name : unique cold runs

Then dim_sum_n was used to extract the number of 1 day, 2 day spells at each lat,lon

This is the bit I am having problems with

I initially had the following line in the do loop below, but the subscripting is unbalanced so it rightly won't work

spell_tot_unique_mn(nr,:,:) = dim_sum_n(cold_mn1({spell(nr)},:,:),0)

.

.

.

So I removed the subscripting which gave me the following do loop, which although it didn't return any erro, when I went to plot the data, it returns the same set of values for each spell duration or 'nr'

; Set range for spell

n1 = 1

n2 = 100 ; ispan to specify all spells

spell = ispan(n1,n2,1) ; eg n1=1, n2=20

nspell = dimsizes(spell)

; Select out 'unique runs'

do nr=0,nspell-1

spell_tot_unique_mn(nr,:,:) = dim_sum_n(cold_mn1,0)

end do

spell_tot_unique_mn!0 = "spell"

spell_tot_unique_mn&spell = spell

copy_VarCoords(cold_mn1(0,:,:), spell_tot_unique_mn(0,:,:)) ; trick for coords

printVarSummary(spell_tot_unique_mn)

print(dimsizes(spell))

printMinMax(spell_tot_unique_mn,True)

Variable: spell_tot_unique_mn

Type: float

Total Size: 548800 bytes

137200 values

Number of Dimensions: 3

Dimensions and sizes: [spell | 100] x [lat | 28] x [lon | 49]

Coordinates:

spell: [1..100]

lat: [73.5..33]

lon: [-27..45]

Number Of Attributes: 2

spell : 1

_FillValue : 9.96921e+36

(0) 100

(0)

(0) min=0 max=976

So I think although the dim_sum_n is summing run length from coldmn1, it is not differentiating between a 1 day run, 2 day run etc?

The full script and all the associated variables are attached in two file.

How can I get the dim_sum_n to sum the 'correct' spell lengths?

Any help much appreciated.

Kind regards

Dominique

_______________________________________________
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 Wed Oct 3 10:35:34 2012

This archive was generated by hypermail 2.1.8 : Mon Oct 08 2012 - 15:54:16 MDT