pyadps 0.2.1b0__py3-none-any.whl → 0.3.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.
@@ -5,20 +5,22 @@ import numpy as np
5
5
  import pandas as pd
6
6
  import pyadps.utils.writenc as wr
7
7
  from pyadps.utils import readrdi
8
- from pyadps.utils.profile_test import side_lobe_beam_angle
9
- from pyadps.utils.regrid import regrid2d, regrid3d
8
+ from pyadps.utils.profile_test import side_lobe_beam_angle,manual_cut_bins
9
+ from pyadps.utils.profile_test import regrid2d, regrid3d
10
10
  from pyadps.utils.signal_quality import (
11
11
  default_mask,
12
12
  ev_check,
13
13
  false_target,
14
14
  pg_check,
15
- qc_check,
15
+ echo_check,
16
+ correlation_check
16
17
  )
17
18
  from pyadps.utils.velocity_test import (
18
19
  despike,
19
20
  flatline,
20
- magnetic_declination,
21
21
  velocity_cutoff,
22
+ wmm2020api,
23
+ velocity_modifier
22
24
  )
23
25
 
24
26
  def main():
@@ -29,16 +31,32 @@ def main():
29
31
  autoprocess(filepath)
30
32
  else:
31
33
  print("File not found!")
32
- except:
34
+ except Exception as e:
35
+ import traceback
33
36
  print("Error: Unable to process the data.")
37
+ traceback.print_exc()
34
38
 
35
- def autoprocess(filepath):
39
+ def autoprocess(config_file,binary_file_path=None):
40
+ # Load configuration
36
41
  config = configparser.ConfigParser()
37
- config.read(filepath)
38
- input_file_name = config.get("FileSettings", "input_file_name")
39
- input_file_path = config.get("FileSettings", "input_file_path")
40
42
 
41
- full_input_file_path = os.path.join(input_file_path, input_file_name)
43
+ # Decode and parse the config file
44
+ # Check if config_file is a file-like object or a file path
45
+ if hasattr(config_file, 'read'):
46
+ # If it's a file-like object, read its content
47
+ config_content = config_file.read().decode("utf-8")
48
+ else:
49
+ # If it's a file path, open the file and read its content
50
+ with open(config_file, 'r', encoding="utf-8") as file:
51
+ config_content = file.read()
52
+ config.read_string(config_content)
53
+
54
+ if not binary_file_path:
55
+ input_file_name = config.get("FileSettings", "input_file_name")
56
+ input_file_path = config.get("FileSettings", "input_file_path")
57
+ full_input_file_path = os.path.join(input_file_path, input_file_name)
58
+ else:
59
+ full_input_file_path = binary_file_path
42
60
 
43
61
  print("File reading started. Please wait for a few seconds ...")
44
62
  ds = readrdi.ReadFile(full_input_file_path)
@@ -55,13 +73,19 @@ def autoprocess(filepath):
55
73
  cells = flobj.field()["Cells"]
56
74
  fdata = flobj.fleader
57
75
  vdata = vlobj.vleader
76
+ # depth = ds.variableleader.depth_of_transducer
58
77
 
59
- mask = default_mask(flobj, velocity)
60
- print("Default Mask created.")
78
+ # Initialize mask
79
+ mask = default_mask(ds)
80
+
81
+ # Debugging statement
61
82
  x = np.arange(0, ensembles, 1)
62
83
  y = np.arange(0, cells, 1)
63
84
  depth = None
64
85
 
86
+ axis_option = config.get("DownloadOptions","axis_option")
87
+
88
+
65
89
  # QC Test
66
90
  isQCTest = config.getboolean("QCTest", "qc_test")
67
91
 
@@ -72,14 +96,15 @@ def autoprocess(filepath):
72
96
  ft = config.getint("QCTest", "false_target")
73
97
  is3Beam = config.getboolean("QCTest", "three_beam")
74
98
  pgt = config.getint("QCTest", "percentage_good")
99
+ orientation = config.get("QCTest", "orientation")
75
100
 
