pyadps 0.2.1b0__py3-none-any.whl → 0.3.1b0__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.
@@ -26,10 +26,19 @@ if "vleadfilename" not in st.session_state:
26
26
  if "attributes" not in st.session_state:
27
27
  st.session_state.attributes = {}
28
28
 
29
- if st.session_state.isVelocityMask:
29
+ if st.session_state.isVelocityTest:
30
30
  st.session_state.final_mask = st.session_state.velocity_mask
31
- st.session_state.final_velocity = st.session_state.veltest_velocity
32
- if st.session_state.isGridSave:
31
+
32
+ if st.session_state.isVelocityModifiedMagnet:
33
+ st.session_state.final_velocity = st.session_state.velocity_magnet
34
+ if st.session_state.isRegridCheck:
35
+ st.session_state.final_velocity = st.session_state.velocity_regrid
36
+ elif st.session_state.isVelocityModifiedSound:
37
+ st.session_state.final_velocity = st.session_state.velocity_sensor
38
+ else:
39
+ st.session_state.final_velocity = st.session_state.velocity
40
+
41
+ if st.session_state.isRegridCheck:
33
42
  st.session_state.final_echo = st.session_state.echo_regrid
34
43
  st.session_state.final_correlation = st.session_state.correlation_regrid
35
44
  st.session_state.final_pgood = st.session_state.pgood_regrid
@@ -38,17 +47,19 @@ if st.session_state.isVelocityMask:
38
47
  st.session_state.final_correlation = st.session_state.correlation
39
48
  st.session_state.final_pgood = st.session_state.pgood
40
49
  else:
41
- if st.session_state.isGridSave:
42
- st.session_state.final_mask = st.session_state.mask_regrid
50
+ if st.session_state.isRegridCheck:
51
+ st.session_state.final_mask = st.session_state.profile_mask_regrid
43
52
  st.session_state.final_velocity = st.session_state.velocity_regrid
44
53
  st.session_state.final_echo = st.session_state.echo_regrid
45
54
  st.session_state.final_correlation = st.session_state.correlation_regrid
46
55
  st.session_state.final_pgood = st.session_state.pgood_regrid
47
56
  else:
48
- if st.session_state.isProfileMask:
57
+ if st.session_state.isProfileTest:
49
58
  st.session_state.final_mask = st.session_state.profile_mask
50
- elif st.session_state.isQCMask:
59
+ elif st.session_state.isQCTest:
51
60
  st.session_state.final_mask = st.session_state.qc_mask
61
+ elif st.session_state.isSensorTest:
62
+ st.session_state.final_mask = st.session_state.sensor_mask
52
63
  else:
53
64
  st.session_state.final_mask = st.session_state.orig_mask
54
65
  st.session_state.final_velocity = st.session_state.velocity
@@ -57,7 +68,7 @@ else:
57
68
  st.session_state.final_pgood = st.session_state.pgood
58
69
 
59
70
 
60
- if "depth" not in st.session_state:
71
+ if "depth_axis" not in st.session_state:
61
72
  st.session_state.isGrid = False
62
73
 
63
74
 
@@ -74,7 +85,8 @@ if not st.session_state.isGrid:
74
85
  st.write(
75
86
  "Data not regrided. Using the mean transducer depth to calculate the depth axis."
76
87
  )
77
- mean_depth = np.mean(st.session_state.vlead.vleader["Depth of Transducer"]) / 10
88
+ # mean_depth = np.mean(st.session_state.vlead.vleader["Depth of Transducer"]) / 10
89
+ mean_depth = np.mean(st.session_state.depth) / 10
78
90
  mean_depth = np.trunc(mean_depth)
79
91
  st.write(f"Mean depth of the transducer is `{mean_depth}`")
80
92
  cells = st.session_state.flead.field()["Cells"]
@@ -83,9 +95,9 @@ if not st.session_state.isGrid:
83
95
  max_depth = mean_depth - bin1dist
84
96
  min_depth = max_depth - cells * cell_size
85
97
  z = np.arange(-1 * max_depth, -1 * min_depth, cell_size)
86
- st.session_state.final_depth = z
98
+ st.session_state.final_depth_axis = z
87
99
  else:
88
- st.session_state.final_depth = st.session_state.depth
100
+ st.session_state.final_depth_axis = st.session_state.depth_axis
89
101
 
