Example #1
0
    def test_progress(self, capsys):
        for i in Progress.range(4, has_output=True, timer=False):
            print('hi')
        stdout, stderr = capsys.readouterr()
        output = """\
0% complete
0% complete
hi
25% complete
hi
50% complete
hi
75% complete
hi
100% complete

"""
        assert stdout ==  output
Example #2
0
    def test_progress(self, capsys):
        for i in Progress.range(4, has_output=True, timer=False):
            print("hi")
        stdout, stderr = capsys.readouterr()
        output = """\
0% complete
0% complete
hi
25% complete
hi
50% complete
hi
75% complete
hi
100% complete

"""
        assert stdout == output
Example #3
0
    def test_progress(self):
        with captured_stdout() as stream:
            for i in Progress.range(4, has_output=True, timer=False):
                print('hi')
                time.sleep(.5)
            stream.seek(0)
            output = """\
0% complete
0% complete
hi
25% complete
hi
50% complete
hi
75% complete
hi
100% complete

"""
            self.assertEqual(stream.read(), output)
Example #4
0
def calculate_lyapunov(unperturbed_file, perturbed_file):  #TODO: remove references to N_calc
    """This function calculates the lyapunov exponent at each integration step between two solutions.
    PARAMETERS:
        unperturbed_file: (string) String object with the file name in which the unperturbed solution is stored
        perturbed_file: (string) String object with the file name in which the perturbed solution is stored
    RETURNS:
        lyaps     : (float[N_steps]) N_steps-dimension array-like containing the values of the lyapunov exponent calcuated between solution1 and solution2 at each integration step for."""
    data_u, mu_u, k_u=read_data.get_data(unperturbed_file,form='lyapunov')
    data_p, mu_p, k_p=read_data.get_data(perturbed_file,form='lyapunov')
    
    lenght=len(data_u)
    try:
      assert lenght==len(data_p)
      assert mu_u==mu_p
      assert k_u==k_p
    except AssertionError:
        print(colors.red|"The integration results are not written as expexted", file=sys.stderr)
        sys.exit([6]) #Integration results are not written as expected
    """ Actual calculation of the Lyapunov exponents"""
    
    """Difference between the two simulations"""
    difference=data_u-data_p                        
    """Norms of the difference vectors"""
    norms=np.linalg.norm(difference, axis=1)
    """Norm of the initial difference"""
    norm_0=norms[0]  
    """Calculating the ln of the ratio between evolved state and initial state"""                               
    log_diff_ratio=np.log(norms/norm_0)
    lyaps=np.empty(lenght)
    cumulative_sum=0
    
    print("Lyapunov exponents calculation:")
    for i in Progress.range(1, lenght):
        """calculating the mean of the ratios from initial state to state i"""
        cumulative_sum+=log_diff_ratio[i]
        lyaps[i]=cumulative_sum/i
        
    return lyaps        
Example #5
0
 def test_progress_empty(self, capsys):
     for i in Progress.range(0, has_output=True, timer=False):
         print('hi')
     stdout, stderr = capsys.readouterr()
     output = '0/0 complete'
     assert output in stdout
Example #6
0
 def test_progress_empty(self, capsys):
     for i in Progress.range(0, has_output=True, timer=False):
         print("hi")
     stdout, stderr = capsys.readouterr()
     output = "0/0 complete"
     assert output in stdout