76
- mask = pg_check(pgood, mask, pgt, threebeam=is3Beam)
77
- mask = qc_check(correlation, mask, ct)
78
- mask = qc_check(echo, mask, et)
79
- mask = ev_check(velocity[3, :, :], mask, evt)
80
- mask = false_target(echo, mask, ft, threebeam=True)
81
- print("QC Test complete.")
101
+ mask = pg_check(ds, mask, pgt, threebeam=is3Beam)
102
+ mask = correlation_check(ds, mask, ct)
103
+ mask = echo_check(ds, mask, et)
104
+ mask = ev_check(ds, mask, evt)
105
+ mask = false_target(ds, mask, ft, threebeam=True)
82
106
 
107
+ # Profile Test
83
108
  endpoints = None
84
109
  isProfileTest = config.getboolean("ProfileTest", "profile_test")
85
110
  if isProfileTest:
@@ -87,8 +112,6 @@ def autoprocess(filepath):
87
112
  if isTrimEnds:
88
113
  start_index = config.getint("ProfileTest", "trim_ends_start_index")
89
114
  end_index = config.getint("ProfileTest", "trim_ends_end_index")
90
- # if start_index < 0 or start_index > ensembles:
91
-
92
115
  if start_index > 0:
93
116
  mask[:, :start_index] = 1
94
117
 
@@ -101,29 +124,69 @@ def autoprocess(filepath):
101
124
 
102
125
  isCutBins = config.getboolean("ProfileTest", "cut_bins")
103
126
  if isCutBins:
127
+ water_column_depth = 0
104
128
  add_cells = config.getint("ProfileTest", "cut_bins_add_cells")
105
- mask = side_lobe_beam_angle(flobj, vlobj, mask, extra_cells=add_cells)
129
+ if orientation == "down":
130
+ water_column_depth = config.get("ProfileTest", "water_column_depth")
131
+ water_column_depth = int(water_column_depth)
132
+ mask = side_lobe_beam_angle(
133
+ ds,
134
+ mask,
135
+ orientation=orientation,
136
+ water_column_depth=water_column_depth,
137
+ extra_cells=add_cells
138
+ )
139
+ else :
140
+ mask = side_lobe_beam_angle(
141
+ ds,
142
+ mask,
143
+ orientation=orientation,
144
+ water_column_depth=water_column_depth,
145
+ extra_cells=add_cells
146
+ )
106
147
 
107
148
  print("Cutbins complete.")
108
149
 
150
+ #Manual Cut Bins
151
+ isManual_cutbins = config.getboolean("ProfileTest", "manual_cutbins")
152
+ if isManual_cutbins:
153
+ raw_bins = config.get("ProfileTest", "manual_cut_bins")
154
+ bin_groups = raw_bins.split("]")
155
+
156
+ for group in bin_groups:
157
+ if group.strip(): # Ignore empty parts
158
+ # Clean and split the values
159
+ clean_group = group.replace("[", "").strip()
160
+ values = list(map(int, clean_group.split(",")))
161
+ min_cell, max_cell, min_ensemble, max_ensemble = values
162
+ mask = manual_cut_bins(mask, min_cell, max_cell, min_ensemble, max_ensemble)
163
+
164
+ print("Manual cut bins applied.")
165
+
166
+
109
167
  isRegrid = config.getboolean("ProfileTest", "regrid")
110
168
  if isRegrid:
111
169
  print("File regridding started. This will take a few seconds ...")
170
+
112
171
  regrid_option = config.get("ProfileTest", "regrid_option")
