pyadps 0.1.1__py3-none-any.whl → 0.2.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.
Files changed (48) hide show
  1. pyadps/Home_Page.py +5 -11
  2. pyadps/pages/01_Read_File.py +17 -190
  3. pyadps/pages/02_View_Raw_Data.py +33 -69
  4. pyadps/pages/03_Download_Raw_File.py +61 -149
  5. pyadps/pages/04_QC_Test.py +334 -0
  6. pyadps/pages/05_Profile_Test.py +575 -0
  7. pyadps/pages/06_Velocity_Test.py +341 -0
  8. pyadps/pages/07_Write_File.py +452 -0
  9. pyadps/utils/__init__.py +3 -3
  10. pyadps/utils/autoprocess.py +78 -344
  11. pyadps/utils/cutbin.py +413 -0
  12. pyadps/utils/metadata/config.ini +4 -22
  13. pyadps/utils/plotgen.py +3 -505
  14. pyadps/utils/profile_test.py +125 -494
  15. pyadps/utils/pyreadrdi.py +17 -27
  16. pyadps/utils/readrdi.py +18 -164
  17. pyadps/utils/{__pycache__/regrid.cpython-312.pyc → regrid.py} +0 -0
  18. pyadps/utils/script.py +147 -197
  19. pyadps/utils/signal_quality.py +24 -344
  20. pyadps/utils/velocity_test.py +31 -79
  21. pyadps/utils/writenc.py +21 -155
  22. {pyadps-0.1.1.dist-info → pyadps-0.2.0b0.dist-info}/METADATA +24 -55
  23. pyadps-0.2.0b0.dist-info/RECORD +31 -0
  24. {pyadps-0.1.1.dist-info → pyadps-0.2.0b0.dist-info}/WHEEL +1 -1
  25. {pyadps-0.1.1.dist-info → pyadps-0.2.0b0.dist-info}/entry_points.txt +0 -1
  26. pyadps/pages/04_Sensor_Health.py +0 -905
  27. pyadps/pages/05_QC_Test.py +0 -476
  28. pyadps/pages/06_Profile_Test.py +0 -971
  29. pyadps/pages/07_Velocity_Test.py +0 -600
  30. pyadps/pages/08_Write_File.py +0 -587
  31. pyadps/pages/09_Auto_process.py +0 -64
  32. pyadps/pages/__pycache__/__init__.cpython-312.pyc +0 -0
  33. pyadps/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  34. pyadps/utils/__pycache__/autoprocess.cpython-312.pyc +0 -0
  35. pyadps/utils/__pycache__/cutbin.cpython-312.pyc +0 -0
  36. pyadps/utils/__pycache__/plotgen.cpython-312.pyc +0 -0
  37. pyadps/utils/__pycache__/profile_test.cpython-312.pyc +0 -0
  38. pyadps/utils/__pycache__/pyreadrdi.cpython-312.pyc +0 -0
  39. pyadps/utils/__pycache__/readrdi.cpython-312.pyc +0 -0
  40. pyadps/utils/__pycache__/script.cpython-312.pyc +0 -0
  41. pyadps/utils/__pycache__/sensor_health.cpython-312.pyc +0 -0
  42. pyadps/utils/__pycache__/signal_quality.cpython-312.pyc +0 -0
  43. pyadps/utils/__pycache__/velocity_test.cpython-312.pyc +0 -0
  44. pyadps/utils/__pycache__/writenc.cpython-312.pyc +0 -0
  45. pyadps/utils/metadata/demo.000 +0 -0
  46. pyadps/utils/sensor_health.py +0 -120
  47. pyadps-0.1.1.dist-info/RECORD +0 -47
  48. {pyadps-0.1.1.dist-info → pyadps-0.2.0b0.dist-info}/LICENSE +0 -0
@@ -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
- Perform a quality control check on the provided data and update the mask
9
- based on a cutoff threshold. Values in `var` that are less than the cutoff
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
- Parameters
13
- ----------
14
- var : numpy.ndarray
15
- The input array containing data to be checked against the cutoff.
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
- # values, counts = np.unique(mask, return_counts=True)
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
- def correlation_check(ds, mask, cutoff=64):
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
- Example
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(ds, mask, cutoff=0, threebeam=True):
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[3, :, :]
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(ds, mask, cutoff=255, threebeam=True):
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(ds):
313
- """
314
- Create a default 2-D mask file based on the velocity data.
315
- This function generates a mask where values are marked as valid or invalid
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(ds, name, data=None):
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
@@ -1,24 +1,9 @@
1
1
  from itertools import groupby
2
- from pygeomag import GeoMag
3
2
 
4
3
  import requests
5
4
  import numpy as np
6
5
  import scipy as sp
7
6
 
8
-
9
- def magdec(glat, glon, alt, time):
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
7
  def wmm2020api(lat1, lon1, year):
23
8
  """
24
9
  This function uses the WMM2020 API to retrieve the magnetic field values at a given location
@@ -33,60 +18,37 @@ def wmm2020api(lat1, lon1, year):
33
18
  Returns:
34
19
  mag -> magnetic declination at the given location in degree.
