6 |
6 |
7 licel_file_header_format = ['Filename', |
7 licel_file_header_format = ['Filename', |
8 'Site StartDate StartTime EndDate EndTime Altitude Longtitude Latitude ZenithAngle', |
8 'Site StartDate StartTime EndDate EndTime Altitude Longtitude Latitude ZenithAngle', |
9 'LS1 Rate1 LS2 Rate2 DataSets', ] |
9 'LS1 Rate1 LS2 Rate2 DataSets', ] |
10 licel_file_channel_format = 'Active AnalogPhoton LaserUsed DataPoints 1 HV BinW Wavelength d1 d2 d3 d4 ADCbits NShots Discriminator ID' |
10 licel_file_channel_format = 'Active AnalogPhoton LaserUsed DataPoints 1 HV BinW Wavelength d1 d2 d3 d4 ADCbits NShots Discriminator ID' |
|
11 |
11 |
12 |
12 class LicelFile: |
13 class LicelFile: |
13 def __init__(self, filename): |
14 def __init__(self, filename): |
14 self.start_time = None |
15 self.start_time = None |
15 self.stop_time = None |
16 self.stop_time = None |
70 channels[channel_name] = channel |
71 channels[channel_name] = channel |
71 f.close() |
72 f.close() |
72 |
73 |
73 self.raw_info = raw_info |
74 self.raw_info = raw_info |
74 self.channels = channels |
75 self.channels = channels |
75 |
76 |
76 |
|
77 |
77 |
78 class LicelFileChannel: |
78 class LicelFileChannel: |
79 |
79 |
80 def __init__(self, raw_info = None, raw_data = None): |
80 def __init__(self, raw_info = None, raw_data = None): |
81 self.raw_info = raw_info |
81 self.raw_info = raw_info |
135 number_of_bins = int(self.raw_info['DataPoints']) |
135 number_of_bins = int(self.raw_info['DataPoints']) |
136 self.z = np.array([dz*bin_number + dz/2.0 for bin_number in range(number_of_bins)]) |
136 self.z = np.array([dz*bin_number + dz/2.0 for bin_number in range(number_of_bins)]) |
137 self.dz = dz |
137 self.dz = dz |
138 self.number_of_bins = number_of_bins |
138 self.number_of_bins = number_of_bins |
139 self.data = channel_data |
139 self.data = channel_data |
|
140 |
140 |
141 |
141 class LicelLidarMeasurement(BaseLidarMeasurement): |
142 class LicelLidarMeasurement(BaseLidarMeasurement): |
142 ''' |
143 ''' |
143 |
144 |
144 ''' |
145 ''' |
145 |
146 |
146 extra_netcdf_parameters = musa_netcdf_parameters |
147 extra_netcdf_parameters = musa_netcdf_parameters |
|
148 raw_info = {} # Keep the raw info from the files |
147 |
149 |
148 def import_file(self, filename): |
150 def import_file(self, filename): |
149 if filename in self.files: |
151 if filename in self.files: |
150 print "File has been imported already:" + filename |
152 print "File has been imported already:" + filename |
151 else: |
153 else: |
152 current_file = LicelFile(filename) |
154 current_file = LicelFile(filename) |
|
155 self.raw_info[current_file.filename] = current_file.raw_info |
|
156 |
153 for channel_name, channel in current_file.channels.items(): |
157 for channel_name, channel in current_file.channels.items(): |
154 if channel_name not in self.channels: |
158 if channel_name not in self.channels: |
155 self.channels[channel_name] = Licel_channel(channel) |
159 self.channels[channel_name] = Licel_channel(channel) |
156 self.channels[channel_name].data[current_file.start_time] = channel.data |
160 self.channels[channel_name].data[current_file.start_time] = channel.data |
157 self.files.append(current_file.filename) |
161 self.files.append(current_file.filename) |
162 self.stop_times.extend(other.stop_times) |
166 self.stop_times.extend(other.stop_times) |
163 |
167 |
164 for channel_name, channel in self.channels.items(): |
168 for channel_name, channel in self.channels.items(): |
165 channel.append(other.channels[channel_name]) |
169 channel.append(other.channels[channel_name]) |
166 |
170 |
167 |
171 def _get_duration(self, raw_start_in_seconds): |
|
172 ''' Return the duration for a given time scale. If only a single |
|
173 file is imported, then this cannot be guessed from the time difference |
|
174 and the raw_info of the file are checked. |
|
175 |
|
176 ''' |
|
177 |
|
178 if len(raw_start_in_seconds) == 1: # If only one file imported |
|
179 raw_info = self.raw_info.itervalues().next() # Get the first (and only) raw_info |
|
180 start_str = "%s %s" % (raw_info['StartDate'], raw_info['StartTime']) |
|
181 end_str = "%s %s" % (raw_info['EndDate'], raw_info['EndTime']) |
|
182 start_time = datetime.datetime.strptime(start_str, "%d/%m/%Y %H:%M:%S") |
|
183 end_time = datetime.datetime.strptime(end_str, "%d/%m/%Y %H:%M:%S") |
|
184 duration = end_time - start_time |
|
185 duration_sec = duration.seconds |
|
186 else: |
|
187 duration_sec = np.diff(raw_start_in_seconds)[0] |
|
188 |
|
189 return duration_sec |
|
190 |
|
191 |
168 class Licel_channel(Lidar_channel): |
192 class Licel_channel(Lidar_channel): |
169 |
193 |
170 def __init__(self, channel_file): |
194 def __init__(self, channel_file): |
171 c = 299792458.0 #Speed of light |
195 c = 299792458.0 #Speed of light |
172 self.wavelength = channel_file.wavelength |
196 self.wavelength = channel_file.wavelength |
189 return "<Licel channel: %s>" % self.info['Wavelength'] |
213 return "<Licel channel: %s>" % self.info['Wavelength'] |
190 |
214 |
191 def __str__(self): |
215 def __str__(self): |
192 return unicode(self).encode('utf-8') |
216 return unicode(self).encode('utf-8') |
193 |
217 |
|
218 |
194 class Licel2009LidarMeasurement(LicelLidarMeasurement): |
219 class Licel2009LidarMeasurement(LicelLidarMeasurement): |
195 extra_netcdf_parameters = musa_2009_netcdf_parameters |
220 extra_netcdf_parameters = musa_2009_netcdf_parameters |
|
221 |
196 |
222 |
197 def match_lines(f1,f2): |
223 def match_lines(f1,f2): |
198 list1 = f1.split() |
224 list1 = f1.split() |
199 list2 = f2.split() |
225 list2 = f2.split() |
200 |
226 |