pyadps 0.1.0b0__py3-none-any.whl → 0.1.2__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.
@@ -18,16 +18,33 @@ 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
+
47
+
31
48
 
32
49
  ################ Functions #######################
33
50
  @st.cache_data()
@@ -38,6 +55,7 @@ def file_access(uploaded_file):
38
55
  f.write(uploaded_file.getvalue())
39
56
  return path
40
57
 
58
+
41
59
  @st.cache_data
42
60
  def read_file(filepath):
43
61
  ds = rd.ReadFile(st.session_state.fpath)
@@ -46,82 +64,200 @@ def read_file(filepath):
46
64
  st.session_state.ds = ds
47
65
 
48
66
  @st.cache_data
49
- def file_write(path, add_attributes=True):
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
+
74
+ @st.cache_data
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(tempdirname.name, get_prefixed_filename("RAW_DAT.nc"))
78
+
79
+ if add_attributes:
80
+ wr.rawnc(
81
+ path,
82
+ st.session_state.rawfilename,
83
+ st.session_state.date1,
84
+ axis_option,
85
+ attributes=st.session_state.attributes,
86
+ )
87
+ else:
88
+ wr.rawnc(
89
+ path, st.session_state.rawfilename, st.session_state.date1, 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(tempvardirname.name, get_prefixed_filename("RAW_FIX.nc"))
96
+
53
97
  if add_attributes:
54
- wr.main(path, st.session_state.rawfilename, attributes=st.session_state.attributes)
98
+ wr.flead_nc(
99
+ path,
100
+ st.session_state.fleadfilename,
101
+ st.session_state.date2,
102
+ axis_option,
103
+ attributes=st.session_state.attributes,
104
+ )
55
105
  else:
56
- wr.main(path, st.session_state.rawfilename)
106
+ wr.flead_nc(
107
+ path, st.session_state.fleadfilename, st.session_state.date2, axis_option
108
+ )
57
109
 
58
110
  @st.cache_data
59
- def file_write_vlead(path, add_attributes=True):
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(tempvardirname.name, get_prefixed_filename("RAW_VAR.nc"))
114
+
63
115
  if add_attributes:
64
- wr.vlead_nc(path, st.session_state.vleadfilename, attributes=st.session_state.attributes)
116
+ wr.vlead_nc(
117
+ path,
118
+ st.session_state.vleadfilename,
119
+ st.session_state.date3,
120
+ axis_option,
121
+ attributes=st.session_state.attributes,
122
+ )
65
123
  else:
66
- wr.vlead_nc(path, st.session_state.vleadfilename)
124
+ wr.vlead_nc(
125
+ path, st.session_state.vleadfilename, st.session_state.date3, axis_option
126
+ )
127
+
128
+
129
+
130
+ if "axis_option" not in st.session_state:
131
+ st.session_state.axis_option = "ensemble" # Default value
67
132
 
68
133
  # UI for attribute selection
69
134
  st.header("NetCDF File", divider="blue")
70
135
 
71
136
  # Option to add attributes
72
- add_attributes = st.radio("Do you want to add attributes to the NetCDF file?", ["No", "Yes"], horizontal=True)
137
+ st.session_state.add_attributes_DRW = st.radio(
138
+ "Do you want to add attributes to the NetCDF file?", ["No", "Yes"], horizontal=True
139
+ )
73
140
 
74
- if add_attributes == "Yes":
141
+ if st.session_state.add_attributes_DRW == "Yes":
75
142
  st.write("### Please fill in the attributes:")
76
-
143
+
77
144
  # Two-column layout
78
145
  col1, col2 = st.columns(2)
79
-
80
- with col1:
81
- st.session_state.attributes['Cruise_No.'] = st.text_input("Cruise No.")
82
- st.session_state.attributes['Ship_Name'] = st.text_input("Ship Name")
83
- st.session_state.attributes['Project_No.'] = st.text_input("Project No.")
84
- st.session_state.attributes['Water_Depth_m'] = st.text_input("Water Depth (m)")
85
- st.session_state.attributes['Deployment_Depth_m'] = st.text_input("Deployment Depth (m)")
86
- st.session_state.attributes['Deployment_Date'] = st.date_input("Deployment Date")
87
- st.session_state.attributes['Recovery_Date'] = st.date_input("Recovery Date")
88
146
 
147
+ with col1:
148
+ st.session_state.attributes["Cruise_No."] = st.text_input("Cruise No.")
149
+ st.session_state.attributes["Ship_Name"] = st.text_input("Ship Name")
150
+ st.session_state.attributes["Project_No."] = st.text_input("Project No.")
151
+ st.session_state.attributes["Water_Depth_m"] = st.text_input("Water Depth (m)")
152
+ st.session_state.attributes["Deployment_Depth_m"] = st.text_input(
153
+ "Deployment Depth (m)"
154
+ )
155
+ st.session_state.attributes["Deployment_Date"] = st.date_input(
156
+ "Deployment Date"
157
+ )
158
+ st.session_state.attributes["Recovery_Date"] = st.date_input("Recovery Date")
89
159
 
90
160
  with col2:
91
- st.session_state.attributes['Latitude'] = st.text_input("Latitude")
92
- st.session_state.attributes['Longitude'] = st.text_input("Longitude")
93
- st.session_state.attributes['Platform_Type'] = st.text_input("Platform Type")
94
- st.session_state.attributes['Participants'] = st.text_area("Participants")
95
- st.session_state.attributes['File_created_by'] = st.text_input("File created by")
96
- st.session_state.attributes['Contact'] = st.text_input("Contact")
97
- st.session_state.attributes['Comments'] = st.text_area("Comments")
161
+ st.session_state.attributes["Latitude"] = st.text_input("Latitude")
162
+ st.session_state.attributes["Longitude"] = st.text_input("Longitude")
163
+ st.session_state.attributes["Platform_Type"] = st.text_input("Platform Type")
164
+ st.session_state.attributes["Participants"] = st.text_area("Participants")
165
+ st.session_state.attributes["File_created_by"] = st.text_input(
166
+ "File created by"
167
+ )
168
+ st.session_state.attributes["Contact"] = st.text_input("Contact")
169
+ st.session_state.attributes["Comments"] = st.text_area("Comments")
98
170
 
99
171
  st.write("Attributes will be added to the NetCDF file once you submit.")
100
-
172
+
173
+
174
+ st.info(f"Current file name: **{st.session_state.filename}**")
175
+
176
+ # Prefix editing option
177
+ st.session_state.use_custom_filename = st.radio(
178
+ "Do you want to edit Output Filename?",
179
+ ["No", "Yes"],
180
+ horizontal=True,
181
+ )
182
+
183
+ if st.session_state.use_custom_filename == "Yes" and not st.session_state.prefix_saved:
184
+ st.session_state.file_prefix = st.text_input(
185
+ "Enter file name (e.g., GD10A000)",
186
+ value=st.session_state.file_prefix,
187
+ )
188
+
189
+ if st.button("Save Filename"):
190
+ if st.session_state.file_prefix.strip():
191
+ st.session_state.prefix_saved = True
192
+ st.rerun()
193
+ else:
194
+ st.warning("Please enter a valid filename before saving.")
195
+
196
+ if st.session_state.prefix_saved:
197
+ st.success(f"Filename saved as: **{st.session_state.file_prefix}**")
198
+
199
+ # Dropdown for axis_option
200
+ st.session_state.axis_option_DRW = st.selectbox(
201
+ "Select x-axis option:",
202
+ options=["time", "ensemble"],
203
+ index=0, # Default to "time"
204
+ )
205
+
206
+ # Ensure it is passed correctly
207
+ # st.session_state.axis_option = axis_option
208
+
101
209
  # Buttons to generate files
102
- download_button = st.button("Generate Raw NetCDF File")
103
- download_var_button = st.button("Generate Raw Variable Leader NetCDF File")
210
+ st.session_state.rawnc_download_DRW = st.button("Generate Raw NetCDF File")
211
+ st.session_state.fleadnc_download_DRW = st.button(
212
+ "Generate Raw Fixed Leader NetCDF File"
213
+ )
214
+ st.session_state.vleadnc_download_DRW = st.button(
215
+ "Generate Raw Variable Leader NetCDF File"
216
+ )
104
217
 
105
- if download_button:
106
- file_write(st.session_state.fpath, add_attributes == "Yes")
218
+ if st.session_state.rawnc_download_DRW:
219
+ file_write(
220
+ st.session_state.fpath,
221
+ st.session_state.axis_option_DRW,
222
+ st.session_state.add_attributes_DRW == "Yes",
223
+ )
107
224
  st.write(st.session_state.rawfilename)
108
225
  with open(st.session_state.rawfilename, "rb") as file:
109
226
  st.download_button(
110
227
  label="Download Raw File",
111
228
  data=file,
112
- file_name="rawfile.nc",
229
+ file_name=get_prefixed_filename("RAW_DAT.nc"),
113
230
  )
114
231
 
115
- if download_var_button:
116
- file_write_vlead(st.session_state.fpath, add_attributes == "Yes")
232
+ if st.session_state.fleadnc_download_DRW:
233
+ file_write_flead(
234
+ st.session_state.fpath,
235
+ st.session_state.axis_option,
236
+ st.session_state.add_attributes_DRW == "Yes",
237
+ )
238
+ st.write(st.session_state.fleadfilename)
239
+ with open(st.session_state.fleadfilename, "rb") as file:
240
+ st.download_button(
241
+ label="Download Fixed Leader",
242
+ data=file,
243
+ file_name=get_prefixed_filename("RAW_FIX.nc"),
244
+ )
245
+
246
+ if st.session_state.vleadnc_download_DRW:
247
+ file_write_vlead(
248
+ st.session_state.fpath,
249
+ st.session_state.axis_option,
250
+ st.session_state.add_attributes_DRW == "Yes",
251
+ )
117
252
  st.write(st.session_state.vleadfilename)
118
253
  with open(st.session_state.vleadfilename, "rb") as file:
119
254
  st.download_button(
120
255
  label="Download Variable Leader",
121
256
  data=file,
122
- file_name="vlead.nc",
257
+ file_name=get_prefixed_filename("RAW_VAR.nc"),
123
258
  )
124
259
 
260
+
125
261
  def download_csv_with_ensemble(data, filename):
126
262
  # Create ensemble numbers from 1 to the number of rows in the data
127
263
  ensembles = np.arange(1, len(next(iter(data.values()))) + 1)
@@ -131,60 +267,62 @@ def download_csv_with_ensemble(data, filename):
131
267
  df.insert(0, "RDI_Ensemble", ensembles) # Add ensemble numbers as the first column
132
268
 
133
269
  # Export the DataFrame as a CSV
134
- csv = df.to_csv(index=False).encode('utf-8')
270
+ csv = df.to_csv(index=False).encode("utf-8")
135
271
  return st.download_button(
136
272
  label=f"Download {filename} as CSV",
137
273
  data=csv,
138
274
  file_name=f"{filename}.csv",
139
- mime='text/csv',
275
+ mime="text/csv",
140
276
  )
141
-
277
+
278
+
142
279
  def download_csv(data, filename):
143
280
  # Convert data to DataFrame if it's not already one
144
281
  if isinstance(data, dict):
145
282
  df = pd.DataFrame.from_dict(data, orient="index").T
146
283
  else:
147
284
  df = pd.DataFrame(data)
148
-
285
+
149
286
  # Export the DataFrame as a CSV
150
- csv = df.to_csv(index=False).encode('utf-8')
287
+ csv = df.to_csv(index=False).encode("utf-8")
151
288
  return st.download_button(
152
289
  label=f"Download {filename} as CSV",
153
290
  data=csv,
154
291
  file_name=f"{filename}.csv",
155
- mime='text/csv',
292
+ mime="text/csv",
156
293
  )
157
-
158
-
294
+
295
+
159
296
  def download_csv1(data, filename):
160
297
  # Convert data to DataFrame if it's not already one
161
298
  if isinstance(data, dict):
162
299
  df = pd.DataFrame.from_dict(data, orient="index").T
163
300
  else:
164
301
  df = pd.DataFrame(data)
165
-
302
+
166
303
  # Create ensemble and depth arrays
167
304
  ensembles = np.arange(1, df.shape[0] + 1)
168
305
  depths = np.arange(1, df.shape[1] + 1)
169
-
306
+
170
307
  # Add ensemble numbers as the first column
171
- df.insert(0, 'Ensemble', ensembles)
172
-
308
+ df.insert(0, "Ensemble", ensembles)
309
+
173
310
  # Transpose the DataFrame to switch rows and columns
174
311
  df = df.T
175
-
312
+
176
313
  # Add depth values as the first row
177
- df.insert(0, 'Depth', [''] + list(depths))
178
-
314
+ df.insert(0, "Depth", [""] + list(depths))
315
+
179
316
  # Export the DataFrame as a CSV
180
- csv = df.to_csv(index=False, header=False).encode('utf-8')
317
+ csv = df.to_csv(index=False, header=False).encode("utf-8")
181
318
  return st.download_button(
182
319
  label=f"Download {filename} as CSV",
183
320
  data=csv,
184
321
  file_name=f"{filename}.csv",
185
- mime='text/csv',
322
+ mime="text/csv",
186
323
  )
187
324
 
325
+
188
326
  # Load data
189
327
  fdata = st.session_state.flead.fleader
190
328
  vdata = st.session_state.vlead.vleader
@@ -202,25 +340,36 @@ X, Y = np.meshgrid(x, y)
202
340
  st.header("Download Raw Data CSV File", divider="blue")
203
341
 
204
342
  # Selection for the data category
205
- data_type = st.selectbox(
343
+ st.session_state.rawcsv_option_DRW = st.selectbox(
206
344
  "Select data type to download:",
207
- ["Fixed Leader", "Variable Leader", "Velocity", "Echo Intensity", "Correlation", "Percent Good"]
345
+ [
346
+ "Velocity",
347
+ "Echo Intensity",
348
+ "Correlation",
349
+ "Percent Good",
350
+ "Variable Leader",
351
+ "Fixed Leader",
352
+ ],
208
353
  )
209
354
 
210
355
  # Show corresponding variable options based on selection
211
- if data_type == "Fixed Leader":
356
+ if st.session_state.rawcsv_option_DRW == "Fixed Leader":
212
357
  # Combine all variables of Fixed Leader into one DataFrame
213
358
  f_combined_data = {var: fdata[var] for var in fdata.keys()}
214
359
  download_csv_with_ensemble(f_combined_data, "Fixed_Leader_All_Variables")
215
360
 
216
- elif data_type == "Variable Leader":
361
+ elif st.session_state.rawcsv_option_DRW == "Variable Leader":
217
362
  # Combine all variables of Variable Leader into one DataFrame
218
363
  v_combined_data = {var: vdata[var] for var in vdata.keys()}
219
364
  download_csv(v_combined_data, "Variable_Leader_All_Variables")
220
365
 
221
366
  else:
222
- beam_download = st.radio("Select beam to download", (1, 2, 3, 4), horizontal=True)
367
+ st.session_state.rawcsv_beam_DRW = st.radio(
368
+ "Select beam to download", (1, 2, 3, 4), horizontal=True
369
+ )
223
370
 
371
+ data_type = st.session_state.rawcsv_option_DRW
372
+ beam_download = st.session_state.rawcsv_beam_DRW
224
373
  if data_type == "Velocity":
225
374
  download_data = velocity[beam_download - 1, :, :]
226
375
  elif data_type == "Echo Intensity":
@@ -231,4 +380,3 @@ else:
231
380
  download_data = pgood[beam_download - 1, :, :]
232
381
 
233
382
  download_csv1(download_data, f"{data_type}_Beam_{beam_download}")
234
-