35
20
  """
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&"
21
+ baseurl = "https://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination?"
43
22
  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
- )
23
+ resultFormat="json"
24
+ url = "{}lat1={}&lon1={}&key={}&startYear{}&resultFormat={}".format(baseurl, lat1, lon1, key, year, resultFormat)
60
25
  response = requests.get(url)
61
26
  data = response.json()
62
27
  results = data["result"][0]
63
28
  mag = [[results["declination"]]]
64
-
29
+
65
30
  return mag
66
31
 
32
+ def magnetic_declination(lat, lon, depth, year):
33
+ """
34
+ The function calculates the magnetic declination at a given location and depth.
35
+ using a local installation of wmm2020 model.
67
36
 
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
37
 
81
- # Returns:
82
- # mag: Magnetic declination (degrees)
83
- # """
84
- # import wmm2020
85
- # mag = wmm2020.wmm(lat, lon, depth, year)
86
- # mag = mag.decl.data
38
+ Args:
39
+ lat (parameter, float): Latitude in decimals
40
+ lon (parameter, float): Longitude in decimals
41
+ depth (parameter, float): depth in m
42
+ year (parameter, integer): Year
87
43
 
88
- # return mag
44
+ Returns:
45
+ mag: Magnetic declination (degrees)
46
+ """
47
+ import wmm2020
48
+ mag = wmm2020.wmm(lat, lon, depth, year)
49
+ mag = mag.decl.data
89
50
 
51
+ return mag
90
52
 
91
53
  def velocity_modifier(velocity, mag):
92
54
  """
@@ -102,17 +64,12 @@ def velocity_modifier(velocity, mag):
102
64
  """
103
65
  mag = np.deg2rad(mag[0][0])
104
66
  velocity = np.where(velocity == -32768, np.nan, velocity)
105
- velocity[0, :, :] = velocity[0, :, :] * np.cos(mag) + velocity[1, :, :] * np.sin(
106
- mag
107
- )
108
- velocity[1, :, :] = -1 * velocity[0, :, :] * np.sin(mag) + velocity[
109
- 1, :, :
110
- ] * np.cos(mag)
67
+ velocity[0, :, :] = velocity[0, :, :] * np.cos(mag) + velocity[1, :, :] * np.sin(mag)
68
+ velocity[1, :, :] = -1 * velocity[0, :, :] * np.sin(mag) + velocity[1, :, :] * np.cos(mag)
111
69
  velocity = np.where(velocity == np.nan, -32768, velocity)
112
70
 
113
71
  return velocity
114
72
 
115
-
116
73
  def velocity_cutoff(velocity, mask, cutoff=250):
117
74
  """
118
75
  Masks all velocities above a cutoff. Note that
@@ -132,7 +89,7 @@ def velocity_cutoff(velocity, mask, cutoff=250):
132
89
  return mask
133
90
 
134
91
 
135
- def despike(velocity, mask, kernel_size=13, cutoff=3):
92
+ def despike(velocity, mask, kernal_size=13, cutoff=150):
136
93
  """
137
94
  Function to remove anomalous spikes in the data over a period of time.
138
95
  A median filter is used to despike the data.
@@ -140,31 +97,26 @@ def despike(velocity, mask, kernel_size=13, cutoff=3):
140
97
  Args:
141
98
  velocity (numpy array, integer): Velocity(depth, time) in mm/s
142
99
  mask (numpy array, integer): Mask file
143
- kernel_size (paramater, integer): Window size for rolling median filter
144
- cutoff (parameter, integer): Number of standard deviations to identify spikes
100
+ kernal_size (paramater, integer): Number of ensembles over which the spike has to be checked
101
+ cutoff (parameter, integer): [TODO:description]
145
102
 
146
103
  Returns:
147
104
  mask
148
105
  """
106
+ cutoff = cutoff * 10
149
107
  velocity = np.where(velocity == -32768, np.nan, velocity)
150
108
  shape = np.shape(velocity)
151
109
  for j in range(shape[0]):
152
- # Apply median filter
153
- filt = sp.signal.medfilt(velocity[j, :], kernel_size)
154
- # Calculate absolute deviation from the rolling median
110
+ filt = sp.signal.medfilt(velocity[j, :], kernal_size)
155
111
  diff = np.abs(velocity[j, :] - filt)
156
- # Calculate threshold for spikes based on standard deviation
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)
112
+ mask[j, :] = np.where(diff < cutoff, mask[j, :], 1)
161
113
  return mask
162
114
 
163
115
 
164
116
  def flatline(
165
117
  velocity,
166
118
  mask,
167
- kernel_size=4,
119
+ kernal_size=4,
168
120
  cutoff=1,
169
121
  ):
170
122
  """
@@ -174,7 +126,7 @@ def flatline(
174
126
  Args:
175
127
  velocity (numpy arrray, integer): Velocity (depth, time)
176
128
  mask (numpy array, integer): Mask file
177
- kernel_size (parameter, integer): No. of ensembles over which flatline has to be detected
129
+ kernal_size (parameter, integer): No. of ensembles over which flatline has to be detected
178
130
  cutoff (parameter, integer): Permitted deviation in velocity
179
131
 
180
132
  Returns:
@@ -191,7 +143,7 @@ def flatline(
191
143
  for k, g in groupby(dummymask):
192
144
  # subset_size = sum(1 for i in g)
193
145
  subset_size = len(list(g))
194
- if k == 1 and subset_size >= kernel_size:
146
+ if k == 1 and subset_size >= kernal_size:
195
147
  mask[j, index : index + subset_size] = 1
196
148
  index = index + subset_size
197
149
  dummymask = np.zeros(shape[1])