pyadps 0.1.0b0__py3-none-any.whl → 0.1.1__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 (50) hide show
  1. pyadps/Home_Page.py +11 -5
  2. pyadps/pages/01_Read_File.py +191 -16
  3. pyadps/pages/02_View_Raw_Data.py +69 -33
  4. pyadps/pages/03_Download_Raw_File.py +161 -60
  5. pyadps/pages/04_Sensor_Health.py +905 -0
  6. pyadps/pages/05_QC_Test.py +476 -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 +587 -0
  10. pyadps/pages/09_Auto_process.py +64 -0
  11. pyadps/pages/__pycache__/__init__.cpython-312.pyc +0 -0
  12. pyadps/utils/__init__.py +3 -3
  13. pyadps/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  14. pyadps/utils/__pycache__/autoprocess.cpython-312.pyc +0 -0
  15. pyadps/utils/__pycache__/cutbin.cpython-312.pyc +0 -0
  16. pyadps/utils/__pycache__/plotgen.cpython-312.pyc +0 -0
  17. pyadps/utils/__pycache__/profile_test.cpython-312.pyc +0 -0
  18. pyadps/utils/__pycache__/pyreadrdi.cpython-312.pyc +0 -0
  19. pyadps/utils/__pycache__/readrdi.cpython-312.pyc +0 -0
  20. pyadps/utils/__pycache__/regrid.cpython-312.pyc +0 -0
  21. pyadps/utils/__pycache__/script.cpython-312.pyc +0 -0
  22. pyadps/utils/__pycache__/sensor_health.cpython-312.pyc +0 -0
  23. pyadps/utils/__pycache__/signal_quality.cpython-312.pyc +0 -0
  24. pyadps/utils/__pycache__/velocity_test.cpython-312.pyc +0 -0
  25. pyadps/utils/__pycache__/writenc.cpython-312.pyc +0 -0
  26. pyadps/utils/autoprocess.py +548 -0
  27. pyadps/utils/metadata/config.ini +99 -0
  28. pyadps/utils/metadata/demo.000 +0 -0
  29. pyadps/utils/plotgen.py +505 -3
  30. pyadps/utils/profile_test.py +526 -145
  31. pyadps/utils/pyreadrdi.py +27 -17
  32. pyadps/utils/readrdi.py +167 -20
  33. pyadps/utils/script.py +197 -147
  34. pyadps/utils/sensor_health.py +120 -0
  35. pyadps/utils/signal_quality.py +344 -24
  36. pyadps/utils/velocity_test.py +103 -20
  37. pyadps/utils/writenc.py +223 -27
  38. {pyadps-0.1.0b0.dist-info → pyadps-0.1.1.dist-info}/METADATA +56 -24
  39. pyadps-0.1.1.dist-info/RECORD +47 -0
  40. {pyadps-0.1.0b0.dist-info → pyadps-0.1.1.dist-info}/WHEEL +1 -1
  41. pyadps-0.1.1.dist-info/entry_points.txt +5 -0
  42. pyadps/pages/04_QC_Test.py +0 -283
  43. pyadps/pages/05_Profile_Test.py +0 -389
  44. pyadps/pages/06_Velocity_Test.py +0 -293
  45. pyadps/pages/07_Write_File.py +0 -367
  46. pyadps/utils/cutbin.py +0 -413
  47. pyadps/utils/regrid.py +0 -122
  48. pyadps-0.1.0b0.dist-info/RECORD +0 -29
  49. pyadps-0.1.0b0.dist-info/entry_points.txt +0 -3
  50. {pyadps-0.1.0b0.dist-info → pyadps-0.1.1.dist-info}/LICENSE +0 -0
