Commits

James Morrison committed c52cdc0

Added wave_power to common package not currently called but will be called by
dwr/wave_concat and awac/awac_stats

Comments (0)

Files changed (2)

hebtools/common/wave_power.py

+gravity = 9.81
+density_seawater = 1025
+depth = 65
+
+import math
+
+def calculate(sig_wave_height, peak_period):
+    """ Given significant wave height in metres and peak period Tp in seconds
+        a tuple with wave power in kW per metre wave crest and wavelength in
+        metres is returned.
+    """
+
+    def calculate_wave_power(sig_wave_height, group_velocity):
+        return gravity * density_seawater * ( (sig_wave_height ** 2) /16 ) * group_velocity
+
+    def calculate_wavelength(peak_period):
+        """
+            Takes the peak period and calculates
+            the wavelength for any depth in metres
+        """
+        energy_period = 0.9 * peak_period
+        numerator= gravity * ( energy_period**2 )
+        denominator= 2 * math.pi
+        first_result = numerator / denominator
+        estimated_wavelength = first_result
+
+        tan_h = math.tanh( ( ( 2 * math.pi ) * depth) / estimated_wavelength )
+        L = tan_h * first_result
+        diff= L - estimated_wavelength
+        while diff > 0.01 or diff < -0.01:
+            tan_h = math.tanh( ( (2 * math.pi) * depth)/ estimated_wavelength )
+            L = tan_h * first_result
+            diff = L - estimated_wavelength
+            estimated_wavelength = estimated_wavelength + ( 0.5 * diff )
+        return estimated_wavelength
+
+    def calculate_wave_number(wavelength):
+        return (2 * math.pi)/wavelength
+        
+    def get_celerity(wavelength, peak_period):
+        energy_period = 0.9 * peak_period
+        gT_over_two_pi = ( gravity * energy_period ) / ( 2 * math.pi )
+        tan_h = math.tanh( ( ( 2 * math.pi ) * depth) / wavelength)
+        return gT_over_two_pi * tan_h
+        
+    def calculate_group_velocity(wavelength, peak_period):
+        celerity = get_celerity(wavelength, peak_period)
+        wave_number = calculate_wave_number(wavelength)
+        numerator= 2 * wave_number * depth
+        denominator = math.sinh(numerator)
+        result = 1 + (numerator / denominator)
+        return 0.5 * result * celerity
+        
+    def get_wave_power_in_kw_p_m(sig_wave_height, peak_period):
+        wavelength = calculate_wavelength(peak_period)
+        group_velocity = calculate_group_velocity(wavelength, peak_period)
+        wave_power = float(calculate_wave_power(sig_wave_height, group_velocity))/1000
+        return wave_power, wavelength
+        
+    return get_wave_power_in_kw_p_m(sig_wave_height_cm, peak_period)

hebtools/dwr/test_dwr.py

 
 number_of_waves = 313053
 test_folder_path = os.path.abspath('../../buoy_data/') + os.path.sep
+year = '2013'
+month = 'February'
     
 class TestParseRaw(unittest.TestCase):
 
    def setUp(self):
        try:        
-           parse_raw.load(test_folder_path)
+           parse_raw.load(test_folder_path, year)
        except WindowsError:
            print "Load Raw Files failed"
 
    def test_wave_height_dataframe(self):
+       print os.getcwd()
        wave_height_dataframe = pd.load('wave_height_dataframe')
        self.assertEqual(len(wave_height_dataframe),number_of_waves)
 
-class TestWaveStats(unittest.TestCase):
+# class TestWaveStats(unittest.TestCase):
 
-    def setUp(self):
-        print "Test"
+    # def setUp(self):
+        # print "Test"
 
-    def test_wave_height_dataframe(self):
-        os.chdir(os.path.join(test_folder_path,'2005','july'))
-        raw_plus_std = pd.load('raw_plus_std')
-        wave_stats.WaveStats(raw_plus_std)
-        wave_height_dataframe = pd.load('wave_height_dataframe')
-        self.assertEqual(len(wave_height_dataframe),number_of_waves)
+    # def test_wave_height_dataframe(self):
+        # os.chdir(os.path.join(test_folder_path, year, month))
+        # raw_plus_std = pd.load('raw_plus_std')
+        # wave_stats.WaveStats(raw_plus_std)
+        # wave_height_dataframe = pd.load('wave_height_dataframe')
+        # self.assertEqual(len(wave_height_dataframe),number_of_waves)
         
-class TestProblemFiles(unittest.TestCase):
+# class TestProblemFiles(unittest.TestCase):
 
-   def setUp(self):
-       try:        
-           problem_files.concat(test_folder_path)
-       except WindowsError:
-           print "ProblemFileConcat failed"
+   # def setUp(self):
+       # try:        
+           # problem_files.concat(test_folder_path)
+       # except WindowsError:
+           # print "ProblemFileConcat failed"
 
-   def test_problem_file_concat(self):
-       os.chdir(test_folder_path)
-       prob_files = np.load('prob_files.npy')
-       self.assertEqual(len(prob_files),0)  
+   # def test_problem_file_concat(self):
+       # os.chdir(test_folder_path)
+       # prob_files = np.load('prob_files.npy')
+       # self.assertEqual(len(prob_files),0)  
 
-class TestWaveConcat(unittest.TestCase):
+# class TestWaveConcat(unittest.TestCase):
 
-    def setUp(self):
-        wave_concat.iterate_over_buoy_years(test_folder_path)
+    # def setUp(self):
+        # wave_concat.iterate_over_buoy_years(test_folder_path)
 
-    def test_wave_concat(self):
-        wave_height_stats_df = pd.load('large_wave_height_df')
-        self.assertEqual(len(wave_height_stats_df),number_of_waves)       
+    # def test_wave_concat(self):
+        # wave_height_stats_df = pd.load('large_wave_height_df')
+        # self.assertEqual(len(wave_height_stats_df),number_of_waves)       
         
 
 if __name__=='__main__':