pyadps 0.2.0b0__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 -211
  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.0b0.dist-info → pyadps-0.3.0.dist-info}/METADATA +63 -33
  29. pyadps-0.3.0.dist-info/RECORD +35 -0
  30. {pyadps-0.2.0b0.dist-info → pyadps-0.3.0.dist-info}/WHEEL +1 -1
  31. {pyadps-0.2.0b0.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.0b0.dist-info/RECORD +0 -31
  39. {pyadps-0.2.0b0.dist-info → pyadps-0.3.0.dist-info}/LICENSE +0 -0
@@ -61,11 +61,12 @@ def fillplot_plotly(data, colorscale="balance", title="Data", xaxis="time"):
61
61
 
62
62
  @st.cache_data
63
63
  def lineplot(data, title, xaxis="time"):
64
+ data1 = np.where(data == -32768, np.nan, data)
64
65
  if xaxis == "time":
65
- df = pd.DataFrame({"date": st.session_state.date, title: data})
66
+ df = pd.DataFrame({"date": st.session_state.date, title: data1})
66
67
  fig = px.line(df, x="date", y=title)
67
68
  else:
68
- df = pd.DataFrame({"ensemble": x, title: data})
69
+ df = pd.DataFrame({"ensemble": x, title: data1})
69
70
  fig = px.line(df, x="ensemble", y=title)
70
71
 
71
72
  st.plotly_chart(fig)
@@ -84,45 +85,100 @@ The ordinate (y-axis) for the heatmap is `bins` as the depth correction is not a
84
85
  xbutton = st.radio("Select an x-axis to plot", ["time", "ensemble"], horizontal=True)
85
86
 
86
87
 
87
- # Fixed Leader Plots
88
- st.header("Fixed Leader", divider="blue")
89
- fbutton = st.radio("Select a dynamic variable to plot:", fdata.keys(), horizontal=True)
90
- lineplot(fdata[fbutton], fbutton, xaxis=str(xbutton))
91
-
92
- # Variable Leader Plots
93
- st.header("Variable Leader", divider="blue")
94
- vbutton = st.radio("Select a dynamic variable to plot:", vdata.keys(), horizontal=True)
95
- lineplot(vdata[vbutton], vbutton, xaxis=str(xbutton))
96
-
97
- basic_options = [
98
- "Pressure",
99
- "Temperature",
100
- "Salinity",
101
- "Depth of Transducer",
102
- "Heading",
103
- "Pitch",
104
- "Roll",
105
- ]
106
-
107
-
108
- st.header("Velocity, Echo Intensity, Correlation & Percent Good", divider="blue")
109
-
110
-
111
- def call_plot(varname, beam, xaxis="time"):
112
- if varname == "Velocity":
113
- fillplot_plotly(velocity[beam - 1, :, :], title=varname, xaxis=xaxis)
114
- elif varname == "Echo":
115
- fillplot_plotly(echo[beam - 1, :, :], title=varname, xaxis=xaxis)
116
- elif varname == "Correlation":
117
- fillplot_plotly(correlation[beam - 1, :, :], title=varname, xaxis=xaxis)
118
- elif varname == "Percent Good":
119
- fillplot_plotly(pgood[beam - 1, :, :], title=varname, xaxis=xaxis)
120
-
121
-
122
- var_option = st.selectbox(
123
- "Select a data type", ("Velocity", "Echo", "Correlation", "Percent Good")
88
+ tab1, tab2, tab3, tab4 = st.tabs(
89
+ ["Primary Data", "Variable Leader", "Fixed Leader", "Advanced"]
124
90
  )
125
- beam = st.radio("Select beam", (1, 2, 3, 4), horizontal=True)
126
- call_plot(var_option, beam, xaxis=str(xbutton))
127
91
 
92
+ with tab3:
93
+ # Fixed Leader Plots
94
+ st.header("Fixed Leader", divider="blue")
95
+ fbutton = st.radio(
96
+ "Select a dynamic variable to plot:", fdata.keys(), horizontal=True
97
+ )
98
+ lineplot(fdata[fbutton], fbutton, xaxis=str(xbutton))
99
+
100
+ with tab2:
101
+ # Variable Leader Plots
102
+ st.header("Variable Leader", divider="blue")
103
+ vbutton = st.radio(
104
+ "Select a dynamic variable to plot:", vdata.keys(), horizontal=True
105
+ )
106
+ lineplot(vdata[vbutton], vbutton, xaxis=str(xbutton))
107
+
108
+ with tab1:
109
+ st.header("Velocity, Echo Intensity, Correlation & Percent Good", divider="blue")
110
+
111
+ def call_plot(varname, beam, xaxis="time"):
112
+ if varname == "Velocity":
113
+ fillplot_plotly(velocity[beam - 1, :, :], title=varname, xaxis=xaxis)
114
+ elif varname == "Echo":
115
+ fillplot_plotly(echo[beam - 1, :, :], title=varname, xaxis=xaxis)
116
+ elif varname == "Correlation":
117
+ fillplot_plotly(correlation[beam - 1, :, :], title=varname, xaxis=xaxis)
118
+ elif varname == "Percent Good":
119
+ fillplot_plotly(pgood[beam - 1, :, :], title=varname, xaxis=xaxis)
120
+
121
+ var_option = st.selectbox(
122
+ "Select a data type", ("Velocity", "Echo", "Correlation", "Percent Good")
123
+ )
124
+ beam = st.radio("Select beam", (1, 2, 3, 4), horizontal=True)
125
+ call_plot(var_option, beam, xaxis=str(xbutton))
126
+
127
+
128
+ with tab4:
129
+ st.header("Advanced Data", divider="blue")
130
+ adv_option = st.selectbox(
131
+ "Select a data type",
132
+ (
133
+ "Bit Result",
134
+ "ADC Channel",
135
+ "Error Status Word 1",
136
+ "Error Status Word 2",
137
+ "Error Status Word 3",
138
+ "Error Status Word 4",
139
+ ),
140
+ )
141
+ if adv_option == "Bit Result":
142
+ bitdata = st.session_state.ds.variableleader.bitresult()
143
+ st.subheader("BIT Result", divider="orange")
144
+ st.write("""
145
+ This field contains the results of Workhorse ADCPs builtin test functions.
146
+ A zero indicates a successful BIT result.
147
+ """)
148
+ bitbutton = st.radio(
149
+ "Select a dynamic variable to plot:", bitdata.keys(), horizontal=True
150
+ )
151
+ lineplot(bitdata[bitbutton], bitbutton, xaxis=str(xbutton))
128
152
 
153
+ elif adv_option == "ADC Channel":
154
+ adcdata = st.session_state.vlead.adc_channel()
155
+ st.subheader("ADC Channel", divider="orange")
156
+ adcbutton = st.radio(
157
+ "Select a dynamic variable to plot:", adcdata.keys(), horizontal=True
158
+ )
159
+ lineplot(adcdata[adcbutton], adcbutton, xaxis=str(xbutton))
160
+ elif adv_option == "Error Status Word 1":
161
+ errordata1 = st.session_state.vlead.error_status_word(esw=1)
162
+ st.subheader("Error Status Word", divider="orange")
163
+ errorbutton = st.radio(
164
+ "Select a dynamic variable to plot:", errordata1.keys(), horizontal=True
165
+ )
166
+ lineplot(errordata1[errorbutton], errorbutton, xaxis=str(xbutton))
167
+ elif adv_option == "Error Status Word 2":
168
+ errordata2 = st.session_state.vlead.error_status_word(esw=2)
169
+ errorbutton = st.radio(
170
+ "Select a dynamic variable to plot:", errordata2.keys(), horizontal=True
171
+ )
172
+ lineplot(errordata2[errorbutton], errorbutton, xaxis=str(xbutton))
173
+ elif adv_option == "Error Status Word 3":
174
+ errordata3 = st.session_state.vlead.error_status_word(esw=3)
175
+ errorbutton = st.radio(
176
+ "Select a dynamic variable to plot:", errordata3.keys(), horizontal=True
177
+ )
178
+ lineplot(errordata3[errorbutton], errorbutton, xaxis=str(xbutton))
179
+ elif adv_option == "Error Status Word 4":
180
+ errordata4 = st.session_state.vlead.error_status_word(esw=4)
181
+ errorbutton = st.radio(
182
+ "Select a dynamic variable to plot:", errordata4.keys(), horizontal=True
183
+ )
184
+ lineplot(errordata4[errorbutton], errorbutton, xaxis=str(xbutton))
@@ -18,16 +18,32 @@ if "fname" not in st.session_state:
18
18
  st.session_state.fname = "No file selected"
19
19
 
20
20
  if "rawfilename" not in st.session_state:
21
- st.session_state.rawfilename = "rawfile.nc"
21
+ st.session_state.rawfilename = "RAW_DAT.nc"
22
+
23
+ if "fleadfilename" not in st.session_state:
24
+ st.session_state.fleadfilename = "RAW_FIX.nc"
22
25
 
23
26
  if "vleadfilename" not in st.session_state:
24
- st.session_state.vleadfilename = "vlead.nc"
27
+ st.session_state.vleadfilename = "RAW_VAR.nc"
25
28
 
26
29
  if "attributes" not in st.session_state:
27
30
  st.session_state.attributes = {}
28
-
29
- if "add_attributes" not in st.session_state:
30
- st.session_state.add_attributes = "No" # Default value
31
+
32
+ if "add_attributes_DRW" not in st.session_state:
33
+ st.session_state.add_attributes_DRW = "No" # Default value
34
+
35
+ if "file_prefix" not in st.session_state:
36
+ raw_basename = os.path.basename(st.session_state.fname)
37
+ st.session_state.filename = os.path.splitext(raw_basename)[0]
38
+ st.session_state.file_prefix = st.session_state.filename
39
+
40
+
41
+ if "prefix_saved" not in st.session_state:
42
+ st.session_state.prefix_saved = False
43
+
44
+ if "filename" not in st.session_state:
45
+ st.session_state.filename = "" # <-- Default file name if not passed
46
+
31
47
 
32
48
  ################ Functions #######################
33
49
  @st.cache_data()
@@ -38,6 +54,7 @@ def file_access(uploaded_file):
38
54
  f.write(uploaded_file.getvalue())
39
55
  return path
40
56
 
57
+
41
58
  @st.cache_data
42
59
  def read_file(filepath):
43
60
  ds = rd.ReadFile(st.session_state.fpath)
@@ -45,25 +62,68 @@ def read_file(filepath):
45
62
  ds.fixensemble()
46
63
  st.session_state.ds = ds
47
64
 
65
+
66
+ @st.cache_data
67
+ def get_prefixed_filename(base_name):
68
+ """Generates the file name with the optional prefix."""
69
+ if st.session_state.file_prefix:
70
+ return f"{st.session_state.file_prefix}_{base_name}"
71
+ return base_name
72
+
73
+
48
74
  @st.cache_data
49
75
  def file_write(path, axis_option, add_attributes=True):
50
76
  tempdirname = tempfile.TemporaryDirectory(delete=False)
51
- st.session_state.rawfilename = tempdirname.name + "/rawfile.nc"
52
-
77
+ st.session_state.rawfilename = os.path.join(
78
+ tempdirname.name, get_prefixed_filename("RAW_DAT.nc")
79
+ )
80
+
81
+ if add_attributes:
82
+ wr.rawnc(
83
+ path,
84
+ st.session_state.rawfilename,
85
+ axis_option=axis_option,
86
+ attributes=st.session_state.attributes,
87
+ )
88
+ else:
89
+ wr.rawnc(path, st.session_state.rawfilename, axis_option)
90
+
91
+
92
+ @st.cache_data
93
+ def file_write_flead(path, axis_option, add_attributes=True):
94
+ tempvardirname = tempfile.TemporaryDirectory(delete=False)
95
+ st.session_state.fleadfilename = os.path.join(
96
+ tempvardirname.name, get_prefixed_filename("RAW_FIX.nc")
97
+ )
98
+
53
99
  if add_attributes:
54
- wr.rawnc(path, st.session_state.rawfilename, st.session_state.date, axis_option, attributes=st.session_state.attributes)
100
+ wr.flead_nc(
101
+ path,
102
+ st.session_state.fleadfilename,
103
+ axis_option=axis_option,
104
+ attributes=st.session_state.attributes,
105
+ )
55
106
  else:
56
- wr.rawnc(path, st.session_state.rawfilename, st.session_state.date,axis_option)
107
+ wr.flead_nc(path, st.session_state.fleadfilename, axis_option)
108
+
57
109
 
58
110
  @st.cache_data
59
111
  def file_write_vlead(path, axis_option, add_attributes=True):
60
112
  tempvardirname = tempfile.TemporaryDirectory(delete=False)
61
- st.session_state.vleadfilename = tempvardirname.name + "/vlead.nc"
62
-
113
+ st.session_state.vleadfilename = os.path.join(
114
+ tempvardirname.name, get_prefixed_filename("RAW_VAR.nc")
115
+ )
116
+
63
117
  if add_attributes:
64
- wr.vlead_nc(path, st.session_state.vleadfilename, st.session_state.date, axis_option, attributes=st.session_state.attributes)
118
+ wr.vlead_nc(
119
+ path,
120
+ st.session_state.vleadfilename,
121
+ axis_option=axis_option,
122
+ attributes=st.session_state.attributes,
123
+ )
65
124
  else:
66
- wr.vlead_nc(path, st.session_state.vleadfilename, st.session_state.date, axis_option)
125
+ wr.vlead_nc(path, st.session_state.vleadfilename, axis_option)
126
+
67
127
 
68
128
  if "axis_option" not in st.session_state:
69
129
  st.session_state.axis_option = "ensemble" # Default value
@@ -72,69 +132,130 @@ if "axis_option" not in st.session_state:
72
132
  st.header("NetCDF File", divider="blue")
73
133
 
74
134
  # Option to add attributes
75
- add_attributes = st.radio("Do you want to add attributes to the NetCDF file?", ["No", "Yes"], horizontal=True)
135
+ st.session_state.add_attributes_DRW = st.radio(
136
+ "Do you want to add attributes to the NetCDF file?", ["No", "Yes"], horizontal=True
137
+ )
76
138
 
77
- if add_attributes == "Yes":
139
+ if st.session_state.add_attributes_DRW == "Yes":
78
140
  st.write("### Please fill in the attributes:")
79
-
141
+
80
142
  # Two-column layout
81
143
  col1, col2 = st.columns(2)
82
-
83
- with col1:
84
- st.session_state.attributes['Cruise_No.'] = st.text_input("Cruise No.")
85
- st.session_state.attributes['Ship_Name'] = st.text_input("Ship Name")
86
- st.session_state.attributes['Project_No.'] = st.text_input("Project No.")
87
- st.session_state.attributes['Water_Depth_m'] = st.text_input("Water Depth (m)")
88
- st.session_state.attributes['Deployment_Depth_m'] = st.text_input("Deployment Depth (m)")
89
- st.session_state.attributes['Deployment_Date'] = st.date_input("Deployment Date")
90
- st.session_state.attributes['Recovery_Date'] = st.date_input("Recovery Date")
91
144
 
145
+ with col1:
146
+ st.session_state.attributes["Cruise_No."] = st.text_input("Cruise No.")
147
+ st.session_state.attributes["Ship_Name"] = st.text_input("Ship Name")
148
+ st.session_state.attributes["Project_No."] = st.text_input("Project No.")
149
+ st.session_state.attributes["Water_Depth_m"] = st.text_input("Water Depth (m)")
150
+ st.session_state.attributes["Deployment_Depth_m"] = st.text_input(
151
+ "Deployment Depth (m)"
152
+ )
153
+ st.session_state.attributes["Deployment_Date"] = st.date_input(
154
+ "Deployment Date"
155
+ )
156
+ st.session_state.attributes["Recovery_Date"] = st.date_input("Recovery Date")
92
157
 
93
158
  with col2:
94
- st.session_state.attributes['Latitude'] = st.text_input("Latitude")
95
- st.session_state.attributes['Longitude'] = st.text_input("Longitude")
96
- st.session_state.attributes['Platform_Type'] = st.text_input("Platform Type")
97
- st.session_state.attributes['Participants'] = st.text_area("Participants")
98
- st.session_state.attributes['File_created_by'] = st.text_input("File created by")
99
- st.session_state.attributes['Contact'] = st.text_input("Contact")
100
- st.session_state.attributes['Comments'] = st.text_area("Comments")
159
+ st.session_state.attributes["Latitude"] = st.text_input("Latitude")
160
+ st.session_state.attributes["Longitude"] = st.text_input("Longitude")
161
+ st.session_state.attributes["Platform_Type"] = st.text_input("Platform Type")
162
+ st.session_state.attributes["Participants"] = st.text_area("Participants")
163
+ st.session_state.attributes["File_created_by"] = st.text_input(
164
+ "File created by"
165
+ )
166
+ st.session_state.attributes["Contact"] = st.text_input("Contact")
167
+ st.session_state.attributes["Comments"] = st.text_area("Comments")
101
168
 
102
169
  st.write("Attributes will be added to the NetCDF file once you submit.")
103
170
 
171
+
172
+ st.info(f"Current file name: **{st.session_state.filename}**")
173
+
174
+ # Prefix editing option
175
+ st.session_state.use_custom_filename = st.radio(
176
+ "Do you want to edit Output Filename?",
177
+ ["No", "Yes"],
178
+ horizontal=True,
179
+ )
180
+
181
+ if st.session_state.use_custom_filename == "Yes" and not st.session_state.prefix_saved:
182
+ st.session_state.file_prefix = st.text_input(
183
+ "Enter file name (e.g., GD10A000)",
184
+ value=st.session_state.file_prefix,
185
+ )
186
+
187
+ if st.button("Save Filename"):
188
+ if st.session_state.file_prefix.strip():
189
+ st.session_state.prefix_saved = True
190
+ st.rerun()
191
+ else:
192
+ st.warning("Please enter a valid filename before saving.")
193
+
194
+ if st.session_state.prefix_saved:
195
+ st.success(f"Filename saved as: **{st.session_state.file_prefix}**")
196
+
104
197
  # Dropdown for axis_option
105
- axis_option = st.selectbox(
198
+ st.session_state.axis_option_DRW = st.selectbox(
106
199
  "Select x-axis option:",
107
- options=["ensemble", "time"],
108
- index=0 # Default to "ensemble"
200
+ options=["time", "ensemble"],
201
+ index=0, # Default to "time"
109
202
  )
110
203
 
111
204
  # Ensure it is passed correctly
112
- st.session_state.axis_option = axis_option
205
+ # st.session_state.axis_option = axis_option
113
206
 
114
207
  # Buttons to generate files
115
- download_button = st.button("Generate Raw NetCDF File")
116
- download_var_button = st.button("Generate Raw Variable Leader NetCDF File")
208
+ st.session_state.rawnc_download_DRW = st.button("Generate Raw NetCDF File")
209
+ st.session_state.fleadnc_download_DRW = st.button(
210
+ "Generate Raw Fixed Leader NetCDF File"
211
+ )
212
+ st.session_state.vleadnc_download_DRW = st.button(
213
+ "Generate Raw Variable Leader NetCDF File"
214
+ )
117
215
 
118
- if download_button:
119
- file_write(st.session_state.fpath, st.session_state.axis_option , add_attributes == "Yes")
216
+ if st.session_state.rawnc_download_DRW:
217
+ file_write(
218
+ st.session_state.fpath,
219
+ st.session_state.axis_option_DRW,
220
+ st.session_state.add_attributes_DRW == "Yes",
221
+ )
120
222
  st.write(st.session_state.rawfilename)
121
223
  with open(st.session_state.rawfilename, "rb") as file:
122
224
  st.download_button(
123
225
  label="Download Raw File",
124
226
  data=file,
125
- file_name="rawfile.nc",
227
+ file_name=get_prefixed_filename("RAW_DAT.nc"),
126
228
  )
127
229
 
128
- if download_var_button:
129
- file_write_vlead(st.session_state.fpath, st.session_state.axis_option, add_attributes == "Yes")
230
+ if st.session_state.fleadnc_download_DRW:
231
+ file_write_flead(
232
+ st.session_state.fpath,
233
+ st.session_state.axis_option,
234
+ st.session_state.add_attributes_DRW == "Yes",
235
+ )
236
+ st.write(st.session_state.fleadfilename)
237
+ with open(st.session_state.fleadfilename, "rb") as file:
238
+ st.download_button(
239
+ label="Download Fixed Leader",
240
+ data=file,
241
+ file_name=get_prefixed_filename("RAW_FIX.nc"),
242
+ )
243
+
244
+ if st.session_state.vleadnc_download_DRW:
245
+ file_write_vlead(
246
+ st.session_state.fpath,
247
+ st.session_state.axis_option,
248
+ st.session_state.add_attributes_DRW == "Yes",
249
+ )
130
250
  st.write(st.session_state.vleadfilename)
131
251
  with open(st.session_state.vleadfilename, "rb") as file:
132
252
  st.download_button(
133
253
  label="Download Variable Leader",
134
254
  data=file,
135
- file_name="vlead.nc",
255
+ file_name=get_prefixed_filename("RAW_VAR.nc"),
136
256
  )
137
257
 
258
+
138
259
  def download_csv_with_ensemble(data, filename):
139
260
  # Create ensemble numbers from 1 to the number of rows in the data
140
261
  ensembles = np.arange(1, len(next(iter(data.values()))) + 1)
@@ -144,60 +265,62 @@ def download_csv_with_ensemble(data, filename):
144
265
  df.insert(0, "RDI_Ensemble", ensembles) # Add ensemble numbers as the first column
145
266
 
146
267
  # Export the DataFrame as a CSV
147
- csv = df.to_csv(index=False).encode('utf-8')
268
+ csv = df.to_csv(index=False).encode("utf-8")
148
269
  return st.download_button(
149
270
  label=f"Download {filename} as CSV",
150
271
  data=csv,
151
272
  file_name=f"{filename}.csv",
152
- mime='text/csv',
273
+ mime="text/csv",
153
274
  )
154
-
275
+
276
+
155
277
  def download_csv(data, filename):
156
278
  # Convert data to DataFrame if it's not already one
157
279
  if isinstance(data, dict):
158
280
  df = pd.DataFrame.from_dict(data, orient="index").T
159
281
  else:
160
282
  df = pd.DataFrame(data)
161
-
283
+
162
284
  # Export the DataFrame as a CSV
163
- csv = df.to_csv(index=False).encode('utf-8')
285
+ csv = df.to_csv(index=False).encode("utf-8")
164
286
  return st.download_button(
165
287
  label=f"Download {filename} as CSV",
166
288
  data=csv,
167
289
  file_name=f"{filename}.csv",
168
- mime='text/csv',
290
+ mime="text/csv",
169
291
  )
170
-
171
-
292
+
293
+
172
294
  def download_csv1(data, filename):
173
295
  # Convert data to DataFrame if it's not already one
174
296
  if isinstance(data, dict):
175
297
  df = pd.DataFrame.from_dict(data, orient="index").T
176
298
  else:
177
299
  df = pd.DataFrame(data)
178
-
300
+
179
301
  # Create ensemble and depth arrays
180
302
  ensembles = np.arange(1, df.shape[0] + 1)
181
303
  depths = np.arange(1, df.shape[1] + 1)
182
-
304
+
183
305
  # Add ensemble numbers as the first column
184
- df.insert(0, 'Ensemble', ensembles)
185
-
306
+ df.insert(0, "Ensemble", ensembles)
307
+
186
308
  # Transpose the DataFrame to switch rows and columns
187
309
  df = df.T
188
-
310
+
189
311
  # Add depth values as the first row
190
- df.insert(0, 'Depth', [''] + list(depths))
191
-
312
+ df.insert(0, "Depth", [""] + list(depths))
313
+
192
314
  # Export the DataFrame as a CSV
193
- csv = df.to_csv(index=False, header=False).encode('utf-8')
315
+ csv = df.to_csv(index=False, header=False).encode("utf-8")
194
316
  return st.download_button(
195
317
  label=f"Download {filename} as CSV",
196
318
  data=csv,
197
319
  file_name=f"{filename}.csv",
198
- mime='text/csv',
320
+ mime="text/csv",
199
321
  )
200
322
 
323
+
201
324
  # Load data
202
325
  fdata = st.session_state.flead.fleader
203
326
  vdata = st.session_state.vlead.vleader
@@ -215,25 +338,36 @@ X, Y = np.meshgrid(x, y)
215
338
  st.header("Download Raw Data CSV File", divider="blue")
216
339
 
217
340
  # Selection for the data category
218
- data_type = st.selectbox(
341
+ st.session_state.rawcsv_option_DRW = st.selectbox(
219
342
  "Select data type to download:",
220
- ["Fixed Leader", "Variable Leader", "Velocity", "Echo Intensity", "Correlation", "Percent Good"]
343
+ [
344
+ "Velocity",
345
+ "Echo Intensity",
346
+ "Correlation",
347
+ "Percent Good",
348
+ "Variable Leader",
349
+ "Fixed Leader",
350
+ ],
221
351
  )
222
352
 
223
353
  # Show corresponding variable options based on selection
224
- if data_type == "Fixed Leader":
354
+ if st.session_state.rawcsv_option_DRW == "Fixed Leader":
225
355
  # Combine all variables of Fixed Leader into one DataFrame
226
356
  f_combined_data = {var: fdata[var] for var in fdata.keys()}
227
357
  download_csv_with_ensemble(f_combined_data, "Fixed_Leader_All_Variables")
228
358
 
229
- elif data_type == "Variable Leader":
359
+ elif st.session_state.rawcsv_option_DRW == "Variable Leader":
230
360
  # Combine all variables of Variable Leader into one DataFrame
231
361
  v_combined_data = {var: vdata[var] for var in vdata.keys()}
232
362
  download_csv(v_combined_data, "Variable_Leader_All_Variables")
233
363
 
234
364
  else:
235
- beam_download = st.radio("Select beam to download", (1, 2, 3, 4), horizontal=True)
365
+ st.session_state.rawcsv_beam_DRW = st.radio(
366
+ "Select beam to download", (1, 2, 3, 4), horizontal=True
367
+ )
236
368
 
369
+ data_type = st.session_state.rawcsv_option_DRW
370
+ beam_download = st.session_state.rawcsv_beam_DRW
237
371
  if data_type == "Velocity":
238
372
  download_data = velocity[beam_download - 1, :, :]
239
373
  elif data_type == "Echo Intensity":
@@ -244,4 +378,3 @@ else:
244
378
  download_data = pgood[beam_download - 1, :, :]
245
379
 
246
380
  download_csv1(download_data, f"{data_type}_Beam_{beam_download}")
247
-