pyadps 0.2.1b0__py3-none-any.whl → 0.3.0__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 (39) hide show
  1. pyadps/Home_Page.py +11 -5
  2. pyadps/pages/01_Read_File.py +623 -215
  3. pyadps/pages/02_View_Raw_Data.py +97 -41
  4. pyadps/pages/03_Download_Raw_File.py +200 -67
  5. pyadps/pages/04_Sensor_Health.py +905 -0
  6. pyadps/pages/05_QC_Test.py +493 -0
  7. pyadps/pages/06_Profile_Test.py +971 -0
  8. pyadps/pages/07_Velocity_Test.py +600 -0
  9. pyadps/pages/08_Write_File.py +623 -0
  10. pyadps/pages/09_Add-Ons.py +168 -0
  11. pyadps/utils/__init__.py +5 -3
  12. pyadps/utils/autoprocess.py +371 -80
  13. pyadps/utils/logging_utils.py +269 -0
  14. pyadps/utils/metadata/config.ini +22 -4
  15. pyadps/utils/metadata/demo.000 +0 -0
  16. pyadps/utils/metadata/flmeta.json +420 -420
  17. pyadps/utils/metadata/vlmeta.json +611 -565
  18. pyadps/utils/multifile.py +292 -0
  19. pyadps/utils/plotgen.py +505 -3
  20. pyadps/utils/profile_test.py +720 -125
  21. pyadps/utils/pyreadrdi.py +164 -92
  22. pyadps/utils/readrdi.py +436 -186
  23. pyadps/utils/script.py +197 -147
  24. pyadps/utils/sensor_health.py +120 -0
  25. pyadps/utils/signal_quality.py +472 -68
  26. pyadps/utils/velocity_test.py +79 -31
  27. pyadps/utils/writenc.py +222 -39
  28. {pyadps-0.2.1b0.dist-info → pyadps-0.3.0.dist-info}/METADATA +13 -14
  29. pyadps-0.3.0.dist-info/RECORD +35 -0
  30. {pyadps-0.2.1b0.dist-info → pyadps-0.3.0.dist-info}/WHEEL +1 -1
  31. {pyadps-0.2.1b0.dist-info → pyadps-0.3.0.dist-info}/entry_points.txt +1 -0
  32. pyadps/pages/04_QC_Test.py +0 -334
  33. pyadps/pages/05_Profile_Test.py +0 -575
  34. pyadps/pages/06_Velocity_Test.py +0 -341
  35. pyadps/pages/07_Write_File.py +0 -452
  36. pyadps/utils/cutbin.py +0 -413
  37. pyadps/utils/regrid.py +0 -279
  38. pyadps-0.2.1b0.dist-info/RECORD +0 -31
  39. {pyadps-0.2.1b0.dist-info → pyadps-0.3.0.dist-info}/LICENSE +0 -0
