licel.py

changeset 22
a2355e871b23
parent 21
406eb996a9cd
child 26
84f7d763deeb
child 27
74f7617f5356
--- a/licel.py	Thu Mar 20 09:17:09 2014 +0200
+++ b/licel.py	Mon May 12 11:14:44 2014 +0300
@@ -9,6 +9,7 @@
                             'LS1 Rate1 LS2 Rate2 DataSets', ]
 licel_file_channel_format = 'Active AnalogPhoton LaserUsed DataPoints 1 HV BinW Wavelength d1 d2 d3 d4 ADCbits NShots Discriminator ID'
 
+
 class LicelFile:
     def __init__(self, filename):
         self.start_time = None
@@ -72,8 +73,7 @@
 
         self.raw_info = raw_info
         self.channels = channels
-    
-    
+       
 
 class LicelFileChannel:
     
@@ -137,6 +137,7 @@
         self.dz = dz
         self.number_of_bins = number_of_bins
         self.data = channel_data
+
         
 class LicelLidarMeasurement(BaseLidarMeasurement):
     '''
@@ -144,12 +145,15 @@
     '''
     
     extra_netcdf_parameters = musa_netcdf_parameters
+    raw_info = {} # Keep the raw info from the files
     
     def import_file(self, filename):
         if filename in self.files:
             print "File has been imported already:" + filename
         else:
             current_file = LicelFile(filename)
+            self.raw_info[current_file.filename] = current_file.raw_info
+            
             for channel_name, channel in current_file.channels.items():
                 if channel_name not in self.channels:
                     self.channels[channel_name] = Licel_channel(channel)
@@ -164,7 +168,27 @@
         for channel_name, channel in self.channels.items():
             channel.append(other.channels[channel_name])
 
+    def _get_duration(self, raw_start_in_seconds):
+        ''' Return the duration for a given time scale. If only a single
+        file is imported, then this cannot be guessed from the time difference
+        and the raw_info of the file are checked.
+         
+        '''
+        
+        if len(raw_start_in_seconds) == 1: # If only one file imported
+            raw_info = self.raw_info.itervalues().next() # Get the first (and only) raw_info
+            start_str = "%s %s" % (raw_info['StartDate'], raw_info['StartTime'])
+            end_str = "%s %s" % (raw_info['EndDate'], raw_info['EndTime'])
+            start_time = datetime.datetime.strptime(start_str, "%d/%m/%Y %H:%M:%S")
+            end_time = datetime.datetime.strptime(end_str, "%d/%m/%Y %H:%M:%S")
+            duration = end_time - start_time
+            duration_sec = duration.seconds
+        else:
+            duration_sec = np.diff(raw_start_in_seconds)[0]
 
+        return duration_sec
+
+       
 class Licel_channel(Lidar_channel):
     
     def __init__(self, channel_file):
@@ -191,9 +215,11 @@
     def __str__(self):
         return unicode(self).encode('utf-8')
 
+
 class Licel2009LidarMeasurement(LicelLidarMeasurement):
     extra_netcdf_parameters = musa_2009_netcdf_parameters
 
+
 def match_lines(f1,f2):
     list1 = f1.split()
     list2 = f2.split()

mercurial