def test_matrix_norm_3d(self):
        """ Test normalization/cleanup of 3D (untraceable) flow matrix"""

        Z = np.array([[[0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ]],

                      [[0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.75]],

                      [[3.7 ,  0.  ,  0.  ],
                       [0.  ,  0.75,  0.  ],
                       [0.  ,  2.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ]]])

        A0 = np.array([[0.   , 0.   ,  0.        ,  0.        ,  0.        ],
                       [0.   , 0.   ,  0.        ,  0.        ,  0.06818182],
                       [1.85 , 0.   ,  0.75      ,  0.66666667,  0.        ]])

        nn_out0 = np.array([True, True, False, False, True, False, False,
                            True, False, False, False, True])

        A, __, nn_in, nn_out = ac.matrix_norm(Z, self.V)

        npt.assert_allclose(A, A0)
        npt.assert_equal(nn_in, np.array([True, True, True]))
        npt.assert_equal(nn_out, nn_out0)
    def test_matrix_norm_3d(self):
        """ Test normalization/cleanup of 3D (untraceable) flow matrix"""

        Z = np.array([[[0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ]],

                      [[0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ],
                       [0.  ,  0.  ,  0.75]],

                      [[3.7 ,  0.  ,  0.  ],
                       [0.  ,  0.75,  0.  ],
                       [0.  ,  2.  ,  0.  ],
                       [0.  ,  0.  ,  0.  ]]])

        A0 = np.array([[0.   , 0.   ,  0.        ,  0.        ,  0.        ],
                       [0.   , 0.   ,  0.        ,  0.        ,  0.06818182],
                       [1.85 , 0.   ,  0.75      ,  0.66666667,  0.        ]])

        nn_out0 = np.array([True, True, False, False, True, False, False,
                            True, False, False, False, True])

        A, __, nn_in, nn_out = ac.matrix_norm(Z, self.V)

        npt.assert_allclose(A, A0)
        npt.assert_equal(nn_in, np.array([True, True, True]))
        npt.assert_equal(nn_out, nn_out0)
    def test_matrix_norm_2d(self):
        """ Test normalization/cleanup of 2D (aggregated flow matrix

        There is 1 null production (second product not produced)."""

        Z = np.array([[0.,  0., 1.],
                      [0.,  0., 0],
                      [3.,  0., 0.5]])

        V = np.array([[4, 1, 0],
                      [0, 0, 0],
                      [0, 0, 2.]])

        A0 = np.array([[0.  ,  0.5 ],
                       [0.6 ,  0.25]])

        A, __, nn_in, nn_out = ac.matrix_norm(Z, V)

        npt.assert_allclose(A, A0)
        npt.assert_equal(nn_in, nn_out, np.array([True, False, True]))
    def test_matrix_norm_2d(self):
        """ Test normalization/cleanup of 2D (aggregated flow matrix

        There is 1 null production (second product not produced)."""

        Z = np.array([[0.,  0., 1.],
                      [0.,  0., 0],
                      [3.,  0., 0.5]])

        V = np.array([[4, 1, 0],
                      [0, 0, 0],
                      [0, 0, 2.]])

        A0 = np.array([[0.  ,  0.5 ],
                       [0.6 ,  0.25]])

        A, __, nn_in, nn_out = ac.matrix_norm(Z, V)

        npt.assert_allclose(A, A0)
        npt.assert_equal(nn_in, nn_out, np.array([True, False, True]))
    def test_matrix_norm_4d(self):
        """ Test normalization/cleanup of 4D (traceable) flow matrix"""

        Z0 = np.array([[[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.75]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[3.7 ,  0.  ,  0.  ],
                         [0.  ,  0.75,  0.  ],
                         [0.  ,  2.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]]])

        A0 = np.array([
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.06818182],
            [1.85      ,  0.        ,  0.75      ,  0.66666667,  0.        ]])

        A, __, nn_in, nn_out = ac.matrix_norm(Z0, self.V)
        npt.assert_allclose(A, A0)
    def test_matrix_norm_4d(self):
        """ Test normalization/cleanup of 4D (traceable) flow matrix"""

        Z0 = np.array([[[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.75]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]],


                       [[[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]],

                        [[3.7 ,  0.  ,  0.  ],
                         [0.  ,  0.75,  0.  ],
                         [0.  ,  2.  ,  0.  ],
                         [0.  ,  0.  ,  0.  ]]]])

        A0 = np.array([
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
            [0.        ,  0.        ,  0.        ,  0.        ,  0.06818182],
            [1.85      ,  0.        ,  0.75      ,  0.66666667,  0.        ]])

        A, __, nn_in, nn_out = ac.matrix_norm(Z0, self.V)
        npt.assert_allclose(A, A0)