|
1 | 1 | import logging |
2 | 2 | from os import PathLike |
3 | 3 |
|
| 4 | +import numpy as np |
| 5 | +import numpy.typing as npt |
| 6 | +from numpy import ma |
| 7 | + |
4 | 8 | from ..ceilo import Ceilo |
| 9 | +from ..ceilo_raw import concatenate_raw |
5 | 10 | from ..common import read_msgs |
| 11 | +from ..noise import remove_noise |
6 | 12 | from ..readers.read_ct import read_ct_file |
7 | 13 |
|
8 | 14 |
|
9 | 15 | def read_ct25k( |
10 | 16 | files: str | PathLike | list[str | PathLike], |
11 | 17 | calibration_factor: float | None = None, |
| 18 | + noise_h2: bool = True, |
12 | 19 | ) -> Ceilo: |
13 | 20 | if calibration_factor is None: |
14 | 21 | calibration_factor = 1.0 |
15 | 22 | logging.warning("Using default calibration factor: %s", calibration_factor) |
16 | | - raw = read_msgs(files, read_ct_file, 905.0) |
17 | | - return Ceilo(raw, calibration_factor) |
| 23 | + |
| 24 | + raw = read_msgs(files, read_ct_file, wavelength=905.0) |
| 25 | + concat = concatenate_raw(raw) |
| 26 | + |
| 27 | + r2 = (concat.range * 1e-3) ** 2 |
| 28 | + beta_calib = concat.beta * calibration_factor |
| 29 | + beta_uncorr = beta_calib / r2 if noise_h2 else _fix_beta(r2, beta_calib) |
| 30 | + |
| 31 | + is_noise = remove_noise(beta_uncorr, noise_floor=6e-8) |
| 32 | + beta_raw = beta_uncorr * r2 |
| 33 | + beta = ma.masked_where(is_noise, beta_raw) |
| 34 | + |
| 35 | + return Ceilo(concat, beta_raw, beta, calibration_factor) |
| 36 | + |
| 37 | + |
| 38 | +def _fix_beta( |
| 39 | + r2: npt.NDArray[np.floating], beta_raw: npt.NDArray[np.floating] |
| 40 | +) -> npt.NDArray[np.floating]: |
| 41 | + range_broad = np.broadcast_to(r2, beta_raw.shape) |
| 42 | + is_strong = beta_raw > 1e-7 |
| 43 | + beta_raw[is_strong] /= range_broad[is_strong] |
| 44 | + return beta_raw |
0 commit comments