doppy 0.3.4__cp310-abi3-win_amd64.whl → 0.3.6__cp310-abi3-win_amd64.whl

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.

Potentially problematic release.


This version of doppy might be problematic. Click here for more details.

doppy/data/cache.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import gzip
2
+ import logging
2
3
  import shutil
3
4
  from io import BytesIO
4
5
  from pathlib import Path
@@ -25,7 +26,12 @@ def cached_record(
25
26
  path.parent.mkdir(parents=True, exist_ok=True)
26
27
  content = session.get(record["downloadUrl"]).content
27
28
  if record["filename"].endswith(".gz"):
28
- content = gzip.decompress(content)
29
+ try:
30
+ content = gzip.decompress(content)
31
+ except EOFError:
32
+ logging.error(f"Failed to recompress {record['filename']}")
33
+ raise
34
+
29
35
  with path.open("wb") as f:
30
36
  f.write(content)
31
37
  return BytesIO(content)
doppy/product/wind.py CHANGED
@@ -129,7 +129,7 @@ class Wind:
129
129
  | Sequence[BufferedIOBase],
130
130
  options: Options | None = None,
131
131
  ) -> Wind:
132
- raws = doppy.raw.WindCube.from_vad_srcs(data)
132
+ raws = doppy.raw.WindCube.from_vad_or_dbs_srcs(data)
133
133
 
134
134
  if len(raws) == 0:
135
135
  raise doppy.exceptions.NoDataError("WindCube data missing")
@@ -140,6 +140,13 @@ class Wind:
140
140
  .non_strictly_increasing_timesteps_removed()
141
141
  .reindex_scan_indices()
142
142
  )
143
+ # select scans with most frequent elevation angle from range (15,85)
144
+ raw = raw[(raw.elevation > 15) & (raw.elevation < 85)]
145
+ elevation_ints = raw.elevation.round().astype(int)
146
+ unique_elevations, counts = np.unique(elevation_ints, return_counts=True)
147
+ most_frequent_elevation = unique_elevations[np.argmax(counts)]
148
+ raw = raw[elevation_ints == most_frequent_elevation]
149
+
143
150
  if len(raw.time) == 0:
144
151
  raise doppy.exceptions.NoDataError("No suitable data for the wind product")
145
152
 
@@ -168,7 +175,9 @@ class Wind:
168
175
  mask = _compute_mask(wind, rmse) | np.any(np.isnan(wind), axis=2)
169
176
  if not np.allclose(elevation, elevation[0]):
170
177
  raise ValueError("Elevation is expected to stay same")
