From 34df72beaab80a83bf4db692d5f207f19c7740f9 Mon Sep 17 00:00:00 2001 From: Simo Tukiainen Date: Tue, 14 Sep 2021 16:19:46 +0300 Subject: [PATCH] Fix based on review --- cloudnetpy/instruments/ceilo.py | 14 +++++++------- cloudnetpy/instruments/ceilometer.py | 5 +++-- cloudnetpy/instruments/lufft.py | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cloudnetpy/instruments/ceilo.py b/cloudnetpy/instruments/ceilo.py index 9b7d7a91..81d02542 100644 --- a/cloudnetpy/instruments/ceilo.py +++ b/cloudnetpy/instruments/ceilo.py @@ -1,13 +1,13 @@ """Module for reading and processing Vaisala / Lufft ceilometers.""" import linecache from typing import Union, Optional +import logging import numpy as np import netCDF4 -from cloudnetpy.instruments.lufft import LufftCeilo, CL61d +from cloudnetpy.instruments.lufft import LufftCeilo, Cl61d from cloudnetpy.instruments.vaisala import ClCeilo, Ct25k from cloudnetpy import utils, output, CloudnetArray from cloudnetpy.metadata import MetaData -import logging def ceilo2nc(full_path: str, @@ -75,14 +75,14 @@ def ceilo2nc(full_path: str, def _initialize_ceilo(full_path: str, - date: Optional[str] = None) -> Union[ClCeilo, Ct25k, LufftCeilo, CL61d]: + date: Optional[str] = None) -> Union[ClCeilo, Ct25k, LufftCeilo, Cl61d]: model = _find_ceilo_model(full_path) if model == 'cl31_or_cl51': return ClCeilo(full_path, date) if model == 'ct25k': return Ct25k(full_path) if model == 'cl61d': - return CL61d(full_path, date) + return Cl61d(full_path, date) return LufftCeilo(full_path, date) @@ -110,7 +110,7 @@ def _find_ceilo_model(full_path: str) -> str: raise RuntimeError('Error: Unknown ceilo model.') -def _append_height(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, CL61d], +def _append_height(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, Cl61d], site_altitude: float) -> None: """Finds height above mean sea level.""" tilt_angle = np.median(ceilo.metadata['tilt_angle']) @@ -120,7 +120,7 @@ def _append_height(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, CL61d], ceilo.data['altitude'] = CloudnetArray(site_altitude, 'altitude') -def _append_data(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, CL61d], +def _append_data(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, Cl61d], beta_variants: tuple, depol_variants: Optional[tuple] = None): """Adds data / metadata as CloudnetArrays to ceilo.data.""" @@ -138,7 +138,7 @@ def _append_data(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, CL61d], ceilo.data[field] = CloudnetArray(np.array(ceilo.metadata[field], dtype=float), field) -def _save_ceilo(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, CL61d], +def _save_ceilo(ceilo: Union[ClCeilo, Ct25k, LufftCeilo, Cl61d], output_file: str, location: str, keep_uuid: bool, diff --git a/cloudnetpy/instruments/ceilometer.py b/cloudnetpy/instruments/ceilometer.py index f65210b6..040e238e 100644 --- a/cloudnetpy/instruments/ceilometer.py +++ b/cloudnetpy/instruments/ceilometer.py @@ -20,6 +20,7 @@ def __init__(self, full_path: str): self.date = [] self.noise_params = (1, 1, 1, (1, 1)) self.calibration_factor = 1 + self.wavelength = None def calc_beta(self) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: """Converts range-corrected raw beta to noise-screened beta.""" @@ -32,11 +33,11 @@ def calc_beta(self) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: def calc_depol(self) -> Tuple[np.ndarray, np.ndarray]: """Converts raw depolarisation to noise-screened depolarisation.""" - snr_limit = 3 + snr_limit = 4 noisy_data = NoisyData(*self._get_args(), snr_limit) + sigma = _calc_sigma_units(self.time, self.range) x_pol = noisy_data.screen_data(self.processed_data['x_pol'], keep_negative=True) depol = x_pol / self.processed_data['p_pol'] - sigma = _calc_sigma_units(self.time, self.range) p_pol_smooth = scipy.ndimage.filters.gaussian_filter(self.processed_data['p_pol'], sigma) x_pol_smooth = scipy.ndimage.filters.gaussian_filter(self.processed_data['x_pol'], sigma) x_pol_smooth = noisy_data.screen_data(x_pol_smooth, is_smoothed=True) diff --git a/cloudnetpy/instruments/lufft.py b/cloudnetpy/instruments/lufft.py index 4576057d..3524ae31 100644 --- a/cloudnetpy/instruments/lufft.py +++ b/cloudnetpy/instruments/lufft.py @@ -14,7 +14,7 @@ def __init__(self, file_name: str, date: Optional[str] = None): self._expected_date = date self.model = 'Lufft CHM15k' self.dataset = netCDF4.Dataset(self.file_name) - self.noise_params = (170, 2e-14, 0.3e-6, (1e-9, 4e-9)) + self.noise_params = (70, 2e-14, 0.3e-6, (1e-9, 4e-9)) self.wavelength = 1064 def read_ceilometer_file(self, calibration_factor: Optional[float] = None) -> None: @@ -82,13 +82,14 @@ def _read_metadata(self) -> dict: return {'tilt_angle': tilt_angle} -class CL61d(LufftCeilo): +class Cl61d(LufftCeilo): """Class for Vaisala CL61d ceilometer.""" def __init__(self, file_name: str, date: Optional[str] = None): super().__init__(file_name) self._expected_date = date self.model = 'Vaisala CL61d' self.wavelength = 910.55 + self.noise_params = (100, 2e-14, 0.3e-6, (1e-9, 4e-9)) def read_ceilometer_file(self, calibration_factor: Optional[float] = None) -> None: """Reads data and metadata from concatenated Vaisala CL61d netCDF file.""" @@ -109,16 +110,15 @@ def _calc_range(self) -> np.ndarray: def _read_date(self) -> List[str]: if self._expected_date: return self._expected_date.split('-') - else: - time = self.dataset.variables['time'][:] - date_first = utils.seconds2date(time[0], epoch=(1970, 1, 1)) - date_last = utils.seconds2date(time[-1], epoch=(1970, 1, 1)) - date_middle = utils.seconds2date(time[round(len(time)/2)], epoch=(1970, 1, 1)) - if date_first != date_last: - logging.warning('No expected date given and different dates in CL61d timestamps.') - return date_middle[:3] - - def _calibrate_backscatter(self, calibration_factor: Union[float, None]) -> np.ndarray: + time = self.dataset.variables['time'][:] + date_first = utils.seconds2date(time[0], epoch=(1970, 1, 1)) + date_last = utils.seconds2date(time[-1], epoch=(1970, 1, 1)) + date_middle = utils.seconds2date(time[round(len(time)/2)], epoch=(1970, 1, 1)) + if date_first != date_last: + logging.warning('No expected date given and different dates in CL61d timestamps.') + return date_middle[:3] + + def _calibrate_backscatter(self, calibration_factor: Optional[float] = None) -> np.ndarray: beta_raw = self._getvar('beta_att') if calibration_factor is None: logging.warning('Using default calibration factor')