ceilopyter 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/CHANGELOG.md +6 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/PKG-INFO +6 -2
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/ceilo.py +8 -2
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/ceilo_raw.py +19 -8
- ceilopyter-0.2.2/ceilopyter/cli.py +164 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/chm15k.py +56 -19
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/cl31.py +1 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/cl51.py +1 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/cl61.py +1 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/cs135.py +1 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/ct25k.py +10 -2
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/instruments/ld40.py +9 -2
- ceilopyter-0.2.2/ceilopyter/noise.py +145 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/readers/read_cl.py +1 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/utils.py +51 -0
- ceilopyter-0.2.2/ceilopyter/version.py +1 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/pyproject.toml +5 -2
- ceilopyter-0.2.2/tests/test_utils.py +29 -0
- ceilopyter-0.2.1/ceilopyter/noise.py +0 -22
- ceilopyter-0.2.1/ceilopyter/version.py +0 -1
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/.github/workflows/publish.yml +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/.github/workflows/test.yml +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/.gitignore +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/.pre-commit-config.yaml +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/LICENSE +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/README.md +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/__init__.py +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/common.py +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/py.typed +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/readers/read_cs.py +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/ceilopyter/readers/read_ct.py +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/data/celio_chennai_2025-03-11.dat +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/data/kauniainen_cl31.dat +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/data/kenttarova_cl31_msg.dat +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/data/palaiseau_cl31_msg.dat +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/data/uto_cl31_msg.dat +0 -0
- {ceilopyter-0.2.1 → ceilopyter-0.2.2}/tests/test_cl.py +0 -0
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 0.2.2 – 2026-10-01
|
|
9
|
+
|
|
10
|
+
- Improve CHM 15k processing
|
|
11
|
+
- Support timestamp format in Kolsass
|
|
12
|
+
- Add command-line interface
|
|
13
|
+
|
|
8
14
|
## 0.2.1 – 2026-04-14
|
|
9
15
|
|
|
10
16
|
- Fix checksum calculation for CL31 messages
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: ceilopyter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Read ceilometer data
|
|
5
5
|
Project-URL: Homepage, https://github.com/actris-cloudnet/ceilopyter
|
|
6
6
|
Project-URL: Issues, https://github.com/actris-cloudnet/ceilopyter/issues
|
|
@@ -13,11 +13,15 @@ Classifier: Operating System :: OS Independent
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
14
|
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: cloudnet-api-client
|
|
17
|
+
Requires-Dist: matplotlib
|
|
16
18
|
Requires-Dist: netcdf4
|
|
17
19
|
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: scipy
|
|
18
21
|
Provides-Extra: dev
|
|
19
22
|
Requires-Dist: pre-commit; extra == 'dev'
|
|
20
23
|
Requires-Dist: release-version; extra == 'dev'
|
|
24
|
+
Requires-Dist: scipy-stubs; extra == 'dev'
|
|
21
25
|
Provides-Extra: test
|
|
22
26
|
Requires-Dist: mypy; extra == 'test'
|
|
23
27
|
Requires-Dist: pytest; extra == 'test'
|
|
@@ -5,28 +5,34 @@ from .ceilo_raw import CeiloRaw
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class Ceilo:
|
|
8
|
-
"""
|
|
8
|
+
"""Ceilometer data.
|
|
9
9
|
|
|
10
10
|
Attributes:
|
|
11
11
|
time: Time
|
|
12
12
|
range: Range (m)
|
|
13
13
|
beta_raw: Non-screened range-corrected backscatter coefficient (sr-1 m-1)
|
|
14
14
|
beta: Screened range-corrected backscatter coefficient (sr-1 m-1)
|
|
15
|
+
beta_smooth: Screened range-corrected smoothed backscatter coefficient
|
|
16
|
+
(sr-1 m-1)
|
|
15
17
|
wavelength: Wavelength (nm)
|
|
16
18
|
zenith_angle: Zenith angle (deg)
|
|
19
|
+
serial_number: Instrument serial number
|
|
17
20
|
"""
|
|
18
21
|
|
|
19
22
|
def __init__(
|
|
20
23
|
self,
|
|
21
24
|
raw: CeiloRaw,
|
|
22
25
|
beta_raw: npt.NDArray[np.floating],
|
|
23
|
-
beta: npt.NDArray[np.floating] | None,
|
|
24
26
|
calibration_factor: float,
|
|
27
|
+
beta: npt.NDArray[np.floating] | None = None,
|
|
28
|
+
beta_smooth: npt.NDArray[np.floating] | None = None,
|
|
25
29
|
):
|
|
26
30
|
self.time = raw.time
|
|
27
31
|
self.range = raw.range
|
|
28
32
|
self.beta = beta
|
|
29
33
|
self.beta_raw = beta_raw
|
|
34
|
+
self.beta_smooth = beta_smooth
|
|
30
35
|
self.calibration_factor = calibration_factor
|
|
31
36
|
self.wavelength = raw.wavelength
|
|
32
37
|
self.zenith_angle = raw.zenith_angle
|
|
38
|
+
self.serial_number = raw.serial_number
|
|
@@ -21,12 +21,14 @@ class CeiloRaw:
|
|
|
21
21
|
beta: npt.NDArray[np.floating],
|
|
22
22
|
wavelength: float,
|
|
23
23
|
zenith_angle: npt.NDArray[np.floating] | None = None,
|
|
24
|
+
serial_number: str | None = None,
|
|
24
25
|
):
|
|
25
26
|
self.time = time
|
|
26
27
|
self.range = range
|
|
27
28
|
self.beta = beta
|
|
28
29
|
self.wavelength = wavelength
|
|
29
30
|
self.zenith_angle = zenith_angle
|
|
31
|
+
self.serial_number = serial_number
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
def concatenate_raw(raw: list[CeiloRaw]) -> CeiloRaw:
|
|
@@ -35,25 +37,33 @@ def concatenate_raw(raw: list[CeiloRaw]) -> CeiloRaw:
|
|
|
35
37
|
if len(raw) == 1:
|
|
36
38
|
return raw[0]
|
|
37
39
|
|
|
40
|
+
serial_number = raw[0].serial_number
|
|
41
|
+
if any(r.serial_number != serial_number for r in raw):
|
|
42
|
+
raise ValueError("Inconsistent serial number")
|
|
43
|
+
|
|
44
|
+
wavelength = raw[0].wavelength
|
|
45
|
+
if any(r.wavelength != wavelength for r in raw):
|
|
46
|
+
raise ValueError("Inconsistent wavelength")
|
|
47
|
+
|
|
38
48
|
all_time = np.concatenate([r.time for r in raw])
|
|
39
|
-
|
|
49
|
+
n_time = len(all_time)
|
|
50
|
+
|
|
51
|
+
uniq_time, time_ind = np.unique(all_time, return_index=True)
|
|
40
52
|
all_zenith_angle = (
|
|
41
53
|
None
|
|
42
54
|
if all(r.zenith_angle is None for r in raw)
|
|
43
|
-
else np.concatenate(
|
|
55
|
+
else np.concatenate(
|
|
56
|
+
[np.broadcast_to(r.zenith_angle, len(r.time)) for r in raw] # type: ignore[arg-type]
|
|
57
|
+
)[time_ind]
|
|
44
58
|
)
|
|
45
59
|
|
|
46
|
-
wavelength = raw[0].wavelength
|
|
47
|
-
if any(r.wavelength != wavelength for r in raw):
|
|
48
|
-
raise ValueError("Inconsistent wavelength")
|
|
49
|
-
|
|
50
60
|
all_rngs = [r.range for r in raw]
|
|
51
61
|
max_rng = max(all_rngs, key=len)
|
|
52
62
|
for rng in all_rngs:
|
|
53
63
|
if not np.array_equal(rng, max_rng[: len(rng)]):
|
|
54
64
|
raise ValueError("Inconsistent ranges")
|
|
55
65
|
|
|
56
|
-
all_beta = ma.masked_all((
|
|
66
|
+
all_beta = ma.masked_all((n_time, len(max_rng)))
|
|
57
67
|
i = 0
|
|
58
68
|
for r in raw:
|
|
59
69
|
all_beta[i : i + len(r.time), : len(r.range)] = r.beta
|
|
@@ -61,9 +71,10 @@ def concatenate_raw(raw: list[CeiloRaw]) -> CeiloRaw:
|
|
|
61
71
|
all_beta = all_beta[time_ind]
|
|
62
72
|
|
|
63
73
|
return CeiloRaw(
|
|
64
|
-
|
|
74
|
+
uniq_time,
|
|
65
75
|
max_rng,
|
|
66
76
|
all_beta,
|
|
67
77
|
wavelength,
|
|
68
78
|
all_zenith_angle,
|
|
79
|
+
serial_number,
|
|
69
80
|
)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import datetime
|
|
3
|
+
import gzip
|
|
4
|
+
import logging
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
import numpy as np
|
|
10
|
+
from cloudnet_api_client import APIClient
|
|
11
|
+
from numpy import ma
|
|
12
|
+
|
|
13
|
+
from ceilopyter import (
|
|
14
|
+
read_chm15k,
|
|
15
|
+
read_cl31,
|
|
16
|
+
read_cl51,
|
|
17
|
+
read_cl61,
|
|
18
|
+
read_cs135,
|
|
19
|
+
read_ct25k,
|
|
20
|
+
read_ld40,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def make_edges(centers):
|
|
25
|
+
edges = np.empty(len(centers) + 1)
|
|
26
|
+
edges[0] = centers[0] - (centers[1] - centers[0]) / 2
|
|
27
|
+
edges[1:-1] = (centers[:-1] + centers[1:]) / 2
|
|
28
|
+
edges[-1] = centers[-1] + (centers[-1] - centers[-2]) / 2
|
|
29
|
+
return edges
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main():
|
|
33
|
+
parser = argparse.ArgumentParser()
|
|
34
|
+
parser.add_argument("-f", "--files", type=Path, nargs="+", help="path to raw data")
|
|
35
|
+
parser.add_argument("-s", "--site", help="Cloudnet site identifier (e.g. hyytiala)")
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"-d",
|
|
38
|
+
"--date",
|
|
39
|
+
type=datetime.date.fromisoformat,
|
|
40
|
+
help="measurement date (YYYY-MM-DD)",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"-i",
|
|
44
|
+
"--instrument",
|
|
45
|
+
choices=[
|
|
46
|
+
"ld40",
|
|
47
|
+
"ct25k",
|
|
48
|
+
"cl31",
|
|
49
|
+
"cl51",
|
|
50
|
+
"cl61d",
|
|
51
|
+
"cs135",
|
|
52
|
+
"chm15k",
|
|
53
|
+
"chm15kx",
|
|
54
|
+
],
|
|
55
|
+
required=True,
|
|
56
|
+
help="instrument identifier",
|
|
57
|
+
)
|
|
58
|
+
parser.add_argument(
|
|
59
|
+
"--noise-h2",
|
|
60
|
+
choices=["on", "off"],
|
|
61
|
+
default="on",
|
|
62
|
+
help="noise range correction (ct25k, cl31, cl51)",
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--calibration-factor", type=float, help="instrument calibration factor"
|
|
66
|
+
)
|
|
67
|
+
args = parser.parse_args()
|
|
68
|
+
|
|
69
|
+
if args.files and (args.site or args.date):
|
|
70
|
+
parser.error("cannot use --files with --site and --date")
|
|
71
|
+
elif args.files:
|
|
72
|
+
file_paths = args.files
|
|
73
|
+
elif args.site and args.date:
|
|
74
|
+
client = APIClient()
|
|
75
|
+
raw_dir = "data_raw/"
|
|
76
|
+
raw_metadata = client.raw_files(
|
|
77
|
+
site_id=args.site,
|
|
78
|
+
date=args.date,
|
|
79
|
+
instrument_id=args.instrument,
|
|
80
|
+
status=["uploaded", "processed"],
|
|
81
|
+
)
|
|
82
|
+
instrument_pids = sorted({r.instrument.pid for r in raw_metadata})
|
|
83
|
+
if len(instrument_pids) > 1:
|
|
84
|
+
logging.warning("Multiple instruments found, using %s", instrument_pids[0])
|
|
85
|
+
raw_metadata = [
|
|
86
|
+
r for r in raw_metadata if r.instrument.pid == instrument_pids[0]
|
|
87
|
+
]
|
|
88
|
+
file_paths = client.download(raw_metadata, raw_dir)
|
|
89
|
+
else:
|
|
90
|
+
parser.error("use --files or --site and --date")
|
|
91
|
+
|
|
92
|
+
file_paths2 = []
|
|
93
|
+
for path_in in file_paths:
|
|
94
|
+
if path_in.suffix.lower() == ".gz":
|
|
95
|
+
path_out = path_in.parent / path_in.stem
|
|
96
|
+
print(f"Decompressing {path_in} to {path_out}")
|
|
97
|
+
with gzip.open(path_in, "rb") as file_in, open(path_out, "wb") as file_out:
|
|
98
|
+
shutil.copyfileobj(file_in, file_out)
|
|
99
|
+
file_paths2.append(path_out)
|
|
100
|
+
else:
|
|
101
|
+
file_paths2.append(path_in)
|
|
102
|
+
|
|
103
|
+
if args.instrument == "ct25k":
|
|
104
|
+
ceilo = read_ct25k(file_paths2, args.calibration_factor, args.noise_h2 == "on")
|
|
105
|
+
elif args.instrument == "cl31":
|
|
106
|
+
ceilo = read_cl31(file_paths2, args.calibration_factor)
|
|
107
|
+
elif args.instrument == "cl51":
|
|
108
|
+
ceilo = read_cl51(file_paths2, args.calibration_factor)
|
|
109
|
+
elif args.instrument in ("chm15k", "chm15kx"):
|
|
110
|
+
ceilo = read_chm15k(file_paths2, args.calibration_factor)
|
|
111
|
+
elif args.instrument == "cl61d":
|
|
112
|
+
ceilo = read_cl61(file_paths2, args.calibration_factor)
|
|
113
|
+
elif args.instrument == "cs135":
|
|
114
|
+
ceilo = read_cs135(file_paths2, args.calibration_factor)
|
|
115
|
+
elif args.instrument == "ld40":
|
|
116
|
+
ceilo = read_ld40(file_paths2, args.calibration_factor)
|
|
117
|
+
else:
|
|
118
|
+
raise NotImplementedError
|
|
119
|
+
|
|
120
|
+
vmin = 1e-7
|
|
121
|
+
vmax = 1e-4
|
|
122
|
+
plt_beta_raw = ma.log10(np.maximum(vmin, ceilo.beta_raw))
|
|
123
|
+
plt_beta = (
|
|
124
|
+
ma.log10(np.maximum(vmin, ceilo.beta)) if ceilo.beta is not None else None
|
|
125
|
+
)
|
|
126
|
+
plt_time = make_edges(np.arange(len(ceilo.time)))
|
|
127
|
+
range_km = ceilo.range / 1000
|
|
128
|
+
plt_rng = make_edges(range_km)
|
|
129
|
+
|
|
130
|
+
fig, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=True, figsize=(15, 5))
|
|
131
|
+
ax1.set_title("beta_raw")
|
|
132
|
+
ax1.set_ylabel("Range (km)")
|
|
133
|
+
ax1.pcolorfast(
|
|
134
|
+
plt_time, plt_rng, plt_beta_raw.T, vmin=np.log10(vmin), vmax=np.log10(vmax)
|
|
135
|
+
)
|
|
136
|
+
ax2.set_title("beta")
|
|
137
|
+
ax2.set_ylabel("Range (km)")
|
|
138
|
+
ax2.set_xlabel("Time index")
|
|
139
|
+
if plt_beta is not None:
|
|
140
|
+
ax2.pcolorfast(
|
|
141
|
+
plt_time, plt_rng, plt_beta.T, vmin=np.log10(vmin), vmax=np.log10(vmax)
|
|
142
|
+
)
|
|
143
|
+
plt.tight_layout()
|
|
144
|
+
|
|
145
|
+
def onclick(event):
|
|
146
|
+
if fig.canvas.manager.toolbar.mode:
|
|
147
|
+
return
|
|
148
|
+
i = round(event.xdata)
|
|
149
|
+
|
|
150
|
+
fig2, axs = plt.subplots(1, 2, sharey=True)
|
|
151
|
+
axs[0].set_title(f"beta_raw i={i}")
|
|
152
|
+
axs[0].plot(ceilo.beta_raw[i], range_km)
|
|
153
|
+
axs[0].set_ylabel("Range (km)")
|
|
154
|
+
axs[1].set_title(f"beta_uncorr i={i}")
|
|
155
|
+
axs[1].plot(ceilo.beta_raw[i] / range_km**2, range_km)
|
|
156
|
+
plt.show()
|
|
157
|
+
|
|
158
|
+
fig.canvas.mpl_connect("button_press_event", onclick)
|
|
159
|
+
|
|
160
|
+
plt.show()
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if __name__ == "__main__":
|
|
164
|
+
main()
|
|
@@ -7,6 +7,9 @@ import numpy.typing as npt
|
|
|
7
7
|
from cftime import num2pydate
|
|
8
8
|
from numpy import ma
|
|
9
9
|
|
|
10
|
+
from ceilopyter.noise import remove_noise
|
|
11
|
+
from ceilopyter.utils import awful_overlap
|
|
12
|
+
|
|
10
13
|
from ..ceilo import Ceilo
|
|
11
14
|
from ..ceilo_raw import CeiloRaw, concatenate_raw
|
|
12
15
|
|
|
@@ -25,17 +28,41 @@ def read_chm15k(
|
|
|
25
28
|
raw.append(_read_file(file))
|
|
26
29
|
concat = concatenate_raw(raw)
|
|
27
30
|
beta_raw = concat.beta * calibration_factor
|
|
28
|
-
|
|
31
|
+
|
|
32
|
+
beta_uncorr = beta_raw / (concat.range * 1e-3) ** 2
|
|
33
|
+
is_noise, beta_smooth = remove_noise(
|
|
34
|
+
concat.time,
|
|
35
|
+
concat.range,
|
|
36
|
+
beta_uncorr,
|
|
37
|
+
noise_floor=4e-9,
|
|
38
|
+
filter_above_negative=True,
|
|
39
|
+
)
|
|
40
|
+
beta = ma.masked_where(is_noise, beta_raw)
|
|
41
|
+
|
|
42
|
+
return Ceilo(
|
|
43
|
+
concat,
|
|
44
|
+
beta_raw=beta_raw,
|
|
45
|
+
beta=beta,
|
|
46
|
+
beta_smooth=beta_smooth,
|
|
47
|
+
calibration_factor=calibration_factor,
|
|
48
|
+
)
|
|
29
49
|
|
|
30
50
|
|
|
31
51
|
def _read_file(file: str | PathLike) -> CeiloRaw:
|
|
32
52
|
with netCDF4.Dataset(file) as nc:
|
|
33
53
|
time = num2pydate(nc["time"][:], nc["time"].units)
|
|
34
|
-
range = nc
|
|
54
|
+
range = _get_range(nc)
|
|
35
55
|
beta = _get_beta(nc)
|
|
36
56
|
wavelength = nc["wavelength"][:]
|
|
37
|
-
zenith_angle = nc["zenith"][:]
|
|
38
|
-
|
|
57
|
+
zenith_angle = nc["zenith"][:] if "zenith" in nc.variables else None
|
|
58
|
+
serial_number = nc.source
|
|
59
|
+
return CeiloRaw(time, range, beta, wavelength, zenith_angle, serial_number)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _get_range(nc: netCDF4.Dataset):
|
|
63
|
+
rng = nc["range"][:]
|
|
64
|
+
res = rng[1] - rng[0]
|
|
65
|
+
return rng - res / 2
|
|
39
66
|
|
|
40
67
|
|
|
41
68
|
def _get_beta(nc: netCDF4.Dataset) -> npt.NDArray[np.floating]:
|
|
@@ -53,37 +80,45 @@ def _get_beta(nc: netCDF4.Dataset) -> npt.NDArray[np.floating]:
|
|
|
53
80
|
# When netcdf_mode is 2 (or unspecified in old files), we have beta_raw
|
|
54
81
|
# without calibration factor applied. This mode is recommended in ACTRIS
|
|
55
82
|
# CCRES ALC SOP.
|
|
83
|
+
# beta = ((P_raw / lp) - b) / (cs * o(r) * p_calc) * r * r
|
|
56
84
|
beta = nc["beta_raw"][:]
|
|
57
85
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
sw_version = _get_sw_version(nc)
|
|
87
|
+
if isinstance(sw_version, np.integer) and sw_version <= 135:
|
|
88
|
+
# beta_raw = P_raw
|
|
89
|
+
laser_pulses = nc["laser_pulses"][:]
|
|
90
|
+
base = np.mean(beta[:, -5:], axis=1) / laser_pulses
|
|
91
|
+
rng = nc["range"][:]
|
|
92
|
+
overlap = awful_overlap(rng, 200, 800)
|
|
93
|
+
signal = beta / laser_pulses[:, np.newaxis] - base[:, np.newaxis]
|
|
94
|
+
beta = signal / overlap * rng**2
|
|
95
|
+
elif isinstance(sw_version, np.integer) or sw_version < "0.702":
|
|
96
|
+
# beta_raw = (P_raw / laser_pulses - base) / stddev
|
|
97
|
+
apd = _get_nn(nc)
|
|
62
98
|
rng = nc["range"][:]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
beta
|
|
66
|
-
beta
|
|
99
|
+
overlap = awful_overlap(rng, 200, 800)
|
|
100
|
+
stddev = nc["stddev"][:]
|
|
101
|
+
signal = beta * stddev[:, np.newaxis]
|
|
102
|
+
beta = signal / (overlap * apd[:, np.newaxis]) * rng**2
|
|
67
103
|
|
|
68
104
|
return beta
|
|
69
105
|
|
|
70
106
|
|
|
71
|
-
def
|
|
107
|
+
def _get_sw_version(nc: netCDF4.Dataset) -> np.integer | str:
|
|
72
108
|
version = nc.software_version
|
|
73
109
|
# In old files, the version is a single integer.
|
|
74
110
|
if isinstance(version, np.integer):
|
|
75
|
-
return
|
|
111
|
+
return version
|
|
76
112
|
# In newer files, the version is a space-separated list: Operating system,
|
|
77
113
|
# FPGA, firmware, CloudDetectionMode (added in firmware version 0.747).
|
|
78
114
|
if isinstance(version, str):
|
|
79
115
|
parts = version.split()
|
|
80
|
-
|
|
81
|
-
return firmware < "0.702"
|
|
116
|
+
return parts[2]
|
|
82
117
|
msg = f"Cannot determine version: {version}"
|
|
83
118
|
raise ValueError(msg)
|
|
84
119
|
|
|
85
120
|
|
|
86
|
-
def _get_nn(nc: netCDF4.Dataset) ->
|
|
121
|
+
def _get_nn(nc: netCDF4.Dataset) -> npt.NDArray[np.floating]:
|
|
87
122
|
"""Correct for changing avalanche photodiode (APD) voltage.
|
|
88
123
|
|
|
89
124
|
References:
|
|
@@ -96,7 +131,9 @@ def _get_nn(nc: netCDF4.Dataset) -> float:
|
|
|
96
131
|
nn1 = nc["NN1"][:]
|
|
97
132
|
else:
|
|
98
133
|
logging.warning("Unable to compute normalized APD: variable nn1 not found")
|
|
99
|
-
return 1
|
|
134
|
+
return np.repeat(1, len(nc["time"]))
|
|
135
|
+
if len(nn1) <= 1 or nn1[1] is ma.masked or nn1[1] == 0:
|
|
136
|
+
return np.repeat(1, len(nc["time"]))
|
|
100
137
|
median_nn1 = ma.median(nn1)
|
|
101
138
|
# Parameters taken from the MATLAB implementation of Cloudnet.
|
|
102
139
|
if 120 < median_nn1 < 160:
|
|
@@ -109,5 +146,5 @@ def _get_nn(nc: netCDF4.Dataset) -> float:
|
|
|
109
146
|
"median nn1 (%s) outside of expected range",
|
|
110
147
|
median_nn1,
|
|
111
148
|
)
|
|
112
|
-
return 1
|
|
149
|
+
return np.repeat(1, len(nc["time"]))
|
|
113
150
|
return step_factor ** (-(nn1 - reference) / scale)
|
|
@@ -17,4 +17,4 @@ def read_cl31(
|
|
|
17
17
|
raw = read_msgs(files, read_cl_file, wavelength=910.0)
|
|
18
18
|
concat = concatenate_raw(raw)
|
|
19
19
|
beta_raw = concat.beta * calibration_factor
|
|
20
|
-
return Ceilo(concat, beta_raw,
|
|
20
|
+
return Ceilo(concat, beta_raw=beta_raw, calibration_factor=calibration_factor)
|
|
@@ -17,4 +17,4 @@ def read_cl51(
|
|
|
17
17
|
raw = read_msgs(files, read_cl_file, wavelength=910.0)
|
|
18
18
|
concat = concatenate_raw(raw)
|
|
19
19
|
beta_raw = concat.beta * calibration_factor
|
|
20
|
-
return Ceilo(concat, beta_raw,
|
|
20
|
+
return Ceilo(concat, beta_raw=beta_raw, calibration_factor=calibration_factor)
|
|
@@ -23,7 +23,7 @@ def read_cl61(
|
|
|
23
23
|
raw = [_read_file(files)]
|
|
24
24
|
concat = concatenate_raw(raw)
|
|
25
25
|
beta_raw = concat.beta * calibration_factor
|
|
26
|
-
return Ceilo(concat, beta_raw,
|
|
26
|
+
return Ceilo(concat, beta_raw=beta_raw, calibration_factor=calibration_factor)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def _read_file(file: str | PathLike) -> CeiloRaw:
|
|
@@ -18,4 +18,4 @@ def read_cs135(
|
|
|
18
18
|
raw = read_msgs(files, read_cs_file, wavelength=905.0)
|
|
19
19
|
concat = concatenate_raw(raw)
|
|
20
20
|
beta_raw = concat.beta * calibration_factor
|
|
21
|
-
return Ceilo(concat, beta_raw,
|
|
21
|
+
return Ceilo(concat, beta_raw=beta_raw, calibration_factor=calibration_factor)
|
|
@@ -28,11 +28,19 @@ def read_ct25k(
|
|
|
28
28
|
beta_calib = concat.beta * calibration_factor
|
|
29
29
|
beta_uncorr = beta_calib / r2 if noise_h2 else _fix_beta(r2, beta_calib)
|
|
30
30
|
|
|
31
|
-
is_noise = remove_noise(
|
|
31
|
+
is_noise, beta_smooth = remove_noise(
|
|
32
|
+
concat.time, concat.range, beta_uncorr, noise_floor=6e-8
|
|
33
|
+
)
|
|
32
34
|
beta_raw = beta_uncorr * r2
|
|
33
35
|
beta = ma.masked_where(is_noise, beta_raw)
|
|
34
36
|
|
|
35
|
-
return Ceilo(
|
|
37
|
+
return Ceilo(
|
|
38
|
+
concat,
|
|
39
|
+
beta_raw=beta_raw,
|
|
40
|
+
beta=beta,
|
|
41
|
+
beta_smooth=beta_smooth,
|
|
42
|
+
calibration_factor=calibration_factor,
|
|
43
|
+
)
|
|
36
44
|
|
|
37
45
|
|
|
38
46
|
def _fix_beta(
|
|
@@ -3,6 +3,9 @@ import logging
|
|
|
3
3
|
from os import PathLike
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
|
+
from numpy import ma
|
|
7
|
+
|
|
8
|
+
from ceilopyter.utils import awful_overlap
|
|
6
9
|
|
|
7
10
|
from ..ceilo import Ceilo
|
|
8
11
|
from ..ceilo_raw import CeiloRaw, concatenate_raw
|
|
@@ -23,7 +26,7 @@ def read_ld40(
|
|
|
23
26
|
raw.append(_read_file(file))
|
|
24
27
|
concat = concatenate_raw(raw)
|
|
25
28
|
beta_raw = concat.beta * calibration_factor
|
|
26
|
-
return Ceilo(concat, beta_raw,
|
|
29
|
+
return Ceilo(concat, beta_raw=beta_raw, calibration_factor=calibration_factor)
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
def _read_file(filename: str | PathLike) -> CeiloRaw:
|
|
@@ -49,6 +52,10 @@ def _read_file(filename: str | PathLike) -> CeiloRaw:
|
|
|
49
52
|
)
|
|
50
53
|
)
|
|
51
54
|
betas.append(np.array([int(v) for v in values[2:]]))
|
|
55
|
+
res = rng[1] - rng[0]
|
|
56
|
+
rng = rng + res / 2
|
|
52
57
|
time = np.array(times)
|
|
53
|
-
|
|
58
|
+
overlap = awful_overlap(rng, 100, 200)
|
|
59
|
+
beta = np.array(betas)
|
|
60
|
+
beta = ma.divide(beta, overlap) * rng**2 * 1e-12
|
|
54
61
|
return CeiloRaw(time, rng, beta, 855)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import numpy.typing as npt
|
|
6
|
+
from numpy import ma
|
|
7
|
+
from numpy.lib.stride_tricks import sliding_window_view
|
|
8
|
+
from scipy.ndimage import gaussian_filter
|
|
9
|
+
|
|
10
|
+
from ceilopyter import utils
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def remove_noise(
|
|
14
|
+
time: npt.NDArray,
|
|
15
|
+
rng: npt.NDArray[np.floating],
|
|
16
|
+
beta_uncorr: npt.NDArray[np.floating],
|
|
17
|
+
noise_floor: float,
|
|
18
|
+
snr_limit: float = 5,
|
|
19
|
+
filter_above_negative: bool = False,
|
|
20
|
+
) -> tuple[npt.NDArray[np.bool_], npt.NDArray[np.floating]]:
|
|
21
|
+
n_range = len(rng)
|
|
22
|
+
zero_ranges = np.all(beta_uncorr == 0, axis=0)
|
|
23
|
+
n_zeros = np.argmax(~zero_ranges[::-1])
|
|
24
|
+
|
|
25
|
+
is_negative = beta_uncorr < 0
|
|
26
|
+
|
|
27
|
+
if filter_above_negative:
|
|
28
|
+
is_above_negative = _mask_low_values_above_consequent_negatives(beta_uncorr)
|
|
29
|
+
beta_uncorr = np.where(is_above_negative, noise_floor, beta_uncorr)
|
|
30
|
+
|
|
31
|
+
smooth, smooth_uncorr = _calc_beta_smooth(time, rng, beta_uncorr)
|
|
32
|
+
cloud_mask = _calc_cloud_mask(time, rng, beta_uncorr)
|
|
33
|
+
|
|
34
|
+
fraction = 0.1
|
|
35
|
+
n_top_gates = round(n_range * fraction)
|
|
36
|
+
beta_top = ma.masked_where(cloud_mask, smooth_uncorr)
|
|
37
|
+
beta_top = beta_top[:, n_range - n_zeros - n_top_gates : n_range - n_zeros]
|
|
38
|
+
noise = ma.std(beta_top, axis=1)
|
|
39
|
+
noise = utils.interpolate_masked(noise)
|
|
40
|
+
noise = np.maximum(noise, noise_floor)
|
|
41
|
+
snr = smooth_uncorr / noise[:, np.newaxis]
|
|
42
|
+
is_noise = snr < snr_limit
|
|
43
|
+
|
|
44
|
+
return is_noise | is_negative, smooth
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _calc_beta_smooth(
|
|
48
|
+
time: npt.NDArray[np.floating],
|
|
49
|
+
rng: npt.NDArray[np.floating],
|
|
50
|
+
beta_uncorr: npt.NDArray[np.floating],
|
|
51
|
+
) -> tuple[npt.NDArray[np.floating], npt.NDArray[np.floating]]:
|
|
52
|
+
cloud_mask, cloud_values, cloud_limit = _calc_naive_cloud_mask(beta_uncorr)
|
|
53
|
+
|
|
54
|
+
beta_uncorr = np.where(cloud_mask, cloud_limit, beta_uncorr)
|
|
55
|
+
sigma = _calc_sigma_units(time, rng)
|
|
56
|
+
smooth_uncorr = gaussian_filter(beta_uncorr, sigma)
|
|
57
|
+
smooth_uncorr[cloud_mask] = cloud_values
|
|
58
|
+
|
|
59
|
+
smooth = smooth_uncorr * (rng * 1e-3) ** 2
|
|
60
|
+
return smooth, smooth_uncorr
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _calc_sigma_units(
|
|
64
|
+
time: npt.NDArray,
|
|
65
|
+
rng: npt.NDArray[np.floating],
|
|
66
|
+
sigma_minutes: float = 1,
|
|
67
|
+
sigma_meters: float = 10,
|
|
68
|
+
) -> tuple[float, float]:
|
|
69
|
+
"""Calculates Gaussian peak std parameters.
|
|
70
|
+
|
|
71
|
+
The amount of smoothing is hard coded. This function calculates how many
|
|
72
|
+
steps in time and height corresponds to this smoothing.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
time: Time.
|
|
76
|
+
rng: Range (m).
|
|
77
|
+
sigma_minutes: Smoothing in minutes.
|
|
78
|
+
sigma_meters: Smoothing in meters.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
tuple: Two element tuple containing number of steps in time and height
|
|
82
|
+
to achieve wanted smoothing.
|
|
83
|
+
"""
|
|
84
|
+
time_step = ma.median(np.diff(time))
|
|
85
|
+
alt_step = ma.median(np.diff(rng))
|
|
86
|
+
x_std = datetime.timedelta(minutes=sigma_minutes) / time_step
|
|
87
|
+
y_std = sigma_meters / alt_step
|
|
88
|
+
return x_std, y_std
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _calc_cloud_mask(
|
|
92
|
+
time: npt.NDArray,
|
|
93
|
+
rng: npt.NDArray[np.floating],
|
|
94
|
+
beta_uncorr: npt.NDArray[np.floating],
|
|
95
|
+
) -> npt.NDArray[np.bool]:
|
|
96
|
+
"""Find clouds using mean and standard deviation.
|
|
97
|
+
|
|
98
|
+
References:
|
|
99
|
+
Kotthaus et al. (2016): Recommendations for processing atmospheric
|
|
100
|
+
attenuated backscatter profiles from Vaisala CL31 ceilometers, Atmos.
|
|
101
|
+
Meas. Tech., 9, 3769–3791, https://doi.org/10.5194/amt-9-3769-2016
|
|
102
|
+
"""
|
|
103
|
+
x_std, y_std = _calc_sigma_units(time, rng, 1, 100)
|
|
104
|
+
x_std = max(3, _ceil_odd(x_std))
|
|
105
|
+
y_std = max(3, _ceil_odd(y_std))
|
|
106
|
+
beta_uncorr_pad = np.pad(
|
|
107
|
+
beta_uncorr, ((x_std // 2, x_std // 2), (y_std // 2, y_std // 2)), "reflect"
|
|
108
|
+
)
|
|
109
|
+
windows = sliding_window_view(beta_uncorr_pad, (x_std, y_std))
|
|
110
|
+
rolling_mean = np.mean(windows, (-1, -2))
|
|
111
|
+
rolling_std = np.std(windows, (-1, -2))
|
|
112
|
+
rv = ma.divide(rolling_std, rolling_mean) ** 2
|
|
113
|
+
return rv < 1
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _calc_naive_cloud_mask(
|
|
117
|
+
beta_uncorr: npt.NDArray[np.floating],
|
|
118
|
+
) -> tuple[npt.NDArray[np.bool_], npt.NDArray[np.floating], float]:
|
|
119
|
+
"""Naively finds strong clouds from ceilometer backscatter."""
|
|
120
|
+
cloud_limit = 5e-6
|
|
121
|
+
cloud_mask = beta_uncorr > cloud_limit
|
|
122
|
+
return cloud_mask, beta_uncorr[cloud_mask], cloud_limit
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _mask_low_values_above_consequent_negatives(
|
|
126
|
+
beta_uncorr: npt.NDArray,
|
|
127
|
+
n_negatives: int = 5,
|
|
128
|
+
threshold: float = 8e-6,
|
|
129
|
+
n_skip_lowest: int = 5,
|
|
130
|
+
) -> npt.NDArray:
|
|
131
|
+
n_time, n_gates = beta_uncorr.shape
|
|
132
|
+
bottom_n_gates = n_gates // 5
|
|
133
|
+
negative_data = beta_uncorr[:, n_skip_lowest : n_skip_lowest + bottom_n_gates] < 0
|
|
134
|
+
n_consequent_negatives = utils.cumsumr(negative_data, axis=1)
|
|
135
|
+
time_indices, alt_indices = np.where(n_consequent_negatives > n_negatives)
|
|
136
|
+
alt_indices += n_skip_lowest
|
|
137
|
+
is_negative = np.zeros(beta_uncorr.shape, dtype=np.bool_)
|
|
138
|
+
for time_ind, alt_ind in zip(time_indices, alt_indices, strict=True):
|
|
139
|
+
profile = beta_uncorr[time_ind, alt_ind:]
|
|
140
|
+
is_negative[time_ind, alt_ind:][profile < threshold] = True
|
|
141
|
+
return is_negative
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _ceil_odd(x):
|
|
145
|
+
return math.ceil(x) | 1
|
|
@@ -8,7 +8,7 @@ from .. import utils
|
|
|
8
8
|
from ..common import InvalidMessageError, Message, Status
|
|
9
9
|
|
|
10
10
|
FORMATS = [
|
|
11
|
-
utils.date_format_to_regex(rb"
|
|
11
|
+
utils.date_format_to_regex(rb"-?%Y-%m-%d %H:%M:%S\r?\n"),
|
|
12
12
|
utils.date_format_to_regex(rb"%Y-%m-%d %H:%M:%S,"),
|
|
13
13
|
]
|
|
14
14
|
|
|
@@ -5,6 +5,7 @@ from collections.abc import Iterator
|
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
import numpy.typing as npt
|
|
8
|
+
from numpy import ma
|
|
8
9
|
|
|
9
10
|
from ceilopyter.common import InvalidMessageError
|
|
10
11
|
|
|
@@ -88,3 +89,53 @@ def next_line(
|
|
|
88
89
|
msg = f"Expected {length} characters but got {len(line)} instead"
|
|
89
90
|
raise InvalidMessageError(msg)
|
|
90
91
|
return line
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def cumsumr(array: npt.NDArray, axis: int = 0) -> npt.NDArray:
|
|
95
|
+
"""Finds cumulative sum that resets on 0.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
array: Input array.
|
|
99
|
+
axis: Axis where the sum is calculated. Default is 0.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Cumulative sum, restarted at 0.
|
|
103
|
+
|
|
104
|
+
Examples:
|
|
105
|
+
>>> x = np.array([0, 0, 1, 1, 0, 0, 0, 1, 1, 1])
|
|
106
|
+
>>> cumsumr(x)
|
|
107
|
+
[0, 0, 1, 2, 0, 0, 0, 1, 2, 3]
|
|
108
|
+
|
|
109
|
+
"""
|
|
110
|
+
cums = array.cumsum(axis=axis)
|
|
111
|
+
return cums - np.maximum.accumulate(cums * (array == 0), axis=axis)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def interpolate_masked(array: npt.NDArray) -> npt.NDArray:
|
|
115
|
+
out = ma.copy(array)
|
|
116
|
+
m = ma.getmaskarray(array)
|
|
117
|
+
if np.all(m):
|
|
118
|
+
return out
|
|
119
|
+
d = np.diff(np.pad(m.astype(np.int8), 1))
|
|
120
|
+
start = np.nonzero(d == 1)[0]
|
|
121
|
+
end = np.nonzero(d == -1)[0]
|
|
122
|
+
for a, b in zip(start, end, strict=True):
|
|
123
|
+
if a == 0:
|
|
124
|
+
out[: b + 1] = out[b]
|
|
125
|
+
elif b == len(array):
|
|
126
|
+
out[a - 1 :] = out[a - 1]
|
|
127
|
+
else:
|
|
128
|
+
out[a - 1 : b + 1] = np.linspace(out[a - 1], out[b], b - a + 2)
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def awful_overlap(
|
|
133
|
+
rng: npt.NDArray[np.floating], rng_zero: float, rng_one: float
|
|
134
|
+
) -> npt.NDArray[np.floating]:
|
|
135
|
+
n = len(rng)
|
|
136
|
+
i = np.nonzero(rng > rng_zero)[0][0]
|
|
137
|
+
j = np.nonzero(rng > rng_one)[0][0]
|
|
138
|
+
zero = np.zeros(i)
|
|
139
|
+
mids = np.linspace(0, 1, j - i)
|
|
140
|
+
ones = np.ones(n - j)
|
|
141
|
+
return np.concatenate([zero, mids, ones])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.2"
|
|
@@ -18,12 +18,15 @@ classifiers = [
|
|
|
18
18
|
"Programming Language :: Python :: 3",
|
|
19
19
|
"Topic :: Scientific/Engineering :: Atmospheric Science",
|
|
20
20
|
]
|
|
21
|
-
dependencies = ["netCDF4", "numpy"]
|
|
21
|
+
dependencies = ["cloudnet-api-client", "matplotlib", "netCDF4", "numpy", "scipy"]
|
|
22
22
|
dynamic = ["version"]
|
|
23
23
|
|
|
24
24
|
[project.optional-dependencies]
|
|
25
25
|
test = ["mypy", "pytest"]
|
|
26
|
-
dev = ["pre-commit", "release-version"]
|
|
26
|
+
dev = ["pre-commit", "release-version", "scipy-stubs"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
ceilopyter = "ceilopyter.cli:main"
|
|
27
30
|
|
|
28
31
|
[project.urls]
|
|
29
32
|
Homepage = "https://github.com/actris-cloudnet/ceilopyter"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from numpy import ma
|
|
4
|
+
from numpy.testing import assert_array_equal
|
|
5
|
+
|
|
6
|
+
from ceilopyter.utils import interpolate_masked
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.parametrize(
|
|
10
|
+
"array,mask,expected",
|
|
11
|
+
[
|
|
12
|
+
([0.0, 0.0, 3.0], [1, 1, 0], [3.0, 3.0, 3.0]),
|
|
13
|
+
([2.0, 0.0, 0.0], [0, 1, 1], [2.0, 2.0, 2.0]),
|
|
14
|
+
([1.0, 0.0, 3.0], [0, 1, 0], [1.0, 2.0, 3.0]),
|
|
15
|
+
([1.0, 0.0, 3.0, 0.0, 5.0], [0, 1, 0, 1, 0], [1.0, 2.0, 3.0, 4.0, 5.0]),
|
|
16
|
+
([1.0, 0.0, 0.0, 0.0, 3.0], [0, 1, 1, 1, 0], [1.0, 1.5, 2.0, 2.5, 3.0]),
|
|
17
|
+
],
|
|
18
|
+
)
|
|
19
|
+
def test_interpolate_masked(array, mask, expected):
|
|
20
|
+
input = ma.array(array, mask=mask)
|
|
21
|
+
actual = interpolate_masked(input)
|
|
22
|
+
assert not ma.is_masked(actual)
|
|
23
|
+
assert_array_equal(actual, expected)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_interpolate_all_masked():
|
|
27
|
+
array = interpolate_masked(ma.masked_all(5))
|
|
28
|
+
assert len(array) == 5
|
|
29
|
+
assert np.all(array.mask)
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
import numpy.typing as npt
|
|
3
|
-
from numpy import ma
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def remove_noise(
|
|
7
|
-
beta_uncorr: npt.NDArray[np.floating], noise_floor: float, snr_limit: float = 5
|
|
8
|
-
) -> npt.NDArray[np.bool_]:
|
|
9
|
-
zero_ranges = np.all(beta_uncorr == 0, axis=0)
|
|
10
|
-
n_zeros = np.argmax(~zero_ranges[::-1])
|
|
11
|
-
|
|
12
|
-
fraction = 0.1
|
|
13
|
-
n_top_gates = round(beta_uncorr.shape[1] * fraction)
|
|
14
|
-
beta_top = beta_uncorr[:, -n_top_gates - n_zeros : -n_zeros]
|
|
15
|
-
noise = ma.std(beta_top, axis=1)
|
|
16
|
-
|
|
17
|
-
noise = np.maximum(noise, noise_floor)
|
|
18
|
-
snr = beta_uncorr / noise[:, np.newaxis]
|
|
19
|
-
|
|
20
|
-
is_noise = snr < snr_limit
|
|
21
|
-
|
|
22
|
-
return is_noise
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|