171
- height = np.array(raw.height, dtype=np.float64)
178
+ if not (raw.height == raw.height[0]).all():
179
+ raise ValueError("Unexpected heights")
180
+ height = np.array(raw.height[0], dtype=np.float64)
172
181
  return Wind(
173
182
  time=time,
174
183
  height=height,
doppy/raw/windcube.py CHANGED
@@ -16,8 +16,8 @@ from doppy.utils import merge_all_equal
16
16
  @dataclass
17
17
  class WindCube:
18
18
  time: npt.NDArray[datetime64] # dim: (time, )
19
- radial_distance: npt.NDArray[np.int64] # dim: (radial_distance, )
20
- height: npt.NDArray[np.int64] # dim: (radial_distance, )
19
+ radial_distance: npt.NDArray[np.int64] # dim: (time, radial_distance)
20
+ height: npt.NDArray[np.int64] # dim: (time,radial_distance)
21
21
  azimuth: npt.NDArray[np.float64] # dim: (time, )
22
22
  elevation: npt.NDArray[np.float64] # dim: (time, )
23
23
  cnr: npt.NDArray[np.float64] # dim: (time, radial_distance)
@@ -27,28 +27,28 @@ class WindCube:
27
27
  system_id: str
28
28
 
29
29
  @classmethod
30
- def from_vad_srcs(
30
+ def from_vad_or_dbs_srcs(
31
31
  cls,
32
32
  data: Sequence[str]
33
33
  | Sequence[Path]
34
34
  | Sequence[bytes]
35
35
  | Sequence[BufferedIOBase],
36
36
  ) -> list[WindCube]:
37
- return [WindCube.from_vad_src(src) for src in data]
37
+ return [WindCube.from_vad_or_dbs_src(src) for src in data]
38
38
 
39
39
  @classmethod
40
- def from_vad_src(cls, data: str | Path | bytes | BufferedIOBase) -> WindCube:
40
+ def from_vad_or_dbs_src(cls, data: str | Path | bytes | BufferedIOBase) -> WindCube:
41
41
  data_bytes = _src_to_bytes(data)
42
42
  nc = Dataset("inmemory.nc", "r", memory=data_bytes)
43
- return _from_vad_src(nc)
43
+ return _from_vad_or_dbs_src(nc)
44
44
 
45
45
  @classmethod
46
46
  def merge(cls, raws: list[WindCube]) -> WindCube:
47
47
  return WindCube(
48
48
  scan_index=_merge_scan_index([r.scan_index for r in raws]),
49
49
  time=np.concatenate([r.time for r in raws]),
50
- height=_merge_range_vars([r.height for r in raws]),
51
- radial_distance=_merge_range_vars([r.radial_distance for r in raws]),
50
+ height=np.concatenate([r.height for r in raws]),
51
+ radial_distance=np.concatenate([r.radial_distance for r in raws]),
52
52
  azimuth=np.concatenate([r.azimuth for r in raws]),
53
53
  elevation=np.concatenate([r.elevation for r in raws]),
54
54
  radial_velocity=np.concatenate([r.radial_velocity for r in raws]),
@@ -71,8 +71,8 @@ class WindCube:
71
71
  if isinstance(index, (int, slice, list, np.ndarray)):
72
72
  return WindCube(
73
73
  time=self.time[index],
74
- radial_distance=self.radial_distance,
75
- height=self.height,
74
+ radial_distance=self.radial_distance[index],
75
+ height=self.height[index],
76
76
  azimuth=self.azimuth[index],
77
77
  elevation=self.elevation[index],
78
78
  radial_velocity=self.radial_velocity[index],
@@ -113,13 +113,6 @@ class WindCube:
113
113
  return self
114
114
 
115
115
 
116
- def _merge_range_vars(vars: list[npt.NDArray[np.int64]]) -> npt.NDArray[np.int64]:
117
- var = np.concatenate([v[np.newaxis, :] for v in vars])
118
- if not (var[0] == var).all():
119
- raise ValueError("Cannot merge unequal range variable")
120
- return np.array(var[0], dtype=np.int64)
121
-
122
-
123
116
  def _merge_scan_index(index_list: list[npt.NDArray[np.int64]]) -> npt.NDArray[np.int64]:
124
117
  if len(index_list) == 0:
125
118
  raise ValueError("cannot merge empty list")
@@ -150,7 +143,7 @@ def _src_to_bytes(data: str | Path | bytes | BufferedIOBase) -> bytes:
150
143
  raise TypeError("Unsupported data type")
151
144
 
152
145
 
153
- def _from_vad_src(nc: Dataset) -> WindCube:
146
+ def _from_vad_or_dbs_src(nc: Dataset) -> WindCube:
154
147
  scan_index_list = []
155
148
  time_list = []
156
149
  cnr_list = []
@@ -160,11 +153,14 @@ def _from_vad_src(nc: Dataset) -> WindCube:
160
153
  elevation_list = []
161
154
  range_list = []
162
155
  height_list = []
156
+ time_reference = (
157
+ nc["time_reference"][:] if "time_reference" in nc.variables else None
158
+ )
163
159
 
164
160
  for i, group in enumerate(
165
161
  nc[group] for group in (nc.variables["sweep_group_name"][:])
166
162
  ):
167
- time_list.append(_extract_datetime64_or_raise(group["time"]))
163
+ time_list.append(_extract_datetime64_or_raise(group["time"], time_reference))
168
164
  radial_wind_speed_list.append(
169
165
  _extract_float64_or_raise(group["radial_wind_speed"])
170
166
  )
@@ -178,17 +174,11 @@ def _from_vad_src(nc: Dataset) -> WindCube:
178
174
  height_list.append(_extract_int64_or_raise(group["measurement_height"]))
179
175
  scan_index_list.append(np.full(group["time"][:].shape, i, dtype=np.int64))
180
176
 
181
- height = np.concatenate(height_list)
182
- if not (height == height[0]).all():
183
- raise ValueError("Unexpected heights")
184
- radial_distance = np.concatenate(range_list)
185
- if not (radial_distance == radial_distance[0]).all():
186
- raise ValueError("Unexpected range")
187
177
  return WindCube(
188
178
  scan_index=np.concatenate(scan_index_list),
189
179
  time=np.concatenate(time_list),
190
- radial_distance=radial_distance[0],
191
- height=height[0],
180
+ radial_distance=np.concatenate(range_list),
181
+ height=np.concatenate(height_list),
192
182
  azimuth=np.concatenate(azimuth_list),
193
183
  elevation=np.concatenate(elevation_list),
194
184
  radial_velocity=np.concatenate(radial_wind_speed_list),
@@ -198,12 +188,21 @@ def _from_vad_src(nc: Dataset) -> WindCube:
198
188
  )
199
189
 
200
190
 
201
- def _extract_datetime64_or_raise(nc: Dataset) -> npt.NDArray[np.datetime64]:
191
+ def _extract_datetime64_or_raise(
192
+ nc: Dataset, time_reference: str | None
193
+ ) -> npt.NDArray[np.datetime64]:
202
194
  match nc.name:
203
195
  case "time":
204
196
  if nc.dimensions != ("time",):
205
197
  raise ValueError
206
- return np.array(num2date(nc[:], units=nc.units), dtype="datetime64[us]")
198
+
199
+ units = nc.units
200
+ if "time_reference" in nc.units:
201
+ if time_reference is not None:
202
+ units = nc.units.replace("time_reference", time_reference)
203
+ else:
204
+ raise ValueError("Unknown time_reference")
205
+ return np.array(num2date(nc[:], units=units), dtype="datetime64[us]")
207
206
  case _:
208
207
  raise ValueError(f"Unexpected variable name {nc.name}")
209
208
 
doppy/rs.pyd CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: doppy
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -131,7 +131,7 @@ raws_bg = doppy.raw.HaloBg.from_srcs(LIST_OF_BACKGROUND_FILES)
131
131
  raw_system_params = doppy.raw.HaloSysParams.from_src(SYSTEM_PARAMS_FILENAME)
132
132
 
133
133
  # Windcube WLS200S
134
- raws_wls200s = doppy.raw.WindCube.from_vad_srcs(LIST_OF_VAD_NETCDF_FILES)
134
+ raws_wls200s = doppy.raw.WindCube.from_vad_or_dbs_srcs(LIST_OF_VAD_NETCDF_FILES)
135
135
 
136
136
  # Windcube WLS70
137
137
  raws_wls70 = doppy.raw.Wls70.from_srcs(LIST_OF_RTD_FILES)
@@ -1,10 +1,10 @@
1
- doppy-0.3.4.dist-info/METADATA,sha256=WXh04XFnBQcfDpb0B9J0lUyLE5j5R0QymYWrsKb0794,4274
2
- doppy-0.3.4.dist-info/WHEEL,sha256=kQSgRz4wLs1NoHeP8cPfiUAbi-20athsJLkIuWHUegk,95
3
- doppy-0.3.4.dist-info/entry_points.txt,sha256=9b_Ca7vJoh6AwL3W8qAPh_UmJ_1Pa6hi-TDfCTDjvSk,43
4
- doppy-0.3.4.dist-info/licenses/LICENSE,sha256=RIAxFjJLTw0wQ3_SM73JoTeppoD99DJJ72cjvVuRrW4,1110
1
+ doppy-0.3.6.dist-info/METADATA,sha256=F4AoXQLWbJE9kzRAF9H5dDOwUWJEFZrC1RSXHZ9Cy1o,4281
2
+ doppy-0.3.6.dist-info/WHEEL,sha256=Tw0ve9H4Xzdrn3r_TkwGVW_TehY5JI5yM2urT-BkFf4,95
3
+ doppy-0.3.6.dist-info/entry_points.txt,sha256=9b_Ca7vJoh6AwL3W8qAPh_UmJ_1Pa6hi-TDfCTDjvSk,43
4
+ doppy-0.3.6.dist-info/licenses/LICENSE,sha256=RIAxFjJLTw0wQ3_SM73JoTeppoD99DJJ72cjvVuRrW4,1110
5
5
  doppy/bench.py,sha256=fLN2iS5mmoYH4qZjD80Vl1h9lp3C-KDfhj9fteWRPtM,260
6
6
  doppy/data/api.py,sha256=c3zbZI3IV7HnzhyFzJpUPOFT20eYFuQlJ5K_1ZEe1Pg,1921
7
- doppy/data/cache.py,sha256=VNPB3XsWGwY2bNXBs1r_sEWF4qBq_U7sJSlSmt1Rxm8,1033
7
+ doppy/data/cache.py,sha256=ERFzH-KjLLXV8fCePsewTepKZXmLwtXxeazmHiFdA80,1203
8
8
  doppy/data/exceptions.py,sha256=JOyekvUO-Ew4ZVezf3_IxZOrPN0IksfUILd8R2YcSts,95
9
9
  doppy/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  doppy/defaults.py,sha256=nhxcZcFd2jyDVbq0azwtekEJEjiz8k21MZmXFlSXAjo,40
@@ -13,17 +13,17 @@ doppy/netcdf.py,sha256=W5YPbsv6CQ2Ycy4sFaIyjfn9YjvDgygczm8j9E1_uAg,4054
13
13
  doppy/options.py,sha256=uyIKM_G2GtbmV6Gve8o13eIShQqUwsnYZ41mhX2ypGE,218
14
14
  doppy/product/stare.py,sha256=ipZuRO8Bc5jWDlPYAxDZQ91gR8OMmnK-D7mNiKo2E7I,23322
15
15
  doppy/product/stare_depol.py,sha256=D0bVRZT4EP-pYHE84lioUxiuB3a2Cl6LvOgCE-YPJZY,9938
16
- doppy/product/wind.py,sha256=da2ZHksxH1A-pN0qbbKx3NkwlooaGfyKlXeTuS92VQQ,16525
16
+ doppy/product/wind.py,sha256=lGkvGf_QeOXtfT5kQEq5GuxKuSsLxTGVwRzoioF525o,17061
17
17
  doppy/product/__init__.py,sha256=xoBEXuhid-bvoof5Ogzpt1dKIhJgNMRyrAinCqUOUUI,241
18
18
  doppy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  doppy/raw/halo_bg.py,sha256=TrqJDUXa1atW2w4UDN9PPx2Mzrc7D9Q2Ndph0yB65p0,5988
20
20
  doppy/raw/halo_hpl.py,sha256=VF8JQ_5N8adLsGNJOlhvKwz0LtNd4oCU76hETe5Vuhk,19007
21
21
  doppy/raw/halo_sys_params.py,sha256=nT9r4F-H0Rf5njee5rYzzLTCm7vm3N_pdJqrW6RtyK4,4041
22
- doppy/raw/windcube.py,sha256=XZEocaAM836ODcx5ZAvJWMWu-hOLDiy68oEGHv39rww,10262
22
+ doppy/raw/windcube.py,sha256=3HU8J5oKtNGRyK38d3y5dNzGsRQc_IxfsVq2MVvWvS8,10211
23
23
  doppy/raw/wls70.py,sha256=2OhjmQ1SoAmjN4npOKFH0eFLyo9RssO7sr-gOtxjAho,7622
24
24
  doppy/raw/__init__.py,sha256=J06q7iykSAWIif4XAxI1jOszkARvLFBR1eU-B9yUXMw,235
25
25
  doppy/utils.py,sha256=lENDTzMVjCOA15Va9WZ6cou-foL5bGbNt4-NbDcnXpc,223
26
26
  doppy/__init__.py,sha256=Af7_8p3oN1nTqS9fo0mVKVuiKf5CAEK69uQa32CSFBA,197
27
27
  doppy/__main__.py,sha256=38hIWWfanILuBBGorQiAaleSC4qYJoIxuzVBkxf7Dng,371
28
- doppy/rs.pyd,sha256=xjawDfh3xMkWLqbcN9pDVB9LBM_iUK5IqMLY6WnwSI0,2100736
29
- doppy-0.3.4.dist-info/RECORD,,
28
+ doppy/rs.pyd,sha256=37LOV4oBENi0N_Ahk39EHsWaGzuZZ-lr69HTqnNMZUQ,2128896
29
+ doppy-0.3.6.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.7.1)
2
+ Generator: maturin (1.7.4)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp310-abi3-win_amd64