iss-lidar 1.2.0__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.
- iss_lidar-1.2.0/LICENSE +24 -0
- iss_lidar-1.2.0/PKG-INFO +22 -0
- iss_lidar-1.2.0/README.md +2 -0
- iss_lidar-1.2.0/pyproject.toml +30 -0
- iss_lidar-1.2.0/setup.cfg +4 -0
- iss_lidar-1.2.0/src/iss_lidar/Lidar_functions.py +514 -0
- iss_lidar-1.2.0/src/iss_lidar/__init__.py +8 -0
- iss_lidar-1.2.0/src/iss_lidar/consensus_set.py +215 -0
- iss_lidar-1.2.0/src/iss_lidar/halo_dl_decode.py +270 -0
- iss_lidar-1.2.0/src/iss_lidar/ppi.py +46 -0
- iss_lidar-1.2.0/src/iss_lidar/ppi_scans_to_vad.py +61 -0
- iss_lidar-1.2.0/src/iss_lidar/tools.py +53 -0
- iss_lidar-1.2.0/src/iss_lidar/vad.py +846 -0
- iss_lidar-1.2.0/src/iss_lidar/vad_to_consensus.py +78 -0
- iss_lidar-1.2.0/src/iss_lidar.egg-info/PKG-INFO +22 -0
- iss_lidar-1.2.0/src/iss_lidar.egg-info/SOURCES.txt +23 -0
- iss_lidar-1.2.0/src/iss_lidar.egg-info/dependency_links.txt +1 -0
- iss_lidar-1.2.0/src/iss_lidar.egg-info/requires.txt +5 -0
- iss_lidar-1.2.0/src/iss_lidar.egg-info/top_level.txt +1 -0
- iss_lidar-1.2.0/tests/test_consensus_set.py +84 -0
- iss_lidar-1.2.0/tests/test_lidar_functions.py +50 -0
- iss_lidar-1.2.0/tests/test_ppi.py +11 -0
- iss_lidar-1.2.0/tests/test_tools.py +35 -0
- iss_lidar-1.2.0/tests/test_vad.py +429 -0
- iss_lidar-1.2.0/tests/test_vad_to_consensus.py +17 -0
iss_lidar-1.2.0/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
University Corporation for Atmospheric Research
|
|
5
|
+
NSF NCAR Earth Observing Laboratory
|
|
6
|
+
All rights reserved.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
iss_lidar-1.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: iss-lidar
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Wind lidar processing library for the NSF NCAR Integrated Sounding System
|
|
5
|
+
Author-email: Isabel Suhr <isabels@ucar.edu>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://github.com/NCAR/iss-lidar
|
|
8
|
+
Project-URL: Issues, https://github.com/NCAR/iss-lidar/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: matplotlib
|
|
16
|
+
Requires-Dist: netCDF4
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: pytz
|
|
19
|
+
Requires-Dist: scipy
|
|
20
|
+
|
|
21
|
+
# iss-lidar
|
|
22
|
+
Lidar processing scripts for the EOL ISS
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "iss-lidar"
|
|
7
|
+
version = "1.2.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Isabel Suhr", email="isabels@ucar.edu" },
|
|
10
|
+
]
|
|
11
|
+
description = "Wind lidar processing library for the NSF NCAR Integrated Sounding System"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = {text = "MIT License"}
|
|
14
|
+
requires-python = ">=3.8"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"matplotlib",
|
|
22
|
+
"netCDF4",
|
|
23
|
+
"numpy",
|
|
24
|
+
"pytz",
|
|
25
|
+
"scipy",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/NCAR/iss-lidar"
|
|
30
|
+
Issues = "https://github.com/NCAR/iss-lidar/issues"
|
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
#!/opt/local/anaconda3/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# pylint: disable=C0103,E1101
|
|
4
|
+
"""
|
|
5
|
+
Created on Thu Feb 4 11:16:18 2021
|
|
6
|
+
|
|
7
|
+
@author: jgebauer
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
import numpy.ma as ma
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
import scipy.interpolate
|
|
14
|
+
from typing import Tuple, List
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class gridded_RHI:
|
|
18
|
+
"""
|
|
19
|
+
This is a class created for gridded RHI data
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, field, x, z, dx, offset, grid_el, grid_range, time):
|
|
23
|
+
self.field = np.array(field)
|
|
24
|
+
self.x = np.array(x)
|
|
25
|
+
self.z = np.array(z)
|
|
26
|
+
self.dx = dx
|
|
27
|
+
self.x_offset = offset[0]
|
|
28
|
+
self.z_offset = offset[1]
|
|
29
|
+
self.time = np.array(time)
|
|
30
|
+
self.grid_el = grid_el
|
|
31
|
+
self.grid_range = grid_range
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def grid_rhi(field, elevation, ranges, dims, dx, offset=None,
|
|
35
|
+
time=None, missing=None):
|
|
36
|
+
"""
|
|
37
|
+
This function will take RHI scans and will put them onto a 2-D cartesian
|
|
38
|
+
grid using linear interpolation
|
|
39
|
+
"""
|
|
40
|
+
if len(dims) != 2:
|
|
41
|
+
raise IOError('Dims must be a 2 length tuple')
|
|
42
|
+
|
|
43
|
+
if offset is not None:
|
|
44
|
+
if len(offset) != 2:
|
|
45
|
+
raise IOError('If offset is specified it must be 2 length tuple')
|
|
46
|
+
else:
|
|
47
|
+
offset = (0, 0)
|
|
48
|
+
|
|
49
|
+
if (time is None) and (len(field.shape) == 2):
|
|
50
|
+
times = 1
|
|
51
|
+
time = [0]
|
|
52
|
+
raw = np.array([field])
|
|
53
|
+
el = np.array([elevation])
|
|
54
|
+
elif (time is None) and (len(field.shape) == 3):
|
|
55
|
+
time = np.arange(field.shape[0])
|
|
56
|
+
el = np.copy(elevation)
|
|
57
|
+
raw = np.copy(field)
|
|
58
|
+
times = len(time)
|
|
59
|
+
else:
|
|
60
|
+
times = len(time)
|
|
61
|
+
raw = np.copy(field)
|
|
62
|
+
el = np.copy(elevation)
|
|
63
|
+
|
|
64
|
+
if missing is not None:
|
|
65
|
+
raw[raw == missing] = np.nan
|
|
66
|
+
|
|
67
|
+
x = ranges[None, :] * np.cos(np.deg2rad(180-el))[:, :, None] + offset[0]
|
|
68
|
+
z = ranges[None, :] * np.sin(np.deg2rad(el))[:, :, None] + offset[1]
|
|
69
|
+
|
|
70
|
+
grid_x, grid_z = np.meshgrid(np.arange(dims[0][0], dims[0][1]+1, dx),
|
|
71
|
+
np.arange(dims[1][0], dims[1][1]+1, dx))
|
|
72
|
+
|
|
73
|
+
grid_range = np.sqrt((grid_x-offset[0])**2 + (grid_z-offset[1])**2)
|
|
74
|
+
grid_el = 180 - np.rad2deg(np.arctan2(grid_z-offset[1], grid_x-offset[0]))
|
|
75
|
+
|
|
76
|
+
grid_field = []
|
|
77
|
+
for i in range(times):
|
|
78
|
+
foo = np.where(~np.isnan(x[i]))
|
|
79
|
+
|
|
80
|
+
grid_field.append(scipy.interpolate.griddata((x[i, foo[0], foo[1]],
|
|
81
|
+
z[i, foo[0], foo[1]]),
|
|
82
|
+
raw[i, foo[0], foo[1]],
|
|
83
|
+
(grid_x, grid_z)))
|
|
84
|
+
|
|
85
|
+
return gridded_RHI(grid_field, grid_x, grid_z, dx, offset, grid_el,
|
|
86
|
+
grid_range, time)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def coplanar_analysis(vr1, vr2, el1, el2, az):
|
|
90
|
+
"""
|
|
91
|
+
This function calculates a coplanar wind field from two gridded RHIs
|
|
92
|
+
"""
|
|
93
|
+
u = np.ones(vr1.shape)*np.nan
|
|
94
|
+
w = np.ones(vr1.shape)*np.nan
|
|
95
|
+
|
|
96
|
+
for i in range(vr1.shape[0]):
|
|
97
|
+
for j in range(vr1.shape[1]):
|
|
98
|
+
|
|
99
|
+
if (~np.isnan(vr1[i, j])) and (~np.isnan(vr2[i, j])):
|
|
100
|
+
M = np.array([[np.sin(np.deg2rad(az)) *
|
|
101
|
+
np.cos(np.deg2rad(el1[i, j])),
|
|
102
|
+
np.sin(np.deg2rad(el1[i, j]))],
|
|
103
|
+
[np.sin(np.deg2rad(az)) *
|
|
104
|
+
np.cos(np.deg2rad(el2[i, j])),
|
|
105
|
+
np.sin(np.deg2rad(el2[i, j]))]])
|
|
106
|
+
|
|
107
|
+
U = np.linalg.solve(M, np.array([vr1[i, j], vr2[i, j]]))
|
|
108
|
+
u[i, j] = U[0]
|
|
109
|
+
w[i, j] = U[1]
|
|
110
|
+
|
|
111
|
+
return u, w
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def vr_variance(field, time, t_avg, axis=0):
|
|
115
|
+
"""
|
|
116
|
+
The function calculates the vr-variance from a timeseries of scans
|
|
117
|
+
"""
|
|
118
|
+
t_avg = t_avg*60
|
|
119
|
+
start = 0
|
|
120
|
+
yo = np.where(time < (time[0]+t_avg))[0]
|
|
121
|
+
end = yo[-1]+1
|
|
122
|
+
var = []
|
|
123
|
+
time_avg = []
|
|
124
|
+
while end < len(time):
|
|
125
|
+
var.append(np.nanvar(field[start:end, :, :], axis=0))
|
|
126
|
+
time_avg.append(np.nanmean(time[start:end]))
|
|
127
|
+
start = end
|
|
128
|
+
yo = np.where(time < (time[start]+t_avg))[0]
|
|
129
|
+
end = yo[-1]+1
|
|
130
|
+
|
|
131
|
+
return np.array(var), np.array(time_avg)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def process_LidarSim_scan(scan, scantype, elevation, azimuth, ranges, time):
|
|
135
|
+
"""
|
|
136
|
+
This function will work with LidarSim data
|
|
137
|
+
"""
|
|
138
|
+
# import this here b/c it's only needed in this function
|
|
139
|
+
from vad import VAD
|
|
140
|
+
if scantype == 'vad':
|
|
141
|
+
el = np.nanmean(elevation)
|
|
142
|
+
vad = VAD.ARM_VAD(scan, ranges, el, azimuth, time)
|
|
143
|
+
|
|
144
|
+
return vad
|
|
145
|
+
|
|
146
|
+
else:
|
|
147
|
+
print('Not a valid scan type')
|
|
148
|
+
return np.nan
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def rhi_vertical_profile(field, elevation, azimuth, ranges, heights, dz, loc,
|
|
152
|
+
offset=None, time=None, missing=None):
|
|
153
|
+
"""
|
|
154
|
+
This function puts vr observations from a RHI onto a vertical grid at one
|
|
155
|
+
location to be used for virtual tower calculations
|
|
156
|
+
"""
|
|
157
|
+
if len(loc) != 2:
|
|
158
|
+
raise IOError('Dims must be a 2 length tuple')
|
|
159
|
+
|
|
160
|
+
if offset is not None:
|
|
161
|
+
if len(offset) != 3:
|
|
162
|
+
raise IOError('If offset is specified it must be 3 length tuple')
|
|
163
|
+
else:
|
|
164
|
+
offset = (0, 0, 0)
|
|
165
|
+
|
|
166
|
+
if (time is None) and (len(field.shape) == 2):
|
|
167
|
+
times = 1
|
|
168
|
+
time = [0]
|
|
169
|
+
raw = np.array([field])
|
|
170
|
+
el = np.array([elevation])
|
|
171
|
+
elif (time is None) and (len(field.shape) == 3):
|
|
172
|
+
time = np.arange(field.shape[0])
|
|
173
|
+
el = np.copy(elevation)
|
|
174
|
+
raw = np.copy(field)
|
|
175
|
+
times = len(time)
|
|
176
|
+
else:
|
|
177
|
+
times = len(time)
|
|
178
|
+
raw = np.copy(field)
|
|
179
|
+
el = np.copy(elevation)
|
|
180
|
+
|
|
181
|
+
if missing is not None:
|
|
182
|
+
raw[raw == missing] = np.nan
|
|
183
|
+
|
|
184
|
+
x = (ranges[None, :] * np.cos(np.deg2rad(el))[:, :, None] *
|
|
185
|
+
np.sin(np.deg2rad(azimuth)) + offset[0])
|
|
186
|
+
y = (ranges[None, :] * np.cos(np.deg2rad(el))[:, :, None] *
|
|
187
|
+
np.cos(np.deg2rad(azimuth)) + offset[1])
|
|
188
|
+
z = ranges[None, :] * np.sin(np.deg2rad(el))[:, :, None] + offset[2]
|
|
189
|
+
|
|
190
|
+
r = np.sqrt(x**2 + y**2)
|
|
191
|
+
|
|
192
|
+
z_interp = np.arange(heights[0], heights[1], dz)
|
|
193
|
+
|
|
194
|
+
z_ranges = np.sqrt((loc[0]-offset[0])**2 +
|
|
195
|
+
(loc[1]-offset[1])**2 + (z_interp-offset[2])**2)
|
|
196
|
+
z_el = np.rad2deg(np.arctan2(z_interp-offset[2],
|
|
197
|
+
np.sqrt((loc[0]-offset[0])**2 +
|
|
198
|
+
(loc[1]-offset[1])**2)))
|
|
199
|
+
|
|
200
|
+
grid_field = []
|
|
201
|
+
grid_x, grid_z = np.meshgrid(np.array(np.sqrt(loc[0]**2 + loc[1]**2)),
|
|
202
|
+
z_interp)
|
|
203
|
+
for i in range(times):
|
|
204
|
+
grid_field.append(scipy.interpolate.griddata((r[i].ravel(),
|
|
205
|
+
z[i].ravel()),
|
|
206
|
+
raw[i].ravel(),
|
|
207
|
+
(grid_x, grid_z))[:, 0])
|
|
208
|
+
|
|
209
|
+
# no vertical_vr object/function included in Josh's code, ignore error
|
|
210
|
+
return vertical_vr(grid_field, loc[0], loc[1], z_interp, # noqa: F821
|
|
211
|
+
dz, offset, z_el, z_ranges, azimuth, time)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def virtual_tower(vr, elevation, azimuth, height, uncertainty=0.45):
|
|
215
|
+
"""
|
|
216
|
+
This function calculates the wind components for a virtual towers
|
|
217
|
+
"""
|
|
218
|
+
if len(vr) == 2:
|
|
219
|
+
u = []
|
|
220
|
+
v = []
|
|
221
|
+
u_uncertainty = []
|
|
222
|
+
v_uncertainty = []
|
|
223
|
+
el1 = np.deg2rad(elevation[0])
|
|
224
|
+
el2 = np.deg2rad(elevation[1])
|
|
225
|
+
az1 = np.deg2rad(azimuth[0])
|
|
226
|
+
az2 = np.deg2rad(azimuth[1])
|
|
227
|
+
for i in range(len(height)):
|
|
228
|
+
if np.isnan(vr[0][i]) or np.isnan(vr[1][i]):
|
|
229
|
+
u.append(np.nan)
|
|
230
|
+
v.append(np.nan)
|
|
231
|
+
|
|
232
|
+
M = np.array([[np.sin(az1)*np.cos(el1[i]), np.cos(az1) *
|
|
233
|
+
np.cos(el1[i])],
|
|
234
|
+
[np.sin(az2)*np.cos(el2[i]), np.cos(az2) *
|
|
235
|
+
np.cos(el2[i])]])
|
|
236
|
+
invM = np.linalg.inv(M)
|
|
237
|
+
temp_u = np.sqrt((invM[0, 0]**2)*(uncertainty**2) +
|
|
238
|
+
(invM[0, 1]**2)*(uncertainty**2))
|
|
239
|
+
temp_v = np.sqrt((invM[1, 0]**2)*(uncertainty**2) +
|
|
240
|
+
(invM[1, 1]**2)*(uncertainty**2))
|
|
241
|
+
u_uncertainty.append(temp_u)
|
|
242
|
+
v_uncertainty.append(temp_v)
|
|
243
|
+
|
|
244
|
+
else:
|
|
245
|
+
M = np.array([[np.sin(az1)*np.cos(el1[i]), np.cos(az1) *
|
|
246
|
+
np.cos(el1[i])],
|
|
247
|
+
[np.sin(az2)*np.cos(el2[i]), np.cos(az2) *
|
|
248
|
+
np.cos(el2[i])]])
|
|
249
|
+
temp = np.linalg.solve(M, np.array([vr[0][i], vr[1][i]]))
|
|
250
|
+
u.append(np.copy(temp[0]))
|
|
251
|
+
v.append(np.copy(temp[1]))
|
|
252
|
+
|
|
253
|
+
invM = np.linalg.inv(M)
|
|
254
|
+
temp_u = np.sqrt((invM[0, 0]**2)*(uncertainty**2) +
|
|
255
|
+
(invM[0, 1]**2)*(uncertainty**2))
|
|
256
|
+
temp_v = np.sqrt((invM[1, 0]**2)*(uncertainty**2) +
|
|
257
|
+
(invM[1, 1]**2)*(uncertainty**2))
|
|
258
|
+
u_uncertainty.append(temp_u)
|
|
259
|
+
v_uncertainty.append(temp_v)
|
|
260
|
+
|
|
261
|
+
return np.array([u, v]), np.array([u_uncertainty, v_uncertainty])
|
|
262
|
+
|
|
263
|
+
elif len(vr) == 3:
|
|
264
|
+
u = []
|
|
265
|
+
v = []
|
|
266
|
+
w = []
|
|
267
|
+
u_uncertainty = []
|
|
268
|
+
v_uncertainty = []
|
|
269
|
+
w_uncertainty = []
|
|
270
|
+
el1 = np.deg2rad(elevation[0])
|
|
271
|
+
el2 = np.deg2rad(elevation[1])
|
|
272
|
+
el3 = np.deg2rad(elevation[2])
|
|
273
|
+
az1 = np.deg2rad(azimuth[0])
|
|
274
|
+
az2 = np.deg2rad(azimuth[1])
|
|
275
|
+
az3 = np.deg2rad(azimuth[2])
|
|
276
|
+
for i in range(len(height)):
|
|
277
|
+
if np.isnan(vr[0][i]) or np.isnan(vr[1][i]):
|
|
278
|
+
u.append(np.nan)
|
|
279
|
+
v.append(np.nan)
|
|
280
|
+
|
|
281
|
+
M = np.array([[np.sin(az1)*np.cos(el1[i]), np.cos(az1) *
|
|
282
|
+
np.cos(el1[i]), np.sin(el1)],
|
|
283
|
+
[np.sin(az2)*np.cos(el2[i]), np.cos(az2) *
|
|
284
|
+
np.cos(el2[i]), np.sin(el2)],
|
|
285
|
+
[np.sin(az3)*np.cos(el3[i]), np.cos(az3) *
|
|
286
|
+
np.cos(el3[i]),
|
|
287
|
+
np.sin(el3)]])
|
|
288
|
+
invM = np.linalg.inv(M)
|
|
289
|
+
temp_u = np.sqrt((invM[0, 0]**2)*(uncertainty**2) +
|
|
290
|
+
(invM[0, 1]**2)*(uncertainty**2) +
|
|
291
|
+
(invM[0, 2]**2)*(uncertainty**2))
|
|
292
|
+
temp_v = np.sqrt((invM[1, 0]**2)*(uncertainty**2) +
|
|
293
|
+
(invM[1, 1]**2)*(uncertainty**2) +
|
|
294
|
+
(invM[1, 2]**2)*(uncertainty**2))
|
|
295
|
+
temp_w = np.sqrt((invM[2, 0]**2)*(uncertainty**2) +
|
|
296
|
+
(invM[2, 1]**2)*(uncertainty**2) +
|
|
297
|
+
(invM[2, 2]**2)*(uncertainty**2))
|
|
298
|
+
|
|
299
|
+
u_uncertainty.append(temp_u)
|
|
300
|
+
v_uncertainty.append(temp_v)
|
|
301
|
+
w_uncertainty.append(temp_w)
|
|
302
|
+
else:
|
|
303
|
+
M = np.array([[np.sin(az1)*np.cos(el1[i]), np.cos(az1) *
|
|
304
|
+
np.cos(el1[i]), np.sin(el1)],
|
|
305
|
+
[np.sin(az2)*np.cos(el2[i]), np.cos(az2) *
|
|
306
|
+
np.cos(el2[i]), np.sin(el2)],
|
|
307
|
+
[np.sin(az3)*np.cos(el3[i]), np.cos(az3) *
|
|
308
|
+
np.cos(el3[i]),
|
|
309
|
+
np.sin(el3)]])
|
|
310
|
+
temp = np.linalg.solve(M, np.array([vr[0][i], vr[1][i],
|
|
311
|
+
vr[2][i]]))
|
|
312
|
+
u.append(np.copy(temp[0]))
|
|
313
|
+
v.append(np.copy(temp[1]))
|
|
314
|
+
w.append(np.copy(temp[2]))
|
|
315
|
+
|
|
316
|
+
invM = np.linalg.inv(M)
|
|
317
|
+
temp_u = np.sqrt((invM[0, 0]**2)*(uncertainty**2) +
|
|
318
|
+
(invM[0, 1]**2)*(uncertainty**2) +
|
|
319
|
+
(invM[0, 2]**2)*(uncertainty**2))
|
|
320
|
+
temp_v = np.sqrt((invM[1, 0]**2)*(uncertainty**2) +
|
|
321
|
+
(invM[1, 1]**2)*(uncertainty**2) +
|
|
322
|
+
(invM[1, 2]**2)*(uncertainty**2))
|
|
323
|
+
temp_w = np.sqrt((invM[2, 0]**2)*(uncertainty**2) +
|
|
324
|
+
(invM[2, 1]**2)*(uncertainty**2) +
|
|
325
|
+
(invM[2, 2]**2)*(uncertainty**2))
|
|
326
|
+
|
|
327
|
+
u_uncertainty.append(temp_u)
|
|
328
|
+
v_uncertainty.append(temp_v)
|
|
329
|
+
w_uncertainty.append(temp_w)
|
|
330
|
+
|
|
331
|
+
return np.array([u, v, w]), np.array([u_uncertainty, v_uncertainty,
|
|
332
|
+
w_uncertainty])
|
|
333
|
+
else:
|
|
334
|
+
print('Input needs to be a length 2 or 3 tuple')
|
|
335
|
+
return np.nan
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def lenshow(x, freq=1, tau_min=3, tau_max=12, plot=False):
|
|
339
|
+
"""
|
|
340
|
+
This function performs a Lenshow correction to lidar data and calculates
|
|
341
|
+
vertical velocity variance. This function was originally written by Tyler
|
|
342
|
+
Bell at CIMMS in Norman, OK.
|
|
343
|
+
|
|
344
|
+
Reads in a timeseries. Freq is in Hz. Default taus are from avg values from
|
|
345
|
+
Bonin Dissertation (2015) Returns avg w'**2 and avg error'**2
|
|
346
|
+
"""
|
|
347
|
+
# Find the perturbation of x
|
|
348
|
+
mean = np.mean(x)
|
|
349
|
+
prime = x - mean
|
|
350
|
+
# Get the autocovariance
|
|
351
|
+
acorr, lags = xcorr(prime, prime)
|
|
352
|
+
# var = np.var(prime)
|
|
353
|
+
acov = acorr # * var
|
|
354
|
+
# Extract lags > 0
|
|
355
|
+
lags = lags[int(len(lags)/2):] * freq
|
|
356
|
+
acov = acov[int(len(acov)/2):]
|
|
357
|
+
# Define the start and end lags
|
|
358
|
+
lag_start = int(tau_min / freq)
|
|
359
|
+
lag_end = int(tau_max / freq)
|
|
360
|
+
# Fit the structure function
|
|
361
|
+
# don't kow which leastsq fn this is referencing
|
|
362
|
+
p1, _ = leastsq(err_funct, [1, .001], # noqa: F821
|
|
363
|
+
args=(lags[lag_start:lag_end],
|
|
364
|
+
acov[lag_start:lag_end]))
|
|
365
|
+
if plot:
|
|
366
|
+
new_lags = np.arange(tau_min, tau_max)
|
|
367
|
+
plt.plot(lags, acov)
|
|
368
|
+
plt.plot(new_lags, fit_funct(p1, new_lags), 'gX')
|
|
369
|
+
plt.plot(0, fit_funct(p1, 0), 'gX')
|
|
370
|
+
plt.xlim(0, tau_max+20)
|
|
371
|
+
plt.xlabel("Lag [s]")
|
|
372
|
+
plt.ylabel("$M_{11} [m^2s^{-2}$]")
|
|
373
|
+
return p1[0], acov[0] - p1[0]
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def lenshow_bonin(x, tau_min=1, tint_first_guess=3, freq=1, max_iter=100,
|
|
377
|
+
plot=False):
|
|
378
|
+
"""
|
|
379
|
+
This is a modified version of the Lenshow correction that adaptively
|
|
380
|
+
selects taus based on the data. This function was originally written by
|
|
381
|
+
Tyler Bell at CIMMS in Norman, OK.
|
|
382
|
+
"""
|
|
383
|
+
# Find the perturbation of x
|
|
384
|
+
mean = np.mean(x)
|
|
385
|
+
prime = x - mean
|
|
386
|
+
# Get the autocovariance
|
|
387
|
+
acorr, lags = xcorr(prime, prime)
|
|
388
|
+
# var = np.var(prime)
|
|
389
|
+
acov = acorr # * var
|
|
390
|
+
# Extract lags > 0
|
|
391
|
+
lags = lags[int(len(lags)/2):] * freq
|
|
392
|
+
acov = acov[int(len(acov)/2):]
|
|
393
|
+
# Define the start and end lags
|
|
394
|
+
lag_start = int(tau_min / freq)
|
|
395
|
+
lag_end = int((tau_min+3) / freq)
|
|
396
|
+
# Fit the structure function
|
|
397
|
+
# fit_funct = lambda p, t: p[0] - p[1]*t**(2./3.)
|
|
398
|
+
# err_funct = lambda p, t, y: fit_funct(p, t) - y
|
|
399
|
+
# Iterate to find t_int
|
|
400
|
+
last_tint = (tau_min+3)
|
|
401
|
+
i = 0
|
|
402
|
+
# again, don't know which leastsq this intends to use
|
|
403
|
+
p1, _ = leastsq(err_funct, [.10, .001], # noqa: F821
|
|
404
|
+
args=(lags[lag_start:lag_end],
|
|
405
|
+
acov[lag_start:lag_end]))
|
|
406
|
+
tint = calc_tint(p1[0], freq, acov, lags)
|
|
407
|
+
while np.abs(last_tint - tint) > 1.:
|
|
408
|
+
if i >= max_iter:
|
|
409
|
+
return None
|
|
410
|
+
else:
|
|
411
|
+
i += 1
|
|
412
|
+
last_tint = tint
|
|
413
|
+
p1, _ = leastsq(err_funct, [.10, .001], # noqa: F821
|
|
414
|
+
args=(lags[lag_start:lag_end],
|
|
415
|
+
acov[lag_start:lag_end]))
|
|
416
|
+
tint = calc_tint(p1[0], freq, acov, lags)
|
|
417
|
+
# Find the time where M11(t) = M11(0)/2
|
|
418
|
+
ind = np.min(np.where(acov <= acov[0]/2))
|
|
419
|
+
# Determine what tau to use
|
|
420
|
+
tau_max = np.min([tint/2., lags[ind]])
|
|
421
|
+
# Do the process
|
|
422
|
+
lag_end = int(tau_max / freq)
|
|
423
|
+
if lag_start+1 >= lag_end:
|
|
424
|
+
lag_end = lag_start + 2
|
|
425
|
+
p1, _ = leastsq(err_funct, [.10, .001], # noqa: F821
|
|
426
|
+
args=(lags[lag_start:lag_end],
|
|
427
|
+
acov[lag_start:lag_end]))
|
|
428
|
+
if plot:
|
|
429
|
+
new_lags = np.arange(tau_min, tau_max)
|
|
430
|
+
plt.plot(lags, acov, 'k')
|
|
431
|
+
plt.plot(new_lags, fit_funct(p1, new_lags), 'rX', label='Adaptive')
|
|
432
|
+
plt.plot(0, fit_funct(p1, 0), 'rX')
|
|
433
|
+
plt.xlim(0, tau_max+20)
|
|
434
|
+
plt.xlabel("Lag [s]")
|
|
435
|
+
plt.ylabel("$M_{11} [m^2s^{-2}$]")
|
|
436
|
+
return p1[0], np.abs(acov[0] - p1[0]), tau_max
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def fit_funct(p, t):
|
|
440
|
+
""" Used in lenshow, lenshow_bonin calculations """
|
|
441
|
+
p[0] - p[1]*t**(2./3.)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def err_funct(p, t, y):
|
|
445
|
+
""" Used in lenshow, lenshow_bonin calculations """
|
|
446
|
+
fit_funct(p, t) - y
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def calc_tint(var, freq, acov, lags):
|
|
450
|
+
"""
|
|
451
|
+
This function is used in the lenshow_bonin function
|
|
452
|
+
"""
|
|
453
|
+
ind = np.min(np.where(acov < 0))
|
|
454
|
+
return freq**-1. + 1./var * sum(acov[1:ind] / freq)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def xcorr(y1, y2):
|
|
458
|
+
"""
|
|
459
|
+
This function calculates the lag correlation of a time series.
|
|
460
|
+
"""
|
|
461
|
+
if len(y1) != len(y2):
|
|
462
|
+
raise ValueError('The lenghts of the inputs should be the same')
|
|
463
|
+
|
|
464
|
+
corr = np.correlate(y1, y2, mode='full')
|
|
465
|
+
unbiased_size = np.correlate(np.ones(len(y1)), np.ones(len(y1)),
|
|
466
|
+
mode='full')
|
|
467
|
+
corr = corr/unbiased_size
|
|
468
|
+
|
|
469
|
+
maxlags = len(y1)-1
|
|
470
|
+
lags = np.arange(-maxlags, maxlags + 1)
|
|
471
|
+
|
|
472
|
+
return corr, lags
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def consensus_avg(vals: ma.array, window: float) -> Tuple[float, List]:
|
|
476
|
+
"""
|
|
477
|
+
This function uses consensus averaging to calculate the mean value of all
|
|
478
|
+
data points that lie within a given window size of each other, where it
|
|
479
|
+
finds the window span with the most points in it and with the smallest
|
|
480
|
+
spread in values. It returns the consensus average and a list of which
|
|
481
|
+
indices of the original array were used in the averaging.
|
|
482
|
+
"""
|
|
483
|
+
# make sure nans are masked
|
|
484
|
+
vals = ma.masked_invalid(vals)
|
|
485
|
+
|
|
486
|
+
# sort but retain original indices
|
|
487
|
+
sorted_idxs = ma.argsort(vals)
|
|
488
|
+
sorted_vals = ma.sort(vals)
|
|
489
|
+
|
|
490
|
+
# if all masked, return
|
|
491
|
+
if sorted_vals.mask.all():
|
|
492
|
+
return (np.nan, [])
|
|
493
|
+
|
|
494
|
+
max_num_inds = 0
|
|
495
|
+
final_range = np.inf
|
|
496
|
+
for v in sorted_vals[sorted_vals.mask == False]: # noqa: E712
|
|
497
|
+
booleans = ma.logical_and(sorted_vals >= v, sorted_vals <= v+window)
|
|
498
|
+
inds = ma.where(booleans)[0]
|
|
499
|
+
num_inds = len(inds)
|
|
500
|
+
val_range = sorted_vals[inds[-1]] - sorted_vals[inds[0]]
|
|
501
|
+
if (num_inds > max_num_inds) or (num_inds == max_num_inds
|
|
502
|
+
and val_range < final_range):
|
|
503
|
+
max_num_inds = num_inds
|
|
504
|
+
final_range = val_range
|
|
505
|
+
final_inds = inds
|
|
506
|
+
|
|
507
|
+
# if there is no window with more than one point in it, return nan
|
|
508
|
+
if max_num_inds < 2:
|
|
509
|
+
return (np.nan, [])
|
|
510
|
+
|
|
511
|
+
final_vals = [sorted_vals[i] for i in final_inds]
|
|
512
|
+
orig_idxs = [sorted_idxs[i] for i in final_inds]
|
|
513
|
+
avg = np.mean(final_vals)
|
|
514
|
+
return (avg, orig_idxs)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from .consensus_set import ConsensusSet
|
|
2
|
+
from .vad_to_consensus import create_cns_filename
|
|
3
|
+
from .vad import VADSet
|
|
4
|
+
from .vad import VAD
|
|
5
|
+
from .ppi import PPI
|
|
6
|
+
from .Lidar_functions import consensus_avg
|
|
7
|
+
from .tools import create_filename
|
|
8
|
+
from .tools import wspd_wdir_from_uv
|