90
102
 
91
103
  # Functions for plotting
@@ -121,7 +133,7 @@ def call_plot(varname, beam, mask=False):
121
133
  if varname == "Velocity":
122
134
  fillplot_plotly(
123
135
  st.session_state.date,
124
- st.session_state.final_depth,
136
+ st.session_state.final_depth_axis,
125
137
  st.session_state.final_velocity[beam - 1, :, :],
126
138
  st.session_state.final_mask,
127
139
  title=varname,
@@ -130,7 +142,7 @@ def call_plot(varname, beam, mask=False):
130
142
  elif varname == "Echo":
131
143
  fillplot_plotly(
132
144
  st.session_state.date,
133
- st.session_state.final_depth,
145
+ st.session_state.final_depth_axis,
134
146
  st.session_state.final_echo[beam - 1, :, :],
135
147
  st.session_state.final_mask,
136
148
  title=varname,
@@ -139,7 +151,7 @@ def call_plot(varname, beam, mask=False):
139
151
  elif varname == "Correlation":
140
152
  fillplot_plotly(
141
153
  st.session_state.date,
142
- st.session_state.final_depth,
154
+ st.session_state.final_depth_axis,
143
155
  st.session_state.final_correlation[beam - 1, :, :],
144
156
  st.session_state.final_mask,
145
157
  title=varname,
@@ -148,7 +160,7 @@ def call_plot(varname, beam, mask=False):
148
160
  elif varname == "Percent Good":
149
161
  fillplot_plotly(
150
162
  st.session_state.date,
151
- st.session_state.final_depth,
163
+ st.session_state.final_depth_axis,
152
164
  st.session_state.final_pgood[beam - 1, :, :],
153
165
  st.session_state.final_mask,
154
166
  title=varname,
@@ -237,15 +249,17 @@ download_button = st.button("Generate Processed files")
237
249
  if download_button:
238
250
  st.session_state.processed_filename = file_write()
239
251
  st.write(":grey[Processed file created. Click the download button.]")
240
- st.write(st.session_state.processed_filename)
241
- depth = np.trunc(st.session_state.final_depth)
252
+ # st.write(st.session_state.processed_filename)
253
+ depth_axis = np.trunc(st.session_state.final_depth_axis)
254
+ final_mask = st.session_state.final_mask
242
255
 
243
256
  if file_type_radio == "NetCDF":
244
257
  if add_attr_button and st.session_state.attributes:
245
258
  # Generate file with attributes
246
259
  wr.finalnc(
247
260
  st.session_state.processed_filename,
248
- depth,
261
+ depth_axis,
262
+ final_mask,
249
263
  st.session_state.date,
250
264
  st.session_state.write_velocity,
251
265
  attributes=st.session_state.attributes, # Pass edited attributes
@@ -254,56 +268,65 @@ if download_button:
254
268
  # Generate file without attributes
255
269
  wr.finalnc(
256
270
  st.session_state.processed_filename,
257
- depth,
271
+ depth_axis,
272
+ final_mask,
258
273
  st.session_state.date,
259
274
  st.session_state.write_velocity,
260
275
  )
261
276
 
262
- with open(st.session_state.processed_filename, "rb") as file:
263
- st.download_button(
264
- label="Download NetCDF File",
265
- data=file,
266
- file_name="processed_file.nc",
267
- )
277
+ with open(st.session_state.processed_filename, "rb") as file:
278
+ st.download_button(
279
+ label="Download NetCDF File",
280
+ data=file,
281
+ file_name="processed_file.nc",
282
+ )
268
283
 
269
284
  if file_type_radio == "CSV":
270
285
  udf = pd.DataFrame(
271
286
  st.session_state.write_velocity[0, :, :].T,
272
287
  index=st.session_state.date,
273
- columns=-1 * depth,
288
+ columns=-1 * depth_axis,
274
289
  )
275
290
  vdf = pd.DataFrame(
276
291
  st.session_state.write_velocity[1, :, :].T,
277
292
  index=st.session_state.date,
278
- columns=-1 * depth,
293
+ columns=-1 * depth_axis,
279
294
  )
280
295
  wdf = pd.DataFrame(
281
296
  st.session_state.write_velocity[2, :, :].T,
282
297
  index=st.session_state.date,
283
- columns=-1 * depth,
298
+ columns=-1 * depth_axis,
284
299
  )
285
300
  ucsv = udf.to_csv().encode("utf-8")
286
301
  vcsv = vdf.to_csv().encode("utf-8")
287
302
  wcsv = wdf.to_csv().encode("utf-8")
303
+ csv_mask = pd.DataFrame(st.session_state.final_mask.T).to_csv().encode("utf-8")
288
304
  st.download_button(
289
- label="Download Zonal Velocity File",
305
+ label="Download Zonal Velocity File (CSV)",
290
306
  data=ucsv,
291
307
  file_name="zonal_velocity.csv",
292
308
  mime="text/csf",
293
309
  )
294
310
  st.download_button(
295
- label="Download Meridional Velocity File",
311
+ label="Download Meridional Velocity File (CSV)",
296
312
  data=vcsv,
297
313
  file_name="meridional_velocity.csv",
298
314
  mime="text/csf",
299
315
  )
300
316
  st.download_button(
301
- label="Download Vertical Velocity File",
317
+ label="Download Vertical Velocity File (CSV)",
302
318
  data=vcsv,
303
319
  file_name="vertical_velocity.csv",
304
320
  mime="text/csf",
305
321
  )
306
322
 
323
+ st.download_button(
324
+ label="Download Final Mask (CSV)",
325
+ data=csv_mask,
326
+ file_name="final_mask.csv",
327
+ mime="text/csv",
328
+ )
329
+
307
330
 
308
331
  # Option to Download Config file
309
332
  # ------------------------------
@@ -324,6 +347,7 @@ if generate_config_radio == "Yes":
324
347
  # Main section
325
348
  config["FileSettings"] = {}
326
349
  config["DownloadOptions"] = {}
350
+ config["SensorTest"] = {"sensor_test": "False"}
327
351
  config["QCTest"] = {"qc_test": "False"}
328
352
  config["ProfileTest"] = {"profile_test": "False"}
329
353
  config["VelocityTest"] = {"velocity_test": "False"}
@@ -342,8 +366,56 @@ if generate_config_radio == "Yes":
342
366
  config["DownloadOptions"]["apply_mask"] = "True"
343
367
  config["DownloadOptions"]["download_mask"] = "True"
344
368
 
369
+ # Sensor Test Options
370
+ if st.session_state.isSensorTest:
371
+ config["SensorTest"]["sensor_test"] = "True"
372
+ if st.session_state.isRollCheck:
373
+ config["RollTest"]["roll_test"] = "True"
374
+ config["SensorTest"]["roll_cutoff"] = str(
375
+ st.session_state.sensor_roll_cutoff
376
+ )
377
+ else:
378
+ config["RollTest"]["roll_test"] = "False"
379
+ if st.session_state.isRollCheck:
380
+ config["SensorTest"]["pitch_cutoff"] = str(
381
+ st.session_state.sensor_pitch_cutoff
382
+ )
383
+
384
+ config["SensorTest"]["depth_modified"] = str(st.session_state.isDepthModified)
385
+ if st.session_state.isDepthModified:
386
+ config["SensorTest"]["depth_input_option"] = str(
387
+ st.session_state.sensor_depthoption
388
+ )
389
+ if st.session_state.sensor_depthoption == "Fixed Value":
390
+ config["SensorTest"]["depth_input"] = str(
391
+ st.session_state.sensor_depthinput
392
+ )
393
+
394
+ config["SensorTest"]["salinity_modified"] = str(
395
+ st.session_state.isSalinityModified
396
+ )
397
+ if st.session_state.isSalinityModified:
398
+ config["SensorTest"]["salinity_input_option"] = str(
399
+ st.session_state.sensor_depthoption
400
+ )
401
+ if st.session_state.sensor_salinityoption == "Fixed Value":
402
+ config["SensorTest"]["salinity_input"] = str(
403
+ st.session_state.sensor_salinityinput
404
+ )
405
+
406
+ config["SensorTest"]["temperature_modified"] = str(
407
+ st.session_state.isTemperatureModified
408
+ )
409
+ if st.session_state.isTemperatureModified:
410
+ config["SensorTest"]["temperature_input_option"] = str(
411
+ st.session_state.sensor_tempoption
412
+ )
413
+ if st.session_state.sensor_tempoption == "Fixed Value":
414
+ config["SensorTest"]["temperature_input"] = str(
415
+ st.session_state.sensor_tempinput
416
+ )
345
417
  # QC Test Options
346
- if st.session_state.isQCMask:
418
+ if st.session_state.isQCTest:
347
419
  config["QCTest"]["qc_test"] = "True"
348
420
 
349
421
  # Add the contents of the current QC Mask thresholds
@@ -352,39 +424,42 @@ if generate_config_radio == "Yes":
352
424
  config["QCTest"][row["Threshold"].replace(" ", "_")] = row["Values"]
353
425
 
354
426
  # Profile Test Options
355
- if st.session_state.isProfileMask:
427
+ if st.session_state.isProfileTest:
356
428
  config["ProfileTest"]["profile_test"] = "True"
357
429
 
358
- if st.session_state.isTrimEnds:
430
+ if st.session_state.isTrimEndsCheck:
359
431
  config["ProfileTest"]["trim_ends"] = "True"
360
432
  config["ProfileTest"]["trim_ends_start_index"] = str(
361
- st.session_state.start_ens
433
+ st.session_state.trimends_start_ens
434
+ )
435
+ config["ProfileTest"]["trim_ends_end_index"] = str(
436
+ st.session_state.trimends_end_ens
362
437
  )
363
- config["ProfileTest"]["trim_ends_end_index"] = str(st.session_state.end_ens)
364
438
  else:
365
439
  config["ProfileTest"]["trim_ends"] = "False"
366
440
 
367
- if st.session_state.isCutBins:
441
+ if st.session_state.isCutBinSideLobeCheck:
368
442
  config["ProfileTest"]["cut_bins"] = "True"
369
443
  config["ProfileTest"]["cut_bins_add_cells"] = str(
370
- st.session_state.extra_cells
444
+ st.session_state.profile_extra_cells
371
445
  )
372
446
  else:
373
447
  config["ProfileTest"]["cut_bins"] = "False"
374
448
 
375
- if st.session_state.isGrid:
449
+ if st.session_state.isCutBinManualCheck:
450
+ config["ProfileTest"]["cut_bins_manual"] = "True"
451
+
452
+ if st.session_state.isRegridCheck:
376
453
  config["ProfileTest"]["regrid"] = "True"
377
- config["ProfileTest"][
378
- "Regrid_Option"
379
- ] = st.session_state.end_bin_option
454
+ config["ProfileTest"]["Regrid_Option"] = st.session_state.end_bin_option
380
455
  else:
381
456
  config["ProfileTest"]["regrid"] = "False"
382
457
 
383
458
  # Velocity Test Section
384
- if st.session_state.isVelocityMask:
459
+ if st.session_state.isVelocityTest:
385
460
  config["VelocityTest"]["velocity_test"] = "True"
386
461
 
387
- if st.session_state.isMagnet:
462
+ if st.session_state.isMagnetCheck:
388
463
  config["VelocityTest"]["magnetic_declination"] = str(True)
389
464
  config["VelocityTest"]["latitude"] = str(st.session_state.lat)
390
465
  config["VelocityTest"]["longitude"] = str(st.session_state.lon)
@@ -393,7 +468,7 @@ if generate_config_radio == "Yes":
393
468
  else:
394
469
  config["VelocityTest"]["magnetic_declination"] = str(False)
395
470
 
396
- if st.session_state.isCutoff:
471
+ if st.session_state.isCutoffCheck:
397
472
  config["VelocityTest"]["cutoff"] = str(True)
398
473
  config["VelocityTest"]["max_zonal_velocity"] = str(st.session_state.maxuvel)
399
474
  config["VelocityTest"]["max_meridional_velocity"] = str(
@@ -405,7 +480,7 @@ if generate_config_radio == "Yes":
405
480
  else:
406
481
  config["VelocityTest"]["cutoff"] = str(False)
407
482
 
408
- if st.session_state.isDespike:
483
+ if st.session_state.isDespikeCheck:
409
484
  config["VelocityTest"]["despike"] = str(True)
410
485
  config["VelocityTest"]["despike_Kernal_Size"] = str(
411
486
  st.session_state.despike_kernal
@@ -416,7 +491,7 @@ if generate_config_radio == "Yes":
416
491
  else:
417
492
  config["VelocityTest"]["Despike"] = str(False)
418
493
 
419
- if st.session_state.isFlatline:
494
+ if st.session_state.isFlatlineCheck:
420
495
  config["VelocityTest"]["flatline"] = str(True)
421
496
  config["VelocityTest"]["flatline_kernal_size"] = str(
422
497
  st.session_state.flatline_kernal
@@ -433,12 +508,15 @@ if generate_config_radio == "Yes":
433
508
  config["Optional"][key] = str(value) # Ensure all values are strings
434
509
 
435
510
  # Write config.ini to a temporary file
436
- config_filepath = "config.ini"
437
- with open(config_filepath, "w") as configfile:
438
- config.write(configfile)
439
-
511
+ # config_filepath = "config.ini"
512
+ # with open(config_filepath, "w") as configfile:
513
+ # config.write(configfile)
514
+ # Create a temporary file for the config.ini
515
+ with tempfile.NamedTemporaryFile("w+", delete=False, suffix=".ini") as temp_config:
516
+ config.write(temp_config)
517
+ temp_config_path = temp_config.name
440
518
  # Allow the user to download the generated config.ini file
441
- with open(config_filepath, "rb") as file:
519
+ with open(temp_config_path, "rb") as file:
442
520
  st.download_button(
443
521
  label="Download config.ini File",
444
522
  data=file,
@@ -0,0 +1,62 @@
1
+ import os
2
+ import tempfile
3
+
4
+ import configparser
5
+ import json
6
+ import streamlit as st
7
+ from utils.autoprocess import autoprocess
8
+
9
+
10
+ @st.cache_data
11
+ def file_access(uploaded_file):
12
+ """
13
+ Function creates temporary directory to store the uploaded file.
14
+ The path of the file is returned
15
+
16
+ Args:
17
+ uploaded_file (string): Name of the uploaded file
18
+
19
+ Returns:
20
+ path (string): Path of the uploaded file
21
+ """
22
+ temp_dir = tempfile.mkdtemp()
23
+ path = os.path.join(temp_dir, uploaded_file.name)
24
+ with open(path, "wb") as f:
25
+ f.write(uploaded_file.getvalue())
26
+ return path
27
+
28
+
29
+ def display_config_as_json(config_file):
30
+ config = configparser.ConfigParser()
31
+ config.read_string(config_file.getvalue().decode("utf-8"))
32
+ st.json({section: dict(config[section]) for section in config.sections()})
33
+
34
+
35
+ def main():
36
+ st.title("ADCP Data Auto Processing Tool")
37
+ st.write("Upload a binary input file and config.ini file for processing.")
38
+
39
+ # File Upload Section
40
+ uploaded_binary_file = st.file_uploader(
41
+ "Upload ADCP Binary File", type=["000", "bin"]
42
+ )
43
+ uploaded_config_file = st.file_uploader(
44
+ "Upload Config File (config.ini)", type=["ini"]
45
+ )
46
+
47
+ if uploaded_binary_file and uploaded_config_file:
48
+ st.success("Files uploaded successfully!")
49
+
50
+ # Display config.ini file content as JSON
51
+ display_config_as_json(uploaded_config_file)
52
+
53
+ fpath = file_access(uploaded_binary_file)
54
+ # Process files
55
+ with st.spinner("Processing files. Please wait..."):
56
+ autoprocess(uploaded_config_file, binary_file_path=fpath)
57
+ st.success("Processing completed successfully!")
58
+ st.write("Processed file written.")
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
pyadps/utils/__init__.py CHANGED
@@ -1,12 +1,11 @@
1
1
  # pyadps/utils/__init__.py
2
2
 
3
- from pyadps.utils.cutbin import *
4
3
  from pyadps.utils.plotgen import *
5
4
  from pyadps.utils.profile_test import *
6
5
  from pyadps.utils.pyreadrdi import *
7
6
  from pyadps.utils.readrdi import *
8
- from pyadps.utils.regrid import *
7
+ from pyadps.utils.sensor_health import *
9
8
  from pyadps.utils.signal_quality import *
10
9
  from pyadps.utils.velocity_test import *
11
10
  from pyadps.utils.writenc import *
12
- # from pyadps.utils.autoprocess import *
11
+ from pyadps.utils.autoprocess import *