pyadps 0.1.0__py3-none-any.whl → 0.1.0b0__py3-none-any.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.
- pyadps/Home_Page.py +5 -11
- pyadps/pages/01_Read_File.py +16 -190
- pyadps/pages/02_View_Raw_Data.py +33 -69
- pyadps/pages/03_Download_Raw_File.py +60 -124
- pyadps/pages/04_QC_Test.py +283 -0
- pyadps/pages/05_Profile_Test.py +389 -0
- pyadps/pages/06_Velocity_Test.py +293 -0
- pyadps/pages/07_Write_File.py +367 -0
- pyadps/utils/__init__.py +3 -3
- pyadps/utils/cutbin.py +413 -0
- pyadps/utils/plotgen.py +3 -505
- pyadps/utils/profile_test.py +145 -526
- pyadps/utils/pyreadrdi.py +6 -13
- pyadps/utils/readrdi.py +20 -167
- pyadps/utils/regrid.py +122 -0
- pyadps/utils/script.py +147 -197
- pyadps/utils/signal_quality.py +24 -344
- pyadps/utils/velocity_test.py +16 -99
- pyadps/utils/writenc.py +27 -104
- {pyadps-0.1.0.dist-info → pyadps-0.1.0b0.dist-info}/METADATA +22 -54
- pyadps-0.1.0b0.dist-info/RECORD +29 -0
- {pyadps-0.1.0.dist-info → pyadps-0.1.0b0.dist-info}/WHEEL +1 -1
- pyadps-0.1.0b0.dist-info/entry_points.txt +3 -0
- pyadps/pages/04_Sensor_Health.py +0 -905
- pyadps/pages/05_QC_Test.py +0 -476
- pyadps/pages/06_Profile_Test.py +0 -971
- pyadps/pages/07_Velocity_Test.py +0 -600
- pyadps/pages/08_Write_File.py +0 -574
- pyadps/pages/09_Auto_process.py +0 -62
- pyadps/utils/autoprocess.py +0 -530
- pyadps/utils/metadata/config.ini +0 -99
- pyadps/utils/metadata/demo.000 +0 -0
- pyadps/utils/sensor_health.py +0 -120
- pyadps-0.1.0.dist-info/RECORD +0 -33
- pyadps-0.1.0.dist-info/entry_points.txt +0 -5
- {pyadps-0.1.0.dist-info → pyadps-0.1.0b0.dist-info}/LICENSE +0 -0
pyadps/utils/signal_quality.py
CHANGED
@@ -1,47 +1,20 @@
|
|
1
1
|
import numpy as np
|
2
2
|
from pyadps.utils.plotgen import PlotNoise
|
3
|
-
from pyadps.utils.readrdi import ReadFile
|
4
3
|
|
5
4
|
|
6
5
|
def qc_check(var, mask, cutoff=0):
|
7
6
|
"""
|
8
|
-
|
9
|
-
|
10
|
-
are marked as invalid in the mask.
|
7
|
+
The module returns the modified mask file after checking the cutoff criteria.
|
8
|
+
All values less than the cuttoff are masked.
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
mask : numpy.ndarray
|
17
|
-
An integer array of the same shape as `var`, where `1` indicates
|
18
|
-
invalid data and `0` indicates valid data.
|
19
|
-
cutoff : int, optional
|
20
|
-
The threshold value for quality control. Any value in `var` less than
|
21
|
-
or equal to this cutoff will be marked as invalid in the mask. Default is 0.
|
10
|
+
Args:
|
11
|
+
var (numpy.ndarray):
|
12
|
+
mask (numpy.ndarray): A mask file having same array size as var
|
13
|
+
cutoff (int): Default cutoff is 0
|
22
14
|
|
23
|
-
Returns
|
24
|
-
|
25
|
-
numpy.ndarray
|
26
|
-
An updated integer mask array of the same shape as `var`, with `1`
|
27
|
-
indicating invalid data and `0` indicating valid data.
|
28
|
-
|
29
|
-
Notes
|
30
|
-
-----
|
31
|
-
- The function modifies the `mask` by applying the cutoff condition.
|
32
|
-
Values in `var` that are less than or equal to the cutoff will be
|
33
|
-
marked as invalid (`1`), while all other values will remain valid (`0`).
|
34
|
-
- Ensure that `var` and `mask` are compatible in shape for element-wise
|
35
|
-
operations.
|
36
|
-
|
37
|
-
Example
|
38
|
-
-------
|
39
|
-
>>> import pyadps
|
40
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
41
|
-
>>> var = ds.echo.data
|
42
|
-
>>> mask = qc_check(var, mask, cutoff=40)
|
15
|
+
Returns:
|
16
|
+
mask (numpy.ndarray): Modified mask file based on cutoff
|
43
17
|
"""
|
44
|
-
|
45
18
|
shape = np.shape(var)
|
46
19
|
if len(shape) == 2:
|
47
20
|
mask[var[:, :] < cutoff] = 1
|
@@ -49,138 +22,16 @@ def qc_check(var, mask, cutoff=0):
|
|
49
22
|
beam = shape[0]
|
50
23
|
for i in range(beam):
|
51
24
|
mask[var[i, :, :] < cutoff] = 1
|
52
|
-
|
25
|
+
values, counts = np.unique(mask, return_counts=True)
|
53
26
|
# print(values, counts, np.round(counts[1] * 100 / np.sum(counts)))
|
54
27
|
return mask
|
55
28
|
|
56
29
|
|
57
|
-
|
58
|
-
|
59
|
-
Perform an correlation check on the provided variable and update the
|
60
|
-
mask to mark valid and invalid values based on a cutoff threshold.
|
61
|
-
|
62
|
-
Parameters
|
63
|
-
----------
|
64
|
-
ds : pyadps.dataset
|
65
|
-
The input pyadps dataframe containing correlation data to be checked.
|
66
|
-
Accepts 2-D or 3-D masks.
|
67
|
-
mask : numpy.ndarray
|
68
|
-
An integer array of the same shape as `var`, where `1` indicates invalid
|
69
|
-
data or masked data and `0` indicates valid data.
|
70
|
-
cutoff : float, optional
|
71
|
-
The threshold value for echo intensity. Any value in `ds.correlation.data` below
|
72
|
-
this cutoff will be considered invalid and marked as `1` in the mask.
|
73
|
-
Default is 64.
|
74
|
-
|
75
|
-
Returns
|
76
|
-
-------
|
77
|
-
numpy.ndarray
|
78
|
-
An updated integer mask array of the same shape as `var`, with `1`
|
79
|
-
indicating invalid or masked data (within the cutoff limit) and `0` indicating
|
80
|
-
valid.
|
81
|
-
|
82
|
-
Notes
|
83
|
-
-----
|
84
|
-
- The function modifies the `mask` based on the cutoff condition. Valid
|
85
|
-
values in `var` retain their corresponding mask value as `0`, while
|
86
|
-
invalid values or previously masked elements are marked as `1`.
|
87
|
-
operations.
|
88
|
-
|
89
|
-
Example
|
90
|
-
-------
|
91
|
-
>>> import pyadps
|
92
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
93
|
-
>>> outmask = correlation_check(ds, mask, cutoff=9999)
|
94
|
-
"""
|
95
|
-
correlation = ds.correlation.data
|
96
|
-
mask = qc_check(correlation, mask, cutoff=cutoff)
|
97
|
-
return mask
|
98
|
-
|
99
|
-
def echo_check(ds, mask, cutoff=40):
|
100
|
-
"""
|
101
|
-
Perform an echo intensity check on the provided variable and update the
|
102
|
-
mask to mark valid and invalid values based on a cutoff threshold.
|
103
|
-
|
104
|
-
Parameters
|
105
|
-
----------
|
106
|
-
ds : pyadps.dataset
|
107
|
-
The input pyadps dataframe containing echo intensity data to be checked.
|
108
|
-
Accepts 2-D or 3-D masks.
|
109
|
-
mask : numpy.ndarray
|
110
|
-
An integer array of the same shape as `var`, where `1` indicates invalid
|
111
|
-
data or masked data and `0` indicates valid data.
|
112
|
-
cutoff : float, optional
|
113
|
-
The threshold value for echo intensity. Any value in `ds.echo.data` below
|
114
|
-
this cutoff will be considered invalid and marked as `1` in the mask.
|
115
|
-
Default is 40.
|
116
|
-
|
117
|
-
Returns
|
118
|
-
-------
|
119
|
-
numpy.ndarray
|
120
|
-
An updated integer mask array of the same shape as `var`, with `1`
|
121
|
-
indicating invalid or masked data (within the cutoff limit) and `0` indicating
|
122
|
-
valid.
|
30
|
+
cor_check = qc_check
|
31
|
+
echo_check = qc_check
|
123
32
|
|
124
|
-
Notes
|
125
|
-
-----
|
126
|
-
- The function modifies the `mask` based on the cutoff condition. Valid
|
127
|
-
values in `var` retain their corresponding mask value as `0`, while
|
128
|
-
invalid values or previously masked elements are marked as `1`.
|
129
|
-
- Ensure that `var` and `mask` are compatible in shape for element-wise
|
130
|
-
operations.
|
131
33
|
|
132
|
-
|
133
|
-
-------
|
134
|
-
>>> import pyadps
|
135
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
136
|
-
>>> outmask = echo_check(ds, mask, cutoff=9999)
|
137
|
-
"""
|
138
|
-
|
139
|
-
echo = ds.echo.data
|
140
|
-
mask = qc_check(echo, mask, cutoff=cutoff)
|
141
|
-
return mask
|
142
|
-
|
143
|
-
|
144
|
-
def ev_check(ds, mask, cutoff=9999):
|
145
|
-
"""
|
146
|
-
Perform an error velocity check on the provided variable and update the
|
147
|
-
mask to mark valid and invalid values based on a cutoff threshold.
|
148
|
-
|
149
|
-
Parameters
|
150
|
-
----------
|
151
|
-
ds : pyadps.dataset
|
152
|
-
The input pyadps dataframe containing error velocity data to be checked.
|
153
|
-
mask : numpy.ndarray
|
154
|
-
An integer array of the same shape as `var`, where `1` indicates invalid
|
155
|
-
data or masked data and `0` indicates valid data.
|
156
|
-
cutoff : float, optional
|
157
|
-
The threshold value for error velocity. Any value in `var` exceeding
|
158
|
-
this cutoff will be considered invalid and marked as `0` in the mask.
|
159
|
-
Default is 9999.
|
160
|
-
|
161
|
-
Returns
|
162
|
-
-------
|
163
|
-
numpy.ndarray
|
164
|
-
An updated integer mask array of the same shape as `var`, with `1`
|
165
|
-
indicating invalid or masked data (within the cutoff limit) and `0` indicating
|
166
|
-
valid.
|
167
|
-
|
168
|
-
Notes
|
169
|
-
-----
|
170
|
-
- The function modifies the `mask` based on the cutoff condition. Valid
|
171
|
-
values in `var` retain their corresponding mask value as `0`, while
|
172
|
-
invalid values or previously masked elements are marked as `1`.
|
173
|
-
- Ensure that `var` and `mask` are compatible in shape for element-wise
|
174
|
-
operations.
|
175
|
-
|
176
|
-
Example
|
177
|
-
-------
|
178
|
-
>>> import pyadps
|
179
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
180
|
-
>>> outmask = ev_check(ds, mask, cutoff=9999)
|
181
|
-
"""
|
182
|
-
|
183
|
-
var = ds.velocity.data[3, :, :]
|
34
|
+
def ev_check(var, mask, cutoff=9999):
|
184
35
|
shape = np.shape(var)
|
185
36
|
var = abs(var)
|
186
37
|
if len(shape) == 2:
|
@@ -189,110 +40,24 @@ def ev_check(ds, mask, cutoff=9999):
|
|
189
40
|
beam = shape[2]
|
190
41
|
for i in range(beam):
|
191
42
|
mask[(var[i, :, :] >= cutoff) & (var[i, :, :] < 32768)] = 1
|
43
|
+
values, counts = np.unique(mask, return_counts=True)
|
44
|
+
# print(values, counts, np.round(counts[1] * 100 / np.sum(counts)))
|
192
45
|
return mask
|
193
46
|
|
194
47
|
|
195
|
-
def pg_check(
|
196
|
-
"""
|
197
|
-
Perform a percent-good check on the provided data and update the mask
|
198
|
-
to mark valid and invalid values based on a cutoff threshold.
|
199
|
-
|
200
|
-
Parameters
|
201
|
-
----------
|
202
|
-
ds : pyadps.dataset
|
203
|
-
The input pyadps dataframe containing percent-good data, where values range from
|
204
|
-
0 to 100 (maximum percent good).
|
205
|
-
mask : numpy.ndarray
|
206
|
-
An integer array of the same shape as `pgood`, where `1` indicates
|
207
|
-
invalid data and `0` indicates valid data.
|
208
|
-
cutoff : float, optional
|
209
|
-
The threshold value for percent good. Any value in `pgood` greater than
|
210
|
-
or equal to this cutoff will be considered valid (marked as `0`),
|
211
|
-
while values not exceeding the cutoff are marked as invalid (`1`).
|
212
|
-
Default is 0.
|
213
|
-
threebeam : bool, optional
|
214
|
-
If `True`, sums up Percent Good 1 and Percent Good 4 for the check.
|
215
|
-
|
216
|
-
Returns
|
217
|
-
-------
|
218
|
-
numpy.ndarray
|
219
|
-
An updated integer mask array of the same shape as `pgood`, with `1`
|
220
|
-
indicating invalid data and `0` indicating valid data.
|
221
|
-
|
222
|
-
Notes
|
223
|
-
-----
|
224
|
-
- The function modifies the `mask` based on the cutoff condition. Valid
|
225
|
-
values in `pgood` are marked as `0`, while invalid values are marked
|
226
|
-
as `1` in the mask.
|
227
|
-
- Ensure that `pgood` and `mask` are compatible in shape for element-wise
|
228
|
-
operations.
|
229
|
-
- If `threebeam` is `True`, the logic may be adjusted to allow partial
|
230
|
-
validity based on specific criteria.
|
231
|
-
|
232
|
-
Example
|
233
|
-
-------
|
234
|
-
>>> import pyadps
|
235
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
236
|
-
>>> outmask = pg_check(ds, mask, cutoff=50, threebeam=True)
|
237
|
-
"""
|
238
|
-
|
239
|
-
pgood = ds.percentgood.data
|
48
|
+
def pg_check(pgood, mask, cutoff=0, threebeam=True):
|
240
49
|
if threebeam:
|
241
50
|
pgood1 = pgood[0, :, :] + pgood[3, :, :]
|
242
51
|
else:
|
243
|
-
pgood1 = pgood[
|
52
|
+
pgood1 = pgood[:, :, :]
|
244
53
|
|
245
54
|
mask[pgood1[:, :] < cutoff] = 1
|
55
|
+
values, counts = np.unique(mask, return_counts=True)
|
56
|
+
# print(values, counts, np.round(counts[1] * 100 / np.sum(counts)))
|
246
57
|
return mask
|
247
58
|
|
248
59
|
|
249
|
-
def false_target(
|
250
|
-
"""
|
251
|
-
Apply a false target detection algorithm based on echo intensity values.
|
252
|
-
This function identifies invalid or false targets in the data and updates
|
253
|
-
the mask accordingly based on a specified cutoff threshold.
|
254
|
-
|
255
|
-
Parameters
|
256
|
-
----------
|
257
|
-
ds : pyadps.dataset
|
258
|
-
The input pyadps dataframe containing echo intensity values, which are used to
|
259
|
-
detect false targets.
|
260
|
-
mask : numpy.ndarray
|
261
|
-
An integer array of the same shape as `echo`, where `1` indicates
|
262
|
-
invalid or false target data and `0` indicates valid data.
|
263
|
-
cutoff : int, optional
|
264
|
-
The threshold value for echo intensity. Any value in `echo` greater
|
265
|
-
than or equal to this cutoff will be considered a false target (invalid),
|
266
|
-
marked as `1` in the mask. Default is 255.
|
267
|
-
threebeam : bool, optional
|
268
|
-
If `True`, applies a relaxed check that considers data valid even
|
269
|
-
when only three beams report valid data. Default is `True`.
|
270
|
-
|
271
|
-
Returns
|
272
|
-
-------
|
273
|
-
numpy.ndarray
|
274
|
-
An updated integer mask array of the same shape as `echo`, with `1`
|
275
|
-
indicating false target or invalid data and `0` indicating valid data.
|
276
|
-
|
277
|
-
Notes
|
278
|
-
-----
|
279
|
-
- The function modifies the `mask` by applying the cutoff condition.
|
280
|
-
Echo values greater than or equal to the cutoff are marked as false
|
281
|
-
targets (`1`), while values below the cutoff are considered valid (`0`).
|
282
|
-
- If `threebeam` is `True`, a more lenient check may be applied to handle
|
283
|
-
data with fewer valid beams.
|
284
|
-
- Ensure that `echo` and `mask` are compatible in shape for element-wise
|
285
|
-
operations.
|
286
|
-
|
287
|
-
Example
|
288
|
-
-------
|
289
|
-
>>> import pyadps
|
290
|
-
>>> ds = pyadps.Readfile('dummy.000')
|
291
|
-
>>> mask = false_target(echo, mask, cutoff=255)
|
292
|
-
"""
|
293
|
-
|
294
|
-
echo = ds.echo.data
|
295
|
-
|
60
|
+
def false_target(echo, mask, cutoff=255, threebeam=True):
|
296
61
|
shape = np.shape(echo)
|
297
62
|
for i in range(shape[1]):
|
298
63
|
for j in range(shape[2]):
|
@@ -309,49 +74,10 @@ def false_target(ds, mask, cutoff=255, threebeam=True):
|
|
309
74
|
return mask
|
310
75
|
|
311
76
|
|
312
|
-
def default_mask(
|
313
|
-
""
|
314
|
-
|
315
|
-
|
316
|
-
based on the missing values from the velocity data.
|
317
|
-
|
318
|
-
Parameters
|
319
|
-
----------
|
320
|
-
ds : pyadps.dataset or numpy.ndarray
|
321
|
-
A pyadps data frame is used to extract velocity and dimensions for the mask.
|
322
|
-
If numpy.ndarray, enter the values for beams, cells and ensembles.
|
323
|
-
|
324
|
-
Returns
|
325
|
-
-------
|
326
|
-
numpy.ndarray
|
327
|
-
A mask array of the same shape as `velocity`, where `1` indicates invalid
|
328
|
-
data and `0` indicates valid data.
|
329
|
-
|
330
|
-
Notes
|
331
|
-
-----
|
332
|
-
- The function uses the velocity data along with the information from the
|
333
|
-
Fixed Leader object to determine which values are valid and which are invalid.
|
334
|
-
|
335
|
-
Example
|
336
|
-
-------
|
337
|
-
>>> import pyadps
|
338
|
-
>>> ds = pyadps.ReadFile('demo.000')
|
339
|
-
>>> mask = pyadps.default_mask(ds)
|
340
|
-
"""
|
341
|
-
if isinstance(ds, ReadFile) or ds.__class__.__name__ == "ReadFile":
|
342
|
-
flobj = ds.fixedleader
|
343
|
-
velocity = ds.velocity.data
|
344
|
-
cells = flobj.field()["Cells"]
|
345
|
-
beams = flobj.field()["Beams"]
|
346
|
-
ensembles = flobj.ensembles
|
347
|
-
elif isinstance(ds, np.ndarray) and ds.ndim == 3:
|
348
|
-
velocity = ds
|
349
|
-
beams = ds.shape[0]
|
350
|
-
cells = ds.shape[1]
|
351
|
-
ensembles = ds.shape[2]
|
352
|
-
else:
|
353
|
-
raise ValueError("Input must be a 3-D numpy array or a PyADPS instance")
|
354
|
-
|
77
|
+
def default_mask(flobj, velocity):
|
78
|
+
cells = flobj.field()["Cells"]
|
79
|
+
beams = flobj.field()["Beams"]
|
80
|
+
ensembles = flobj.ensembles
|
355
81
|
mask = np.zeros((cells, ensembles))
|
356
82
|
# Ignore mask for error velocity
|
357
83
|
for i in range(beams - 1):
|
@@ -359,53 +85,7 @@ def default_mask(ds):
|
|
359
85
|
return mask
|
360
86
|
|
361
87
|
|
362
|
-
def qc_prompt(
|
363
|
-
"""
|
364
|
-
Prompt the user to confirm or adjust the quality control threshold for a specific
|
365
|
-
parameter based on predefined ranges. The function provides an interactive interface
|
366
|
-
for the user to adjust thresholds for various quality control criteria, with options
|
367
|
-
for certain thresholds like "Echo Intensity Thresh" to check the noise floor.
|
368
|
-
|
369
|
-
Parameters
|
370
|
-
----------
|
371
|
-
flobj : FixedLeader
|
372
|
-
An instance of the FixedLeader class that holds metadata and configuration
|
373
|
-
data. The `flobj` is used to retrieve the current threshold values based on
|
374
|
-
the provided parameter name.
|
375
|
-
name : str
|
376
|
-
The name of the parameter for which the threshold is being adjusted. Examples
|
377
|
-
include "Echo Intensity Thresh", "Correlation Thresh", "Percent Good Min", etc.
|
378
|
-
data : numpy.ndarray, optional
|
379
|
-
The data associated with the threshold. This is required for parameters like
|
380
|
-
"Echo Intensity Thresh" where a noise floor check might be performed. Default is None.
|
381
|
-
|
382
|
-
Returns
|
383
|
-
-------
|
384
|
-
int
|
385
|
-
The updated threshold value, either the default or the new value entered by the user.
|
386
|
-
|
387
|
-
Notes
|
388
|
-
-----
|
389
|
-
- The function will prompt the user to change the threshold for the given `name` parameter.
|
390
|
-
- For certain parameters, the user may be asked if they would like to check the noise floor
|
391
|
-
(for example, for "Echo Intensity Thresh"). This triggers the display of a plot and lets
|
392
|
-
the user select a new threshold.
|
393
|
-
- The function ensures that the new threshold is within the acceptable range for each parameter.
|
394
|
-
- The default thresholds are provided if the user chooses not to change them.
|
395
|
-
|
396
|
-
Example
|
397
|
-
-------
|
398
|
-
>>> import pyadps
|
399
|
-
>>> ds = pyadps.ReadFile('demo.000')
|
400
|
-
>>> name = "Echo Intensity Thresh"
|
401
|
-
>>> threshold = qc_prompt(ds, name, data)
|
402
|
-
The default threshold for echo intensity thresh is 0
|
403
|
-
Would you like to change the threshold [y/n]: y
|
404
|
-
Would you like to check the noise floor [y/n]: y
|
405
|
-
Threshold changed to 50
|
406
|
-
"""
|
407
|
-
|
408
|
-
flobj = ds.fixedleader
|
88
|
+
def qc_prompt(flobj, name, data=None):
|
409
89
|
cutoff = 0
|
410
90
|
if name == "Echo Intensity Thresh":
|
411
91
|
cutoff = 0
|
pyadps/utils/velocity_test.py
CHANGED
@@ -1,106 +1,28 @@
|
|
1
1
|
from itertools import groupby
|
2
|
-
from pygeomag import GeoMag
|
3
2
|
|
4
|
-
import requests
|
5
3
|
import numpy as np
|
6
4
|
import scipy as sp
|
5
|
+
import wmm2020
|
7
6
|
|
8
7
|
|
9
|
-
def
|
10
|
-
# Selecting COF file According to given year
|
11
|
-
if time >= 2010 and time < 2030:
|
12
|
-
var = 2010 + (int(time) - 2010) // 5 * 5
|
13
|
-
file_name = "wmm/WMM_{}.COF".format(str(var))
|
14
|
-
geo_mag = GeoMag(coefficients_file=file_name)
|
15
|
-
else:
|
16
|
-
geo_mag = GeoMag("wmm/WMM_2025.COF")
|
17
|
-
result = geo_mag.calculate(glat=glat, glon=glon, alt=alt, time=time)
|
18
|
-
|
19
|
-
return [[result.d]]
|
20
|
-
|
21
|
-
|
22
|
-
def wmm2020api(lat1, lon1, year):
|
23
|
-
"""
|
24
|
-
This function uses the WMM2020 API to retrieve the magnetic field values at a given location
|
25
|
-
The API need latitude, longitude and year to perform the calculation. The key in the function
|
26
|
-
must be updated time to time since the API is subjected to timely updates and the key may change.
|
27
|
-
|
28
|
-
Args:
|
29
|
-
Latitude (float)
|
30
|
-
Longitude (float)
|
31
|
-
startYear (int)
|
32
|
-
|
33
|
-
Returns:
|
34
|
-
mag -> magnetic declination at the given location in degree.
|
35
|
-
"""
|
36
|
-
baseurl_wmm = (
|
37
|
-
"https://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination?"
|
38
|
-
)
|
39
|
-
baseurl_igrf = (
|
40
|
-
"https://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination?"
|
41
|
-
)
|
42
|
-
baseurl_emm = "https://emmcalc.geomag.info/?magneticcomponent=d&"
|
43
|
-
key = "zNEw7"
|
44
|
-
resultFormat = "json"
|
45
|
-
if year >= 2025:
|
46
|
-
baseurl = baseurl_wmm
|
47
|
-
model = "WMM"
|
48
|
-
elif year >= 2019:
|
49
|
-
baseurl = baseurl_wmm
|
50
|
-
model = "IGRF"
|
51
|
-
elif year >= 2000:
|
52
|
-
baseurl = baseurl_emm
|
53
|
-
model = "EMM"
|
54
|
-
elif year >= 1590:
|
55
|
-
baseurl = baseurl_igrf
|
56
|
-
model = "IGRF"
|
57
|
-
url = "{}model={}&lat1={}&lon1={}&key={}&startYear={}&resultFormat={}".format(
|
58
|
-
baseurl, model, lat1, lon1, key, year, resultFormat
|
59
|
-
)
|
60
|
-
response = requests.get(url)
|
61
|
-
data = response.json()
|
62
|
-
results = data["result"][0]
|
63
|
-
mag = [[results["declination"]]]
|
64
|
-
|
65
|
-
return mag
|
66
|
-
|
67
|
-
|
68
|
-
# Commentin magnetic_declination model since the method is no longer using.
|
69
|
-
# def magnetic_declination(lat, lon, depth, year):
|
70
|
-
# """
|
71
|
-
# The function calculates the magnetic declination at a given location and depth.
|
72
|
-
# using a local installation of wmm2020 model.
|
73
|
-
|
74
|
-
|
75
|
-
# Args:
|
76
|
-
# lat (parameter, float): Latitude in decimals
|
77
|
-
# lon (parameter, float): Longitude in decimals
|
78
|
-
# depth (parameter, float): depth in m
|
79
|
-
# year (parameter, integer): Year
|
80
|
-
|
81
|
-
# Returns:
|
82
|
-
# mag: Magnetic declination (degrees)
|
83
|
-
# """
|
84
|
-
# import wmm2020
|
85
|
-
# mag = wmm2020.wmm(lat, lon, depth, year)
|
86
|
-
# mag = mag.decl.data
|
87
|
-
|
88
|
-
# return mag
|
89
|
-
|
90
|
-
|
91
|
-
def velocity_modifier(velocity, mag):
|
8
|
+
def magnetic_declination(velocity, lat, lon, depth, year):
|
92
9
|
"""
|
93
10
|
The function uses magnetic declination from wmm2020 to correct
|
94
11
|
the horizontal velocities
|
95
12
|
|
96
13
|
Args:
|
97
|
-
|
98
|
-
|
14
|
+
velocity (numpy array): velocity(beam, depth, time)
|
15
|
+
lat (parameter, float): Latitude in decimals
|
16
|
+
lon (parameter, float): Longitude in decimals
|
17
|
+
depth (parameter, float): depth in m
|
18
|
+
year (parameter, integer): Year
|
99
19
|
|
100
20
|
Returns:
|
101
21
|
velocity (numpy array): Rotated velocity using magnetic declination
|
22
|
+
mag: Magnetic declination (degrees)
|
102
23
|
"""
|
103
|
-
mag =
|
24
|
+
mag = wmm2020.wmm(lat, lon, depth, year)
|
25
|
+
mag = np.deg2rad(mag.decl.data)
|
104
26
|
velocity = np.where(velocity == -32768, np.nan, velocity)
|
105
27
|
velocity[0, :, :] = velocity[0, :, :] * np.cos(mag) + velocity[1, :, :] * np.sin(
|
106
28
|
mag
|
@@ -110,7 +32,7 @@ def velocity_modifier(velocity, mag):
|
|
110
32
|
] * np.cos(mag)
|
111
33
|
velocity = np.where(velocity == np.nan, -32768, velocity)
|
112
34
|
|
113
|
-
return velocity
|
35
|
+
return velocity, np.rad2deg(mag)
|
114
36
|
|
115
37
|
|
116
38
|
def velocity_cutoff(velocity, mask, cutoff=250):
|
@@ -132,7 +54,7 @@ def velocity_cutoff(velocity, mask, cutoff=250):
|
|
132
54
|
return mask
|
133
55
|
|
134
56
|
|
135
|
-
def despike(velocity, mask, kernal_size=13, cutoff=
|
57
|
+
def despike(velocity, mask, kernal_size=13, cutoff=150):
|
136
58
|
"""
|
137
59
|
Function to remove anomalous spikes in the data over a period of time.
|
138
60
|
A median filter is used to despike the data.
|
@@ -140,24 +62,19 @@ def despike(velocity, mask, kernal_size=13, cutoff=3):
|
|
140
62
|
Args:
|
141
63
|
velocity (numpy array, integer): Velocity(depth, time) in mm/s
|
142
64
|
mask (numpy array, integer): Mask file
|
143
|
-
kernal_size (paramater, integer):
|
144
|
-
cutoff (parameter, integer):
|
65
|
+
kernal_size (paramater, integer): Number of ensembles over which the spike has to be checked
|
66
|
+
cutoff (parameter, integer): [TODO:description]
|
145
67
|
|
146
68
|
Returns:
|
147
69
|
mask
|
148
70
|
"""
|
71
|
+
cutoff = cutoff * 10
|
149
72
|
velocity = np.where(velocity == -32768, np.nan, velocity)
|
150
73
|
shape = np.shape(velocity)
|
151
74
|
for j in range(shape[0]):
|
152
|
-
# Apply median filter
|
153
75
|
filt = sp.signal.medfilt(velocity[j, :], kernal_size)
|
154
|
-
# Calculate absolute deviation from the rolling median
|
155
76
|
diff = np.abs(velocity[j, :] - filt)
|
156
|
-
|
157
|
-
std_dev = np.nanstd(diff)
|
158
|
-
spike_threshold = cutoff * std_dev
|
159
|
-
# Apply mask after identifying spikes
|
160
|
-
mask[j, :] = np.where(diff < spike_threshold, mask[j, :], 1)
|
77
|
+
mask[j, :] = np.where(diff < cutoff, mask[j, :], 1)
|
161
78
|
return mask
|
162
79
|
|
163
80
|
|