climate.tsonis

Provides classes for generating and analyzing complex climate networks.

class pyunicorn.climate.tsonis.TsonisClimateNetwork(data, threshold=None, link_density=None, non_local=False, node_weight_type='surface', winter_only=True, silence_level=0)[source]

Bases: ClimateNetwork

Encapsulates a Tsonis climate network.

Construct a static climate network following Tsonis et al. from the Pearson correlation matrix at zero lag.

Hence, Tsonis climate networks are undirected due to the symmetry of the correlation matrix.

References: [Tsonis2004], [Tsonis2006], [Tsonis2008b], [Tsonis2008c].

static SmallTestNetwork()[source]

Return a 6-node undirected test climate network from a test data set.

Example:

>>> r(TsonisClimateNetwork.SmallTestNetwork().adjacency)
array([[0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0],
       [0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 0]])
Return type:

Network instance

__init__(data, threshold=None, link_density=None, non_local=False, node_weight_type='surface', winter_only=True, silence_level=0)[source]

Initialize an instance of TsonisClimateNetwork.

Note

Either threshold OR link_density have to be given!

Possible choices for node_weight_type:
  • None (constant unit weights)

  • “surface” (cos lat)

  • “irrigation” (cos**2 lat)

Parameters:
  • data (:classL`.ClimateData`) – The climate data used for network construction.

  • threshold (float) – The threshold of similarity measure, above which two nodes are linked in the network.

  • link_density (float) – The networks’s desired link density.

  • non_local (bool) – Determines, whether links between spatially close nodes should be suppressed.

  • ode_weight_type (str) – The type of geographical node weight to be used.

  • winter_only (bool) – Determines, whether only data points from the winter months (December, January and February) should be used for analysis. Possibly, this further suppresses the annual cycle in the time series.

  • silence_level (int) – The inverse level of verbosity of the object.

__str__()[source]

Return a string representation of TsonisClimateNetwork.

Example:

>>> print(TsonisClimateNetwork.SmallTestNetwork())
TsonisClimateNetwork:
ClimateNetwork:
GeoNetwork:
Network: undirected, 6 nodes, 6 links, link density 0.400.
Geographical boundaries:
         time     lat     lon
   min    0.0    0.00    2.50
   max    9.0   25.00   15.00
Threshold: 0.5
Local connections filtered out: False
Use only data points from winter months: False
_calculate_correlation(anomaly)[source]

Return the correlation matrix at zero lag.

Parameters:

anomaly (2D Numpy array (time, index)) – the anomaly time series from which to calculate the correlation matrix at zero lag.

Return type:

2D Numpy array (index, index)

Returns:

the correlation matrix at zero lag.

_set_winter_only(winter_only)[source]

Toggle use of exclusively winter data points for network generation.

Parameters:

winter_only (bool) – Indicates, whether only winter months were used for network generation.

calculate_similarity_measure(anomaly)[source]

Encapsulate the calculation of the correlation matrix at zero lag.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork()._calculate_correlation(
...     anomaly=ClimateData.SmallTestData().anomaly())
array([[ 1.        , -0.25377226, -1.        ,
         0.25377226,  1.        , -0.25377226],
       [-0.25377226,  1.        ,  0.25377226,
        -1.        , -0.25377226,  1.        ],
       [-1.        ,  0.25377226,  1.        ,
        -0.25377226, -1.        ,  0.25377226],
       [ 0.25377226, -1.        , -0.25377226,
         1.        ,  0.25377226, -1.        ],
       [ 1.        , -0.25377226, -1.        ,
         0.25377226,  1.        , -0.25377226],
       [-0.25377226,  1.        ,  0.25377226,
        -1.        , -0.25377226,  1.        ]], dtype=float32)
Parameters:

anomaly (2D Numpy array (time, index)) – the anomaly time series from which to calculate the correlation matrix at zero lag.

Return type:

2D Numpy array (index, index)

Returns:

the correlation matrix at zero lag.

correlation()[source]

Return the correlation matrix at zero lag.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork().correlation()
array([[ 1.        ,  0.25377226,  1.        ,
         0.25377226,  1.        ,  0.25377226],
       [ 0.25377226,  1.        ,  0.25377226,
         1.        ,  0.25377226,  1.        ],
       [ 1.        ,  0.25377226,  1.        ,
         0.25377226,  1.        ,  0.25377226],
       [ 0.25377226,  1.        ,  0.25377226,
         1.        ,  0.25377226,  1.        ],
       [ 1.        ,  0.25377226,  1.        ,
         0.25377226,  1.        ,  0.25377226],
       [ 0.25377226,  1.        ,  0.25377226,
         1.        ,  0.25377226,  1.        ]], dtype=float32)
Return type:

2D Numpy array (index, index)

Returns:

the correlation matrix at zero lag.

correlation_weighted_average_path_length()[source]

Return correlation weighted average path length.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork().                correlation_weighted_average_path_length()
1.0
Return float:

the correlation weighted average path length.

correlation_weighted_closeness()[source]

Return correlation weighted closeness.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork().                correlation_weighted_closeness()
array([ 0.25, 0.25, 0.25, 0.25, 0.25, 0.25])
Return type:

1D Numpy array [index]

Returns:

the correlation weighted closeness sequence.

data

(ClimateData) - The climate data used for network construction.

local_correlation_weighted_vulnerability()[source]

Return correlation weighted vulnerability.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork().                local_correlation_weighted_vulnerability()
array([ 0., 0., 0., 0., 0., 0.])
Return type:

1D Numpy array [index]

Returns:

the correlation weighted vulnerability sequence.

set_winter_only(winter_only)[source]

Toggle use of exclusively winter data points for network generation.

Also explicitly re(generates) the instance of TsonisClimateNetwork.

Example:

>>> net = TsonisClimateNetwork.SmallTestNetwork()
>>> net.set_winter_only(winter_only=False)
>>> net.n_links
6
Parameters:

winter_only (bool) – Indicates, whether only winter months were used for network generation.

winter_only()[source]

Indicate, if only winter months were used for network generation.

Example:

>>> TsonisClimateNetwork.SmallTestNetwork().winter_only()
False
Return bool:

whether only winter months were used for network generation.