Skip to content

Commit

Permalink
Fix based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Sep 14, 2021
1 parent 5d1f307 commit 34df72b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
14 changes: 7 additions & 7 deletions cloudnetpy/instruments/ceilo.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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'])
Expand All @@ -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."""
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions cloudnetpy/instruments/ceilometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions cloudnetpy/instruments/lufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand All @@ -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')
Expand Down

0 comments on commit 34df72b

Please sign in to comment.