Drawing frequency distribution of the daily maximum urban heat island intensity as a function of the time of day

37 Views Asked by At

I am pretty new to python. I am currently working with urban heat island intensity. The first 10 rows of the 3-hourly uhi intensity data is as follows,

uhii = array([[ 1.9,  1.4,  1. ,  0.6,  1.9,  0.6,  0.5,  2. ],
              [-2.1, -1.3, -3. ,  1.8,  0.7,  1. ,  0.8,  0. ],
              [ 0.2,  0.4, -1.8,  1.1,  0.2, -0.2,  0.4,  0. ],
              [ 0.5,  0. , -0.2,  1. ,  0.8,  0.1,  3.4, -0.1],
              [ 1.3,  0. ,  0. ,  0.7,  0. ,  0.9, -1. ,  1. ],
              [ 1.4,  1.6,  0.6,  0.4, -0.5,  0.4,  1.9,  0.7],
              [ 0.8,  0.7,  0.5,  1.6,  1.5,  0.9,  1.7,  1. ],
              [ 0.1, -1.6, -0.3,  2.4,  0.9, -0.2,  0.5,  0.4],
              [ 0.2, -1.5, -0.1,  1.1,  0.5,  0.6, -0.2,  0.4],
              [ 1.2,  1.6, -1.2, -0.4, -0.5,  1.2,  0.6,  1.6]])])

here, the hours are 3,6,9,12,15,18,21,00 LST, respectively. I want and array that will give the the number of occurrence of maximum UHII at a certain LST.

For example, in the uhii array, maximum occurs at 3 LST (along column 1) only once, and at 12 LST (along column 4) 4 times, at 21 LST (along column 7) 3 times.

Therefore, if I consider this uhii array, the result I want is

result = array([1,1,0,4,0,0,3,1])

I think I need the loop function, but I cant figure out how to write the logical steps that will lead me to the result I want.

The shape of this uhii array is (10,8), but the data I am working with has a shape of (9922,8).

1

There are 1 best solutions below

0
maciek97x On

You can use numpy. First you need to compute maximum for each row

np.max(uhii, axis=1)

Result:

array([2. , 1.8, 1.1, 3.4, 1.3, 1.9, 1.7, 2.4, 1.1, 1.6])

Then check if value is the maximum by:

uhii == np.max(uhii, axis=1)[np.newaxis, :].T

Result:

array([[False, False, False, False, False, False, False,  True],
       [False, False, False,  True, False, False, False, False],
       [False, False, False,  True, False, False, False, False],
       [False, False, False, False, False, False,  True, False],
       [ True, False, False, False, False, False, False, False],
       [False, False, False, False, False, False,  True, False],
       [False, False, False, False, False, False,  True, False],
       [False, False, False,  True, False, False, False, False],
       [False, False, False,  True, False, False, False, False],
       [False,  True, False, False, False, False, False,  True]])

And finally compute sum for each column:

np.sum(uhii == np.max(uhii, axis=1)[np.newaxis, :].T, axis=0)

Result:

array([1, 1, 0, 4, 0, 0, 3, 2])