113
- z, velocity = regrid3d(
114
- flobj,
115
- vlobj,
116
- velocity,
117
- -32768,
118
- trimends=endpoints,
119
- )
120
- z, echo = regrid3d(flobj, vlobj, echo, -32768, trimends=endpoints)
121
- z, correlation = regrid3d(
122
- flobj, vlobj, correlation, -32768, trimends=endpoints
123
- )
124
- z, pgood = regrid3d(flobj, vlobj, pgood, -32768, trimends=endpoints)
125
- z, mask = regrid2d(flobj, vlobj, mask, 1, trimends=endpoints)
126
- depth = z
172
+ interpolate = config.get("ProfileTest", "regrid_interpolation")
173
+ boundary = 0
174
+ if regrid_option == "Manual":
175
+ boundary = config.get("ProfileTest","transducer_depth")
176
+ z, velocity = regrid3d(ds,velocity, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
177
+ z, echo = regrid3d(ds,echo, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
178
+ z, correlation = regrid3d(ds,correlation, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
179
+ z, pgood = regrid3d(ds,pgood, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
180
+ z, mask = regrid2d(ds,mask, 1,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
181
+ depth = z
182
+ else :
183
+ z, velocity = regrid3d(ds,velocity, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
184
+ z, echo = regrid3d(ds,echo, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
185
+ z, correlation = regrid3d(ds,correlation, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
186
+ z, pgood = regrid3d(ds,pgood, -32768,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
187
+ z, mask = regrid2d(ds,mask, 1,trimends=endpoints,orientation=orientation,method=interpolate,boundary_limit=boundary)
188
+ depth = z
189
+
127
190
  print("Regrid Complete.")
128
191
 
129
192
  print("Profile Test complete.")
@@ -138,12 +201,15 @@ def autoprocess(filepath):
138
201
  maglon = config.getfloat("VelocityTest", "longitude")
139
202
  magdep = config.getfloat("VelocityTest", "depth")
140
203
  magyear = config.getfloat("VelocityTest", "year")
204
+ year = int(magyear)
205
+ # mag = config.getfloat("VelocityTest", "mag")
141
206
 
142
- velocity, mag = magnetic_declination(
143
- velocity, maglat, maglon, magdep, magyear
144
- )
145
- print(f"Magnetic Declination applied. The value is {mag[0]} degrees.")
146
207
 
208
+ mag = wmm2020api(
209
+ maglat, maglon, year
210
+ )
211
+ velocity = velocity_modifier(velocity,mag)
212
+ print(f"Magnetic Declination applied. The value is {mag[0]} degrees.")
147
213
  isCutOff = config.getboolean("VelocityTest", "cutoff")
148
214
  if isCutOff:
149
215
  maxu = config.getint("VelocityTest", "max_zonal_velocity")
@@ -196,6 +262,7 @@ def autoprocess(filepath):
196
262
  kernal_size=despike_kernal,
197
263
  cutoff=despike_cutoff,
198
264
  )
265
+
199
266
  print("Flatlines in velocity removed.")
200
267
 
201
268
  print("Velocity Test complete.")
@@ -239,14 +306,13 @@ def autoprocess(filepath):
239
306
  }
240
307
  )
241
308
 
242
- date = pd.to_datetime(date_df)
309
+ date_raw = pd.to_datetime(date_df)
310
+ date_vlead = pd.to_datetime(date_df)
311
+ date_final = pd.to_datetime(date_df)
243
312
 
244
313
  print("Time axis created.")
245
314
 
246
- isWriteRawNC = config.get("DownloadOptions", "download_raw")
247
- isWriteProcNC = config.get("DownloadOptions", "download_processed")
248
315
  isAttributes = config.get("Optional", "attributes")
249
-
250
316
  if isAttributes:
251
317
  attributes = [att for att in config["Optional"]]
252
318
  attributes = dict(config["Optional"].items())
@@ -254,15 +320,31 @@ def autoprocess(filepath):
254
320
  else:
255
321
  attributes = None
256
322
 
323
+ isWriteRawNC = config.get("DownloadOptions", "download_raw")
324
+ isWriteVleadNC = config.get("DownloadOptions", "download_vlead")
325
+ isWriteProcNC = config.get("DownloadOptions", "download_processed")
326
+
257
327
  if isWriteRawNC:
258
328
  filepath = config.get("FileSettings", "output_file_path")
259
329
  filename = config.get("FileSettings", "output_file_name_raw")
260
330
  output_file_path = os.path.join(filepath, filename)
261
331
  if isAttributes:
262
- wr.rawnc(full_input_file_path, output_file_path, attributes=attributes)
332
+ wr.rawnc(full_input_file_path, output_file_path, date_raw, axis_option, attributes, isAttributes)
263
333
 
264
334
  print("Raw file written.")
265
335
 
336
+ if isWriteVleadNC:
337
+ filepath = config.get("FileSettings", "output_file_path")
338
+ filename = config.get("FileSettings", "output_file_name_vlead")
339
+ output_file_path = os.path.join(filepath, filename)
340
+ if isAttributes:
341
+ wr.vlead_nc(full_input_file_path, output_file_path, date_vlead, axis_option, attributes, isAttributes)
342
+
343
+ print("Vlead file written.")
344
+
345
+
346
+ depth1 = depth
347
+
266
348
  if isWriteProcNC:
267
349
  filepath = config.get("FileSettings", "output_file_path")
268
350
  filename = config.get("FileSettings", "output_file_name_processed")
@@ -270,8 +352,9 @@ def autoprocess(filepath):
270
352
 
271
353
  wr.finalnc(
272
354
  full_file_path,
273
- depth,
274
- date,
355
+ depth1,
356
+ mask,
357
+ date_final,
275
358
  velocity,
276
359
  attributes=attributes, # Pass edited attributes
277
360
  )
@@ -4,8 +4,9 @@ input_file_path = /home/user/data/
4
4
  input_file_name = adcp_raw.000
5
5
 
6
6
  # Output file settings. Do not enter file extension.
7
- output_file_path = /home/user/output/
7
+ output_file_path = /home/nio/Videos/output/
8
8
  output_file_name_raw = adcp_raw.nc
9
+ output_file_name_vlead = adcp_vlead.nc
9
10
  output_file_name_processed = adcp_proc.nc
10
11
 
11
12
  # Choose between 'netcdf' or 'csv' for the raw output format
@@ -16,11 +17,18 @@ output_format_processed = csv
16
17
 
17
18
  [DownloadOptions]
18
19
  # Options to download raw and/or processed output files
20
+ axis_option = ensemble
19
21
  download_raw = True
22
+ download_vlead = True
20
23
  download_processed = True
21
24
  apply_mask = True
22
25
  download_mask = True
23
26
 
27
+ [SensorTest]
28
+ sensor_test = True
29
+ transducer_depth = 200
30
+
31
+
24
32
  [QCTest]
25
33
  # Enable or Disable QC Test (True/False)
26
34
  qc_test = True
@@ -30,6 +38,8 @@ echo_intensity = 40
30
38
  false_target = 50
31
39
  three_beam = True
32
40
  percentage_good = 50
41
+ orientation = up
42
+
33
43
 
34
44
  [ProfileTest]
35
45
  # Enable or Disable Profile Test (True/False)
@@ -39,17 +49,22 @@ trim_ends_start_index = 2
39
49
  trim_ends_end_index = 17086
40
50
  cut_bins = True
41
51
  cut_bins_add_cells = 2
52
+ manual_cutbins = True
53
+ manual_cut_bins = [2,10,0,8000] [40,42,0,8000] [12,14,0,8000]
42
54
  regrid = True
43
- regrid_option = Bin
55
+ regrid_option = Cell
56
+ regrid_interpolation = nearest
57
+ transducer_depth = 200
58
+ water_column_depth = 200
44
59
 
45
60
  [VelocityTest]
46
61
  # Enable or Disable Velocity Test (True/False)
47
62
  velocity_test = True
48
63
  magnetic_declination = True
49
64
  latitude = 0.0
50
- longitude = 0.1
65
+ longitude = 83.0
51
66
  depth = 0
52
- year = 2024
67
+ year = 2025
53
68
  cutoff = True
54
69
  max_zonal_velocity = 250
55
70
  max_meridional_velocity = 250
@@ -79,3 +94,6 @@ file_created_by = xxxx
79
94
  contact = abcd
80
95
  comments = No comments
81
96
 
97
+
98
+
99
+
Binary file