# HG changeset patch # User Victor Nicolae # Date 1510299552 -7200 # Node ID f3f0b9e4a4275071000aacca3f58c910457cac2d # Parent 22b773693a3c4d13920ea80e0a40584576f7f8fd Include more parameters from licel input files in the NetCDF output file. diff -r 22b773693a3c -r f3f0b9e4a427 atmospheric_lidar/generic.py --- a/atmospheric_lidar/generic.py Tue Nov 07 17:24:33 2017 +0200 +++ b/atmospheric_lidar/generic.py Fri Nov 10 09:39:12 2017 +0200 @@ -334,14 +334,29 @@ temp_v = f.createVariable(channel_var, variable_type, ('channels',)) for n, channel in enumerate(channels): temp_v[n] = params.channel_parameters[channel][channel_var] + + # Write the custom subclass parameters: + for param in self.getCustomParameters(): + temp_v = f.createVariable(param["name"], param["type"], param["dimensions"]) + + for (value, n) in zip(param["values"], range(len(param["values"]))): + temp_v[n] = value # Write the values of fixed channel parameters: fill_value = -9999 for param in self._get_provided_extra_parameters(): if param in channel_variables.keys(): - temp_v = f.createVariable(param, channel_variables[param][1], channel_variables[param][0]) + try: + temp_v = f.createVariable(param, channel_variables[param][1], channel_variables[param][0]) + except RuntimeError: + logging.warning("NetCDF variable \"%s\" ignored because it was read from the input files!" % param) + continue else: - temp_v = f.createVariable(param, 'd', ('channels',), fill_value = fill_value) + try: + temp_v = f.createVariable(param, 'd', ('channels',), fill_value = fill_value) + except RuntimeError: + logging.warning("NetCDF variable \"%s\" ignored because it was read from the input files!" % param) + continue for (channel, n) in zip(channels, range(len(channels))): try: @@ -378,11 +393,15 @@ temp_raw_stop[:len(stop_time), n] = stop_time # Laser shots - temp_v = f.createVariable('Laser_Shots', 'i', ('time', 'channels')) - for (channel, n) in zip(channels, range(len(channels))): - time_length = len(self.variables['Raw_Data_Start_Time'][self.variables['id_timescale'][channel]]) - # Array slicing stoped working as usual ex. temp_v[:10] = 100 does not work. ??? np.ones was added. - temp_v[:time_length, n] = np.ones(time_length) * params.channel_parameters[channel]['Laser_Shots'] + try: + temp_v = f.createVariable('Laser_Shots', 'i', ('time', 'channels')) + for (channel, n) in zip(channels, range(len(channels))): + time_length = len(self.variables['Raw_Data_Start_Time'][self.variables['id_timescale'][channel]]) + # Array slicing stoped working as usual ex. temp_v[:10] = 100 does not work. ??? np.ones was added. + temp_v[:time_length, n] = np.ones(time_length) * params.channel_parameters[channel]['Laser_Shots'] + except RuntimeError: + logging.warning("NetCDF variable \"%s\" ignored because it was read from the input files!" % "LaserShots") + # Raw lidar data temp_v = f.createVariable('Raw_Lidar_Data', 'd', ('time', 'channels', 'points')) @@ -494,6 +513,15 @@ def get_dark_measurements(self): return None + + def getCustomParameters(self): + """ + Abstract method to provide custom NetCDF parameters + that should be included in the final NetCDF file. + This method should be implemented by subclasses of + BaseLidarMeasurement. + """ + pass @property def mean_time(self): diff -r 22b773693a3c -r f3f0b9e4a427 atmospheric_lidar/licel.py --- a/atmospheric_lidar/licel.py Tue Nov 07 17:24:33 2017 +0200 +++ b/atmospheric_lidar/licel.py Fri Nov 10 09:39:12 2017 +0200 @@ -194,6 +194,8 @@ extra_netcdf_parameters = musa_netcdf_parameters raw_info = {} # Keep the raw info from the files durations = {} # Keep the duration of the files + laser_shots = [] + files = [] def __init__(self, filelist=None, use_id_as_name=False): self.use_id_as_name = use_id_as_name @@ -206,11 +208,16 @@ current_file = LicelFile(filename, use_id_as_name=self.use_id_as_name) self.raw_info[current_file.filename] = current_file.raw_info self.durations[current_file.filename] = current_file.duration() + + file_laser_shots = [] for channel_name, channel in current_file.channels.items(): if channel_name not in self.channels: self.channels[channel_name] = LicelChannel(channel) self.channels[channel_name].data[current_file.start_time] = channel.data + file_laser_shots.append(channel.raw_info['NShots']) + + self.laser_shots.append(file_laser_shots) self.files.append(current_file.filename) def append(self, other): @@ -234,6 +241,27 @@ duration_sec = np.diff(raw_start_in_seconds)[0] return duration_sec + + def getCustomParameters(self): + params = [{ + "name": "DAQ_Range", + "dimensions": ('channels',), + "type": 'd', + "values": [self.channels[x].raw_info['Discriminator'] for x in self.channels.keys()] + }, { + "name": "LR_Input", + "dimensions": ('channels',), + "type": 'i', + "values": [self.channels[x].raw_info['LaserUsed'] for x in self.channels.keys()] + }, { + "name": "Laser_Shots", + "dimensions": ('time', 'channels',), + "type": 'i', + "values": self.laser_shots + }, + ] + + return params class LicelChannel(LidarChannel): @@ -249,7 +277,8 @@ self.points = channel_file.number_of_bins self.rc = [] self.duration = channel_file.duration - + self.raw_info = channel_file.raw_info + def append(self, other): if self.info != other.info: raise ValueError('Channel info are different. Data can not be combined.')