@@ -1,293 +0,0 @@
1
- import numpy as np
2
- import pandas as pd
3
- import plotly.express as px
4
- import plotly.graph_objects as go
5
- import streamlit as st
6
- from plotly.subplots import make_subplots
7
- from plotly_resampler import FigureResampler
8
- from streamlit.runtime.state import session_state
9
- from utils.profile_test import side_lobe_beam_angle
10
- from utils.signal_quality import default_mask
11
- from utils.velocity_test import (despike, flatline, magnetic_declination,
12
- velocity_cutoff)
13
-
14
- if "flead" not in st.session_state:
15
- st.write(":red[Please Select Data!]")
16
- st.stop()
17
-
18
- flobj = st.session_state.flead
19
- vlobj = st.session_state.vlead
20
- fdata = flobj.fleader
21
- vdata = vlobj.vleader
22
-
23
-
24
- ####### Initialize Mask File ##############
25
- # Is this the best way?
26
- if st.session_state.isProfileMask or st.session_state.isQCMask:
27
- st.write(":grey[Working on a saved mask file ...]")
28
- if st.session_state.isVelocityMask:
29
- st.write(
30
- ":orange[Warning: Velocity test already completed. Reset to change settings.]"
31
- )
32
- reset_selectbox = st.selectbox(
33
- "Choose reset option",
34
- ("Profile Test", "QC Test", "Default"),
35
- index=None,
36
- placeholder="Reset mask to ...",
37
- )
38
- if reset_selectbox == "Default":
39
- st.write("Default mask file selected")
40
- st.session_state.maskd = st.session_state.orig_mask
41
- st.session_state.dummyvelocity = st.session_state.velocity
42
- elif reset_selectbox == "QC Test":
43
- st.write("QC Test mask file selected")
44
- st.session_state.maskd = st.session_state.qc_mask
45
- st.session_state.dummyvelocity = st.session_state.velocity
46
- elif reset_selectbox == "Profile Test":
47
- st.session_state.maskd = st.session_state.profile_mask
48
- if st.session_state.isGridSave:
49
- st.session_state.dummyvelocity = st.session_state.velocity_regrid
50
- else:
51
- st.session_state.dummyvelocity = st.session_state.velocity
52
- else:
53
- st.session_state.maskd = st.session_state.velocity_mask
54
- st.session_state.dummyvelocity = st.session_state.velocity
55
- else:
56
- if st.session_state.isProfileMask:
57
- st.session_state.maskd = st.session_state.profile_mask
58
- elif st.session_state.isQCMask:
59
- st.session_state.maskd = st.session_state.qc_mask
60
- else:
61
- st.session_state.maskd = st.session_state.orig_mask
62
- else:
63
- st.write(":grey[Creating a new mask file ...]")
64
-
65
-
66
- if "isCutoff" not in st.session_state:
67
- st.session_state.isMagnet = False
68
- st.session_state.isCutoff = False
69
- st.session_state.isDespike = False
70
- st.session_state.isFlatline = False
71
-
72
- if "maskd" not in st.session_state:
73
- if st.session_state.isProfileMask:
74
- st.session_state.maskd = np.copy(st.session_state.profile_mask)
75
- elif st.session_state.isQCMask:
76
- st.session_state.maskd = np.copy(st.session_state.qc_mask)
77
- else:
78
- st.session_state.maskd = np.copy(st.session_state.orig_mask)
79
-
80
- # If data are not regrided use the default one
81
- if st.session_state.isGridSave:
82
- st.session_state.dummyvelocity = np.copy(st.session_state.velocity_regrid)
83
- else:
84
- st.session_state.dummyvelocity = np.copy(st.session_state.velocity)
85
-
86
- velocity = st.session_state.dummyvelocity
87
-
88
- ensembles = st.session_state.head.ensembles
89
- cells = flobj.field()["Cells"]
90
- x = np.arange(0, ensembles, 1)
91
- y = np.arange(0, cells, 1)
92
-
93
-
94
- ########### Introduction ##########
95
- st.header("Velocity Test", divider="orange")
96
-
97
- st.write(
98
- """
99
- The processing in this page apply only to the velocity data.
100
- """
101
- )
102
-
103
- ############ Magnetic Declination ##############
104
- st.header("Magnetic Declination", divider="blue")
105
- st.write(
106
- """
107
- The magnetic declination is obtained from World Magnetic Model 2020 (WMM2020).
108
- The python wrapper module `wmm2020` is available from this [Link](https://github.com/space-physics/wmm2020).
109
- If the magnetic declination is reset, re-run the remaining tests again.
110
- """
111
- )
112
-
113
- if "isMagnetButton" not in st.session_state:
114
- st.session_state.isMagnetButton = False
115
-
116
-
117
- def toggle_btns():
118
- st.session_state.isMagnetButton = not st.session_state.isMagnetButton
119
-
120
-
121
- with st.form(key="magnet_form"):
122
- lat = st.number_input("Latitude", -90.0, 90.0, 0.0, step=1.0)
123
- lon = st.number_input("Longitude", 0.0, 360.0, 0.1, step=1.0, format="%.4f")
124
- depth = st.number_input("Depth", 0, 1000, 0, step=1)
125
- year = st.number_input("Year", 1950, 2100, 2024, 1)
126
-
127
- if st.form_submit_button(
128
- "Compute", on_click=toggle_btns, disabled=st.session_state.isMagnetButton
129
- ):
130
- st.session_state.dummyvelocity, mag = magnetic_declination(
131
- velocity, lat, lon, depth, year
132
- )
133
- st.session_state.lat = lat
134
- st.session_state.lon = lon
135
- st.session_state.magnetic_dec_depth = depth
136
- st.session_state.year = year
137
- st.session_state.angle = np.trunc(mag[0][0])
138
- st.session_state.isMagnet = True
139
-
140
- if st.session_state.isMagnet:
141
- st.write(f"Magnetic declination: {st.session_state.angle}\u00b0")
142
- st.write(":green[Magnetic declination correction applied to velocities]")
143
-
144
- if st.button(
145
- "Reset Magnetic Declination",
146
- on_click=toggle_btns,
147
- disabled=not st.session_state.isMagnetButton,
148
- ):
149
- st.session_state.dummyvelocity = np.copy(velocity)
150
- st.session_state.isMagnet = False
151
-
152
- ############# Velocity Cutoffs #################
153
- st.header("Velocity Cutoffs", divider="blue")
154
- st.write(
155
- """
156
- Drop velocities whose magnitude is larger than the threshold.
157
- """
158
- )
159
- with st.form(key="cutbin_form"):
160
- maxuvel = st.number_input("Maximum Zonal Velocity Cutoff (cm/s)", 0, 2000, 250, 1)
161
- maxvvel = st.number_input(
162
- "Maximum Meridional Velocity Cutoff (cm/s)", 0, 2000, 250, 1
163
- )
164
- maxwvel = st.number_input("Maximum Vertical Velocity Cutoff (cm/s)", 0, 2000, 15, 1)
165
- submit_cutoff = st.form_submit_button(label="Submit")
166
-
167
- if submit_cutoff:
168
-
169
- st.session_state.maxuvel = maxuvel
170
- st.session_state.maxvvel = maxvvel
171
- st.session_state.maxwvel = maxwvel
172
-
173
-
174
- st.session_state.maskd = velocity_cutoff(
175
- velocity[0, :, :], st.session_state.maskd, cutoff=maxuvel
176
- )
177
- st.session_state.maskd = velocity_cutoff(
178
- velocity[1, :, :], st.session_state.maskd, cutoff=maxvvel
179
- )
180
- st.session_state.maskd = velocity_cutoff(
181
- velocity[2, :, :], st.session_state.maskd, cutoff=maxwvel
182
- )
183
- st.session_state.isCutoff = True
184
-
185
-
186
- if st.session_state.isCutoff:
187
- st.write("Cutoff Applied")
188
- a = {
189
- "Max. Zonal Velocity": maxuvel,
190
- "Max. Meridional Velocity": maxvvel,
191
- "Max. Vertical Velocity": maxwvel,
192
- }
193
- st.write(a)
194
-
195
-
196
- ############## DESPIKE DATA #################
197
- st.header("Despike Data", divider="blue")
198
- despike_kernal = st.number_input(
199
- "Enter Despike Kernal Size for Median Filter", 0, 1000, 5, 1
200
- )
201
- despike_cutoff = st.number_input("Enter Despike Cutoff (mm/s)", 0, 1000, 150, 1)
202
- despike_button = st.button("Despike")
203
- if despike_button:
204
-
205
- st.session_state.despike_kernal = despike_kernal
206
- st.session_state.despike_cutoff = despike_cutoff
207
-
208
- st.session_state.maskd = despike(
209
- velocity[0, :, :],
210
- st.session_state.maskd,
211
- kernal_size=despike_kernal,
212
- cutoff=despike_cutoff,
213
- )
214
- st.session_state.maskd = despike(
215
- velocity[1, :, :],
216
- st.session_state.maskd,
217
- kernal_size=despike_kernal,
218
- cutoff=despike_cutoff,
219
- )
220
- st.session_state.isDespike = True
221
-
222
- if st.session_state.isDespike:
223
- st.write("Data Despiked")
224
- b = {
225
- "Kernal Size": despike_kernal,
226
- "Despike Cutoff": despike_cutoff,
227
- }
228
- st.write(b)
229
-
230
- st.header("Remove Flatline", divider="blue")
231
- flatline_kernal = st.number_input("Enter Flatline Kernal Size", 0, 100, 13, 1)
232
- flatline_cutoff = st.number_input("Enter Flatline deviation", 0, 100, 1, 1)
233
-
234
- flatline_button = st.button("Remove Flatline")
235
-
236
- if flatline_button:
237
- st.session_state.flatline_kernal = flatline_kernal
238
- st.session_state.flatline_cutoff = flatline_cutoff
239
-
240
- st.session_state.maskd = flatline(
241
- velocity[0, :, :],
242
- st.session_state.maskd,
243
- kernal_size=flatline_kernal,
244
- cutoff=flatline_cutoff,
245
- )
246
- st.session_state.maskd = flatline(
247
- velocity[1, :, :],
248
- st.session_state.maskd,
249
- kernal_size=flatline_kernal,
250
- cutoff=flatline_cutoff,
251
- )
252
- st.session_state.maskd = flatline(
253
- velocity[2, :, :],
254
- st.session_state.maskd,
255
- kernal_size=flatline_kernal,
256
- cutoff=flatline_cutoff,
257
- )
258
- st.session_state.isFlatline = True
259
-
260
- if st.session_state.isFlatline:
261
- st.write(":green[Flatline Removed]")
262
- b = {
263
- "Kernal Size": flatline_kernal,
264
- "Flatline Cutoff": flatline_cutoff,
265
- }
266
- st.write(b)
267
-
268
-
269
- ##################### SAVE DATA ###################
270
- st.header("Save & Reset Data", divider="blue")
271
-
272
-
273
- def reset_data():
274
- st.session_state.dummyvelocity = np.copy(st.session_state.velocity_regrid)
275
- st.session_state.isMagnet = False
276
- st.session_state.isCutoff = False
277
- st.session_state.isDespike = False
278
- st.session_state.isFlatline = False
279
-
280
-
281
- col1, col2 = st.columns([1, 1])
282
- with col1:
283
- save_button = st.button(label="Save Data")
284
- if save_button:
285
- st.session_state.veltest_velocity = np.copy(st.session_state.dummyvelocity)
286
- st.session_state.velocity_mask = np.copy(st.session_state.maskd)
287
- st.session_state.isVelocityMask = True
288
- st.write(":green[Mask data saved]")
289
- else:
290
- st.write(":red[Data not saved]")
291
-
292
- with col2:
293
- st.button(label="Reset Data", on_click=reset_data)
@@ -1,367 +0,0 @@
1
- import tempfile
2
-
3
- import numpy as np
4
- import pandas as pd
5
- import plotly.graph_objects as go
6
- import streamlit as st
7
- import utils.writenc as wr
8
- from plotly_resampler import FigureResampler
9
- import configparser
10
-
11
-
12
- if "flead" not in st.session_state:
13
- st.write(":red[Please Select Data!]")
14
- st.stop()
15
-
16
- if "fname" not in st.session_state:
17
- st.session_state.fname = "No file selected"
18
-
19
- if "rawfilename" not in st.session_state:
20
- st.session_state.rawfilename = "rawfile.nc"
21
-
22
- if "vleadfilename" not in st.session_state:
23
- st.session_state.vleadfilename = "vlead.nc"
24
-
25
-
26
- # Check if attributes exist in session state
27
- if "attributes" not in st.session_state:
28
- st.session_state.attributes = {}
29
-
30
- if st.session_state.isVelocityMask:
31
- st.session_state.final_mask = st.session_state.velocity_mask
32
- st.session_state.final_velocity = st.session_state.veltest_velocity
33
- if st.session_state.isGridSave:
34
- st.session_state.final_echo = st.session_state.echo_regrid
35
- st.session_state.final_correlation = st.session_state.correlation_regrid
36
- st.session_state.final_pgood = st.session_state.pgood_regrid
37
- else:
38
- st.session_state.final_echo = st.session_state.echo
39
- st.session_state.final_correlation = st.session_state.correlation
40
- st.session_state.final_pgood = st.session_state.pgood
41
- else:
42
- if st.session_state.isGridSave:
43
- st.session_state.final_mask = st.session_state.mask_regrid
44
- st.session_state.final_velocity = st.session_state.velocity_regrid
45
- st.session_state.final_echo = st.session_state.echo_regrid
46
- st.session_state.final_correlation = st.session_state.correlation_regrid
47
- st.session_state.final_pgood = st.session_state.pgood_regrid
48
- else:
49
- if st.session_state.isProfileMask:
50
- st.session_state.final_mask = st.session_state.profile_mask
51
- elif st.session_state.isQCMask:
52
- st.session_state.final_mask = st.session_state.qc_mask
53
- else:
54
- st.session_state.final_mask = st.session_state.orig_mask
55
- st.session_state.final_velocity = st.session_state.velocity
56
- st.session_state.final_echo = st.session_state.echo
57
- st.session_state.final_correlation = st.session_state.correlation
58
- st.session_state.final_pgood = st.session_state.pgood
59
-
60
-
61
- if "depth" not in st.session_state:
62
- st.session_state.isGrid = False
63
-
64
-
65
- @st.cache_data
66
- def file_write(filename="processed_file.nc"):
67
- tempdirname = tempfile.TemporaryDirectory(delete=False)
68
- outfilepath = tempdirname.name + "/" + filename
69
- return outfilepath
70
-
71
-
72
- # If the data is not regrided based on pressure sensor. Use the mean depth
73
- if not st.session_state.isGrid:
74
- st.write(":red[WARNING!]")
75
- st.write(
76
- "Data not regrided. Using the mean transducer depth to calculate the depth axis."
77
- )
78
- mean_depth = np.mean(st.session_state.vlead.vleader["Depth of Transducer"]) / 10
79
- mean_depth = np.trunc(mean_depth)
80
- st.write(f"Mean depth of the transducer is `{mean_depth}`")
81
- cells = st.session_state.flead.field()["Cells"]
82
- cell_size = st.session_state.flead.field()["Depth Cell Len"] / 100
83
- bin1dist = st.session_state.flead.field()["Bin 1 Dist"] / 100
84
- max_depth = mean_depth - bin1dist
85
- min_depth = max_depth - cells * cell_size
86
- z = np.arange(-1 * max_depth, -1 * min_depth, cell_size)
87
- st.session_state.final_depth = z
88
- else:
89
- st.session_state.final_depth = st.session_state.depth
90
-
91
-
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
- st.plotly_chart(fig)
117
-
118
-
119
- def call_plot(varname, beam, mask=False):
120
- if varname == "Velocity":
121
- fillplot_plotly(
122
- st.session_state.date,
123
- st.session_state.final_depth,
124
- st.session_state.final_velocity[beam - 1, :, :],
125
- st.session_state.final_mask,
126
- title=varname,
127
- mask=mask,
128
- )
129
- elif varname == "Echo":
130
- fillplot_plotly(
131
- st.session_state.date,
132
- st.session_state.final_depth,
133
- st.session_state.final_echo[beam - 1, :, :],
134
- st.session_state.final_mask,
135
- title=varname,
136
- mask=mask,
137
- )
138
- elif varname == "Correlation":
139
- fillplot_plotly(
140
- st.session_state.date,
141
- st.session_state.final_depth,
142
- st.session_state.final_correlation[beam - 1, :, :],
143
- st.session_state.final_mask,
144
- title=varname,
145
- mask=mask,
146
- )
147
- elif varname == "Percent Good":
148
- fillplot_plotly(
149
- st.session_state.date,
150
- st.session_state.final_depth,
151
- st.session_state.final_pgood[beam - 1, :, :],
152
- st.session_state.final_mask,
153
- title=varname,
154
- mask=mask,
155
- )
156
-
157
-
158
- st.header("View Processed Data", divider="blue")
159
- var_option = st.selectbox(
160
- "Select a data type", ("Velocity", "Echo", "Correlation", "Percent Good")
161
- )
162
- beam = st.radio("Select beam", (1, 2, 3, 4), horizontal=True)
163
-
164
- mask_radio = st.radio("Apply Mask", ("Yes", "No"), horizontal=True)
165
- plot_button = st.button("Plot Processed Data")
166
- if plot_button:
167
- if mask_radio == "Yes":
168
- call_plot(var_option, beam, mask=True)
169
- elif mask_radio == "No":
170
- call_plot(var_option, beam, mask=False)
171
-
172
-
173
- st.header("Write Data", divider="blue")
174
-
175
- mask_data_radio = st.radio("Do you want to mask the final data?", ("Yes", "No"))
176
-
177
- if mask_data_radio == "Yes":
178
- mask = st.session_state.final_mask
179
- st.session_state.write_velocity = np.copy(st.session_state.final_velocity)
180
- st.session_state.write_velocity[:, mask == 1] = -32768
181
- else:
182
- st.session_state.write_velocity = np.copy(st.session_state.final_velocity)
183
-
184
-
185
- file_type_radio = st.radio("Select output file format:", ("NetCDF", "CSV"))
186
-
187
- if file_type_radio == "NetCDF":
188
- add_attr_button = st.checkbox("Add attributes to NetCDF file")
189
-
190
- if add_attr_button:
191
- st.write("### Modify Attributes")
192
-
193
- # Create two-column layout for attributes
194
- col1, col2 = st.columns(2)
195
-
196
- with col1:
197
- # Display attributes in the first column
198
- for key in ["Cruise_No.", "Ship_Name", "Project_No.", "Water_Depth_m", "Deployment_Depth_m","Deployment_Date","Recovery_Date"]:
199
- if key in st.session_state.attributes:
200
- st.session_state.attributes[key] = st.text_input(key, value=st.session_state.attributes[key])
201
- else:
202
- st.session_state.attributes[key] = st.text_input(key)
203
-
204
- with col2:
205
- # Display attributes in the second column
206
- for key in ["Latitude", "Longitude","Platform_Type","Participants", "File_created_by", "Contact", "Comments"]:
207
- if key in st.session_state.attributes:
208
- st.session_state.attributes[key] = st.text_input(key, value=st.session_state.attributes[key])
209
- else:
210
- st.session_state.attributes[key] = st.text_input(key)
211
-
212
- download_button = st.button("Generate Processed files")
213
-
214
- if download_button:
215
- st.session_state.processed_filename = file_write()
216
- st.write(":grey[Processed file created. Click the download button.]")
217
- st.write(st.session_state.processed_filename)
218
- depth = np.trunc(st.session_state.final_depth)
219
-
220
- if file_type_radio == "NetCDF":
221
- if add_attr_button and st.session_state.attributes:
222
- # Generate file with attributes
223
- wr.finalnc(
224
- st.session_state.processed_filename,
225
- depth,
226
- st.session_state.date,
227
- st.session_state.write_velocity,
228
- attributes=st.session_state.attributes # Pass edited attributes
229
- )
230
- else:
231
- # Generate file without attributes
232
- wr.finalnc(
233
- st.session_state.processed_filename,
234
- depth,
235
- st.session_state.date,
236
- st.session_state.write_velocity
237
- )
238
-
239
- with open(st.session_state.processed_filename, "rb") as file:
240
- st.download_button(
241
- label="Download NetCDF File",
242
- data=file,
243
- file_name="processed_file.nc",
244
- )
245
-
246
- if file_type_radio == "CSV":
247
- udf = pd.DataFrame(
248
- st.session_state.write_velocity[0, :, :].T,
249
- index=st.session_state.date,
250
- columns=-1 * depth,
251
- )
252
- vdf = pd.DataFrame(
253
- st.session_state.write_velocity[1, :, :].T,
254
- index=st.session_state.date,
255
- columns=-1 * depth,
256
- )
257
- wdf = pd.DataFrame(
258
- st.session_state.write_velocity[2, :, :].T,
259
- index=st.session_state.date,
260
- columns=-1 * depth,
261
- )
262
- ucsv = udf.to_csv().encode("utf-8")
263
- vcsv = vdf.to_csv().encode("utf-8")
264
- wcsv = wdf.to_csv().encode("utf-8")
265
- st.download_button(
266
- label="Download Zonal Velocity File",
267
- data=ucsv,
268
- file_name="zonal_velocity.csv",
269
- mime="text/csf",
270
- )
271
- st.download_button(
272
- label="Download Meridional Velocity File",
273
- data=vcsv,
274
- file_name="meridional_velocity.csv",
275
- mime="text/csf",
276
- )
277
- st.download_button(
278
- label="Download Vertical Velocity File",
279
- data=vcsv,
280
- file_name="vertical_velocity.csv",
281
- mime="text/csf",
282
- )
283
-
284
-
285
- # Header for the Config.ini File Generator
286
- st.header("Config.ini File Generator", divider="blue")
287
-
288
- # Radio button to decide whether to generate the config.ini file
289
- generate_config_radio = st.radio("Do you want to generate a config.ini file?", ("No", "Yes"))
290
-
291
- if generate_config_radio == "Yes":
292
- # Create a config parser object
293
- config = configparser.ConfigParser()
294
-
295
- # Main section
296
- config["Main"] = {
297
- "Input_FileName": st.session_state.fname
298
- }
299
-
300
- if st.session_state.isQCMask:
301
- config["QC Test"] = {}
302
-
303
- # Add the contents of the current QC Mask thresholds
304
- if "newthresh" in st.session_state:
305
- for idx, row in st.session_state.newthresh.iterrows():
306
- config["QC Test"][row["Threshold"].replace(" ", "_")] = row["Values"]
307
-
308
-
309
- # Profile Test section
310
- if st.session_state.isProfileMask:
311
- config["Profile Test"] = {}
312
-
313
- if st.session_state.update_mask:
314
-
315
- config["Profile Test"]["Change_Range"] = str(st.session_state.ens_range)
316
- config["Profile Test"]["Deployment_ensembles"] = str(st.session_state.start_ens)
317
- config["Profile Test"]["Recovery_ensembles"] = str(st.session_state.end_ens)
318
-
319
- if st.session_state.update_mask_cutbin:
320
- config["Profile Test"]["Beam"] = str(st.session_state.beam + 1) # Adding 1 since beams are 1-based
321
- config["Profile Test"]["cell_to_delete"] = str(st.session_state.extra_cells)
322
-
323
- if st.session_state.isGrid:
324
- config["Profile Test"]["Regrid_Depth_cells"] = st.session_state.last_cell # Bin or Surface
325
-
326
-
327
- # Velocity Test Section
328
- if st.session_state.isVelocityMask:
329
- config["Velocity Test"] = {}
330
-
331
- if st.session_state.isMagnet:
332
- config["Velocity Test"]["Latitude"] = str(st.session_state.lat)
333
- config["Velocity Test"]["Longitude"] = str(st.session_state.lon)
334
- config["Velocity Test"]["Depth"] = str(st.session_state.magnetic_dec_depth)
335
- config["Velocity Test"]["Year"] = str(st.session_state.year)
336
-
337
- if st.session_state.isCutoff:
338
- config["Velocity Test"]["Max_Zoank"] = str(st.session_state.maxuvel)
339
- config["Velocity Test"]["Max_Meridional"] = str(st.session_state.maxvvel)
340
- config["Velocity Test"]["Max_Vertical"] = str(st.session_state.maxwvel)
341
-
342
- if st.session_state.isDespike:
343
- config["Velocity Test"]["Despike_Kernal_Size"] = str(st.session_state.despike_kernal)
344
- config["Velocity Test"]["Despike_Cutoff"] = str(st.session_state.despike_cutoff)
345
-
346
- if st.session_state.isFlatline:
347
- config["Velocity Test"]["Flatline_Kernal"] = str(st.session_state.flatline_kernal)
348
- config["Velocity Test"]["Flatline_Deviation"] = str(st.session_state.flatline_cutoff)
349
-
350
-
351
- # Optional section (attributes)
352
- config["Optional"] = {}
353
- for key, value in st.session_state.attributes.items():
354
- config["Optional"][key] = str(value) # Ensure all values are strings
355
-
356
- # Write config.ini to a temporary file
357
- config_filepath = "config.ini"
358
- with open(config_filepath, "w") as configfile:
359
- config.write(configfile)
360
-
361
- # Allow the user to download the generated config.ini file
362
- with open(config_filepath, "rb") as file:
363
- st.download_button(
364
- label="Download config.ini File",
365
- data=file,
366
- file_name="config.ini",
367
- )