-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_galileo.py
115 lines (100 loc) · 3.65 KB
/
test_galileo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from os import path
from tempfile import TemporaryDirectory
import netCDF4
import numpy as np
import pytest
from cloudnetpy.exceptions import ValidTimeStampError
from cloudnetpy.instruments import galileo
from tests.unit.all_products_fun import Check
from tests.unit.radar_fun import RadarFun
SCRIPT_PATH = path.dirname(path.realpath(__file__))
FILEPATH = f"{SCRIPT_PATH}/data/galileo/"
class TestGalileo2nc(Check):
site_meta = {
"name": "Chilbolton",
"latitude": 50,
"longitude": 104.5,
"altitude": 50,
}
temp_dir = TemporaryDirectory()
temp_path = temp_dir.name + "/galileo.nc"
uuid = galileo.galileo2nc(FILEPATH, temp_path, site_meta)
date = "2023-03-08"
def test_variable_names(self):
keys = {
"Zh",
"v",
"width",
"ldr",
"SNR",
"time",
"range",
"radar_frequency",
"nyquist_velocity",
"latitude",
"longitude",
"altitude",
"zenith_angle",
"azimuth_angle",
"height",
"beamwidthH",
"beamwidthV",
"antenna_diameter",
}
assert set(self.nc.variables.keys()) == keys
def test_variables(self):
assert np.isclose(
self.nc.variables["radar_frequency"][:].data,
94.0,
atol=0.1,
) # Hard coded
assert np.all(
np.isclose(self.nc.variables["zenith_angle"][:].data, 0.0, atol=0.1),
)
def test_common_radar(self):
radar_fun = RadarFun(self.nc, self.site_meta, self.date, self.uuid)
for name, method in RadarFun.__dict__.items():
if "test_" in name:
getattr(radar_fun, name)()
def test_long_names(self):
data = [
("SNR", "Signal-to-noise ratio"),
]
for key, expected in data:
if key in self.nc.variables:
value = self.nc.variables[key].long_name
assert value == expected, f"{value} != {expected}"
def test_global_attributes(self):
assert self.nc.source == "RAL Space Galileo"
assert self.nc.title == f'Galileo cloud radar from {self.site_meta["name"]}'
def test_filename_argument(self, tmp_path):
test_path = tmp_path / "date.nc"
filename = f"{FILEPATH}galileo-file-1.nc"
galileo.galileo2nc(filename, test_path, self.site_meta)
def test_correct_date_validation(self, tmp_path):
test_path = tmp_path / "date.nc"
galileo.galileo2nc(FILEPATH, test_path, self.site_meta, date=self.date)
def test_wrong_date_validation(self, tmp_path):
test_path = tmp_path / "invalid.nc"
with pytest.raises(ValidTimeStampError):
galileo.galileo2nc(FILEPATH, test_path, self.site_meta, date="2021-01-03")
def test_uuid_from_user(self, tmp_path):
test_path = tmp_path / "uuid.nc"
uuid_from_user = "kissa"
uuid = galileo.galileo2nc(
FILEPATH,
test_path,
self.site_meta,
uuid=uuid_from_user,
)
with netCDF4.Dataset(test_path) as nc:
assert nc.file_uuid == uuid_from_user
assert uuid == uuid_from_user
def test_geolocation_from_source_file(self, tmp_path):
test_path = tmp_path / "geo.nc"
meta_without_geolocation = {"name": "Kumpula"}
galileo.galileo2nc(FILEPATH, test_path, meta_without_geolocation)
with netCDF4.Dataset(test_path) as nc:
for key in ("latitude", "longitude", "altitude"):
assert key in nc.variables
assert nc.variables[key][:] > 0