atmospheric_lidar/licel.py

changeset 173
9c29ffa49f2d
parent 170
9face926ccab
child 176
34866a2a1aa5
--- a/atmospheric_lidar/licel.py	Wed Dec 12 16:39:21 2018 +0200
+++ b/atmospheric_lidar/licel.py	Wed Dec 12 18:02:39 2018 +0200
@@ -154,7 +154,7 @@
 
     channel_data_class = LicelChannelData
 
-    def __init__(self, file_path, use_id_as_name=False, licel_timezone="UTC", import_now=True):
+    def __init__(self, file_path, use_id_as_name=False, licel_timezone="UTC", import_now=True, fix_zenith_angle=False):
         """
         This is run when creating a new object.
 
@@ -168,10 +168,12 @@
         licel_timezone : str
            The timezone of dates found in the Licel files. Should match the available
            timezones in the TZ database.
-        import_file : bool
+        import_now : bool
            If True, the header and data are read immediately. If not, the user has to call the
            corresponding methods directly. This is used to speed up reading files when only
            header information are required.
+        fix_zenith_angle : bool
+           If True, it corrects the old Raymetrics convention of zenith angle definition (zenith = -90 degrees)
         """
         self.file_path = file_path
         self.file_name = os.path.basename(file_path)
@@ -180,6 +182,7 @@
         self.start_time = None
         self.stop_time = None
         self.licel_timezone = licel_timezone
+        self.fix_zenith_angle = fix_zenith_angle
 
         if import_now:
             self.import_file()
@@ -283,7 +286,30 @@
         self.altitude = float(self.raw_info['altitude'])
         self.longitude = float(self.raw_info['longitude'])
         self.latitude = float(self.raw_info['latitude'])
-        self.zenith_angle = float(self.raw_info['zenith_angle'])
+
+        self.zenith_angle_raw = float(self.raw_info['zenith_angle'])
+
+        if self.fix_zenith_angle:
+            self.zenith_angle = self._correct_zenith_angle(self.zenith_angle_raw)
+        else:
+            self.zenith_angle = self.zenith_angle_raw
+
+    @staticmethod
+    def _correct_zenith_angle(zenith_angle):
+        """ Correct zenith angle from Raymetrics convention (zenith = -90 degrees).
+
+        Parameters
+        ----------
+        zenith_angle : float
+           Zenith angle in Raymetrics convention.
+
+        Returns
+        -------
+        corrected_angle : float
+           Corrected zenith angle.
+        """
+        corrected_angle = 90 - zenith_angle
+        return corrected_angle
 
     def _read_second_header_line(self, f):
         """ Read the second line of a licel file. """
@@ -439,7 +465,7 @@
     channel_class = LicelChannel
     photodiode_class = PhotodiodeChannel
 
-    def __init__(self, file_list=None, use_id_as_name=False, licel_timezone='UTC'):
+    def __init__(self, file_list=None, use_id_as_name=False, licel_timezone='UTC', fix_zenith_angle=False):
         self.raw_info = {}  # Keep the raw info from the files
         self.durations = {}  # Keep the duration of the files
         self.laser_shots = []
@@ -447,6 +473,7 @@
         self.use_id_as_name = use_id_as_name
         self.licel_timezone = licel_timezone
         self.photodiodes = {}
+        self.fix_zenith_angle = fix_zenith_angle
 
         super(LicelLidarMeasurement, self).__init__(file_list)
 
@@ -456,7 +483,8 @@
             logger.warning("File has been imported already: %s" % filename)
         else:
             logger.debug('Importing file {0}'.format(filename))
-            current_file = self.file_class(filename, use_id_as_name=self.use_id_as_name, licel_timezone=self.licel_timezone)
+            current_file = self.file_class(filename, use_id_as_name=self.use_id_as_name,
+                                           licel_timezone=self.licel_timezone, fix_zenith_angle=self.fix_zenith_angle)
             self.raw_info[current_file.file_path] = current_file.raw_info
             self.durations[current_file.file_path] = current_file.duration()
 

mercurial