@@ -1,452 +0,0 @@
1
- import configparser
2
- import tempfile
3
-
4
- import numpy as np
5
- import pandas as pd
6
- import plotly.graph_objects as go
7
- import streamlit as st
8
- import utils.writenc as wr
9
- from plotly_resampler import FigureResampler
10
-
11
- if "flead" not in st.session_state:
12
- st.write(":red[Please Select Data!]")
13
- st.stop()
14
-
15
- if "fname" not in st.session_state:
16
- st.session_state.fname = "No file selected"
17
-
18
- if "rawfilename" not in st.session_state:
19
- st.session_state.rawfilename = "rawfile.nc"
20
-
21
- if "vleadfilename" not in st.session_state:
22
- st.session_state.vleadfilename = "vlead.nc"
23
-
24
-
25
- # Check if attributes exist in session state
26
- if "attributes" not in st.session_state:
27
- st.session_state.attributes = {}
28
-
29
- if st.session_state.isVelocityMask:
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:
33
- st.session_state.final_echo = st.session_state.echo_regrid
34
- st.session_state.final_correlation = st.session_state.correlation_regrid
35
- st.session_state.final_pgood = st.session_state.pgood_regrid
36
- else:
37
- st.session_state.final_echo = st.session_state.echo
38
- st.session_state.final_correlation = st.session_state.correlation
39
- st.session_state.final_pgood = st.session_state.pgood
40
- else:
41
- if st.session_state.isGridSave:
42
- st.session_state.final_mask = st.session_state.mask_regrid
43
- st.session_state.final_velocity = st.session_state.velocity_regrid
44
- st.session_state.final_echo = st.session_state.echo_regrid
45
- st.session_state.final_correlation = st.session_state.correlation_regrid
46
- st.session_state.final_pgood = st.session_state.pgood_regrid
47
- else:
48
- if st.session_state.isProfileMask:
49
- st.session_state.final_mask = st.session_state.profile_mask
50
- elif st.session_state.isQCMask:
51
- st.session_state.final_mask = st.session_state.qc_mask
52
- else:
53
- st.session_state.final_mask = st.session_state.orig_mask
54
- st.session_state.final_velocity = st.session_state.velocity
55
- st.session_state.final_echo = st.session_state.echo
56
- st.session_state.final_correlation = st.session_state.correlation
57
- st.session_state.final_pgood = st.session_state.pgood
58
-
59
-
60
- if "depth" not in st.session_state:
61
- st.session_state.isGrid = False
62
-
63
-
64
- @st.cache_data
65
- def file_write(filename="processed_file.nc"):
66
- tempdirname = tempfile.TemporaryDirectory(delete=False)
67
- outfilepath = tempdirname.name + "/" + filename
68
- return outfilepath
69
-
70
-
71
- # If the data is not regrided based on pressure sensor. Use the mean depth
72
- if not st.session_state.isGrid:
73
- st.write(":red[WARNING!]")
74
- st.write(
75
- "Data not regrided. Using the mean transducer depth to calculate the depth axis."
76
- )
77
- mean_depth = np.mean(st.session_state.vlead.vleader["Depth of Transducer"]) / 10
78
- mean_depth = np.trunc(mean_depth)
79
- st.write(f"Mean depth of the transducer is `{mean_depth}`")
80
- cells = st.session_state.flead.field()["Cells"]
81
- cell_size = st.session_state.flead.field()["Depth Cell Len"] / 100
82
- bin1dist = st.session_state.flead.field()["Bin 1 Dist"] / 100
83
- max_depth = mean_depth - bin1dist
84
- min_depth = max_depth - cells * cell_size
85
- z = np.arange(-1 * max_depth, -1 * min_depth, cell_size)
86
- st.session_state.final_depth = z
87
- else:
88
- st.session_state.final_depth = st.session_state.depth
89
-
90
-
91
- # Functions for plotting
92
- @st.cache_data
93
- def fillplot_plotly(
94
- x, y, data, maskdata, colorscale="balance", title="Data", mask=False
95
- ):
96
- fig = FigureResampler(go.Figure())
97
- if mask:
98
- data1 = np.where(maskdata == 1, np.nan, data)
99
- else:
100
- data1 = np.where(data == -32768, np.nan, data)
101
-
102
- fig.add_trace(
103
- go.Heatmap(
104
- z=data1[:, 0:-1],
105
- x=x,
106
- y=y,
107
- colorscale=colorscale,
108
- hoverongaps=False,
109
- )
110
- )
111
- fig.update_layout(
112
- xaxis=dict(showline=True, mirror=True),
113
- yaxis=dict(showline=True, mirror=True),
114
- title_text=title,
115
- )
116
- fig.update_yaxes(autorange="reversed")
117
- st.plotly_chart(fig)
118
-
119
-
120
- def call_plot(varname, beam, mask=False):
121
- if varname == "Velocity":
122
- fillplot_plotly(
123
- st.session_state.date,
124
- st.session_state.final_depth,
125
- st.session_state.final_velocity[beam - 1, :, :],
126
- st.session_state.final_mask,
127
- title=varname,
128
- mask=mask,
129
- )
130
- elif varname == "Echo":
131
- fillplot_plotly(
132
- st.session_state.date,
133
- st.session_state.final_depth,
134
- st.session_state.final_echo[beam - 1, :, :],
135
- st.session_state.final_mask,
136
- title=varname,
137
- mask=mask,
138
- )
139
- elif varname == "Correlation":
140
- fillplot_plotly(
141
- st.session_state.date,
142
- st.session_state.final_depth,
143
- st.session_state.final_correlation[beam - 1, :, :],
144
- st.session_state.final_mask,
145
- title=varname,
146
- mask=mask,
147
- )
148
- elif varname == "Percent Good":
149
- fillplot_plotly(
150
- st.session_state.date,
151
- st.session_state.final_depth,
152
- st.session_state.final_pgood[beam - 1, :, :],
153
- st.session_state.final_mask,
154
- title=varname,
155
- mask=mask,
156
- )
157
-
158
-
159
- # Option to View Processed Data
160
- st.header("View Processed Data", divider="blue")
161
- var_option = st.selectbox(
162
- "Select a data type", ("Velocity", "Echo", "Correlation", "Percent Good")
163
- )
164
- beam = st.radio("Select beam", (1, 2, 3, 4), horizontal=True)
165
-
166
- mask_radio = st.radio("Apply Mask", ("Yes", "No"), horizontal=True)
167
- plot_button = st.button("Plot Processed Data")
168
- if plot_button:
169
- if mask_radio == "Yes":
170
- call_plot(var_option, beam, mask=True)
171
- elif mask_radio == "No":
172
- call_plot(var_option, beam, mask=False)
173
-
174
-
175
- # Option to Write Processed Data
176
- st.header("Write Data", divider="blue")
177
-
178
- mask_data_radio = st.radio("Do you want to mask the final data?", ("Yes", "No"))
179
-
180
- if mask_data_radio == "Yes":
181
- mask = st.session_state.final_mask
182
- st.session_state.write_velocity = np.copy(st.session_state.final_velocity)
183
- st.session_state.write_velocity[:, mask == 1] = -32768
184
- else:
185
- st.session_state.write_velocity = np.copy(st.session_state.final_velocity)
186
-
187
-
188
- file_type_radio = st.radio("Select output file format:", ("NetCDF", "CSV"))
189
-
190
- if file_type_radio == "NetCDF":
191
- add_attr_button = st.checkbox("Add attributes to NetCDF file")
192
-
193
- if add_attr_button:
194
- st.write("### Modify Attributes")
195
-
196
- # Create two-column layout for attributes
197
- col1, col2 = st.columns(2)
198
-
199
- with col1:
200
- # Display attributes in the first column
201
- for key in [
202
- "Cruise_No.",
203
- "Ship_Name",
204
- "Project_No.",
205
- "Water_Depth_m",
206
- "Deployment_Depth_m",
207
- "Deployment_Date",
208
- "Recovery_Date",
209
- ]:
210
- if key in st.session_state.attributes:
211
- st.session_state.attributes[key] = st.text_input(
212
- key, value=st.session_state.attributes[key]
213
- )
214
- else:
215
- st.session_state.attributes[key] = st.text_input(key)
216
-
217
- with col2:
218
- # Display attributes in the second column
219
- for key in [
220
- "Latitude",
221
- "Longitude",
222
- "Platform_Type",
223
- "Participants",
224
- "File_created_by",
225
- "Contact",
226
- "Comments",
227
- ]:
228
- if key in st.session_state.attributes:
229
- st.session_state.attributes[key] = st.text_input(
230
- key, value=st.session_state.attributes[key]
231
- )
232
- else:
233
- st.session_state.attributes[key] = st.text_input(key)
234
-
235
- download_button = st.button("Generate Processed files")
236
-
237
- if download_button:
238
- st.session_state.processed_filename = file_write()
239
- 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)
242
-
243
- if file_type_radio == "NetCDF":
244
- if add_attr_button and st.session_state.attributes:
245
- # Generate file with attributes
246
- wr.finalnc(
247
- st.session_state.processed_filename,
248
- depth,
249
- st.session_state.date,
250
- st.session_state.write_velocity,
251
- attributes=st.session_state.attributes, # Pass edited attributes
252
- )
253
- else:
254
- # Generate file without attributes
255
- wr.finalnc(
256
- st.session_state.processed_filename,
257
- depth,
258
- st.session_state.date,
259
- st.session_state.write_velocity,
260
- )
261
-
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
- )
268
-
269
- if file_type_radio == "CSV":
270
- udf = pd.DataFrame(
271
- st.session_state.write_velocity[0, :, :].T,
272
- index=st.session_state.date,
273
- columns=-1 * depth,
274
- )
275
- vdf = pd.DataFrame(
276
- st.session_state.write_velocity[1, :, :].T,
277
- index=st.session_state.date,
278
- columns=-1 * depth,
279
- )
280
- wdf = pd.DataFrame(
281
- st.session_state.write_velocity[2, :, :].T,
282
- index=st.session_state.date,
283
- columns=-1 * depth,
284
- )
285
- ucsv = udf.to_csv().encode("utf-8")
286
- vcsv = vdf.to_csv().encode("utf-8")
287
- wcsv = wdf.to_csv().encode("utf-8")
288
- st.download_button(
289
- label="Download Zonal Velocity File",
290
- data=ucsv,
291
- file_name="zonal_velocity.csv",
292
- mime="text/csf",
293
- )
294
- st.download_button(
295
- label="Download Meridional Velocity File",
296
- data=vcsv,
297
- file_name="meridional_velocity.csv",
298
- mime="text/csf",
299
- )
300
- st.download_button(
301
- label="Download Vertical Velocity File",
302
- data=vcsv,
303
- file_name="vertical_velocity.csv",
304
- mime="text/csf",
305
- )
306
-
307
-
308
- # Option to Download Config file
309
- # ------------------------------
310
-
311
- # Header for the Config.ini File Generator
312
- st.header("Config.ini File Generator", divider="blue")
313
-
314
- # Radio button to decide whether to generate the config.ini file
315
- generate_config_radio = st.radio(
316
- "Do you want to generate a config.ini file?", ("No", "Yes")
317
- )
318
-
319
-
320
- if generate_config_radio == "Yes":
321
- # Create a config parser object
322
- config = configparser.ConfigParser()
323
-
324
- # Main section
325
- config["FileSettings"] = {}
326
- config["DownloadOptions"] = {}
327
- config["QCTest"] = {"qc_test": "False"}
328
- config["ProfileTest"] = {"profile_test": "False"}
329
- config["VelocityTest"] = {"velocity_test": "False"}
330
- config["Optional"] = {"attributes": "False"}
331
-
332
- config["FileSettings"]["input_file_path"] = ""
333
- config["FileSettings"]["input_file_name"] = st.session_state.fname
334
- config["FileSettings"]["output_file_path"] = ""
335
- config["FileSettings"]["output_file_name_raw"] = ""
336
- config["FileSettings"]["output_file_name_processed"] = ""
337
- config["FileSettings"]["output_format_raw"] = str(file_type_radio).lower()
338
- config["FileSettings"]["output_format_processed"] = str(file_type_radio).lower()
339
-
340
- config["DownloadOptions"]["download_raw"] = "True"
341
- config["DownloadOptions"]["download_processed"] = "True"
342
- config["DownloadOptions"]["apply_mask"] = "True"
343
- config["DownloadOptions"]["download_mask"] = "True"
344
-
345
- # QC Test Options
346
- if st.session_state.isQCMask:
347
- config["QCTest"]["qc_test"] = "True"
348
-
349
- # Add the contents of the current QC Mask thresholds
350
- if "newthresh" in st.session_state:
351
- for idx, row in st.session_state.newthresh.iterrows():
352
- config["QCTest"][row["Threshold"].replace(" ", "_")] = row["Values"]
353
-
354
- # Profile Test Options
355
- if st.session_state.isProfileMask:
356
- config["ProfileTest"]["profile_test"] = "True"
357
-
358
- if st.session_state.isTrimEnds:
359
- config["ProfileTest"]["trim_ends"] = "True"
360
- config["ProfileTest"]["trim_ends_start_index"] = str(
361
- st.session_state.start_ens
362
- )
363
- config["ProfileTest"]["trim_ends_end_index"] = str(st.session_state.end_ens)
364
- else:
365
- config["ProfileTest"]["trim_ends"] = "False"
366
-
367
- if st.session_state.isCutBins:
368
- config["ProfileTest"]["cut_bins"] = "True"
369
- config["ProfileTest"]["cut_bins_add_cells"] = str(
370
- st.session_state.extra_cells
371
- )
372
- else:
373
- config["ProfileTest"]["cut_bins"] = "False"
374
-
375
- if st.session_state.isGrid:
376
- config["ProfileTest"]["regrid"] = "True"
377
- config["ProfileTest"][
378
- "Regrid_Option"
379
- ] = st.session_state.end_bin_option
380
- else:
381
- config["ProfileTest"]["regrid"] = "False"
382
-
383
- # Velocity Test Section
384
- if st.session_state.isVelocityMask:
385
- config["VelocityTest"]["velocity_test"] = "True"
386
-
387
- if st.session_state.isMagnet:
388
- config["VelocityTest"]["magnetic_declination"] = str(True)
389
- config["VelocityTest"]["latitude"] = str(st.session_state.lat)
390
- config["VelocityTest"]["longitude"] = str(st.session_state.lon)
391
- config["VelocityTest"]["depth"] = str(st.session_state.magnetic_dec_depth)
392
- config["VelocityTest"]["year"] = str(st.session_state.year)
393
- else:
394
- config["VelocityTest"]["magnetic_declination"] = str(False)
395
-
396
- if st.session_state.isCutoff:
397
- config["VelocityTest"]["cutoff"] = str(True)
398
- config["VelocityTest"]["max_zonal_velocity"] = str(st.session_state.maxuvel)
399
- config["VelocityTest"]["max_meridional_velocity"] = str(
400
- st.session_state.maxvvel
401
- )
402
- config["VelocityTest"]["max_vertical_velocity"] = str(
403
- st.session_state.maxwvel
404
- )
405
- else:
406
- config["VelocityTest"]["cutoff"] = str(False)
407
-
408
- if st.session_state.isDespike:
409
- config["VelocityTest"]["despike"] = str(True)
410
- config["VelocityTest"]["despike_Kernal_Size"] = str(
411
- st.session_state.despike_kernal
412
- )
413
- config["VelocityTest"]["despike_Cutoff"] = str(
414
- st.session_state.despike_cutoff
415
- )
416
- else:
417
- config["VelocityTest"]["Despike"] = str(False)
418
-
419
- if st.session_state.isFlatline:
420
- config["VelocityTest"]["flatline"] = str(True)
421
- config["VelocityTest"]["flatline_kernal_size"] = str(
422
- st.session_state.flatline_kernal
423
- )
424
- config["VelocityTest"]["flatline_deviation"] = str(
425
- st.session_state.flatline_cutoff
426
- )
427
- else:
428
- config["VelocityTest"]["flatline"] = str(False)
429
-
430
- # Optional section (attributes)
431
- config["Optional"] = {}
432
- for key, value in st.session_state.attributes.items():
433
- config["Optional"][key] = str(value) # Ensure all values are strings
434
-
435
- # 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
-
440
- # Allow the user to download the generated config.ini file
441
- with open(config_filepath, "rb") as file:
442
- st.download_button(
443
- label="Download config.ini File",
444
- data=file,
445
- file_name="config.ini",
446
- )
447
-
448
- display_config_radio = st.radio(
449
- "Do you want to display config.ini file?", ("No", "Yes")
450
- )
451
- if display_config_radio == "Yes":
452
- st.write({section: dict(config[section]) for section in config.sections()})